Difference between revisions of "Extension:WikiaInfo.php"
(1.0.2 - don't show naked domains if a www also exists) |
(1.0.3 - add mediawiki version to items in list) |
||
| 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] | ||
| Line 7: | Line 7: | ||
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.3, 2007-09-26'); |
$wgExtensionFunctions[] = 'wfSetupWikiaInfo'; | $wgExtensionFunctions[] = 'wfSetupWikiaInfo'; | ||
| Line 34: | Line 34: | ||
$this->setHeaders(); | $this->setHeaders(); | ||
$wgOut->addWikiText("=== Currently Installed Wikia ===\n"); | $wgOut->addWikiText("=== Currently Installed Wikia ===\n"); | ||
| + | |||
| + | # Get the inode numbers of the mediawiki code-bases | ||
| + | $codebases = array(); | ||
| + | $handle = opendir('/var/www'); | ||
| + | while (false !== ($codebase = readdir($handle))) { | ||
| + | if (ereg('^mediawiki-(.+)$',$codebase,$ver)) { | ||
| + | $stat = stat("/var/www/$codebase"); | ||
| + | $codebases[$stat[1]] = $ver[1]; | ||
| + | } | ||
| + | } | ||
| + | closedir($handle); | ||
# Get list of domain symlinks by inode | # Get list of domain symlinks by inode | ||
| Line 64: | Line 75: | ||
$table = "{{#tree:openlevels=1\n"; | $table = "{{#tree:openlevels=1\n"; | ||
foreach ($wikia as $file => $domains) { | foreach ($wikia as $file => $domains) { | ||
| − | if ( | + | if (is_array($domains)) { |
| − | $table .= "*'''$file'''\n"; | + | $stat = stat("$dir/$file/wiki"); |
| + | $ver = $codebases[$stat[1]]; | ||
| + | $table .= "*'''$file''' ($ver)\n"; | ||
| + | $table .= "**[[$file/LocalSettings.php|LocalSettings.php]]\n"; | ||
sort($domains); | sort($domains); | ||
foreach ($domains as $domain) if (!in_array("www.$domain",$domains)) { | foreach ($domains as $domain) if (!in_array("www.$domain",$domains)) { | ||
$wiki = "http://$domain/wiki/index.php?title"; | $wiki = "http://$domain/wiki/index.php?title"; | ||
$table .= "**[http://$domain $domain]\n"; | $table .= "**[http://$domain $domain]\n"; | ||
| − | |||
$table .= "***[$wiki=Special:Recentchanges Recent changes]\n"; | $table .= "***[$wiki=Special:Recentchanges Recent changes]\n"; | ||
$table .= "***[$wiki=Special:Version Version]\n"; | $table .= "***[$wiki=Special:Version Version]\n"; | ||
Revision as of 00:12, 26 September 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.3, 2007-09-26');
$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; $this->setHeaders(); $wgOut->addWikiText("=== Currently Installed Wikia ===\n");
# Get the inode numbers of the mediawiki code-bases $codebases = array(); $handle = opendir('/var/www'); while (false !== ($codebase = readdir($handle))) { if (ereg('^mediawiki-(.+)$',$codebase,$ver)) { $stat = stat("/var/www/$codebase"); $codebases[$stat[1]] = $ver[1]; } } closedir($handle);
# 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 (don't show naked domains if a www also exists)
$table = "
openlevels=1\n";
foreach ($wikia as $file => $domains) { if (is_array($domains)) { $stat = stat("$dir/$file/wiki"); $ver = $codebases[$stat[1]]; $table .= "*$file ($ver)\n"; $table .= "**LocalSettings.php\n"; sort($domains); foreach ($domains as $domain) if (!in_array("www.$domain",$domains)) { $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()); } ?>



