Difference between revisions of "Extension:WikiaInfo.php"

From Organic Design wiki
(1.0.1 - change layout to tree)
m (add heading)
Line 32: Line 32:
 
function execute() {
 
function execute() {
 
global $wgOut;
 
global $wgOut;
 
 
$this->setHeaders();
 
$this->setHeaders();
 +
$wgOut->addWikiText("=== Currently Installed Wikia ===\n");
  
 
# Get list of domain symlinks by inode
 
# Get list of domain symlinks by inode
Line 62: Line 62:
  
 
# Render the list
 
# Render the list
$table = "__NOTOC__\n{{#tree:openlevels=1\n";
+
$table = "{{#tree:openlevels=1\n";
 
foreach ($wikia as $file => $domains) {
 
foreach ($wikia as $file => $domains) {
 
if (count($domains)) {
 
if (count($domains)) {

Revision as of 22:18, 1 September 2007

<?php

  1. Extension:WikiaInfo
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:PhpCategory:Extensions created with Template:SpecialPage

Category:Extensions:WikiaInfo
  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:Nad
  3. - Started: 2007-08-27

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('WIKIAINFO_VERSION','1.0.1, 2007-09-02');

$wgExtensionFunctions[] = 'wfSetupWikiaInfo';

$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:WikiaInfo', 'author' => 'User:Nad', 'description' => 'List the currently running wikia and the domains pointing to them', 'url' => 'http://www.organicdesign.co.nz/Extension:WikiaInfo.php', 'version' => WIKIAINFO_VERSION );

require_once "$IP/includes/SpecialPage.php";

  1. Define a new class based on the SpecialPage class

class SpecialWikiaInfo extends SpecialPage {

# Constructor function SpecialWikiaInfo() { SpecialPage::SpecialPage('WikiaInfo','sysop',true,false,false,false); }

# Override SpecialPage::execute() function execute() { global $wgOut; $this->setHeaders(); $wgOut->addWikiText("=== Currently Installed Wikia ===\n");

# Get list of domain symlinks by inode $domains = array(); $dir = $GLOBALS['domains']; $handle = opendir($dir); while (false !== ($link = readdir($handle))) { if (!ereg('^\\.',$link)) { $stat = stat("$dir/$link"); $inode = $stat[1]; if (is_array($domains[$inode])) $domains[$inode][] = $link; else $domains[$inode] = array($link); } } closedir($handle);

# Loop through settings files associating with domains $wikia = array(); $dir = $GLOBALS['settings']; $handle = opendir($dir); while (false !== ($file = readdir($handle))) { $stat = stat("$dir/$file"); $inode = $stat[1]; if (!ereg('^\\.',$file)) $wikia[$file] = $domains[$inode]; } closedir($handle); ksort($wikia);

# Render the list

$table = "

openlevels=1\n";

foreach ($wikia as $file => $domains) { if (count($domains)) { $table .= "*$file\n"; sort($domains); foreach ($domains as $domain) { $wiki = "http://$domain/wiki/index.php?title"; $table .= "**$domain\n"; $table .= "***settings\n"; $table .= "***[$wiki=Special:Recentchanges Recent changes]\n"; $table .= "***[$wiki=Special:Version Version]\n"; $table .= "***[$wiki=Special:Statistics Statistics]\n"; } } } $table .= "

\n";

$wgOut->addWikiText($table);

}

}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupWikiaInfo() { global $wgLanguageCode,$wgMessageCache; $wgMessageCache->addMessages(array('wikiainfo' => 'Current Wikia Information')); SpecialPage::addPage(new SpecialWikiaInfo()); } ?>