Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | /** |
43 | 43 | * Returns the status and User element |
44 | 44 | * |
45 | | - * @param Title $title |
| 45 | + * @param Title $title a title of page |
46 | 46 | * @return array|bool Array containing the status and User object |
47 | 47 | */ |
48 | 48 | public static function getAnonFromTitle( Title $title ) { |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | /** |
76 | 76 | * Returns the status and User element |
77 | 77 | * |
78 | | - * @param Title $title |
| 78 | + * @param Title $title a title of page |
79 | 79 | * @return array|bool Array containing the status and User object |
80 | 80 | */ |
81 | 81 | public static function getUserInfoFromTitle( Title $title ) { |
— | — | @@ -82,6 +82,7 @@ |
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
| 86 | + // We create an user object using name of user parsed from title |
86 | 87 | $user = User::newFromName( $title->getBaseText() ); |
87 | 88 | // Invalid user |
88 | 89 | if ( !($user instanceof User) ) { |
— | — | @@ -102,6 +103,8 @@ |
103 | 104 | * |
104 | 105 | */ |
105 | 106 | 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 |
106 | 109 | if ( $user_type instanceof User ) { |
107 | 110 | $user = $user_type; |
108 | 111 | } else if ( is_string( $user_type ) ){ |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -80,6 +80,7 @@ |
81 | 81 | 'remoteExtPath' => 'OnlineStatusBar', |
82 | 82 | ); |
83 | 83 | |
| 84 | +// Load other files of extension |
84 | 85 | $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php"; |
85 | 86 | $wgAutoloadClasses['OnlineStatusBar_StatusCheck'] = "$dir/OnlineStatusBar.status.php"; |
86 | 87 | $wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBarHooks.php"; |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php |
— | — | @@ -39,7 +39,9 @@ |
40 | 40 | */ |
41 | 41 | public static function updateStatus() { |
42 | 42 | global $wgUser; |
| 43 | + // Purge user page (optional) |
43 | 44 | OnlineStatusBar::purge( $wgUser ); |
| 45 | + // Update status |
44 | 46 | OnlineStatusBar_StatusCheck::updateStatus(); |
45 | 47 | return true; |
46 | 48 | } |
— | — | @@ -53,13 +55,21 @@ |
54 | 56 | */ |
55 | 57 | public static function renderBar( &$article, &$outputDone, &$pcache ) { |
56 | 58 | $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 | + } |
57 | 65 | |
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 ); |
62 | 71 | } |
63 | 72 | |
| 73 | + // In case we were unable to get a status let's quit |
64 | 74 | if ( $result === false ) { |
65 | 75 | return true; |
66 | 76 | } |
— | — | @@ -67,7 +77,7 @@ |
68 | 78 | /** @var $user User */ |
69 | 79 | list( $status, $user ) = $result; |
70 | 80 | |
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 |
72 | 82 | if ( $user->getOption( 'OnlineStatusBar_hide' ) == true ) { |
73 | 83 | return true; |
74 | 84 | } |