Difference between revisions of "Extension:CurrentUsers"

From Organic Design wiki
m
m (convert wg->eg, wf->ef)
Line 9: Line 9:
 
define('CURRENTUSERS_VERSION','1.0.3, 2008-03-27');
 
define('CURRENTUSERS_VERSION','1.0.3, 2008-03-27');
  
$wgCurrentUsersMagic           = 'currentusers';
+
$egCurrentUsersMagic           = 'currentusers';
$wgCurrentUsersTemplate       = 'CurrentUsers';
+
$egCurrentUsersTemplate       = 'CurrentUsers';
$wgCurrentUsersTimeout         = 60;
+
$egCurrentUsersTimeout         = 60;
 
   
 
   
$wgExtensionFunctions[]        = 'wfSetupCurrentUsers';
+
$wgExtensionFunctions[]        = 'efSetupCurrentUsers';
$wgHooks['LanguageGetMagic'][] = 'wfCurrentUsersLanguageGetMagic';
+
$wgHooks['LanguageGetMagic'][] = 'efCurrentUsersLanguageGetMagic';
 
   
 
   
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
Line 25: Line 25:
 
   
 
   
 
# Called from $wgExtensionFunctions array when initialising extensions
 
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupCurrentUsers() {
+
function efSetupCurrentUsers() {
global $wgUser,$wgParser,$wgCurrentUsers,$wgCurrentUsersTimeout,$wgCurrentUsersMagic;
+
global $wgUser,$wgParser,$egCurrentUsers,$egCurrentUsersTimeout,$egCurrentUsersMagic;
$wgParser->setFunctionHook($wgCurrentUsersMagic,'wfCurrentUsersMagic');
+
$wgParser->setFunctionHook($egCurrentUsersMagic,'efCurrentUsersMagic');
 
if (strtolower($_REQUEST['title']) == 'robots.txt') $bot = 'bot';
 
if (strtolower($_REQUEST['title']) == 'robots.txt') $bot = 'bot';
 
else $bot = '';
 
else $bot = '';
Line 36: Line 36:
 
$now = $h*60+$m;
 
$now = $h*60+$m;
 
$user = $wgUser->getUserPage()->getText();
 
$user = $wgUser->getUserPage()->getText();
$wgCurrentUsers = array("$h:$m:$user");
+
$egCurrentUsers = array("$h:$m:$user");
 
         $bot = '';
 
         $bot = '';
 
foreach ($data as $item) {
 
foreach ($data as $item) {
Line 43: Line 43:
 
if ($age < 0) $age += 1440;
 
if ($age < 0) $age += 1440;
 
if ($u == $user && $b == 'bot') $bot = $b;
 
if ($u == $user && $b == 'bot') $bot = $b;
if ($u != '' && $u != $user && $age < $wgCurrentUsersTimeout) $wgCurrentUsers[] = "$h:$m:$u:$b";
+
if ($u != '' && $u != $user && $age < $egCurrentUsersTimeout) $egCurrentUsers[] = "$h:$m:$u:$b";
 
}
 
}
$wgCurrentUsers[0] .= ":$bot";
+
$egCurrentUsers[0] .= ":$bot";
file_put_contents($file,join("\n",$wgCurrentUsers));
+
file_put_contents($file,join("\n",$egCurrentUsers));
 
}
 
}
 
   
 
   
 
# 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 efCurrentUsersLanguageGetMagic(&$magicWords,$langCode = 0) {
global $wgCurrentUsersMagic;
+
global $egCurrentUsersMagic;
$magicWords[$wgCurrentUsersMagic] = array(0,$wgCurrentUsersMagic);
+
$magicWords[$egCurrentUsersMagic] = array(0,$egCurrentUsersMagic);
 
return true;
 
return true;
 
}
 
}
  
function wfCurrentUsersMagic(&$parser) {
+
function efCurrentUsersMagic(&$parser) {
global $wgCurrentUsers,$wgCurrentUsersTemplate, $wgTitle;
+
global $egCurrentUsers,$egCurrentUsersTemplate, $wgTitle;
 
$parser->disableCache();
 
$parser->disableCache();
 
$users = '';
 
$users = '';
 
$guests = 0;
 
$guests = 0;
 
$bots = 0;
 
$bots = 0;
foreach ($wgCurrentUsers as $item) {
+
foreach ($egCurrentUsers as $item) {
 
list($h,$m,$u,$b) = split(':',$item);
 
list($h,$m,$u,$b) = split(':',$item);
 
if (User::isIP($u)) $b ? $bots++ : $guests++;
 
if (User::isIP($u)) $b ? $bots++ : $guests++;
else $users .= "{"."{"."$wgCurrentUsersTemplate|$h:$m|$u|}"."}\n";
+
else $users .= "{"."{"."$egCurrentUsersTemplate|$h:$m|$u|}"."}\n";
 
}
 
}
if ($guests) $users .= "{"."{"."$wgCurrentUsersTemplate|Guests||$guests}"."}\n";
+
if ($guests) $users .= "{"."{"."$egCurrentUsersTemplate|Guests||$guests}"."}\n";
if ($bots)  $users .= "{"."{"."$wgCurrentUsersTemplate|Robots||$bots}"."}\n";
+
if ($bots)  $users .= "{"."{"."$egCurrentUsersTemplate|Robots||$bots}"."}\n";
 
$users =  $parser->preprocess($users,$wgTitle,$parser->mOptions);
 
$users =  $parser->preprocess($users,$wgTitle,$parser->mOptions);
 
         return array(
 
         return array(

Revision as of 00:57, 27 March 2008

<?php

  1. Extension:CurrentUsers
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:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:Extension
  3. - Started: 2007-07-25

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('CURRENTUSERS_VERSION','1.0.3, 2008-03-27');

$egCurrentUsersMagic = 'currentusers'; $egCurrentUsersTemplate = 'CurrentUsers'; $egCurrentUsersTimeout = 60;

$wgExtensionFunctions[] = 'efSetupCurrentUsers'; $wgHooks['LanguageGetMagic'][] = 'efCurrentUsersLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'CurrentUsers', 'author' => 'User:Nad', 'description' => 'An example extension made with Template:Extension', 'url' => 'http://www.mediawiki.org/wiki/Extension:CurrentUsers', 'version' => CURRENTUSERS_VERSION );

  1. Called from $wgExtensionFunctions array when initialising extensions

function efSetupCurrentUsers() { global $wgUser,$wgParser,$egCurrentUsers,$egCurrentUsersTimeout,$egCurrentUsersMagic; $wgParser->setFunctionHook($egCurrentUsersMagic,'efCurrentUsersMagic'); if (strtolower($_REQUEST['title']) == 'robots.txt') $bot = 'bot'; else $bot = ; $file = dirname(__FILE__).'/CurrentUsers.txt'; $data = file($file); $h = strftime('%H'); $m = strftime('%M'); $now = $h*60+$m; $user = $wgUser->getUserPage()->getText(); $egCurrentUsers = array("$h:$m:$user");

       $bot = ;

foreach ($data as $item) { list($h,$m,$u,$b) = split(':',trim($item)); $age = $now-$h*60-$m; if ($age < 0) $age += 1440; if ($u == $user && $b == 'bot') $bot = $b; if ($u != && $u != $user && $age < $egCurrentUsersTimeout) $egCurrentUsers[] = "$h:$m:$u:$b"; } $egCurrentUsers[0] .= ":$bot"; file_put_contents($file,join("\n",$egCurrentUsers)); }

  1. Needed in MediaWiki >1.8.0 for magic word hooks to work properly

function efCurrentUsersLanguageGetMagic(&$magicWords,$langCode = 0) { global $egCurrentUsersMagic; $magicWords[$egCurrentUsersMagic] = array(0,$egCurrentUsersMagic); return true; }

function efCurrentUsersMagic(&$parser) { global $egCurrentUsers,$egCurrentUsersTemplate, $wgTitle; $parser->disableCache(); $users = ; $guests = 0; $bots = 0; foreach ($egCurrentUsers as $item) { list($h,$m,$u,$b) = split(':',$item); if (User::isIP($u)) $b ? $bots++ : $guests++; else $users .= "{"."{"."$egCurrentUsersTemplate|$h:$m|$u|}"."}\n"; } if ($guests) $users .= "{"."{"."$egCurrentUsersTemplate|Guests||$guests}"."}\n"; if ($bots) $users .= "{"."{"."$egCurrentUsersTemplate|Robots||$bots}"."}\n"; $users = $parser->preprocess($users,$wgTitle,$parser->mOptions);

       return array(

$users, 'found' => true, 'nowiki' => false, 'noparse' => false, 'noargs' => false, 'isHTML' => false ); }