Difference between revisions of "Extension:CurrentUsers"
m |
(oops, entries not expiring) |
||
Line 4: | Line 4: | ||
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}} | # - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}} | ||
# - Started: 2007-07-25 | # - Started: 2007-07-25 | ||
− | + | ||
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
− | + | ||
define('CURRENTUSERS_VERSION','1.0.0, 2007-07-25'); | define('CURRENTUSERS_VERSION','1.0.0, 2007-07-25'); | ||
Line 12: | Line 12: | ||
$wgCurrentUsersTemplate = 'CurrentUsers'; | $wgCurrentUsersTemplate = 'CurrentUsers'; | ||
$wgCurrentUsersTimeout = 30; | $wgCurrentUsersTimeout = 30; | ||
− | + | ||
$wgExtensionFunctions[] = 'wfSetupCurrentUsers'; | $wgExtensionFunctions[] = 'wfSetupCurrentUsers'; | ||
$wgHooks['LanguageGetMagic'][] = 'wfCurrentUsersLanguageGetMagic'; | $wgHooks['LanguageGetMagic'][] = 'wfCurrentUsersLanguageGetMagic'; | ||
− | + | ||
$wgExtensionCredits['parserhook'][] = array( | $wgExtensionCredits['parserhook'][] = array( | ||
'name' => 'CurrentUsers', | 'name' => 'CurrentUsers', | ||
Line 23: | Line 23: | ||
'version' => CURRENTUSERS_VERSION | 'version' => CURRENTUSERS_VERSION | ||
); | ); | ||
− | + | ||
# Called from $wgExtensionFunctions array when initialising extensions | # Called from $wgExtensionFunctions array when initialising extensions | ||
function wfSetupCurrentUsers() { | function wfSetupCurrentUsers() { | ||
Line 37: | Line 37: | ||
foreach ($data as $item) { | foreach ($data as $item) { | ||
list($h,$m,$u) = split(':',trim($item)); | list($h,$m,$u) = split(':',trim($item)); | ||
− | if ($u != '' && $u != $user && $h*60 | + | if ($u != '' && $u != $user && $now-$h*60-$m < $wgCurrentUsersTimeout) $wgCurrentUsers[] = "$h:$m:$u"; |
} | } | ||
file_put_contents($file,join("\n",$wgCurrentUsers)); | file_put_contents($file,join("\n",$wgCurrentUsers)); | ||
} | } | ||
− | + | ||
# Needed in MediaWiki >1.8.0 for magic word hooks to work properly | # Needed in MediaWiki >1.8.0 for magic word hooks to work properly | ||
function wfCurrentUsersLanguageGetMagic(&$magicWords,$langCode = 0) { | function wfCurrentUsersLanguageGetMagic(&$magicWords,$langCode = 0) { |
Revision as of 11:02, 25 July 2007
<?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');
$wgCurrentUsersMagic = 'currentusers'; $wgCurrentUsersTemplate = 'CurrentUsers'; $wgCurrentUsersTimeout = 30;
$wgExtensionFunctions[] = 'wfSetupCurrentUsers'; $wgHooks['LanguageGetMagic'][] = 'wfCurrentUsersLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'CurrentUsers', 'author' => 'User:Nad', 'description' => 'Allows a list of currently active users to be embedded into a page using a template', 'url' => 'http://www.mediawiki.org/wiki/Extension:CurrentUsers', 'version' => CURRENTUSERS_VERSION );
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupCurrentUsers() { global $wgUser,$wgParser,$wgCurrentUsers,$wgCurrentUsersTimeout,$wgCurrentUsersMagic; $wgParser->setFunctionHook($wgCurrentUsersMagic,'wfCurrentUsersMagic'); $file = dirname(__FILE__).'/CurrentUsers.txt'; $data = file($file); $h = strftime('%H'); $m = strftime('%M'); $now = $h*60+$m; $user = $wgUser->getUserPage()->getText(); $wgCurrentUsers = array("$h:$m:$user"); foreach ($data as $item) { list($h,$m,$u) = split(':',trim($item)); if ($u != && $u != $user && $now-$h*60-$m < $wgCurrentUsersTimeout) $wgCurrentUsers[] = "$h:$m:$u"; } file_put_contents($file,join("\n",$wgCurrentUsers)); }
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfCurrentUsersLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgCurrentUsersMagic; $magicWords[$wgCurrentUsersMagic] = array(0,$wgCurrentUsersMagic); return true; }
function wfCurrentUsersMagic(&$parser) { global $wgCurrentUsers,$wgCurrentUsersTemplate; $parser->disableCache(); $users = ; $guests = 0; foreach ($wgCurrentUsers as $item) { list($h,$m,$u) = split(':',$item); if (ereg("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$",$u)) $guests++; else $users .= "{"."{"."$wgCurrentUsersTemplate|$h:$m|$u|}"."}\n"; } if ($guests) $users .= "{"."{"."$wgCurrentUsersTemplate|Guests||$guests}"."}\n"; return $users; } ?>