r100956 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100955‎ | r100956 | r100957 >
Date:07:59, 27 October 2011
Author:petrb
Status:deferred
Tags:
Comment:
implement new variable {{isonline}} which can be used too
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -10,6 +10,7 @@
1111 * @file
1212 * @ingroup Extensions
1313 * @author Petr Bena <benapetr@gmail.com>
 14+ * @author of magic word Alexandre Emsenhuber
1415 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1516 * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation
1617 */
@@ -32,12 +33,42 @@
3334 $modeText = $wgOnlineStatusBarModes[$mode];
3435 return Html::element( 'img', array( 'src' => $icon ) );
3536 }
 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+ }
3657
37 - static function GetNow() {
 58+ public static function GetNow() {
3859 return gmdate( 'Ymdhis', time() );
3960 }
4061
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() {
4273 global $wgUser, $wgOnlineStatusBarDefaultOnline;
4374 if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) {
4475 $dbw = wfGetDB( DB_MASTER );
@@ -51,7 +82,18 @@
5283 return false;
5384 }
5485
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() {
5698 global $wgUser, $wgOnlineStatusBarDefaultOffline;
5799 if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) {
58100 OnlineStatusBar::UpdateDb();
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php
@@ -23,12 +23,15 @@
2424 'onlinestatusbar-status' => 'What is the default status you wish to use:',
2525 // Section for config
2626 '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)',
2729 );
2830
2931 $messages['qqq'] = array(
3032 'onlinestatusbar-desc' => '{{desc}}',
3133 '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",
3234 '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',
3336 'onlinestatusbar-status' => 'Message in config asking what status they want to use, option box',
3437 'prefs-onlinestatus' => 'Section for config, located in preferences - misc',
3538 );
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -63,7 +63,8 @@
6464 // how long to wait until user is considered as offline
6565 $wgOnlineStatusBar_LogoutTime = 3600;
6666 // position of status bar
67 -$wgOnlineStatusBarY = "-35";
 67+// change to -35 to have it in title bar
 68+$wgOnlineStatusBarY = "0";
6869
6970 $wgHooks['LoadExtensionSchemaUpdates'][] = 'wfOnlineStatusBar_CkSchema';
7071 function wfOnlineStatusBar_CkSchema( $updater = null ) {
@@ -89,14 +90,21 @@
9091 OnlineStatusBar::UpdateStatus();
9192 $ns = $article->getTitle()->getNamespace();
9293 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 );
98106 $modetext = $wgOnlineStatusBarModes[$mode];
99107 $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();
101109 $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
102110 }
103111 }
@@ -113,6 +121,7 @@
114122 function wfOnlineStatusBar_PreferencesHook( $user, &$preferences ) {
115123 global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
116124 $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' );
117126 $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
118127 'options' => array(
119128 $wgOnlineStatusBarModes['online'] => 'online',
@@ -130,6 +139,11 @@
131140 // set defaults
132141 $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
133142 $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
 143+ $defaultOptions['OnlineStatusBar_hide'] = false;
134144 // quit
135145 return true;
136146 }
 147+
 148+$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBar::MagicWordVar';
 149+$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBar::MagicWordSet';
 150+$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBar::ParserGetVariable';

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100865better way to get page ownerpetrb20:36, 26 October 2011

Status & tagging log