r79814 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79813‎ | r79814 | r79815 >
Date:13:26, 7 January 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Now using the ressource loader
* Removed OnlineStatus::init()
* Removed usage of $wgTitle
Modified paths:
  • /trunk/extensions/OnlineStatus/OnlineStatus.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatus/OnlineStatus.php
@@ -4,7 +4,7 @@
55 * Extension that adds a new toggle in user preferences to show if the user is
66 * aviabled or not. See http://mediawiki.org/wiki/Extension:OnlineStatus for
77 * more informations.
8 - * Require MediaWiki 1.16 alpha r52503 or higher to work.
 8+ * Require MediaWiki 1.17 r77011 or higher to work.
99 *
1010 * @file
1111 * @ingroup Extensions
@@ -41,34 +41,34 @@
4242 $wgExtensionMessagesFiles['OnlineStatus'] = dirname( __FILE__ ) . '/OnlineStatus.i18n.php';
4343 $wgExtensionMessagesFiles['OnlineStatusMagic'] = dirname( __FILE__ ) . '/OnlineStatus.i18n.magic.php';
4444
45 -// FIXME: Should be a separate class file
46 -class OnlineStatus {
47 - // FIXME: Can't this just be in the core bit instead of the class? The init() will not have to be called
48 - static function init(){
49 - global $wgExtensionFunctions, $wgHooks, $wgAjaxExportList;
 45+// Hooks for the Parser
 46+$wgHooks['ParserFirstCallInit'][] = 'OnlineStatus::ParserFirstCallInit';
5047
51 - // Hooks for the Parser
52 - $wgHooks['ParserFirstCallInit'][] = 'OnlineStatus::ParserFirstCallInit';
 48+// Magic words hooks
 49+$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatus::MagicWordVariable';
 50+$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatus::ParserGetVariable';
5351
54 - // Magic words hooks
55 - $wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatus::MagicWordVariable';
56 - $wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatus::ParserGetVariable';
 52+// Hooks for Special:Preferences
 53+$wgHooks['GetPreferences'][] = 'OnlineStatus::GetPreferences';
5754
58 - // Hooks for Special:Preferences
59 - $wgHooks['GetPreferences'][] = 'OnlineStatus::GetPreferences';
 55+// User hook
 56+$wgHooks['UserLoginComplete'][] = 'OnlineStatus::UserLoginComplete';
 57+$wgHooks['UserLogoutComplete'][] = 'OnlineStatus::UserLogoutComplete';
6058
61 - // User hook
62 - $wgHooks['UserLoginComplete'][] = 'OnlineStatus::UserLoginComplete';
63 - $wgHooks['UserLogoutComplete'][] = 'OnlineStatus::UserLogoutComplete';
 59+// User page
 60+$wgHooks['BeforePageDisplay'][] = 'OnlineStatus::BeforePageDisplay';
 61+$wgHooks['PersonalUrls'][] = 'OnlineStatus::PersonalUrls';
6462
65 - // User page
66 - $wgHooks['BeforePageDisplay'][] = 'OnlineStatus::BeforePageDisplay';
67 - $wgHooks['PersonalUrls'][] = 'OnlineStatus::PersonalUrls';
 63+// Ajax stuff
 64+$wgAjaxExportList[] = 'OnlineStatus::Ajax';
6865
69 - // Ajax stuff
70 - $wgAjaxExportList[] = 'OnlineStatus::Ajax';
71 - }
 66+$wgResourceModules['ext.onlineStatus'] = array(
 67+ 'scripts' => 'extensions/OnlineStatus/OnlineStatus.js',
 68+ 'styles' => 'extensions/OnlineStatus/OnlineStatus.css',
 69+);
7270
 71+// FIXME: Should be a separate class file
 72+class OnlineStatus {
7373 /**
7474 * Get the user online status
7575 *
@@ -274,18 +274,16 @@
275275 * Hook function for BeforePageDisplay
276276 */
277277 static function BeforePageDisplay( &$out ){
278 - global $wgTitle, $wgRequest, $wgUser;
 278+ global $wgRequest, $wgUser;
279279 global $wgUseAjax;
280280
281281 if( $wgUser->isLoggedIn() && $wgUseAjax ){
282 - global $wgScriptPath;
283 - $out->addScriptFile( "{$wgScriptPath}/extensions/OnlineStatus/OnlineStatus.js" );
284 - $out->addExtensionStyle( "{$wgScriptPath}/extensions/OnlineStatus/OnlineStatus.css" );
 282+ $out->addModules( 'ext.onlineStatus' );
285283 }
286284
287285 if( !in_array( $wgRequest->getVal( 'action', 'view' ), array( 'view', 'purge' ) ) )
288286 return true;
289 - $status = self::GetUserStatus( $wgTitle, true );
 287+ $status = self::GetUserStatus( $out->getTitle(), true );
290288 if( $status === null )
291289 return true;
292290 $out->setSubtitle( wfMsgExt( 'onlinestatus-subtitle-' . $status, array( 'parse' ) ) );
@@ -316,5 +314,3 @@
317315 return true;
318316 }
319317 }
320 -
321 -OnlineStatus::init();

Status & tagging log