Difference between revisions of "Extension:WikiaInfo.php"
m (Extension:WikiaInfo moved to Extension:WikiaInfo.php) |
m |
||
| Line 1: | Line 1: | ||
<?php | <?php | ||
| − | # Extension:WikiaInfo{{Category:Extensions}}{{php}}{{Category:Extensions created with Template:SpecialPage}}{{Category:OD2}} | + | # Extension:WikiaInfo{{Category:Extensions}}{{php}}{{Category:Extensions created with Template:SpecialPage}}{{Category:OD2}}{{Category:Extensions:WikiaInfo}} |
# - 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 33: | Line 33: | ||
global $wgOut; | global $wgOut; | ||
| − | $ | + | $this->setHeaders(); |
# Get list of domain symlinks by inode | # Get list of domain symlinks by inode | ||
$domains = array(); | $domains = array(); | ||
| − | $ | + | $dir = $GLOBALS['domains']; |
| + | $handle = opendir($dir); | ||
while (false !== ($link = readdir($handle))) { | while (false !== ($link = readdir($handle))) { | ||
if (!ereg('^\\.',$link)) { | if (!ereg('^\\.',$link)) { | ||
| − | $stat = stat($link); | + | $stat = stat("$dir/$link"); |
$inode = $stat[1]; | $inode = $stat[1]; | ||
if (is_array($domains[$inode])) $domains[$inode][] = $link; | if (is_array($domains[$inode])) $domains[$inode][] = $link; | ||
| Line 48: | Line 49: | ||
closedir($handle); | closedir($handle); | ||
| − | # Loop through settings files | + | # Loop through settings files associating with domains |
| − | $wikia = array(); | + | $wikia = array(); |
| − | $ | + | $dir = $GLOBALS['settings']; |
| + | $handle = opendir($dir); | ||
while (false !== ($file = readdir($handle))) { | while (false !== ($file = readdir($handle))) { | ||
| − | if (!ereg('^\\.',$file)) | + | $stat = stat("$dir/$file"); |
| − | + | $inode = $stat[1]; | |
| − | + | if (!ereg('^\\.',$file)) $wikia[$file] = $domains[$inode]; | |
| − | + | } | |
| − | + | closedir($handle); | |
| − | + | ksort($wikia); | |
| − | + | ||
| + | # Render the list | ||
| + | foreach ($wikia as $file => $domains) { | ||
| + | $wgOut->addWikiText("=== $file ===\n"); | ||
| + | if (is_array($domains)) { | ||
| + | foreach ($domains as $domain) $wgOut->addWikiText("*[http://$domain $domain]\n"); | ||
} | } | ||
} | } | ||
| − | |||
| − | |||
} | } | ||
Revision as of 06:43, 27 August 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.0, 2007-08-27');
$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();
# 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 foreach ($wikia as $file => $domains) { $wgOut->addWikiText("=== $file ===\n"); if (is_array($domains)) { foreach ($domains as $domain) $wgOut->addWikiText("*$domain\n"); } }
}
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWikiaInfo() { global $wgLanguageCode,$wgMessageCache; $wgMessageCache->addMessages(array('wikiainfo' => 'Current Wikia Information')); SpecialPage::addPage(new SpecialWikiaInfo()); } ?>



