https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115434

Revision: 115434
Author:   siebrand
Date:     2012-05-25 11:03:05 +0000 (Fri, 25 May 2012)
Log Message:
-----------
Update indentation and some other coding style related thingies.

No functional changes. Ping r115429.

Modified Paths:
--------------
    trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php
    trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
    trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.php
    trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
    trunk/extensions/OnlineStatusBar/OnlineStatusBar.sql
    trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php
    trunk/extensions/OnlineStatusBar/README

Modified: trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php
===================================================================
--- trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php    2012-05-25 
10:46:29 UTC (rev 115433)
+++ trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php    2012-05-25 
11:03:05 UTC (rev 115434)
@@ -1,9 +1,4 @@
 <?php
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo "This is a part of mediawiki and can't be started separately";
-       die();
-}
-
 /**
  * Hooks for OnlineStatusBar api's
  *
@@ -18,10 +13,12 @@
        public function execute() {
                $params = $this->extractRequestParams();
                $result = OnlineStatusBar::getUserInfoFromString( 
$params['user'] );
+
                // if user is IP and we track them
                if ( User::isIP( $params['user'] ) && $result === false ) {
                        $result = OnlineStatusBar::getAnonFromString( 
$params['user'] );
                }
+
                if ( $result === false ) {
                        $ret = 'unknown';
                } else {
@@ -29,7 +26,8 @@
                }
 
                $this->getResult()->addValue(
-                       null, $this->getModuleName(), array( 'result' => $ret ) 
);
+                       null, $this->getModuleName(), array( 'result' => $ret )
+               );
        }
 
        public function getAllowedParams() {
@@ -54,13 +52,13 @@
 
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
-               array( 'code' => 'unknown', 'info' => "User doesn't allow to 
display user status" ),
+                       array( 'code' => 'unknown', 'info' => "User doesn't 
allow to display user status" ),
                ) );
        }
 
        public function getExamples() {
                return array(
-               'api.php?action=query&prop=onlinestatus&onlinestatususer=Petrb',
+                       
'api.php?action=query&prop=onlinestatus&onlinestatususer=Petrb',
                );
        }
 

Modified: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
===================================================================
--- trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php   2012-05-25 
10:46:29 UTC (rev 115433)
+++ trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php   2012-05-25 
11:03:05 UTC (rev 115434)
@@ -1,9 +1,4 @@
 <?php
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo "This is a part of mediawiki and can't be started separately";
-       die();
-}
-
 /**
  * Main file of Online status bar extension.
  *
@@ -21,11 +16,9 @@
         * return HTML
         **/
        public static function getStatusBarHtml() {
-               return <<<HTML
-<div class="onlinestatusbarbody metadata onlinestatusbartop" id="status-top">
+               return '<div class="onlinestatusbarbody metadata 
onlinestatusbartop" id="status-top">
 <div class="onlinestatusbaricon">
-</div></div>
-HTML;
+</div></div>';
        }
 
        /**
@@ -33,9 +26,11 @@
         */
        public static function getAnonFromTitle( Title $title ) {
                global $wgOnlineStatusBarTrackIpUsers;
+
                if ( $wgOnlineStatusBarTrackIpUsers == false ) {
                        return false;
                }
+
                $user = User::newFromId( 0 );
                $user->setName( $title->getBaseText() );
 
@@ -54,6 +49,7 @@
          */
        public static function getAnonFromString( $username ) {
                global $wgOnlineStatusBarTrackIpUsers;
+
                // if user is anon and we don't track them stop
                if ( $wgOnlineStatusBarTrackIpUsers == false ) {
                        return false;
@@ -79,10 +75,12 @@
         */
        public static function getUserInfoFromTitle( Title $title ) {
                $user = User::newFromName( $title->getBaseText() );
+
                // check
                if ( !( $user instanceof User ) ) {
                        return false;
                }
+
                if ( !self::isValid( $user ) ) {
                        return false;
                }
@@ -99,10 +97,12 @@
        public static function getUserInfoFromString( $username ) {
                // We create an user object using name of user parsed from title
                $user = User::newFromName( $username );
+
                // Invalid user
                if ( !( $user instanceof User ) ) {
                        return false;
                }
+
                if ( !self::isValid( $user ) ) {
                        return false;
                }
@@ -141,7 +141,6 @@
                return true;
        }
 
-
        /**
         * @param $delayed
         * @param $away
@@ -160,9 +159,9 @@
                                                $time = 
$wgOnlineStatusBar_AwayTime;
                                        } else {
                                                $time = $user->getOption(
-                                                               
'OnlineStatusBar_awaytime',
-                                                               
$wgOnlineStatusBar_AwayTime
-                                                               );
+                                                       
'OnlineStatusBar_awaytime',
+                                                       
$wgOnlineStatusBar_AwayTime
+                                               );
                                        }
                                        return wfTimestamp( TS_UNIX ) - ( $time 
* 60 );
                        }

Modified: trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.php
===================================================================
--- trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.php  2012-05-25 
10:46:29 UTC (rev 115433)
+++ trunk/extensions/OnlineStatusBar/OnlineStatusBar.hooks.php  2012-05-25 
11:03:05 UTC (rev 115434)
@@ -1,8 +1,4 @@
 <?php
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo "This is a part of mediawiki and can't be started separately";
-       die();
-}
 
 /**
  * Hooks for OnlineStatusBar
@@ -17,11 +13,11 @@
        public static function ckSchema( $updater = null ) {
                if ( $updater !== null ) {
                        $updater->addExtensionUpdate( array( 'addtable',
-                                                       'online_status',
-                                                       dirname( __FILE__ ) .
-                                                       '/OnlineStatusBar.sql',
-                                                       true )
-                                               );
+                               'online_status',
+                               dirname( __FILE__ ) .
+                               '/OnlineStatusBar.sql',
+                               true )
+                       );
                } else {
                        global $wgExtNewTables;
                        $wgExtNewTables[] = array(
@@ -110,38 +106,45 @@
        public static function preferencesHook( User $user, array &$preferences 
) {
                global $wgOnlineStatusBarDefaultOnline, 
$wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBar_AwayTime,
                        $wgOnlineStatusBar_LogoutTime, $wgOnlineStatusBarModes;
-               $preferences['OnlineStatusBar_active'] = array( 'type' => 
'toggle',
-                                                       'label-message' => 
'onlinestatusbar-used',
-                                                       'section' => 
'misc/onlinestatus'
-                                                       );
-               $preferences['OnlineStatusBar_hide'] = array( 'type' => 
'toggle',
-                                                       'label-message' => 
'onlinestatusbar-hide',
-                                                       'section' => 
'misc/onlinestatus'
-                                                       );
-               $preferences['OnlineStatusBar_away'] = array( 'type' => 
'toggle',
-                                                       'label-message' => 
'onlinestatusbar-away',
-                                                       'section' => 
'misc/onlinestatus'
-                                                       );
-               $preferences['OnlineStatusBar_autoupdate'] = array( 'type' => 
'toggle',
-                                                               'label-message' 
=> 'onlinestatusbar-purge',
-                                                               'section' => 
'misc/onlinestatus'
-                                                       );
-               $preferences['OnlineStatusBar_status'] = array( 'type' => 
'radio',
-                                                               'label-message' 
=> 'onlinestatusbar-status',
-                                                               'section' => 
'misc/onlinestatus',
-                               'options' => array(
+
+               $preferences['OnlineStatusBar_active'] = array(
+                       'type' => 'toggle',
+                       'label-message' => 'onlinestatusbar-used',
+                       'section' => 'misc/onlinestatus'
+               );
+               $preferences['OnlineStatusBar_hide'] = array(
+                       'type' => 'toggle',
+                       'label-message' => 'onlinestatusbar-hide',
+                       'section' => 'misc/onlinestatus'
+               );
+               $preferences['OnlineStatusBar_away'] = array(
+                       'type' => 'toggle',
+                       'label-message' => 'onlinestatusbar-away',
+                       'section' => 'misc/onlinestatus'
+               );
+               $preferences['OnlineStatusBar_autoupdate'] = array(
+                       'type' => 'toggle',
+                       'label-message' => 'onlinestatusbar-purge',
+                       'section' => 'misc/onlinestatus'
+               );
+               $preferences['OnlineStatusBar_status'] = array(
+                       'type' => 'radio',
+                       'label-message' => 'onlinestatusbar-status',
+                       'section' => 'misc/onlinestatus',
+                       'options' => array(
                                wfMessage( 'onlinestatusbar-status-online' 
)->escaped() => 'online',
                                wfMessage( 'onlinestatusbar-status-busy' 
)->escaped() => 'busy',
                                wfMessage( 'onlinestatusbar-status-away' 
)->escaped() => 'away',
                                wfMessage( 'onlinestatusbar-status-hidden' 
)->escaped() => 'hidden'
                        ),
                );
-               $preferences['OnlineStatusBar_awaytime'] = array( 'min' => 2,
-                                                               'max' => 
$wgOnlineStatusBar_LogoutTime,
-                                                               'type' => 'int',
-                                                               'label-message' 
=> 'onlinestatusbar-away-time',
-                                                               'section' => 
'misc/onlinestatus'
-                                                       );
+               $preferences['OnlineStatusBar_awaytime'] = array(
+                       'min' => 2,
+                       'max' => $wgOnlineStatusBar_LogoutTime,
+                       'type' => 'int',
+                       'label-message' => 'onlinestatusbar-away-time',
+                       'section' => 'misc/onlinestatus'
+               );
                return true;
        }
 

Modified: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
===================================================================
--- trunk/extensions/OnlineStatusBar/OnlineStatusBar.php        2012-05-25 
10:46:29 UTC (rev 115433)
+++ trunk/extensions/OnlineStatusBar/OnlineStatusBar.php        2012-05-25 
11:03:05 UTC (rev 115434)
@@ -43,12 +43,14 @@
        'scripts' => 'resources/ext.onlinestatusbar.js',
        'localBasePath' => dirname ( __FILE__ ),
        'remoteExtPath' => 'OnlineStatusBar',
-       'messages' => array (   'onlinestatusbar-status-offline',
-                               'onlinestatusbar-status-online',
-                               'onlinestatusbar-status-unknown',
-                               'onlinestatusbar-status-busy',
-                               'onlinestatusbar-status-away',
-                               'onlinestatusbar-line' ),
+       'messages' => array (
+               'onlinestatusbar-status-offline',
+               'onlinestatusbar-status-online',
+               'onlinestatusbar-status-unknown',
+               'onlinestatusbar-status-busy',
+               'onlinestatusbar-status-away',
+               'onlinestatusbar-line'
+       ),
 );
 
 // Load other files of extension

Modified: trunk/extensions/OnlineStatusBar/OnlineStatusBar.sql
===================================================================
--- trunk/extensions/OnlineStatusBar/OnlineStatusBar.sql        2012-05-25 
10:46:29 UTC (rev 115433)
+++ trunk/extensions/OnlineStatusBar/OnlineStatusBar.sql        2012-05-25 
11:03:05 UTC (rev 115434)
@@ -3,4 +3,3 @@
        `timestamp` binary(14) NOT NULL default '19700101000000',
        PRIMARY KEY USING HASH (`username`)
 ) ENGINE=MEMORY;
-

Modified: trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php
===================================================================
--- trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php 2012-05-25 
10:46:29 UTC (rev 115433)
+++ trunk/extensions/OnlineStatusBar/OnlineStatusBar.status.php 2012-05-25 
11:03:05 UTC (rev 115434)
@@ -1,9 +1,4 @@
 <?php
-if ( !defined( 'MEDIAWIKI' ) ) {
-               echo "This is a part of mediawiki and can't be started 
separately";
-               die();
-}
-
 /**
  * File which contains status check for Online status bar extension.
  *
@@ -35,11 +30,14 @@
         */
        private static function setCache( $user, $values, $type, $time = null ) 
{
                global $wgOnlineStatusBar_WriteTime, $wgMemc;
+
                // get a key
                $cache_key = self::getCacheKey( $user, $type );
+
                if ( $time === null ) {
                        $time = $wgOnlineStatusBar_WriteTime;
                }
+
                $wgMemc->set( $cache_key, $values, $time );
                return true;
        }
@@ -51,13 +49,14 @@
         */
        private static function getCache( $user, $type ) {
                global $wgMemc;
+
                // get a key
                $cache_key = self::getCacheKey( $user, $type );
+
                // get a value
                return $wgMemc->get( $cache_key );
        }
 
-
        /**
         * Status check
         * @param $user User
@@ -66,6 +65,7 @@
         */
        public static function getStatus( $user, $delayed_check = false ) {
                global $wgOnlineStatusBarDefaultOffline, 
$wgOnlineStatusBarDefaultOnline;
+
                // instead of delete every time just select the records which 
are not that old
                if ( !$delayed_check ) {
                        // first try to use cache
@@ -75,13 +75,14 @@
                                $t_time = OnlineStatusBar::getTimeoutDate();
                                $dbr = wfGetDB( DB_SLAVE );
                                $result = $dbr->selectField(
-                                               'online_status',
-                                               'timestamp',
-                                               array( 'username' => 
$user->getName(),
-                                               'timestamp > ' .
-                                               $dbr->addQuotes( 
$dbr->timestamp( $t_time ) ) ),
-                                               __METHOD__, array( 'LIMIT 1', 
'ORDER BY timestamp DESC' )
-                                       );
+                                       'online_status',
+                                       'timestamp',
+                                       array( 'username' => $user->getName(),
+                                       'timestamp > ' .
+                                       $dbr->addQuotes( $dbr->timestamp( 
$t_time ) ) ),
+                                       __METHOD__, array( 'LIMIT 1', 'ORDER BY 
timestamp DESC' )
+                               );
+
                                // cache it
                                self::setCache( $user->getName(), $result, 
ONLINESTATUSBAR_NORMAL_CACHE );
                        }
@@ -89,13 +90,16 @@
                        // checking only if we need to do write or not
                        $result = self::getCache( $user->getName(), 
ONLINESTATUSBAR_DELAYED_CACHE );
                        $w_time = OnlineStatusBar::getTimeoutDate( 
ONLINESTATUSBAR_CK_DELAYED );
+
                        if ( $result == '' ) {
                                $dbr = wfGetDB( DB_SLAVE );
-                               $result = $dbr->selectField( 'online_status',
-                                               'timestamp',
-                                               array( 'username' => 
$user->getName() ),
-                                               __METHOD__, array( 'LIMIT 1', 
'ORDER BY timestamp DESC' )
-                                       );
+                               $result = $dbr->selectField(
+                                       'online_status',
+                                       'timestamp',
+                                       array( 'username' => $user->getName() ),
+                                       __METHOD__, array( 'LIMIT 1', 'ORDER BY 
timestamp DESC' )
+                               );
+
                                // cache it
                                if ( $result !== false && $result > 
wfTimestamp( TS_MW, $w_time ) ) {
                                        self::setCache( $user->getName(), 
$result, ONLINESTATUSBAR_DELAYED_CACHE );
@@ -109,16 +113,15 @@
                        // let's check if it isn't anon
                        if ( $user->isLoggedIn() ) {
                                $status = $user->getOption( 
'OnlineStatusBar_status', $wgOnlineStatusBarDefaultOnline );
+
                                if ( $delayed_check ) {
                                        // check if it's old or not
                                        if ( $result < wfTimestamp( TS_MW, 
$w_time ) ) {
                                                $status = 'write';
                                        }
                                } else if ( $user->getOption( 
'OnlineStatusBar_away', true ) == true ) {
-                                       if ( $result < wfTimestamp( TS_MW,
-                                                       
OnlineStatusBar::getTimeoutDate( ONLINESTATUSBAR_CK_AWAY,
-                                                       $user )
-                                               ) ) {
+                                       $timeoutDate = wfTimestamp(     TS_MW, 
OnlineStatusBar::getTimeoutDate( ONLINESTATUSBAR_CK_AWAY, $user ) );
+                                       if ( $result < $timeoutDate ) {
                                                $status = 'away';
                                        }
                                }
@@ -145,10 +148,12 @@
         */
        public static function updateDB() {
                global $wgUser;
+
                // Skip users we don't track
                if ( OnlineStatusBar::isValid ( $wgUser ) != true ) {
                        return false;
                }
+
                // If we track them, let's insert it to the table
                $dbw = wfGetDB( DB_MASTER );
                $timestamp = $dbw->timestamp();
@@ -169,9 +174,11 @@
        static function deleteStatus( $userName ) {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->delete( 'online_status', array( 'username' => $userName 
), __METHOD__ ); // delete user
+
                // remove from cache
                self::setCache( $userName, '', ONLINESTATUSBAR_NORMAL_CACHE );
                self::setCache( $userName, '', ONLINESTATUSBAR_DELAYED_CACHE );
+
                return true;
        }
 
@@ -181,6 +188,7 @@
          */
        public static function updateStatus() {
                global $wgUser, $wgOnlineStatusBarDefaultOffline;
+
                // if anon users are not tracked and user is anon leave it
                if ( !OnlineStatusBar::isValid( $wgUser ) ) {
                        return false;
@@ -213,21 +221,26 @@
         */
        public static function deleteOld() {
                global $wgOnlineStatusBarAutoDelete;
+
                if ( !$wgOnlineStatusBarAutoDelete ) {
                        return 0;
                }
+
                if ( self::getCache( 'null', 'delete' ) == 'true' ) {
                        return 0;
                }
+
                // Check if we actually need to delete something before we 
write to master
                $dbr = wfGetDB( DB_SLAVE );
                $time = OnlineStatusBar::getTimeoutDate();
-               $result = $dbr->selectField( 'online_status',
-                               'timestamp',
-                               array( 'timestamp < ' .
-                               $dbr->addQuotes( $dbr->timestamp( $time ) ) ),
-                               __METHOD__, array( 'LIMIT 1' )
-                       );
+               $result = $dbr->selectField(
+                       'online_status',
+                       'timestamp',
+                       array( 'timestamp < ' .
+                       $dbr->addQuotes( $dbr->timestamp( $time ) ) ),
+                       __METHOD__, array( 'LIMIT 1' )
+               );
+
                if ( $result === false ) {
                        // no need for delete
                        return 0;

Modified: trunk/extensions/OnlineStatusBar/README
===================================================================
--- trunk/extensions/OnlineStatusBar/README     2012-05-25 10:46:29 UTC (rev 
115433)
+++ trunk/extensions/OnlineStatusBar/README     2012-05-25 11:03:05 UTC (rev 
115434)
@@ -1,3 +1,4 @@
 OnlineStatus Bar extension for MediaWiki
 
-This extensions adds a small bar showing user status on userspace of each user 
who enabled it in preferences.
+This extensions adds a small bar showing user status on userspace of each user
+who enabled it in preferences.


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to