Extension:CurrentUsers
<?php
- Extension:CurrentUsers
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:NadCategory:Extensions created with Template:Extension
- - Started: 2007-07-25
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('CURRENTUSERS_VERSION','1.0.0, 2007-07-25');
$wgExtensionFunctions[] = 'wfSetupCurrentUsers'; $wgHooks['LanguageGetMagic'][] = 'wfCurrentUsersLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'CurrentUsers', 'author' => 'User:Nad', 'description' => 'An example extension made with Template:Extension', 'url' => 'http://www.organicdesign.co.nz/Extension:Example', 'version' => CURRENTUSERS_VERSION );
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupCurrentUsers() { global $wgUser,$wgParser,$wgCurrentUsers; $wgParser->setFunctionHook('currentusers','wfCurrentUsersMagic'); $file = dirname(__FILE__).'/CurrentUsers.txt'; $data = file($file); $time = strftime('%H:%M'); $user = $wgUser->getUserPage()->getText(); $wgCurrentUsers = array("$time $user"); $max = 50; foreach ($data as $i) if ($max-->0 && ereg('^.+ (.+)$',$i,$m) && $m[1] != $user) $wgCurrentUsers[] = $i; file_put_contents($file,$wgCurrentUsers); }
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfCurrentUsersLanguageGetMagic(&$magicWords,$langCode = 0) { $magicWords['currentusers'] = array(0,'currentusers'); return true; }
function wfCurrentUsersMagic(&$parser,$count = 5) { global $wgCurrentUsers; $users = ; for ($i = 0; $i < $count; $i++) if (isset($wgCurrentUsers[$i])) $users .= '*'.$wgCurrentUsers[$i]."\n"; return $users; } ?>