Extension talk:WhosOnline/Archive 2

Wish: Permit staying invisible
Hi, thanks for this wonderful extension which works smoothly on our closed 1.23.8 Mediawiki. It's inspiring to see the fellow user's interest. But, sometimes, depending on atmospheric pressure ;-), one might want to log in without being seen. I wonder how to make this possible. Perhaps just through a special URL parameter or so? Avacpio (talk) 05:24, 12 December 2014 (UTC)

Bug in MW 1.24 ?
Hi, there seems to be a little bug for the special page. The does work.

[Fri Dec 12 19:34:56 2014] [error] [client 129.194.30.22] PHP Catchable fatal error: Argument 1 passed to Language::viewPrevNext must be an instance of Title, string given, called in /export/data/portails/fmediawiki/extensions/WhosOnline/WhosOnlineSpecialPage.php on line 84 and defined in /export/data/portails/fmediawiki/languages/Language.php on line 4633, referer: http://edutechwiki.unige.ch/fr/Bases_psychop%C3%A9dagogiques_des_technologies_%C3%A9ducatives

Life example: http://edutechwiki.unige.ch/fr/Sp%C3%A9cial:Qui_est_en_ligne

- Daniel K. Schneider (talk) 18:46, 12 December 2014 (UTC)


 * The Problem is wfViewPrevNext used in getNavigationBar, Deprecated since 1.19 and removed in 1.24. You should replace getNavigationBar in WhosOnlineSpecialPage.php with this:

function getNavigationBar { global $wgContLang,$wgLang;

$query = ''; $offset = $this->mOffset; $limit = $this->mLimit; $link = $wgContLang->specialpage( 'WhosOnline' ); $atend = $this->countUsersOnline < ( $this->mLimit + $this->mOffset ); // show next link $query = wfCgiToArray( '' ); if( is_object( $link ) ) { $title = $link; } else { $title = Title::newFromText( $link ); if( is_null( $title ) ) { return false; }		}

return $wgLang->viewPrevNext(			$title,			$offset,			$limit,			$query,			$atend); } }

May be not perfect but it work. --79.209.109.156 18:48, 21 December 2014 (UTC)
 * Yes I can confirm too that the solution above works with MW1.24 (example). Thanx again ! Would be nice if someone who has the powers and the know how could merge it into the Git master :) - Daniel K. Schneider (talk) 10:09, 21 April 2015 (UTC)

Update: Tried to get this extension working in 1.23 and received the same error-message, but the above modification is a correct solution to get it working in MW 1.23.

New Bug in Mediawiki 1.24
Hi

Did the change listed above to get the Special Page working. But now I get the following error:

Notice: Undefined variable: link in mediawiki/htdocs/extensions/WhosOnline/WhosOnlineSpecialPage.php on line 88


 * It fixed my issues.  Mlpearc  ( open channel ) 20:34, 4 January 2015 (UTC)


 * change  to    --178.24.206.247 20:13, 15 January 2015 (UTC)

Show the online time a user is logged on
Hi, I like the extension, but I'm also interested in seeing how long a user is online, so I made a few modifications, giving me the following output:

Who's online View (previous 50 | next 50) (20 | 50 | 100 | 250 | 500)

161.90.43.138 Online for 0 hours 24 minutes 43 seconds Admin [Admin] Online for 0 hours 34 minutes 8 seconds

Are you interested in the code? Maybe it can be implemented as an extra option so that someone can choose whether or not to show the online time.

Update: Modified it so it can be optional with an extra variable $wgWhosOnlineShowTime.


 * Sharing is caring, so it'd be lovely if you could share your modifications. :-) --Jack Phoenix (Contact) 21:18, 23 August 2015 (UTC)

OK :

WhosOnline.php:

Added at line 36:

// Showing how long a user is logged on (default false) $wgWhosOnlineShowTime = false;

WhosOnlineSpecialPage.php:

 * @modified by Dick Pluim to show online time */

if ( !defined( 'MEDIAWIKI' ) ) { exit( 1 ); }

class PagerWhosOnline extends IndexPager { function __construct { parent::__construct; $this->mLimit = $this->mDefaultLimit; }

function getQueryInfo { global $wgWhosOnlineShowAnons;

return array(			'tables' => array( 'online' ),			'fields'  => array( 'username' ,'timestamp' ),			'options' => array( 'ORDER BY' => 'username' ),			'conds'   => $wgWhosOnlineShowAnons					? array					: array( 'userid != 0' )		); }

// use classical LIMIT/OFFSET instead of sorting by table key function reallyDoQuery( $offset, $limit, $descending ) { $info = $this->getQueryInfo; $tables = $info['tables']; $fields = $info['fields']; $conds = isset( $info['conds'] ) ? $info['conds'] : array; $options = isset( $info['options'] ) ? $info['options'] : array;

$options['LIMIT'] = intval( $limit ); $options['OFFSET'] = intval( $offset );

$res = $this->mDb->select( $tables, $fields, $conds, __METHOD__, $options );

return new ResultWrapper( $this->mDb, $res ); }

function getIndexField { return 'username'; // dummy }

function formatRow( $row ) { global $wgWhosOnlineShowTime ; ## seems that timestamp in table online is 1 hour off, so ... #date_default_timezone_set( 'UTC' ); $current_time = gmdate ( 'YmdHis', time );

$start_date = new DateTime($row->timestamp); $since_start = $start_date->diff(new DateTime($current_time));

$logged_on_time = 'Online for '. $since_start->h.' hours '. $since_start->i.' minutes '. $since_start->s. ' seconds' ;

$userPageLink = Title::makeTitle( NS_USER, $row->username )->getFullURL; if ( $wgWhosOnlineShowTime ) {

return '>'. htmlspecialchars( $row->username ). ' '. htmlspecialchars( $logged_on_time ). ''; }               else {  return '>'. htmlspecialchars( $row->username ). ''; }

}

// extra methods function countUsersOnline { wfProfileIn( __METHOD__ );

$row = $this->mDb->selectRow(			'online',			'COUNT(*) AS cnt',			'userid != 0',                       'timestamp',			__METHOD__		); $users = (int) $row->cnt;

wfProfileOut( __METHOD__ );

return $users; }

function getNavigationBar { global $wgContLang,$wgLang;

$query = ''; $offset = $this->mOffset; $limit = $this->mLimit; $link = $wgContLang->specialpage( 'WhosOnline' ); $atend = $this->countUsersOnline < ( $this->mLimit + $this->mOffset ); // show next link $query = wfCgiToArray( '' ); if( is_object( $link ) ) { $title = $link; } else { $title = Title::newFromText( $link ); if( is_null( $title ) ) { return false; }               }

return $wgLang->viewPrevNext(                       $title,                        $offset,                        $limit,                        $query,                        $atend); } }

class SpecialWhosOnline extends IncludableSpecialPage { public function __construct { parent::__construct( 'WhosOnline' ); }

// get list of logged-in users being online protected function getAnonsOnline { wfProfileIn( __METHOD__ );

$dbr = wfGetDB( DB_SLAVE );

$row = $dbr->selectRow(			'online',			'COUNT(*) AS cnt',			'userid = 0',                       'timestamp', 			__METHOD__		); $guests = (int) $row->cnt;

wfProfileOut( __METHOD__ );

return $guests; }

public function execute( $para ) { global $wgOut, $wgDBname;

$db = wfGetDB( DB_MASTER ); $db->selectDB( $wgDBname ); $old = gmdate( 'YmdHis', time - 3600 );
 * 1) 		$db->delete( 'online', array( 'timestamp < "' . $old . '"' ), __METHOD__ );

$this->setHeaders;

$pager = new PagerWhosOnline;

$showNavigation = !$this->including; if ( $para ) { $bits = preg_split( '/\s*,\s*/', trim( $para ) ); foreach ( $bits as $bit ) { if ( $bit == 'shownav' ) { $showNavigation = true; }				if ( is_numeric( $bit ) ) { $pager->mLimit = $bit; }

$m = array; if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) { $pager->mLimit = intval( $m[1] ); }			}		}

$body = $pager->getBody;

if ( $showNavigation ) { $wgOut->addHTML( $pager->getNavigationBar ); }

$wgOut->addHTML( '' . $body . '' ); } }

Update: I also removed the deletion of the entry db->delete etc.

And when you go for the first time to the Who's Online specialpage it will be empty. When refreshing it will show f.e. you as being logged on for a few seconds where you might have been online for a while.

Fatal error running update.php on V1.5.0
I'm running MW v1.25.1, and just installed WhosOnline v1.5.0 using the new startup line. However, running /mw-config/ produces:
 * Fatal error: Uncaught exception 'Exception' with message '/home/sanders4/public_html/wiki/extensions/WhosOnline/extension.json does not exist!' in /home/sanders4/public_html/wiki/includes/registration/ExtensionRegistry.php:79 Stack trace:
 * 1) 0 /home/sanders4/public_html/wiki/includes/GlobalFunctions.php(181): ExtensionRegistry->queue('/home/sanders4/...')
 * 2) 1 /home/sanders4/public_html/wiki/LocalSettings.php(390): wfLoadExtension('WhosOnline')
 * 3) 2 /home/sanders4/public_html/wiki/includes/WebStart.php(124): require_once('/home/sanders4/...')
 * 4) 3 /home/sanders4/public_html/wiki/index.php(38): require('/home/sanders4/...')
 * 5) 4 /home/sanders4/public_html/wiki/index.php5(26): require('/home/sanders4/...')
 * 6) 5 {main} thrown in /home/sanders4/public_html/wiki/includes/registration/ExtensionRegistry.php on line 79

The error is correct, extension.json does in deed not exist. WmBliss (talk) 02:51, 12 October 2015 (UTC)