r101015 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101014‎ | r101015 | r101016 >
Date:18:25, 27 October 2011
Author:petrb
Status:deferred
Tags:
Comment:
fixed anon users who caused crash or at least didn't work even a bit
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -126,18 +126,21 @@
127127 * @return string
128128 */
129129 static function GetStatus( $userName ) {
130 - global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname;
 130+ global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultIpUsers, $wgOnlineStatusBarDefaultOnline, $wgDBname;
131131 $dbw = wfGetDB( DB_MASTER );
132132 OnlineStatusBar::DeleteOld();
133133 $user = User::newFromName( $userName );
134 - if ( $user == null ) {
 134+ if ( $user == null && User::isIP ( $userName ) != true ) {
135135 // something is wrong
136136 return $wgOnlineStatusBarDefaultOffline;
137137 }
138138 $result = $dbw->selectField( 'online_status', 'username', array( 'username' => $userName ),
139139 __METHOD__, array( 'limit 1', 'order by timestamp desc' ) );
140 - if ( $result ) {
 140+ if ( $result && $user != null ) {
141141 return $user->getOption( "OnlineStatusBar_status", $wgOnlineStatusDefaultOnline );
 142+ } else if ( $result && User::isIP ( $userName ) && $wgOnlineStatusBarDefaultIpUsers ) {
 143+ // user is anon
 144+ return $wgOnlineStatusBarDefaultOnline;
142145 }
143146 return $wgOnlineStatusBarDefaultOffline;
144147 }
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
@@ -47,23 +47,36 @@
4848 * @return bool
4949 */
5050 public static function renderBar( &$article, &$outputDone, &$pcache ) {
51 - global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut;
 51+ global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarDefaultIpUsers, $wgOnlineStatusBarModes, $wgOut;
5252 OnlineStatusBar::UpdateStatus();
 53+ $anon = false;
5354 $ns = $article->getTitle()->getNamespace();
5455 if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
5556 $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
56 - if ( $user == null ) {
 57+ $userName = $article->getTitle()->getBaseText();
 58+ if ( User::isIP ( $userName ) != true && $user == null ) {
5759 return true;
5860 }
59 - $username = $user->getName();
60 - if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
61 - return true;
 61+ if ( User::isIP ( $userName ) && $user == null && $wgOnlineStatusBarDefaultIpUsers ) {
 62+ // it's anon user and we want to track them
 63+ $sanitizedusername = $userName;
 64+ $anon = true;
 65+ } else {
 66+ // Fix capitalisation issues
 67+ $sanitizedusername = $user->getName();
6268 }
63 - if ( OnlineStatusBar::IsValid( $username ) ) {
64 - $mode = OnlineStatusBar::GetStatus( $username );
 69+ if ( $anon == false )
 70+ {
 71+ //we don't want to check this
 72+ if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
 73+ return true;
 74+ }
 75+ }
 76+ if ( OnlineStatusBar::IsValid( $userName ) ) {
 77+ $mode = OnlineStatusBar::GetStatus( $userName );
6578 $modetext = $wgOnlineStatusBarModes[$mode];
6679 $image = OnlineStatusBar::getImageHtml( $mode );
67 - $text = wfMessage( 'onlinestatusbar-line', $username )->rawParams( $image )->params( $modetext )->escaped();
 80+ $text = wfMessage( 'onlinestatusbar-line', $userName )->rawParams( $image )->params( $modetext )->escaped();
6881 $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
6982 }
7083 }
@@ -143,6 +156,11 @@
144157 public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
145158 global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline;
146159 if( $index == 'isonline' ){
 160+ $ns = $parser->getTitle()->getNamespace();
 161+ if ( ( $ns != NS_USER_TALK ) && ( $ns != NS_USER ) ) {
 162+ $ret = "unknown";
 163+ return true;
 164+ }
147165 $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
148166
149167 if ( OnlineStatusBar::IsValid($name) != true ) {

Status & tagging log