Difference between revisions of "Extension:WikiaInfo.php"
(sort-key) |
(1.0.8 - don't openlevels=1 anymore - too many wikia) |
||
Line 1: | Line 1: | ||
<?php | <?php | ||
− | + | /** | |
− | + | * Extension:WikiaInfo | |
− | + | * {{Category:Extensions}}{{php}}{{Category:Extensions created with Template:SpecialPage}} | |
− | + | * | |
+ | * @package MediaWiki | ||
+ | * @subpackage Extensions | ||
+ | * @author Aran Dunkley [http://www.organicdesign.co.nz/nad User:Nad] | ||
+ | * @copyright © 2007 Aran Dunkley | ||
+ | * @licence GNU General Public Licence 2.0 or later | ||
+ | */ | ||
− | 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.8, 2009-03-23' ); |
$egWikiaInfoDataDir = '/var/lib/mysql'; | $egWikiaInfoDataDir = '/var/lib/mysql'; | ||
Line 14: | Line 20: | ||
$wgExtensionCredits['specialpage'][] = array( | $wgExtensionCredits['specialpage'][] = array( | ||
− | 'name' => 'Special:WikiaInfo', | + | 'name' => 'Special:WikiaInfo', |
'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', | 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', | ||
'description' => 'List the currently running wikia and the domains pointing to them', | 'description' => 'List the currently running wikia and the domains pointing to them', | ||
− | 'url' | + | 'url' => 'http://www.organicdesign.co.nz/Extension:WikiaInfo.php', |
'version' => WIKIAINFO_VERSION | 'version' => WIKIAINFO_VERSION | ||
− | + | ); | |
− | require_once "$IP/includes/SpecialPage.php"; | + | require_once( "$IP/includes/SpecialPage.php" ); |
/** | /** | ||
Line 28: | Line 34: | ||
class SpecialWikiaInfo extends SpecialPage { | class SpecialWikiaInfo extends SpecialPage { | ||
− | |||
− | |||
− | |||
function SpecialWikiaInfo() { | function SpecialWikiaInfo() { | ||
− | SpecialPage::SpecialPage('WikiaInfo', 'sysop', true, false, false, false); | + | SpecialPage::SpecialPage( 'WikiaInfo', 'sysop', true, false, false, false ); |
} | } | ||
Line 38: | Line 41: | ||
* Return passed size as Bytes, KB, MB, GB | * Return passed size as Bytes, KB, MB, GB | ||
*/ | */ | ||
− | function friendlySize($size) { | + | function friendlySize( $size ) { |
$suffix = 'Bytes'; | $suffix = 'Bytes'; | ||
− | if ($size >> 30) { $size >>= 30; $suffix = 'GB'; } | + | if ( $size >> 30 ) { $size >>= 30; $suffix = 'GB'; } |
− | elseif ($size >> 20) { $size >>= 20; $suffix = 'MB'; } | + | elseif ( $size >> 20 ) { $size >>= 20; $suffix = 'MB'; } |
− | elseif ($size >> 10) { $size >>= 10; $suffix = 'KB'; } | + | elseif ( $size >> 10 ) { $size >>= 10; $suffix = 'KB'; } |
return "$size $suffix"; | return "$size $suffix"; | ||
} | } | ||
Line 52: | Line 55: | ||
global $wgOut, $domains, $settings, $egWikiaInfoDataDir; | global $wgOut, $domains, $settings, $egWikiaInfoDataDir; | ||
$this->setHeaders(); | $this->setHeaders(); | ||
− | $wgOut->addWikiText("\n\n"); | + | $wgOut->addWikiText( "\n\n" ); |
# Render tree of databases | # Render tree of databases | ||
− | if ($egWikiaInfoDataDir) { | + | if ( $egWikiaInfoDataDir ) { |
$dbcount = 0; | $dbcount = 0; | ||
$alltotal = 0; | $alltotal = 0; | ||
Line 61: | Line 64: | ||
$tree = "*'''Databases'''\n"; | $tree = "*'''Databases'''\n"; | ||
$databases = array(); | $databases = array(); | ||
− | foreach (glob("$egWikiaInfoDataDir/*") as $db) if (is_dir($db)) { | + | foreach ( glob( "$egWikiaInfoDataDir/*" ) as $db ) if ( is_dir( $db ) ) { |
$dbcount++; | $dbcount++; | ||
$tables = array(); | $tables = array(); | ||
$total = 0; | $total = 0; | ||
− | foreach (glob("$db/*.???") as $file) { | + | foreach ( glob( "$db/*.???" ) as $file ) { |
− | $stat = stat($file); | + | $stat = stat( $file ); |
$size = $stat[7]; | $size = $stat[7]; | ||
$total += $size; | $total += $size; | ||
− | $table = preg_replace("|^(.*/)?(.+?)\\....$|", "$2", $file); | + | $table = preg_replace( "|^(.*/)?(.+?)\\....$|", "$2", $file ); |
− | $tables[$table] = isset($tables[$table]) ? $tables[$table]+$size : $size; | + | $tables[$table] = isset( $tables[$table] ) ? $tables[$table]+$size : $size; |
} | } | ||
$alltotal += $total; | $alltotal += $total; | ||
− | $ntable = count($tables); | + | $ntable = count( $tables ); |
$alltable += $ntable; | $alltable += $ntable; | ||
− | $total = $this->friendlySize($total); | + | $total = $this->friendlySize( $total ); |
− | $tree .= "**".basename($db)." ($ntable tables, $total | + | $tree .= "**" . basename( $db ) . " ($ntable tables, $total)\n"; |
− | |||
} | } | ||
− | $alltotal = $this->friendlySize($alltotal); | + | $alltotal = $this->friendlySize( $alltotal ); |
− | $tree = "{"."{#tree:root=<big><b>$dbcount Databases ($alltable tables, $alltotal)</b></big> | + | $tree = "{"."{#tree:root=<big><b>$dbcount Databases ($alltable tables, $alltotal)</b></big>|id=databasetree|\n$tree"; |
$tree .= "}"."}\n"; | $tree .= "}"."}\n"; | ||
− | $wgOut->addWikiText($tree); | + | $wgOut->addWikiText( $tree ); |
} | } | ||
$codebases = array(); | $codebases = array(); | ||
− | foreach (glob('/var/www/mediawiki-*') as $codebase) { | + | foreach ( glob( '/var/www/mediawiki-*' ) as $codebase ) { |
$stat = stat($codebase); | $stat = stat($codebase); | ||
$codebases[$stat[1]] = basename($codebase); | $codebases[$stat[1]] = basename($codebase); | ||
Line 94: | Line 96: | ||
# Get list of domain symlinks by inode | # Get list of domain symlinks by inode | ||
$dlist = array(); | $dlist = array(); | ||
− | foreach (glob("$domains/*") as $link) { | + | foreach ( glob( "$domains/*" ) as $link ) { |
$stat = stat($link); | $stat = stat($link); | ||
$inode = $stat[1]; | $inode = $stat[1]; | ||
− | if (is_array($dlist[$inode])) $dlist[$inode][] = basename($link); | + | if ( is_array( $dlist[$inode] ) ) $dlist[$inode][] = basename( $link ); |
− | else $dlist[$inode] = array(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) { | + | foreach ( glob( "$settings/*" ) as $file ) { |
− | $stat = stat($file); | + | $stat = stat( $file ); |
$wikia[basename($file)] = $dlist[$stat[1]]; | $wikia[basename($file)] = $dlist[$stat[1]]; | ||
} | } | ||
− | 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) | ||
− | $tree = "{"."{#tree:root=<big><b>Currently Installed Wikia</b></big> | + | $tree = "{"."{#tree:root=<big><b>Currently Installed Wikia</b></big>|id=wikiatree|\n"; |
− | foreach ($wikia as $file => $dlist) if (is_array($dlist)) { | + | foreach ( $wikia as $file => $dlist ) if ( is_array( $dlist ) ) { |
− | $stat = stat("$settings/$file/wiki"); | + | $stat = stat( "$settings/$file/wiki" ); |
$ver = $codebases[$stat[1]]; | $ver = $codebases[$stat[1]]; | ||
$tree .= "*'''$file''' ($ver)\n"; | $tree .= "*'''$file''' ($ver)\n"; | ||
$tree .= "**[[Config:$file/LocalSettings.php|LocalSettings.php]]\n"; | $tree .= "**[[Config:$file/LocalSettings.php|LocalSettings.php]]\n"; | ||
− | sort($dlist); | + | sort( $dlist ); |
− | foreach ($dlist as $domain) { | + | foreach ( $dlist as $domain ) { |
$wiki = "http://$domain/wiki/index.php?title"; | $wiki = "http://$domain/wiki/index.php?title"; | ||
$tree .= "**[http://$domain $domain]\n"; | $tree .= "**[http://$domain $domain]\n"; | ||
Line 126: | Line 128: | ||
} | } | ||
$tree .= "}"."}\n"; | $tree .= "}"."}\n"; | ||
− | $wgOut->addWikiText($tree); | + | $wgOut->addWikiText( $tree ); |
} | } | ||
Line 136: | Line 138: | ||
*/ | */ | ||
function wfSetupWikiaInfo() { | function wfSetupWikiaInfo() { | ||
− | global $wgLanguageCode,$wgMessageCache; | + | global $wgLanguageCode, $wgMessageCache; |
− | $wgMessageCache->addMessages(array('wikiainfo' => 'Current Wikia Information')); | + | $wgMessageCache->addMessages( array( 'wikiainfo' => 'Current Wikia Information' ) ); |
− | SpecialPage::addPage(new SpecialWikiaInfo()); | + | SpecialPage::addPage( new SpecialWikiaInfo() ); |
} | } |
Revision as of 10:25, 23 March 2009
<?php /**
* Extension:WikiaInfo *
Template:PhpCategory:Extensions created with Template:SpecialPage
* * @package MediaWiki * @subpackage Extensions * @author Aran Dunkley User:Nad * @copyright © 2007 Aran Dunkley * @licence GNU General Public Licence 2.0 or later */
if ( !defined('MEDIAWIKI' ) ) die( 'Not an entry point.' );
define( 'WIKIAINFO_VERSION', '1.0.8, 2009-03-23' );
$egWikiaInfoDataDir = '/var/lib/mysql';
$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 {
function SpecialWikiaInfo() { SpecialPage::SpecialPage( 'WikiaInfo', 'sysop', true, false, false, false ); }
/** * Return passed size as Bytes, KB, MB, GB */ function friendlySize( $size ) { $suffix = 'Bytes'; if ( $size >> 30 ) { $size >>= 30; $suffix = 'GB'; } elseif ( $size >> 20 ) { $size >>= 20; $suffix = 'MB'; } elseif ( $size >> 10 ) { $size >>= 10; $suffix = 'KB'; } return "$size $suffix"; }
/** * Override SpecialPage::execute() */ function execute() { global $wgOut, $domains, $settings, $egWikiaInfoDataDir; $this->setHeaders(); $wgOut->addWikiText( "\n\n" );
# Render tree of databases if ( $egWikiaInfoDataDir ) { $dbcount = 0; $alltotal = 0; $alltable = 0; $tree = "*Databases\n"; $databases = array(); foreach ( glob( "$egWikiaInfoDataDir/*" ) as $db ) if ( is_dir( $db ) ) { $dbcount++; $tables = array(); $total = 0; foreach ( glob( "$db/*.???" ) as $file ) { $stat = stat( $file ); $size = $stat[7]; $total += $size; $table = preg_replace( "|^(.*/)?(.+?)\\....$|", "$2", $file ); $tables[$table] = isset( $tables[$table] ) ? $tables[$table]+$size : $size; } $alltotal += $total; $ntable = count( $tables ); $alltable += $ntable; $total = $this->friendlySize( $total ); $tree .= "**" . basename( $db ) . " ($ntable tables, $total)\n"; } $alltotal = $this->friendlySize( $alltotal ); $tree = "{"."{#tree:root=$dbcount Databases ($alltable tables, $alltotal)|id=databasetree|\n$tree"; $tree .= "}"."}\n"; $wgOut->addWikiText( $tree ); }
$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) $tree = "{"."{#tree:root=Currently Installed Wikia|id=wikiatree|\n"; foreach ( $wikia as $file => $dlist ) if ( is_array( $dlist ) ) { $stat = stat( "$settings/$file/wiki" ); $ver = $codebases[$stat[1]]; $tree .= "*$file ($ver)\n"; $tree .= "**LocalSettings.php\n"; sort( $dlist ); foreach ( $dlist as $domain ) { $wiki = "http://$domain/wiki/index.php?title"; $tree .= "**$domain\n"; $tree .= "***[$wiki=Special:Recentchanges Recent changes]\n"; $tree .= "***[$wiki=Special:Version Version]\n"; $tree .= "***[$wiki=Special:Statistics Statistics]\n"; } } $tree .= "}"."}\n"; $wgOut->addWikiText( $tree );
}
}
/*
* Called from $wgExtensionFunctions array when initialising extensions */
function wfSetupWikiaInfo() { global $wgLanguageCode, $wgMessageCache; $wgMessageCache->addMessages( array( 'wikiainfo' => 'Current Wikia Information' ) ); SpecialPage::addPage( new SpecialWikiaInfo() ); }