r103803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103802‎ | r103803 | r103804 >
Date:13:08, 21 November 2011
Author:petrb
Status:deferred
Tags:
Comment:
performance tweak
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -41,7 +41,7 @@
4242 /**
4343 * Returns the status and User element
4444 *
45 - * @param Title $title
 45+ * @param Title $title a title of page
4646 * @return array|bool Array containing the status and User object
4747 */
4848 public static function getAnonFromTitle( Title $title ) {
@@ -74,7 +74,7 @@
7575 /**
7676 * Returns the status and User element
7777 *
78 - * @param Title $title
 78+ * @param Title $title a title of page
7979 * @return array|bool Array containing the status and User object
8080 */
8181 public static function getUserInfoFromTitle( Title $title ) {
@@ -82,6 +82,7 @@
8383 return false;
8484 }
8585
 86+ // We create an user object using name of user parsed from title
8687 $user = User::newFromName( $title->getBaseText() );
8788 // Invalid user
8889 if ( !($user instanceof User) ) {
@@ -102,6 +103,8 @@
103104 *
104105 */
105106 public static function purge( $user_type ) {
 107+ // First of all we need to know if we already have user object or just a name
 108+ // if so let's create new object
106109 if ( $user_type instanceof User ) {
107110 $user = $user_type;
108111 } else if ( is_string( $user_type ) ){
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -80,6 +80,7 @@
8181 'remoteExtPath' => 'OnlineStatusBar',
8282 );
8383
 84+// Load other files of extension
8485 $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php";
8586 $wgAutoloadClasses['OnlineStatusBar_StatusCheck'] = "$dir/OnlineStatusBar.status.php";
8687 $wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBarHooks.php";
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
@@ -39,7 +39,9 @@
4040 */
4141 public static function updateStatus() {
4242 global $wgUser;
 43+ // Purge user page (optional)
4344 OnlineStatusBar::purge( $wgUser );
 45+ // Update status
4446 OnlineStatusBar_StatusCheck::updateStatus();
4547 return true;
4648 }
@@ -53,13 +55,21 @@
5456 */
5557 public static function renderBar( &$article, &$outputDone, &$pcache ) {
5658 $context = $article->getContext();
 59+
 60+ // Performace fix
 61+ $title = $article->getTitle();
 62+ if ( $title->getNamespace() != NS_USER && $title->getNamespace() != NS_USER_TALK ) {
 63+ return true;
 64+ }
5765
58 - OnlineStatusBar_StatusCheck::updateStatus();
59 - $result = OnlineStatusBar::getUserInfoFromTitle( $article->getTitle() );
60 - if ( $result === false && User::isIP ( $article->getTitle()->getBaseText() ) ) {
61 - $result = OnlineStatusBar::getAnonFromTitle( $article->getTitle() );
 66+ // Retrieve status of user parsed from title
 67+ $result = OnlineStatusBar::getUserInfoFromTitle( $title );
 68+ // In case that status can't be parsed we check if it isn't anon
 69+ if ( $result === false && User::isIP ( $title->getBaseText() ) ) {
 70+ $result = OnlineStatusBar::getAnonFromTitle( $title );
6271 }
6372
 73+ // In case we were unable to get a status let's quit
6474 if ( $result === false ) {
6575 return true;
6676 }
@@ -67,7 +77,7 @@
6878 /** @var $user User */
6979 list( $status, $user ) = $result;
7080
71 - // Don't display status of those who have opted out
 81+ // Don't display status of those who don't want to show bar but only use magic
7282 if ( $user->getOption( 'OnlineStatusBar_hide' ) == true ) {
7383 return true;
7484 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r103806Fixed line I accidentaly removedpetrb13:31, 21 November 2011

Status & tagging log