Difference between revisions of "Extension:WikiaInfo.php"

From Organic Design wiki
(1.0.4 - link to LocalSettings in Config NS)
(change directory searches to globs)
Line 1: Line 1:
 
<?php
 
<?php
# Extension:WikiaInfo{{Category:Extensions|WikiaInfo}}{{php}}{{Category:Extensions created with Template:SpecialPage|WikiaInfo}}{{Category:OD2}}
+
# 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.4, 2007-09-30');
+
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");
  
# Get the inode numbers of the mediawiki code-bases
 
 
$codebases = array();
 
$codebases = array();
$handle  = opendir('/var/www');
+
foreach (glob('/var/www/mediawiki-*') as $codebase) {
while (false !== ($codebase = readdir($handle))) {
+
$stat = stat($codebase);
if (ereg('^mediawiki-(.+)$',$codebase,$ver)) {
+
$codebases[$stat[1]] = basename($codebase);
$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
$domains = array();
+
$dlist = array();
$dir    = $GLOBALS['domains'];
+
foreach (glob("$domains/*") as $link) {
$handle  = opendir($dir);
+
$stat  = stat($link);
while (false !== ($link = readdir($handle))) {
+
$inode = $stat[1];
if (!ereg('^\\.',$link)) {
+
if (is_array($dlist[$inode])) $dlist[$inode][] = basename($link);
$stat  = stat("$dir/$link");
+
else $dlist[$inode] = array(basename($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
 
# Loop through settings files associating with domains
 
$wikia  = array();
 
$wikia  = array();
$dir    = $GLOBALS['settings'];
+
foreach (glob("$settings/*") as $file) {
$handle = opendir($dir);
+
$stat = stat($file);
while (false !== ($file = readdir($handle))) {
+
$wikia[basename($file)] = $dlist[$stat[1]];
$stat = stat("$dir/$file");
 
$inode = $stat[1];
 
if (!ereg('^\\.',$file)) $wikia[$file] = $domains[$inode];
 
 
}
 
}
closedir($handle);
 
 
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 => $domains) {
+
foreach ($wikia as $file => $dlist) if (is_array($dlist)) {
if (is_array($domains)) {
+
$stat  = stat("$settings/$file/wiki");
$stat  = stat("$dir/$file/wiki");
+
$ver    = $codebases[$stat[1]];
$ver    = $codebases[$stat[1]];
+
$table .= "*'''$file''' ($ver)\n";
$table .= "*'''$file''' ($ver)\n";
+
$table .= "**[[Config:$file/LocalSettings.php|LocalSettings.php]]\n";
$table .= "**[[Config:$file/LocalSettings.php|LocalSettings.php]]\n";
+
sort($dlist);
sort($domains);
+
foreach ($dlist as $domain) {
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";
+
$table .= "***[$wiki=Special:Statistics Statistics]\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

  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

  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.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";

  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,$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);

}

}

  1. Called from $wgExtensionFunctions array when initialising extensions

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