r101006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101005‎ | r101006 | r101007 >
Date:17:40, 27 October 2011
Author:petrb
Status:deferred
Tags:
Comment:
improved little 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
@@ -26,7 +26,12 @@
2727 $text</div></div>
2828 HTML;
2929 }
30 -
 30+
 31+ /**
 32+ * Returns image
 33+ * @param $mode User
 34+ * @return string
 35+ */
3136 public static function GetImageHtml( $mode ) {
3237 global $wgExtensionAssetsPath, $wgOnlineStatusBarIcon, $wgOnlineStatusBarModes;
3338 $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarIcon[$mode]}";
@@ -34,34 +39,39 @@
3540 return Html::element( 'img', array( 'src' => $icon ) );
3641 }
3742
38 - public static function GetNow() {
39 - return gmdate( 'Ymdhis', time() );
40 - }
41 -
 43+ /**
 44+ * @param $title Title
 45+ * @return user
 46+ */
4247 public static function GetOwnerFromTitle ( $title )
4348 {
4449 if ( $title === null ) {
4550 return null;
4651 }
47 - $username = preg_replace( '/\/.*/', '', $title->getText() );
 52+ $username = $title->getBaseText();
4853 $user_object = User::newFromName ( $username );
4954 return $user_object;
5055 }
5156
 57+ /**
 58+ * @return bool
 59+ */
5260 public static function UpdateDb() {
5361 global $wgUser, $wgOnlineStatusBarDefaultOnline;
5462 if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) {
5563 $dbw = wfGetDB( DB_MASTER );
5664 $row = array(
5765 'username' => $wgUser->getName(),
58 - 'timestamp' => $dbw->timestamp( wfTimestamp() ), /// fixme
 66+ 'timestamp' => $dbw->timestamp(),
5967 );
6068 $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' );
6169 }
62 -
6370 return false;
6471 }
6572
 73+ /**
 74+ * @return bool
 75+ */
6676 public static function UpdateStatus() {
6777 global $wgUser, $wgOnlineStatusBarDefaultOffline;
6878 if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) {
@@ -77,9 +87,11 @@
7888 );
7989
8090 return false;
81 -
8291 }
8392
 93+ /**
 94+ * @return int
 95+ */
8496 public static function DeleteOld() {
8597 global $wgOnlineStatusBar_LogoutTime, $wgDBname;
8698 $dbw = wfGetDB( DB_MASTER );
@@ -89,54 +101,54 @@
90102 return 0;
91103 }
92104
93 - public static function IsValid( $id ) {
 105+
 106+ /**
 107+ * @param $userName string
 108+ * @return bool
 109+ */
 110+ public static function IsValid( $userName ) {
94111 global $wgOnlineStatusBarDefaultIpUsers, $wgOnlineStatusBarDefaultEnabled;
95112 // checks if anon
96 - if ( User::isIP( $id ) ) {
 113+ if ( User::isIP( $userName ) ) {
97114 return $wgOnlineStatusBarDefaultIpUsers;
98115 }
99 - $user = User::newFromName( $id );
 116+ $user = User::newFromName( $userName );
100117 // check if exist
101118 if ( $user == null ) {
102119 return false;
103120 }
104121 // do we track them
105 - $value = $user->getOption( "OnlineStatusBar_active" );
106 - if ( $value === null ) {
107 - return $wgOnlineStatusBarDefaultEnabled;
108 - }
109 - if ( $value == true ) {
110 - return true;
111 - }
112 - return false;
 122+ return $user->getOption( "OnlineStatusBar_active", $wgOnlineStatusBarDefaultEnabled );
113123 }
114124
115 - static function GetStatus( $userID ) {
 125+ /**
 126+ * @param $userName string
 127+ * @return string
 128+ */
 129+ static function GetStatus( $userName ) {
116130 global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname;
117131 $dbw = wfGetDB( DB_MASTER );
118132 OnlineStatusBar::DeleteOld();
119 - $user = User::newFromName( $userID );
 133+ $user = User::newFromName( $userName );
120134 if ( $user == null ) {
121135 // something is wrong
122136 return $wgOnlineStatusBarDefaultOffline;
123137 }
124 - $result = $dbw->selectField( 'online_status', 'username', array( 'username' => $userID ),
 138+ $result = $dbw->selectField( 'online_status', 'username', array( 'username' => $userName ),
125139 __METHOD__, array( 'limit 1', 'order by timestamp desc' ) );
126140 if ( $result ) {
127 - $status = $user->getOption( "OnlineStatusBar_status" );
128 - if ( $status === null || $status == "" ) {
129 - return $wgOnlineStatusBarDefaultOnline;
130 - } else {
131 - return $status;
132 - }
 141+ return $user->getOption( "OnlineStatusBar_status", $wgOnlineStatusDefaultOnline );
133142 }
134 -
135143 return $wgOnlineStatusBarDefaultOffline;
136144 }
137145
138 - static function DeleteStatus( $userId ) {
 146+ /**
 147+ * @param $userName string
 148+ * @return bool
 149+ */
 150+ static function DeleteStatus( $userName ) {
139151 $dbw = wfGetDB( DB_MASTER );
140 - $dbw->delete( 'online_status', array( 'username' => $userId ), __METHOD__ ); // delete user
 152+ $dbw->delete( 'online_status', array( 'username' => $userName ), __METHOD__ ); // delete user
141153 return true;
142154 }
143155 }
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
@@ -11,7 +11,7 @@
1212 * @return bool
1313 */
1414 public static function ckSchema( $updater = null ) {
15 - if ( ( $updater === null ) != true ){
 15+ if ( $updater !== null ){
1616 $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
1717 } else {
1818 global $wgExtNewTables;
@@ -52,7 +52,7 @@
5353 $ns = $article->getTitle()->getNamespace();
5454 if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
5555 $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
56 - if ( $user === null ) {
 56+ if ( $user == null ) {
5757 return true;
5858 }
5959 $username = $user->getName();
@@ -111,7 +111,6 @@
112112 */
113113 public static function magicWordVar ( array &$magicWords, $ln ) {
114114 $magicWords['isonline'] = array ( 0, 'isonline' );
115 -
116115 return true;
117116 }
118117
@@ -142,7 +141,7 @@
143142 * @return bool
144143 */
145144 public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
146 - global $wgOnlineStatusBarModes;
 145+ global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline;
147146 if( $index == 'isonline' ){
148147 $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
149148
@@ -150,7 +149,10 @@
151150 $ret = "unknown";
152151 return true;
153152 }
154 - $ret = $wgOnlineStatusBarModes[OnlineStatusBar::GetStatus( $name )];
 153+ $ret = OnlineStatusBar::GetStatus( $name );
 154+ if ( $ret == "hidden" ) {
 155+ $ret = $wgOnlineStatusBarDefaultOffline;
 156+ }
155157 }
156158 return true;
157159 }

Sign-offs

UserFlagDate
Nikerabbitinspected06:25, 28 October 2011

Status & tagging log