r100844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100843‎ | r100844 | r100845 >
Date:19:01, 26 October 2011
Author:johnduhart
Status:ok
Tags:
Comment:
Formatting code per MediaWiki coding conventions
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -16,8 +16,7 @@
1717
1818 class OnlineStatusBar {
1919
20 - public static function Get_Html( $text, $mode )
21 - {
 20+ public static function Get_Html( $text, $mode ) {
2221 global $wgOnlineStatusBarColor, $wgOnlineStatusBarY;
2322 $color = $wgOnlineStatusBarColor[$mode];
2423 return <<<HTML
@@ -26,26 +25,24 @@
2726 $text</div></div>
2827 HTML;
2928 }
 29+
3030 public static function GetImageHtml( $mode ) {
3131 global $wgExtensionAssetsPath, $wgOnlineStatusBarIcon, $wgOnlineStatusBarModes;
3232 $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarIcon[$mode]}";
3333 $modeText = $wgOnlineStatusBarModes[$mode];
3434 return Html::element( 'img', array( 'src' => $icon ) );
3535 }
36 -
37 - static function GetNow()
38 - {
 36+
 37+ static function GetNow() {
3938 return gmdate( 'Ymdhis', time() );
4039 }
4140
42 - static function UpdateDb()
43 - {
 41+ static function UpdateDb() {
4442 global $wgUser, $wgOnlineStatusBarDefaultOnline;
45 - if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline )
46 - {
 43+ if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) != $wgOnlineStatusBarDefaultOnline ) {
4744 $dbw = wfGetDB( DB_MASTER );
4845 $row = array(
49 - 'username' => strtolower($wgUser->getName()),
 46+ 'username' => strtolower( $wgUser->getName() ),
5047 'timestamp' => $dbw->timestamp( wfTimestamp() ),
5148 );
5249 $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' );
@@ -54,11 +51,9 @@
5552 return false;
5653 }
5754
58 - static function UpdateStatus()
59 - {
 55+ static function UpdateStatus() {
6056 global $wgUser, $wgOnlineStatusBarDefaultOffline;
61 - if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline )
62 - {
 57+ if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) {
6358 OnlineStatusBar::UpdateDb();
6459 return true;
6560 }
@@ -66,7 +61,7 @@
6762 $dbw->update(
6863 'online_status',
6964 array( 'timestamp' => $dbw->timestamp( wfTimestamp() ) ),
70 - array( 'username' => strtolower($wgUser->getID()) ),
 65+ array( 'username' => strtolower( $wgUser->getID() ) ),
7166 __METHOD__
7267 );
7368
@@ -74,34 +69,29 @@
7570
7671 }
7772
78 - public static function DeleteOld()
79 - {
 73+ public static function DeleteOld() {
8074 global $wgOnlineStatusBar_LogoutTime, $wgDBname;
8175 $dbw = wfGetDB( DB_MASTER );
8276 $time = wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_LogoutTime;
8377 $time = $dbw->addQuotes( $dbw->timestamp( $time ) - $wgOnlineStatusBar_LogoutTime );
84 - $dbw->delete( 'online_status', array( "timestamp < $time" ) , __METHOD__ );
 78+ $dbw->delete( 'online_status', array( "timestamp < $time" ), __METHOD__ );
8579 return 0;
8680 }
8781
88 - public static function IsValid($id)
89 - {
 82+ public static function IsValid( $id ) {
9083 global $wgOnlineStatusBarDefaultIpUsers;
9184 // checks if anon
92 - if (User::isIP($id))
93 - {
 85+ if ( User::isIP( $id ) ) {
9486 return $wgOnlineStatusBarDefaultIpUsers;
9587 }
96 - $user = User::newFromName($id);
 88+ $user = User::newFromName( $id );
9789 // check if exist
98 - if ($user == null)
99 - {
 90+ if ( $user == null ) {
10091 return false;
101 - }
 92+ }
10293 // do we track them
103 - if ($user->getOption("OnlineStatusBar_active") == true)
104 - {
105 - return true;
 94+ if ( $user->getOption( "OnlineStatusBar_active" ) == true ) {
 95+ return true;
10696 }
10797 return false;
10898 }
@@ -110,21 +100,18 @@
111101 global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline, $wgDBname;
112102 $dbw = wfGetDB( DB_MASTER );
113103 OnlineStatusBar::DeleteOld();
114 - $user = User::newFromName($userID);
115 - if ($user == null)
116 - {
117 - //something is wrong
 104+ $user = User::newFromName( $userID );
 105+ if ( $user == null ) {
 106+ // something is wrong
118107 return $wgOnlineStatusBarDefaultOffline;
119108 }
120 - $result = $dbw->selectField( 'online_status', 'username', array( 'username' => strtolower($userID) ), __METHOD__, array( 'limit 1', 'order by timestamp desc' ) );
121 - if ( $result )
122 - {
123 - $status = $user->getOption("OnlineStatusBar_status");
124 - if ($status == null || $status == "")
125 - {
 109+ $result = $dbw->selectField( 'online_status', 'username', array( 'username' => strtolower( $userID ) ),
 110+ __METHOD__, array( 'limit 1', 'order by timestamp desc' ) );
 111+ if ( $result ) {
 112+ $status = $user->getOption( "OnlineStatusBar_status" );
 113+ if ( $status == null || $status == "" ) {
126114 return $wgOnlineStatusBarDefaultOnline;
127 - } else
128 - {
 115+ } else {
129116 return $status;
130117 }
131118 }
@@ -132,9 +119,8 @@
133120 return $wgOnlineStatusBarDefaultOffline;
134121 }
135122
136 - static function DeleteStatus( $userId )
137 - {
138 - $dbw = wfGetDB ( DB_MASTER );
 123+ static function DeleteStatus( $userId ) {
 124+ $dbw = wfGetDB( DB_MASTER );
139125 $dbw->delete( 'online_status', array( 'username' => $userId ), __METHOD__ ); // delete user
140126 return true;
141127 }
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -24,27 +24,27 @@
2525 );
2626
2727 $dir = dirname( __FILE__ );
28 -$wgExtensionMessagesFiles['OnlineStatusBar'] = "$dir/OnlineStatusBar.i18n.php";
 28+$wgExtensionMessagesFiles['OnlineStatusBar'] = "$dir/OnlineStatusBar.i18n.php";
2929
3030 $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php";
3131
3232 // Configuration
3333 // Those values can be overriden in LocalSettings, do not change it here
34 -$wgOnlineStatusBarModes = array (
 34+$wgOnlineStatusBarModes = array(
3535 'online' => "On-line",
3636 'busy' => "Busy",
3737 'away' => "Away",
3838 'hidden' => "Offline",
3939 'offline' => "Offline",
4040 );
41 -$wgOnlineStatusBarIcon = array (
 41+$wgOnlineStatusBarIcon = array(
4242 'online' => "20px-Ledgreen.svg.png",
4343 'busy' => "20px-Ledorange.svg.png",
4444 'away' => "20px-Ledorange.svg.png",
4545 'hidden' => "20px-Nuvola_apps_krec.svg.png",
4646 'offline' => "20px-Nuvola_apps_krec.svg.png",
4747 );
48 -$wgOnlineStatusBarColor = array (
 48+$wgOnlineStatusBarColor = array(
4949 'online' => "green",
5050 'busy' => "orange",
5151 'away' => "orange",
@@ -66,40 +66,32 @@
6767 $wgOnlineStatusBarY = "-35";
6868
6969 $wgHooks['LoadExtensionSchemaUpdates'][] = 'wfOnlineStatusBar_CkSchema';
70 -function wfOnlineStatusBar_CkSchema( $updater = null )
71 -{
72 - if ( $updater != null )
73 - {
74 - $updater->addExtensionUpdate( array ( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
75 - }
76 - else
77 - {
 70+function wfOnlineStatusBar_CkSchema( $updater = null ) {
 71+ if ( $updater != null ) {
 72+ $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
 73+ } else {
7874 global $wgExtNewTables;
7975 $wgExtNewTables[] = array(
80 - 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' );
 76+ 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' );
8177 }
8278 return true;
8379 }
8480
8581 $wgHooks['UserLogoutComplete'][] = 'wfOnlineStatusBar_Logout';
86 -function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name )
87 -{
 82+function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name ) {
8883 OnlineStatusBar::DeleteStatus( $old_name );
8984 return true;
9085 }
9186
9287 $wgHooks['ArticleViewHeader'][] = 'wfOnlineStatusBar_RenderBar';
93 -function wfOnlineStatusBar_RenderBar( &$article, &$outputDone, &$pcache )
94 -{
 88+function wfOnlineStatusBar_RenderBar( &$article, &$outputDone, &$pcache ) {
9589 global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut;
9690 OnlineStatusBar::UpdateStatus();
9791 $ns = $article->getTitle()->getNamespace();
98 - if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) )
99 - {
 92+ if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
10093 // better way to get a username would be great :)
10194 $user = preg_replace( '/\/.*/', '', preg_replace( '/^.*\:/', "", $article->getTitle() ) );
102 - if (OnlineStatusBar::IsValid($user))
103 - {
 95+ if ( OnlineStatusBar::IsValid( $user ) ) {
10496 $mode = OnlineStatusBar::GetStatus( $user );
10597 $modetext = $wgOnlineStatusBarModes[$mode];
10698 $image = OnlineStatusBar::getImageHtml( $mode );
@@ -111,25 +103,23 @@
112104 }
113105
114106 $wgHooks['UserLoginComplete'][] = 'wfOnlineStatusBar_UpdateStatus';
115 -function wfOnlineStatusBar_UpdateStatus()
116 -{
 107+function wfOnlineStatusBar_UpdateStatus() {
117108 OnlineStatusBar::UpdateDb();
118109 return true;
119110 }
120111
121112 $wgHooks['GetPreferences'][] = 'wfOnlineStatusBar_PreferencesHook';
122 -function wfOnlineStatusBar_PreferencesHook($user, &$preferences)
123 -{
 113+function wfOnlineStatusBar_PreferencesHook( $user, &$preferences ) {
124114 global $wgOnlineStatusBarModes;
125 - $preferences['OnlineStatusBar_active'] = array ('type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'gadgets/onlinestatus' );
126 - $preferences['OnlineStatusBar_status'] = array ('type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'gadgets/onlinestatus',
127 - 'options' => array(
128 - $wgOnlineStatusBarModes['online'] => 'online',
129 - $wgOnlineStatusBarModes['busy'] => 'busy',
130 - $wgOnlineStatusBarModes['away'] => 'away',
131 - $wgOnlineStatusBarModes['hidden'] => 'hidden'
132 - ),
133 - 'default' => 'online',
134 - );
 115+ $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'gadgets/onlinestatus' );
 116+ $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'gadgets/onlinestatus',
 117+ 'options' => array(
 118+ $wgOnlineStatusBarModes['online'] => 'online',
 119+ $wgOnlineStatusBarModes['busy'] => 'busy',
 120+ $wgOnlineStatusBarModes['away'] => 'away',
 121+ $wgOnlineStatusBarModes['hidden'] => 'hidden'
 122+ ),
 123+ 'default' => 'online',
 124+ );
135125 return true;
136126 }

Status & tagging log