r101460 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101459‎ | r101460 | r101461 >
Date:08:48, 1 November 2011
Author:petrb
Status:deferred
Tags:
Comment:
created download for extension in 1.18 branch
Modified paths:
  • /branches/REL1_18/extensions/OnlineStatusBar (added) (history)

Diff [purge]

Index: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -0,0 +1,212 @@
 2+<?
 3+if ( !defined( 'MEDIAWIKI' ) ) {
 4+ echo "This is a part of mediawiki and can't be started separately";
 5+ die();
 6+}
 7+
 8+/**
 9+ * Main file of Online status bar extension.
 10+ *
 11+ * @file
 12+ * @ingroup Extensions
 13+ * @author Petr Bena <benapetr@gmail.com>
 14+ * @author of magic word Alexandre Emsenhuber
 15+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 16+ * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation
 17+ */
 18+
 19+class OnlineStatusBar {
 20+
 21+ public static function getStatusBarHtml( $text ) {
 22+ return <<<HTML
 23+<div class="onlinestatusbarbody metadata onlinestatusbartop" id="status-top">
 24+<div class="onlinestatusbaricon">
 25+$text</div></div>
 26+HTML;
 27+ }
 28+
 29+ /**
 30+ * Returns image element
 31+ *
 32+ * @param $mode String
 33+ * @return string
 34+ */
 35+ public static function GetImageHtml( $mode ) {
 36+ global $wgExtensionAssetsPath, $wgOnlineStatusBarIcon, $wgOnlineStatusBarModes;
 37+ $icon = "$wgExtensionAssetsPath/OnlineStatusBar/{$wgOnlineStatusBarIcon[$mode]}";
 38+ return Html::element( 'img', array( 'src' => $icon ) );
 39+ }
 40+
 41+
 42+ /**
 43+ * Returns the status and User element
 44+ *
 45+ * @param Title $title
 46+ * @return array|bool Array containing the status and User object
 47+ */
 48+ public static function getAnonFromTitle( Title $title ) {
 49+ global $wgOnlineStatusBarTrackIpUsers;
 50+ if ( $wgOnlineStatusBarTrackIpUsers == false ) {
 51+ return false;
 52+ }
 53+
 54+ if ( $title->getNamespace() != NS_USER && $title->getNamespace() != NS_USER_TALK ) {
 55+ return false;
 56+ }
 57+
 58+ $user = User::newFromId( 0 );
 59+ $user->setName( $title->getBaseText() );
 60+
 61+ // Check if something wrong didn't happen
 62+ if ( $user === false ) {
 63+ return false;
 64+ }
 65+
 66+ $status = self::getStatus( $user );
 67+
 68+ return array( $status, $user );
 69+ }
 70+
 71+
 72+ /**
 73+ * Returns the status and User element
 74+ *
 75+ * @param Title $title
 76+ * @return array|bool Array containing the status and User object
 77+ */
 78+ public static function getUserInfoFromTitle( Title $title ) {
 79+ if ( $title->getNamespace() != NS_USER && $title->getNamespace() != NS_USER_TALK ) {
 80+ return false;
 81+ }
 82+
 83+ $user = User::newFromName( $title->getBaseText() );
 84+ // Invalid user
 85+ if ( $user === false ) {
 86+ return false;
 87+ }
 88+ if ( !self::isValid( $user ) ) {
 89+ return false;
 90+ }
 91+
 92+ $status = self::getStatus( $user );
 93+
 94+ return array( $status, $user );
 95+ }
 96+
 97+ /**
 98+ * @param $user User
 99+ * @return String
 100+ */
 101+ public static function getStatus( $user, $update = false ) {
 102+ global $wgOnlineStatusBarDefaultOffline, $wgOnlineStatusBarDefaultOnline;
 103+ // remove old entries
 104+ if ( $update )
 105+ {
 106+ self::DeleteOld();
 107+ }
 108+
 109+ $dbr = wfGetDB( DB_SLAVE );
 110+ $result = $dbr->selectField( 'online_status', 'username', array( 'username' => $user->getName() ),
 111+ __METHOD__, array( 'LIMIT 1', 'ORDER BY timestamp DESC' ) );
 112+
 113+ if ( $result === false ) {
 114+ $status = $wgOnlineStatusBarDefaultOffline;
 115+ } else {
 116+ // let's check if it isn't anon
 117+ if ( $user->isLoggedIn() ) {
 118+ $status = $user->getOption( 'OnlineStatusBar_status', $wgOnlineStatusBarDefaultOnline );
 119+ } else {
 120+ $status = $wgOnlineStatusBarDefaultOnline;
 121+ }
 122+ }
 123+
 124+ if ( $status == 'hidden' ) {
 125+ $status = 'offline';
 126+ }
 127+
 128+ return $status;
 129+ }
 130+
 131+ /**
 132+ * Insert to the database
 133+ * @return bool
 134+ */
 135+ public static function UpdateDb() {
 136+ global $wgUser, $wgOnlineStatusBarDefaultOnline;
 137+ // Skip users we don't track
 138+ if ( self::IsValid ( $wgUser ) != true ) {
 139+ return false;
 140+ }
 141+ // If we track them, let's insert it to the table
 142+ $dbw = wfGetDB( DB_MASTER );
 143+ $row = array(
 144+ 'username' => $wgUser->getName(),
 145+ 'timestamp' => $dbw->timestamp(),
 146+ );
 147+ $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' );
 148+ return false;
 149+ }
 150+
 151+ /**
 152+ * @return bool
 153+ */
 154+ public static function UpdateStatus() {
 155+ global $wgUser, $wgOnlineStatusBarDefaultOffline;
 156+ if ( OnlineStatusBar::GetStatus( $wgUser, true ) == $wgOnlineStatusBarDefaultOffline ) {
 157+ OnlineStatusBar::UpdateDb();
 158+ return true;
 159+ }
 160+
 161+ $dbw = wfGetDB( DB_MASTER );
 162+ $dbw->update(
 163+ 'online_status',
 164+ array( 'timestamp' => $dbw->timestamp() ),
 165+ array( 'username' => $wgUser->getName() ),
 166+ __METHOD__
 167+ );
 168+
 169+ return false;
 170+ }
 171+
 172+ /**
 173+ * @return int
 174+ */
 175+ public static function DeleteOld() {
 176+ global $wgOnlineStatusBar_LogoutTime;
 177+ $dbw = wfGetDB( DB_MASTER );
 178+ // calculate time and convert it back to mediawiki format
 179+ $time = wfTimestamp( TS_UNIX ) - $wgOnlineStatusBar_LogoutTime;
 180+ $dbw->delete( 'online_status', array( "timestamp < " . $dbw->addQuotes( $dbw->timestamp( $time ) ) ), __METHOD__ );
 181+ return 0;
 182+ }
 183+
 184+
 185+ /**
 186+ * Checks to see if the user can be tracked
 187+ *
 188+ * @param User $user
 189+ * @return bool
 190+ */
 191+ public static function isValid( User $user ) {
 192+ global $wgOnlineStatusBarTrackIpUsers, $wgOnlineStatusBarDefaultEnabled;
 193+
 194+ // checks if anon
 195+ if ( $user->isAnon() ) {
 196+ return $wgOnlineStatusBarTrackIpUsers;
 197+ }
 198+
 199+ // do we track them
 200+ return $user->getOption( "OnlineStatusBar_active", $wgOnlineStatusBarDefaultEnabled );
 201+ }
 202+
 203+ /**
 204+ * Delete user who logged out
 205+ * @param $userName string
 206+ * @return bool
 207+ */
 208+ static function DeleteStatus( $userName ) {
 209+ $dbw = wfGetDB( DB_MASTER );
 210+ $dbw->delete( 'online_status', array( 'username' => $userName ), __METHOD__ ); // delete user
 211+ return true;
 212+ }
 213+}
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.body.php
___________________________________________________________________
Added: svn:eol-style
1214 + native
Index: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php
@@ -0,0 +1,176 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for Online status bar extension.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/**
 13+ * English
 14+ * @author Petr Bena
 15+ * @author John Du Hart
 16+ */
 17+$messages['en'] = array(
 18+ // Description
 19+ 'onlinestatusbar-desc' => 'Status bar which shows whether a user is online, based on preferences, on their user page',
 20+ // Status bar text line (User is now Offline) etc.
 21+ 'onlinestatusbar-line' => '$1 is now $2 $3',
 22+ // Message in config asking user if they want to enable it
 23+ 'onlinestatusbar-used' => 'Do you want to let others see if you are online?',
 24+ // Message in config asking what status they want to use
 25+ 'onlinestatusbar-status' => 'What is the default status you wish to use:',
 26+ // Section for config
 27+ 'prefs-onlinestatus' => 'Online status',
 28+ // Message in config
 29+ 'onlinestatusbar-hide' => 'Do you want to hide the status bar in order to use just the magic word? (For advanced users)',
 30+
 31+ 'onlinestatusbar-status-online' => 'On-line',
 32+ 'onlinestatusbar-status-busy' => 'Busy',
 33+ 'onlinestatusbar-status-away' => 'Away',
 34+ 'onlinestatusbar-status-offline' => 'Offline',
 35+ 'onlinestatusbar-status-hidden' => 'Hidden',
 36+);
 37+
 38+/** Message documentation (Message documentation)
 39+ * @author John Du Hart
 40+ * @author Petr Bena
 41+ */
 42+$messages['qqq'] = array(
 43+ 'onlinestatusbar-desc' => '{{desc}}',
 44+ 'onlinestatusbar-line' => 'Status bar text line (User is now Offline), parameters:
 45+* $1 is user
 46+* $2 is a picture of status (small icon in color of status)
 47+* $3 a status, it will appear in title bar of their user space pages',
 48+ 'onlinestatusbar-used' => 'Message in config asking user if they want to enable it, checkbox',
 49+ 'onlinestatusbar-status' => 'Message in config asking what status they want to use, option box',
 50+ 'prefs-onlinestatus' => 'Section for config, located in preferences - misc',
 51+ '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',
 52+ 'onlinestatusbar-status-online' => 'Status for users who mark themselves as active',
 53+ 'onlinestatusbar-status-busy' => 'Status for users who mark themselves as busy',
 54+ 'onlinestatusbar-status-away' => 'Status for users who mark themselves as away',
 55+ 'onlinestatusbar-status-offline' => 'Status for users who are offline',
 56+ 'onlinestatusbar-status-hidden' => 'Status for users who mark themselves as hidden (used on preferences only)',
 57+);
 58+
 59+/** German (Deutsch)
 60+ * @author Kghbln
 61+ */
 62+$messages['de'] = array(
 63+ 'onlinestatusbar-desc' => 'Ermöglicht, abhängig von der Benutzereinstellung, die Anzeige des Onlinestatus eines Benutzers auf dessen Benutzerseite',
 64+ 'onlinestatusbar-line' => '$1 ist gerade $3 $2',
 65+ 'onlinestatusbar-used' => 'Möchtest du, dass andere Benutzer deinen Onlinestatus sehen?',
 66+ 'onlinestatusbar-status' => 'Welchen Status möchtest du standardmäßig nutzen:',
 67+ 'prefs-onlinestatus' => 'Onlinestatus',
 68+ 'onlinestatusbar-hide' => "Möchtest du die Statusleiste ausblenden, um stattdessen lediglich das ''Magic Word'' zu nutzen? (Für Fortgeschrittene)",
 69+ 'onlinestatusbar-status-online' => 'Online',
 70+ 'onlinestatusbar-status-busy' => 'Beschäftigt',
 71+ 'onlinestatusbar-status-away' => 'Abwesend',
 72+ 'onlinestatusbar-status-offline' => 'Offline',
 73+ 'onlinestatusbar-status-hidden' => 'Versteckt',
 74+);
 75+
 76+/** German (formal address) (‪Deutsch (Sie-Form)‬)
 77+ * @author Kghbln
 78+ */
 79+$messages['de-formal'] = array(
 80+ 'onlinestatusbar-used' => 'Möchten Sie, dass andere Benutzer Ihren Onlinestatus sehen?',
 81+ 'onlinestatusbar-status' => 'Welchen Status möchten Sie standardmäßig nutzen:',
 82+ 'onlinestatusbar-hide' => "Möchten Sie die Statusleiste ausblenden, um stattdessen lediglich das ''Magic Word'' zu nutzen? (Für Fortgeschrittene)",
 83+);
 84+
 85+/** French (Français)
 86+ * @author DavidL
 87+ */
 88+$messages['fr'] = array(
 89+ 'onlinestatusbar-desc' => "Barre d'état montrant si un utilisateur est en ligne, basé sur les préférences, sur leur page utilisateur",
 90+ 'onlinestatusbar-line' => '$1 est maintenant $2 $3',
 91+ 'onlinestatusbar-used' => 'Voulez-vous permettre que les autres voient si vous êtes en ligne ?',
 92+ 'onlinestatusbar-status' => 'Quel est le statut par défaut que vous souhaitez utiliser :',
 93+ 'prefs-onlinestatus' => 'État en ligne',
 94+ 'onlinestatusbar-hide' => "Voulez-vous masquer la barre d'état afin d'utiliser le mot magique seulement ? (Pour les utilisateurs avancés)",
 95+);
 96+
 97+/** Galician (Galego)
 98+ * @author Toliño
 99+ */
 100+$messages['gl'] = array(
 101+ 'onlinestatusbar-desc' => 'Barra de estado que mostra na páxina de usuario se un usuario está conectado',
 102+ 'onlinestatusbar-line' => '$1 está $2 $3 nestes intres',
 103+ 'onlinestatusbar-used' => 'Quere deixar que os outros poidan ver se está conectado?',
 104+ 'onlinestatusbar-status' => 'Cal é o estado por defecto que quere usar:',
 105+ 'prefs-onlinestatus' => 'Conectado',
 106+ 'onlinestatusbar-hide' => 'Quere agochar a barra de estado para usar unicamente a palabra máxica? (Para usuarios avanzados)',
 107+ 'onlinestatusbar-status-online' => 'Conectado',
 108+ 'onlinestatusbar-status-busy' => 'Ocupado',
 109+ 'onlinestatusbar-status-away' => 'Non dispoñible',
 110+ 'onlinestatusbar-status-offline' => 'Desconectado',
 111+ 'onlinestatusbar-status-hidden' => 'Agochado',
 112+);
 113+
 114+/** Upper Sorbian (Hornjoserbsce)
 115+ * @author Michawiki
 116+ */
 117+$messages['hsb'] = array(
 118+ 'onlinestatusbar-line' => '$1 je nětko $3 $2',
 119+ 'prefs-onlinestatus' => 'Onlinestatus',
 120+ 'onlinestatusbar-status-online' => 'Online',
 121+ 'onlinestatusbar-status-busy' => 'Ma dźěło',
 122+ 'onlinestatusbar-status-away' => 'Preč',
 123+ 'onlinestatusbar-status-offline' => 'Offline',
 124+ 'onlinestatusbar-status-hidden' => 'Schowany',
 125+);
 126+
 127+/** Luxembourgish (Lëtzebuergesch)
 128+ * @author Robby
 129+ */
 130+$messages['lb'] = array(
 131+ 'onlinestatusbar-line' => '$1 ass elo $2 $3',
 132+ 'onlinestatusbar-used' => 'Wëllt dir datt Anerer kënne gesinn op Dir online sidd?',
 133+ 'onlinestatusbar-status-busy' => 'Beschäftegt',
 134+ 'onlinestatusbar-status-away' => 'Net do',
 135+ 'onlinestatusbar-status-hidden' => 'Verstoppt',
 136+);
 137+
 138+/** Macedonian (Македонски)
 139+ * @author Bjankuloski06
 140+ */
 141+$messages['mk'] = array(
 142+ 'onlinestatusbar-desc' => 'Статусник што прикажува дали корисникот е на линија, зависно од нагодувањата на корисничката страница',
 143+ 'onlinestatusbar-line' => '$1 сега е $2 $3',
 144+ 'onlinestatusbar-used' => 'Дали сакате другите да знаат кога сте на линија?',
 145+ 'onlinestatusbar-status' => 'Вашиот статус по основно:',
 146+ 'prefs-onlinestatus' => 'Вклученост',
 147+ 'onlinestatusbar-hide' => 'Дали би сакале да го скриете статусникот за да го користите само волшебниот збор (за напредни корисници)',
 148+ 'onlinestatusbar-status-online' => 'Вклучен',
 149+ 'onlinestatusbar-status-busy' => 'Зафатен',
 150+ 'onlinestatusbar-status-away' => 'Отсутен',
 151+ 'onlinestatusbar-status-offline' => 'Исклучен',
 152+ 'onlinestatusbar-status-hidden' => 'Скриен',
 153+);
 154+
 155+/** Dutch (Nederlands)
 156+ * @author Siebrand
 157+ */
 158+$messages['nl'] = array(
 159+ 'onlinestatusbar-line' => '$1 is nu $2 $3',
 160+ 'onlinestatusbar-used' => 'Wilt u andere gebruikers laten zien dat u online bent?',
 161+ 'onlinestatusbar-status' => 'Welke standaard status wilt u gebruiken:',
 162+ 'prefs-onlinestatus' => 'Onlinestatus',
 163+ 'onlinestatusbar-hide' => 'Wilt u de statusbalk verbergen en alleen het magische woord gebruiken (voor gevorderde gebruikers)?',
 164+ 'onlinestatusbar-status-online' => 'Online',
 165+ 'onlinestatusbar-status-busy' => 'Druk',
 166+ 'onlinestatusbar-status-away' => 'Weg',
 167+ 'onlinestatusbar-status-offline' => 'Offline',
 168+ 'onlinestatusbar-status-hidden' => 'Verborgen',
 169+);
 170+
 171+/** Telugu (తెలుగు)
 172+ * @author Veeven
 173+ */
 174+$messages['te'] = array(
 175+ 'onlinestatusbar-used' => 'మీరు ఆన్‌లైనులో ఉన్నట్టు ఇతరులుకు చూపించాలా?',
 176+);
 177+
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php
___________________________________________________________________
Added: svn:eol-style
1178 + native
Index: branches/REL1_18/extensions/OnlineStatusBar/statusred.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/statusred.png
___________________________________________________________________
Added: svn:mime-type
2179 + image/png
Index: branches/REL1_18/extensions/OnlineStatusBar/statusorange.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/statusorange.png
___________________________________________________________________
Added: svn:mime-type
3180 + image/png
Index: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -0,0 +1,68 @@
 2+<?php
 3+/**
 4+ * Insert a special box on user page showing their status.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @author Petr Bena <benapetr@gmail.com>
 9+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 10+ * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ echo "This is a part of mediawiki and can't be started separately";
 15+ die();
 16+}
 17+
 18+$wgExtensionCredits[version_compare( $wgVersion, '1.17', '>=' ) ? 'userpage tools' : 'other'][] = array(
 19+ 'path' => __FILE__,
 20+ 'name' => 'Online status bar',
 21+ 'version' => '1.0.0',
 22+ 'author' => array( 'Petr Bena' ),
 23+ 'descriptionmsg' => 'onlinestatusbar-desc',
 24+ 'url' => 'http://www.mediawiki.org/wiki/Extension:OnlineStatusBar',
 25+);
 26+
 27+$dir = dirname( __FILE__ );
 28+$wgExtensionMessagesFiles['OnlineStatusBar'] = "$dir/OnlineStatusBar.i18n.php";
 29+
 30+$wgResourceModules['ext.OnlineStatusBar'] = array (
 31+ 'styles' => 'OnlineStatusBar.css',
 32+ 'localBasePath' => dirname ( __FILE__ ),
 33+ 'remoteExtPath' => 'OnlineStatusBar',
 34+);
 35+
 36+$wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php";
 37+$wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBarHooks.php";
 38+
 39+// Configuration
 40+// Those values can be overriden in LocalSettings, do not change it here
 41+$wgOnlineStatusBarIcon = array(
 42+ 'online' => "statusgreen.png",
 43+ 'busy' => "statusorange.png",
 44+ 'away' => "statusorange.png",
 45+ 'hidden' => "statusred.png",
 46+ 'offline' => "statusred.png",
 47+);
 48+
 49+// default for anonymous and uknown users
 50+$wgOnlineStatusBarTrackIpUsers = false;
 51+// default for online
 52+$wgOnlineStatusBarDefaultOnline = "online";
 53+// default for offline
 54+$wgOnlineStatusBarDefaultOffline = "offline";
 55+// if users have this feature enabled by default
 56+$wgOnlineStatusBarDefaultEnabled = false;
 57+// how long to wait until user is considered as offline
 58+$wgOnlineStatusBar_LogoutTime = 3600;
 59+
 60+$wgHooks['LoadExtensionSchemaUpdates'][] = 'OnlineStatusBarHooks::ckSchema';
 61+$wgHooks['UserLogoutComplete'][] = 'OnlineStatusBarHooks::logout';
 62+$wgHooks['ArticleViewHeader'][] = 'OnlineStatusBarHooks::renderBar';
 63+$wgHooks['UserLoginComplete'][] = 'OnlineStatusBarHooks::updateStatus';
 64+$wgHooks['GetPreferences'][] = 'OnlineStatusBarHooks::preferencesHook';
 65+$wgHooks['UserGetDefaultOptions'][] = 'OnlineStatusBarHooks::setDefaultOptions';
 66+$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBarHooks::magicWordVar';
 67+$wgHooks['BeforePageDisplay'][] = 'OnlineStatusBarHooks::stylePage';
 68+$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBarHooks::magicWordSet';
 69+$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBarHooks::parserGetVariable';
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.php
___________________________________________________________________
Added: svn:eol-style
170 + native
Index: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.css
@@ -0,0 +1,24 @@
 2+/*
 3+This is a part of css used on english wp, it's needed for wikis
 4+where topicon isn't defined
 5+*/
 6+div.onlinestatusbartop {
 7+ position: absolute;
 8+ top: -2em;
 9+ margin-right: -10px;
 10+ display: block !important;
 11+}
 12+
 13+div.onlinestatusbaricon {
 14+ border: 0px solid black;
 15+ background: transparent;
 16+ float: right;
 17+ position: relative;
 18+ top: 0px;
 19+ padding: 5px;
 20+}
 21+
 22+div.onlinestatusbarbody {
 23+ right:0px;
 24+ margin-top:-10px;
 25+}
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.css
___________________________________________________________________
Added: svn:eol-style
126 + native
Index: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
@@ -0,0 +1,170 @@
 2+<?php
 3+
 4+/**
 5+ * Hooks for OnlineStatusBar
 6+ *
 7+ * @group Extensions
 8+ */
 9+class OnlineStatusBarHooks {
 10+ /**
 11+ * @param DatabaseUpdater|null $updater
 12+ * @return bool
 13+ */
 14+ public static function ckSchema( $updater = null ) {
 15+ if ( $updater !== null ) {
 16+ $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
 17+ } else {
 18+ global $wgExtNewTables;
 19+ $wgExtNewTables[] = array(
 20+ 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' );
 21+ }
 22+ return true;
 23+ }
 24+
 25+ /**
 26+ * @param $user User
 27+ * @param $inject_html string
 28+ * @param $old_name string
 29+ * @return bool
 30+ */
 31+ public static function logout( &$user, &$inject_html, $old_name ) {
 32+ OnlineStatusBar::DeleteStatus( $old_name );
 33+ return true;
 34+ }
 35+
 36+ /**
 37+ * Called everytime when it's needed to update db
 38+ * @return bool
 39+ */
 40+ public static function updateStatus() {
 41+ OnlineStatusBar::UpdateDb();
 42+ return true;
 43+ }
 44+
 45+ /**
 46+ * Creates a bar
 47+ * @param $article Article
 48+ * @param $outputDone bool
 49+ * @param $pcache string
 50+ * @return bool
 51+ */
 52+ public static function renderBar( &$article, &$outputDone, &$pcache ) {
 53+ $context = $article->getContext();
 54+
 55+ OnlineStatusBar::UpdateStatus();
 56+ $result = OnlineStatusBar::getUserInfoFromTitle( $article->getTitle() );
 57+ if ( $result === false && User::isIP ( $article->getTitle()->getBaseText() ) ) {
 58+ $result = OnlineStatusBar::getAnonFromTitle( $article->getTitle() );
 59+ }
 60+
 61+ if ( $result === false ) {
 62+ return true;
 63+ }
 64+
 65+ /** @var $user User */
 66+ list( $status, $user ) = $result;
 67+
 68+ // Don't display status of those who have opted out
 69+ if ( $user->getOption( 'OnlineStatusBar_hide' ) == true ) {
 70+ return true;
 71+ }
 72+
 73+ $modetext = wfMessage( 'onlinestatusbar-status-' . $status )->toString();
 74+ $image = OnlineStatusBar::getImageHtml( $status );
 75+ $text = wfMessage( 'onlinestatusbar-line', $user->getName() )
 76+ ->rawParams( $image )->params( $modetext )->escaped();
 77+ $context->getOutput()->addHtml( OnlineStatusBar::getStatusBarHtml( $text ) );
 78+
 79+ return true;
 80+ }
 81+
 82+ /**
 83+ * Insert user options
 84+ * @param $user User
 85+ * @param $preferences array
 86+ * @return bool
 87+ */
 88+ public static function preferencesHook( User $user, array &$preferences ) {
 89+ global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
 90+ $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' );
 91+ $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' );
 92+ $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
 93+ 'options' => array(
 94+ wfMessage( 'onlinestatusbar-status-online' )->escaped() => 'online',
 95+ wfMessage( 'onlinestatusbar-status-busy' )->escaped() => 'busy',
 96+ wfMessage( 'onlinestatusbar-status-away' )->escaped() => 'away',
 97+ wfMessage( 'onlinestatusbar-status-hidden' )->escaped() => 'hidden'
 98+ ),
 99+ );
 100+ return true;
 101+ }
 102+
 103+ /**
 104+ * @param $defaultOptions array
 105+ * @return bool
 106+ */
 107+ public static function setDefaultOptions( &$defaultOptions ) {
 108+ global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled;
 109+ // set defaults
 110+ $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
 111+ $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
 112+ $defaultOptions['OnlineStatusBar_hide'] = false;
 113+ // quit
 114+ return true;
 115+ }
 116+
 117+ /**
 118+ * @param $magicWords array
 119+ * @param $ln string (language)
 120+ * @return bool
 121+ */
 122+ public static function magicWordVar( array &$magicWords, $ln ) {
 123+ $magicWords['isonline'] = array( 0, 'isonline' );
 124+ return true;
 125+ }
 126+
 127+ /**
 128+ * @param $out OutputPage
 129+ * @param $skin Skin
 130+ * @return bool
 131+ */
 132+ public static function stylePage( &$out, &$skin ) {
 133+ $out->addModules( 'ext.OnlineStatusBar' );
 134+ return true;
 135+ }
 136+
 137+ /**
 138+ * @param $vars array
 139+ * @return bool
 140+ */
 141+ public static function magicWordSet( &$vars ) {
 142+ $vars[] = 'isonline';
 143+ return true;
 144+ }
 145+
 146+ /**
 147+ * @param $parser Parser
 148+ * @param $varCache ??
 149+ * @param $index ??
 150+ * @param $ret string?
 151+ * @return bool
 152+ */
 153+ public static function parserGetVariable( &$parser, &$varCache, &$index, &$ret ) {
 154+ if ( $index != 'isonline' ) {
 155+ return true;
 156+ }
 157+
 158+ $result = OnlineStatusBar::getUserInfoFromTitle( $parser->getTitle() );
 159+ if ( User::isIP( $parser->getTitle()->getBaseText() ) && $result == null ) {
 160+ $result = OnlineStatusBar::getAnonFromTitle( $parser->getTitle() );
 161+ }
 162+
 163+ if ( $result == false ) {
 164+ $ret = "unknown";
 165+ return true;
 166+ }
 167+
 168+ $ret = $result[0];
 169+ return true;
 170+ }
 171+}
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
___________________________________________________________________
Added: svn:eol-style
1172 + native
Index: branches/REL1_18/extensions/OnlineStatusBar/statusgreen.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/statusgreen.png
___________________________________________________________________
Added: svn:mime-type
2173 + image/png
Index: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.sql
@@ -0,0 +1,6 @@
 2+CREATE TABLE /*$wgDBprefix*/online_status (
 3+ `username` varchar(255) NOT NULL default '',
 4+ `timestamp` char(14) NOT NULL default '',
 5+ PRIMARY KEY USING HASH (`username`)
 6+) ENGINE=MEMORY;
 7+
Property changes on: branches/REL1_18/extensions/OnlineStatusBar/OnlineStatusBar.sql
___________________________________________________________________
Added: svn:eol-style
18 + native

Status & tagging log