|
|
(23 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
− | <?php
| + | {{svn|extensions|MediaWiki/CurrentUsers/CurrentUsers.php}} |
− | # Extension:CurrentUsers{{Category:Extensions|CurrentUsers}}{{php}}
| + | [[Category:Extensions|CurrentUsers]] |
− | # - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
| |
− | # - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category: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' => '[http://www.organicdesign.co.nz/nad User:Nad]',
| |
− | 'description' => 'An example extension made with [http://www.organicdesign.co.nz/Template:Extension 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;
| |
− | }
| |
− | ?>
| |