Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | * @file |
12 | 12 | * @ingroup Extensions |
13 | 13 | * @author Petr Bena <benapetr@gmail.com> |
| 14 | + * @author of magic word Alexandre Emsenhuber |
14 | 15 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
15 | 16 | * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation |
16 | 17 | */ |
— | — | @@ -32,12 +33,42 @@ |
33 | 34 | $modeText = $wgOnlineStatusBarModes[$mode]; |
34 | 35 | return Html::element( 'img', array( 'src' => $icon ) ); |
35 | 36 | } |
| 37 | + |
| 38 | + public static function ParserGetVariable ( &$parser, &$varCache, &$index, &$ret ){ |
| 39 | + global $wgOnlineStatusBarDefaultOffline; |
| 40 | + if( $index == 'isonline' ){ |
| 41 | + $name = self::GetOwnerFromTitle ( $parser->getTitle() )->getName(); |
| 42 | + |
| 43 | + if ( self::IsValid($name) != true ) { |
| 44 | + $ret = "false"; |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + if( self::GetStatus ( $name ) == $wgOnlineStatusBarDefaultOffline ) { |
| 49 | + $ret = "false"; |
| 50 | + return true; |
| 51 | + } else { |
| 52 | + $ret = "true"; |
| 53 | + } |
| 54 | + } |
| 55 | + return true; |
| 56 | + } |
36 | 57 | |
37 | | - static function GetNow() { |
| 58 | + public static function GetNow() { |
38 | 59 | return gmdate( 'Ymdhis', time() ); |
39 | 60 | } |
40 | 61 | |
41 | | - static function UpdateDb() { |
| 62 | + public static function GetOwnerFromTitle ( $title ) |
| 63 | + { |
| 64 | + if ( $title === null ) { |
| 65 | + return null; |
| 66 | + } |
| 67 | + $username = preg_replace( '/\/.*/', '', $title->getText() ); |
| 68 | + $user_object = User::newFromName ( $username ); |
| 69 | + return $user_object; |
| 70 | + } |
| 71 | + |
| 72 | + public static function UpdateDb() { |
42 | 73 | global $wgUser, $wgOnlineStatusBarDefaultOnline; |
43 | 74 | if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) { |
44 | 75 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -51,7 +82,18 @@ |
52 | 83 | return false; |
53 | 84 | } |
54 | 85 | |
55 | | - static function UpdateStatus() { |
| 86 | + public static function MagicWordSet ( &$vars ) { |
| 87 | + $vars[] = 'isonline'; |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + public static function MagicWordVar ( &$magicWords, $ln ) { |
| 92 | + $magicWords['isonline'] = array ( 0, 'isonline' ); |
| 93 | + |
| 94 | + return true; |
| 95 | + } |
| 96 | + |
| 97 | + public static function UpdateStatus() { |
56 | 98 | global $wgUser, $wgOnlineStatusBarDefaultOffline; |
57 | 99 | if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) { |
58 | 100 | OnlineStatusBar::UpdateDb(); |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php |
— | — | @@ -23,12 +23,15 @@ |
24 | 24 | 'onlinestatusbar-status' => 'What is the default status you wish to use:', |
25 | 25 | // Section for config |
26 | 26 | 'prefs-onlinestatus' => 'Online Status', |
| 27 | + // Message in config |
| 28 | + 'onlinestatusbar-hide' => 'Do you want to hide the status bar in order to use just the magic word? (For advanced users)', |
27 | 29 | ); |
28 | 30 | |
29 | 31 | $messages['qqq'] = array( |
30 | 32 | 'onlinestatusbar-desc' => '{{desc}}', |
31 | 33 | 'onlinestatusbar-line' => "Status bar text line (User is now Offline), parameters:\n* $1 is user\n* $2 is a picture of status (small icon in color of status)\n* $3 a status, it will appear in title bar of their user space pages", |
32 | 34 | 'onlinestatusbar-used' => 'Message in config asking user if they want to enable it, checkbox', |
| 35 | + 'onlinestatusbar-hide' => 'Ask user if they want to hide status bar this is useful when they are using custom template but need to check if they are online', |
33 | 36 | 'onlinestatusbar-status' => 'Message in config asking what status they want to use, option box', |
34 | 37 | 'prefs-onlinestatus' => 'Section for config, located in preferences - misc', |
35 | 38 | ); |
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php |
— | — | @@ -63,7 +63,8 @@ |
64 | 64 | // how long to wait until user is considered as offline |
65 | 65 | $wgOnlineStatusBar_LogoutTime = 3600; |
66 | 66 | // position of status bar |
67 | | -$wgOnlineStatusBarY = "-35"; |
| 67 | +// change to -35 to have it in title bar |
| 68 | +$wgOnlineStatusBarY = "0"; |
68 | 69 | |
69 | 70 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'wfOnlineStatusBar_CkSchema'; |
70 | 71 | function wfOnlineStatusBar_CkSchema( $updater = null ) { |
— | — | @@ -89,14 +90,21 @@ |
90 | 91 | OnlineStatusBar::UpdateStatus(); |
91 | 92 | $ns = $article->getTitle()->getNamespace(); |
92 | 93 | if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) { |
93 | | - // better way to get a username would be great :) |
94 | | - $user = $article->getTitle(); |
95 | | - $user = preg_replace( '/\/.*/', '', substr($user, strpos($user, ":") + 1)); |
96 | | - if ( OnlineStatusBar::IsValid( $user ) ) { |
97 | | - $mode = OnlineStatusBar::GetStatus( $user ); |
| 94 | + $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() ); |
| 95 | + if ( $user == null ) { |
| 96 | + return true; |
| 97 | + } |
| 98 | + $username = $user->getName(); |
| 99 | + if ( $user != null ) { |
| 100 | + if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) { |
| 101 | + return true; |
| 102 | + } |
| 103 | + } |
| 104 | + if ( OnlineStatusBar::IsValid( $username ) ) { |
| 105 | + $mode = OnlineStatusBar::GetStatus( $username ); |
98 | 106 | $modetext = $wgOnlineStatusBarModes[$mode]; |
99 | 107 | $image = OnlineStatusBar::getImageHtml( $mode ); |
100 | | - $text = wfMessage( 'onlinestatusbar-line', $user )->rawParams( $image )->params( $modetext )->escaped(); |
| 108 | + $text = wfMessage( 'onlinestatusbar-line', $username )->rawParams( $image )->params( $modetext )->escaped(); |
101 | 109 | $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) ); |
102 | 110 | } |
103 | 111 | } |
— | — | @@ -113,6 +121,7 @@ |
114 | 122 | function wfOnlineStatusBar_PreferencesHook( $user, &$preferences ) { |
115 | 123 | global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes; |
116 | 124 | $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' ); |
| 125 | + $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' ); |
117 | 126 | $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus', |
118 | 127 | 'options' => array( |
119 | 128 | $wgOnlineStatusBarModes['online'] => 'online', |
— | — | @@ -130,6 +139,11 @@ |
131 | 140 | // set defaults |
132 | 141 | $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline; |
133 | 142 | $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled; |
| 143 | + $defaultOptions['OnlineStatusBar_hide'] = false; |
134 | 144 | // quit |
135 | 145 | return true; |
136 | 146 | } |
| 147 | + |
| 148 | +$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBar::MagicWordVar'; |
| 149 | +$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBar::MagicWordSet'; |
| 150 | +$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBar::ParserGetVariable'; |