Difference between revisions of "Extension:WikiaInfo.php"
(1.0.4 - link to LocalSettings in Config NS) |
(change directory searches to globs) |
||
| Line 1: | Line 1: | ||
<?php | <?php | ||
| − | # Extension:WikiaInfo{{Category:Extensions | + | # Extension:WikiaInfo{{Category:Extensions}}{{php}}{{Category:Extensions created with Template:SpecialPage}}{{Category:OD2}} |
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | # - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html) | ||
# - Author: [http://www.organicdesign.co.nz/nad User:Nad] | # - Author: [http://www.organicdesign.co.nz/nad User:Nad] | ||
# - Started: 2007-08-27 | # - Started: 2007-08-27 | ||
| − | + | ||
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
| − | + | ||
| − | define('WIKIAINFO_VERSION','1.0. | + | define('WIKIAINFO_VERSION','1.0.5, 2007-10-02'); |
| − | + | ||
$wgExtensionFunctions[] = 'wfSetupWikiaInfo'; | $wgExtensionFunctions[] = 'wfSetupWikiaInfo'; | ||
| − | + | ||
$wgExtensionCredits['specialpage'][] = array( | $wgExtensionCredits['specialpage'][] = array( | ||
'name' => 'Special:WikiaInfo', | 'name' => 'Special:WikiaInfo', | ||
| Line 18: | Line 18: | ||
'version' => WIKIAINFO_VERSION | 'version' => WIKIAINFO_VERSION | ||
); | ); | ||
| − | + | ||
require_once "$IP/includes/SpecialPage.php"; | require_once "$IP/includes/SpecialPage.php"; | ||
| − | + | ||
# Define a new class based on the SpecialPage class | # Define a new class based on the SpecialPage class | ||
class SpecialWikiaInfo extends SpecialPage { | class SpecialWikiaInfo extends SpecialPage { | ||
| − | + | ||
# Constructor | # Constructor | ||
function SpecialWikiaInfo() { | function SpecialWikiaInfo() { | ||
SpecialPage::SpecialPage('WikiaInfo','sysop',true,false,false,false); | SpecialPage::SpecialPage('WikiaInfo','sysop',true,false,false,false); | ||
} | } | ||
| − | + | ||
# Override SpecialPage::execute() | # Override SpecialPage::execute() | ||
function execute() { | function execute() { | ||
| − | global $wgOut; | + | global $wgOut,$domains,$settings; |
$this->setHeaders(); | $this->setHeaders(); | ||
$wgOut->addWikiText("=== Currently Installed Wikia ===\n"); | $wgOut->addWikiText("=== Currently Installed Wikia ===\n"); | ||
| − | |||
$codebases = array(); | $codebases = array(); | ||
| − | + | foreach (glob('/var/www/mediawiki-*') as $codebase) { | |
| − | + | $stat = stat($codebase); | |
| − | + | $codebases[$stat[1]] = basename($codebase); | |
| − | |||
| − | |||
| − | |||
} | } | ||
| − | |||
# Get list of domain symlinks by inode | # Get list of domain symlinks by inode | ||
| − | $ | + | $dlist = array(); |
| − | $ | + | foreach (glob("$domains/*") as $link) { |
| − | + | $stat = stat($link); | |
| − | + | $inode = $stat[1]; | |
| − | + | if (is_array($dlist[$inode])) $dlist[$inode][] = basename($link); | |
| − | + | else $dlist[$inode] = array(basename($link)); | |
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | |||
# Loop through settings files associating with domains | # Loop through settings files associating with domains | ||
$wikia = array(); | $wikia = array(); | ||
| − | $ | + | foreach (glob("$settings/*") as $file) { |
| − | + | $stat = stat($file); | |
| − | + | $wikia[basename($file)] = $dlist[$stat[1]]; | |
| − | $stat | ||
| − | $ | ||
| − | |||
} | } | ||
| − | |||
ksort($wikia); | ksort($wikia); | ||
# Render the list (don't show naked domains if a www also exists) | # Render the list (don't show naked domains if a www also exists) | ||
| − | $table = "{{#tree:openlevels=1\n"; | + | $table = "{"."{#tree:openlevels=1\n"; |
| − | foreach ($wikia as $file => $ | + | foreach ($wikia as $file => $dlist) if (is_array($dlist)) { |
| − | + | $stat = stat("$settings/$file/wiki"); | |
| − | + | $ver = $codebases[$stat[1]]; | |
| − | + | $table .= "*'''$file''' ($ver)\n"; | |
| − | + | $table .= "**[[Config:$file/LocalSettings.php|LocalSettings.php]]\n"; | |
| − | + | sort($dlist); | |
| − | + | foreach ($dlist as $domain) { | |
| − | + | $wiki = "http://$domain/wiki/index.php?title"; | |
| − | + | $table .= "**[http://$domain $domain]\n"; | |
| − | + | $table .= "***[$wiki=Special:Recentchanges Recent changes]\n"; | |
| − | + | $table .= "***[$wiki=Special:Version Version]\n"; | |
| − | + | $table .= "***[$wiki=Special:Statistics Statistics]\n"; | |
| − | |||
| − | |||
} | } | ||
} | } | ||
| − | $table .= "}}\n"; | + | $table .= "}"."}\n"; |
$wgOut->addWikiText($table); | $wgOut->addWikiText($table); | ||
Revision as of 04:02, 2 October 2007
<?php
- Extension:WikiaInfo
Template:PhpCategory:Extensions created with Template:SpecialPage
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:Nad
- - Started: 2007-08-27
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('WIKIAINFO_VERSION','1.0.5, 2007-10-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";
- 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,$domains,$settings; $this->setHeaders(); $wgOut->addWikiText("=== Currently Installed Wikia ===\n");
$codebases = array(); foreach (glob('/var/www/mediawiki-*') as $codebase) { $stat = stat($codebase); $codebases[$stat[1]] = basename($codebase); }
# Get list of domain symlinks by inode $dlist = array(); foreach (glob("$domains/*") as $link) { $stat = stat($link); $inode = $stat[1]; if (is_array($dlist[$inode])) $dlist[$inode][] = basename($link); else $dlist[$inode] = array(basename($link)); }
# Loop through settings files associating with domains $wikia = array(); foreach (glob("$settings/*") as $file) { $stat = stat($file); $wikia[basename($file)] = $dlist[$stat[1]]; } ksort($wikia);
# Render the list (don't show naked domains if a www also exists) $table = "{"."{#tree:openlevels=1\n"; foreach ($wikia as $file => $dlist) if (is_array($dlist)) { $stat = stat("$settings/$file/wiki"); $ver = $codebases[$stat[1]]; $table .= "*$file ($ver)\n"; $table .= "**LocalSettings.php\n"; sort($dlist); foreach ($dlist as $domain) { $wiki = "http://$domain/wiki/index.php?title"; $table .= "**$domain\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);
}
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiaInfo() { global $wgLanguageCode,$wgMessageCache; $wgMessageCache->addMessages(array('wikiainfo' => 'Current Wikia Information')); SpecialPage::addPage(new SpecialWikiaInfo()); } ?>



