r100997 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100996‎ | r100997 | r100998 >
Date:16:20, 27 October 2011
Author:johnduhart
Status:deferred (Comments)
Tags:
Comment:
Moved hooks into their own class
This undoes something from r100996 but I need to run
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php (added) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.body.php
@@ -34,25 +34,6 @@
3535 return Html::element( 'img', array( 'src' => $icon ) );
3636 }
3737
38 - public static function ParserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
39 - global $wgOnlineStatusBarModes;
40 - if( $index == 'isonline' ){
41 - $name = self::GetOwnerFromTitle ( $parser->getTitle() )->getName();
42 -
43 - if ( self::IsValid($name) != true ) {
44 - $ret = "unknown";
45 - return true;
46 - }
47 - $ret = $wgOnlineStatusBarModes[self::GetStatus( $name )];
48 - }
49 - return true;
50 - }
51 -
52 - public static function StylePage ( &$out, &$skin ) {
53 - $out->addModules ( 'ext.OnlineStatusBar' );
54 - return true;
55 - }
56 -
5738 public static function GetNow() {
5839 return gmdate( 'Ymdhis', time() );
5940 }
@@ -73,7 +54,7 @@
7455 $dbw = wfGetDB( DB_MASTER );
7556 $row = array(
7657 'username' => $wgUser->getName(),
77 - 'timestamp' => $dbw->timestamp( wfTimestamp() ),
 58+ 'timestamp' => $dbw->timestamp( wfTimestamp() ), /// fixme
7859 );
7960 $dbw->insert( 'online_status', $row, __METHOD__, 'DELAYED' );
8061 }
@@ -81,17 +62,6 @@
8263 return false;
8364 }
8465
85 - public static function MagicWordSet ( &$vars ) {
86 - $vars[] = 'isonline';
87 - return true;
88 - }
89 -
90 - public static function MagicWordVar ( &$magicWords, $ln ) {
91 - $magicWords['isonline'] = array ( 0, 'isonline' );
92 -
93 - return true;
94 - }
95 -
9666 public static function UpdateStatus() {
9767 global $wgUser, $wgOnlineStatusBarDefaultOffline;
9868 if ( OnlineStatusBar::GetStatus( $wgUser->getName() ) == $wgOnlineStatusBarDefaultOffline ) {
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.php
@@ -1,9 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) {
4 - echo "This is a part of mediawiki and can't be started separately";
5 - die();
6 -}
7 -
83 /**
94 * Insert a special box on user page showing their status.
105 *
@@ -14,6 +9,11 @@
1510 * @link http://www.mediawiki.org/wiki/Extension:OnlineStatusBar Documentation
1611 */
1712
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ echo "This is a part of mediawiki and can't be started separately";
 15+ die();
 16+}
 17+
1818 $wgExtensionCredits[version_compare( $wgVersion, '1.17', '>=' ) ? 'userpage tools' : 'other'][] = array(
1919 'path' => __FILE__,
2020 'name' => 'Online status bar',
@@ -30,9 +30,10 @@
3131 'styles' => 'OnlineStatusBar.css',
3232 'localBasePath' => dirname ( __FILE__ ),
3333 'remoteExtPath' => 'OnlineStatusBar',
34 - );
 34+);
3535
3636 $wgAutoloadClasses['OnlineStatusBar'] = "$dir/OnlineStatusBar.body.php";
 37+$wgAutoloadClasses['OnlineStatusBarHooks'] = "$dir/OnlineStatusBarHooks.php";
3738
3839 // Configuration
3940 // Those values can be overriden in LocalSettings, do not change it here
@@ -69,83 +70,13 @@
7071 // how long to wait until user is considered as offline
7172 $wgOnlineStatusBar_LogoutTime = 3600;
7273
73 -$wgHooks['LoadExtensionSchemaUpdates'][] = 'wfOnlineStatusBar_CkSchema';
74 -function wfOnlineStatusBar_CkSchema( $updater = null ) {
75 - if ( $updater !== null ){
76 - $updater->addExtensionUpdate( array( 'addtable', 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql', true ) );
77 - } else {
78 - global $wgExtNewTables;
79 - $wgExtNewTables[] = array(
80 - 'online_status', dirname( __FILE__ ) . '/OnlineStatusBar.sql' );
81 - }
82 - return true;
83 -}
84 -
85 -$wgHooks['UserLogoutComplete'][] = 'wfOnlineStatusBar_Logout';
86 -function wfOnlineStatusBar_Logout( &$user, &$inject_html, $old_name ) {
87 - OnlineStatusBar::DeleteStatus( $old_name );
88 - return true;
89 -}
90 -
91 -$wgHooks['ArticleViewHeader'][] = 'wfOnlineStatusBar_RenderBar';
92 -function wfOnlineStatusBar_RenderBar( &$article, &$outputDone, &$pcache ) {
93 - global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut;
94 - OnlineStatusBar::UpdateStatus();
95 - $ns = $article->getTitle()->getNamespace();
96 - if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
97 - $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
98 - if ( $user == null ) {
99 - return true;
100 - }
101 - $username = $user->getName();
102 - if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
103 - return true;
104 - }
105 - if ( OnlineStatusBar::IsValid( $username ) ) {
106 - $mode = OnlineStatusBar::GetStatus( $username );
107 - $modetext = $wgOnlineStatusBarModes[$mode];
108 - $image = OnlineStatusBar::getImageHtml( $mode );
109 - $text = wfMessage( 'onlinestatusbar-line', $username )->rawParams( $image )->params( $modetext )->escaped();
110 - $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
111 - }
112 - }
113 - return true;
114 -}
115 -
116 -$wgHooks['UserLoginComplete'][] = 'wfOnlineStatusBar_UpdateStatus';
117 -function wfOnlineStatusBar_UpdateStatus() {
118 - OnlineStatusBar::UpdateDb();
119 - return true;
120 -}
121 -
122 -$wgHooks['GetPreferences'][] = 'wfOnlineStatusBar_PreferencesHook';
123 -function wfOnlineStatusBar_PreferencesHook( $user, &$preferences ) {
124 - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
125 - $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' );
126 - $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' );
127 - $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
128 - 'options' => array(
129 - $wgOnlineStatusBarModes['online'] => 'online',
130 - $wgOnlineStatusBarModes['busy'] => 'busy',
131 - $wgOnlineStatusBarModes['away'] => 'away',
132 - $wgOnlineStatusBarModes['hidden'] => 'hidden'
133 - ),
134 - );
135 - return true;
136 -}
137 -
138 -$wgHooks['UserGetDefaultOptions'][] = 'wfOnlineStatusBar_SetDefaultOptions';
139 -function wfOnlineStatusBar_SetDefaultOptions( &$defaultOptions ) {
140 - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled;
141 - // set defaults
142 - $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
143 - $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
144 - $defaultOptions['OnlineStatusBar_hide'] = false;
145 - // quit
146 - return true;
147 -}
148 -
149 -$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBar::MagicWordVar';
150 -$wgHooks['BeforePageDisplay'][] = 'OnlineStatusBar::StylePage';
151 -$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBar::MagicWordSet';
152 -$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBar::ParserGetVariable';
 74+$wgHooks['LoadExtensionSchemaUpdates'][] = 'OnlineStatusBarHooks::ckSchema';
 75+$wgHooks['UserLogoutComplete'][] = 'OnlineStatusBarHooks::logout';
 76+$wgHooks['ArticleViewHeader'][] = 'OnlineStatusBarHooks::renderBar';
 77+$wgHooks['UserLoginComplete'][] = 'OnlineStatusBarHooks::updateStatus';
 78+$wgHooks['GetPreferences'][] = 'OnlineStatusBarHooks::preferencesHook';
 79+$wgHooks['UserGetDefaultOptions'][] = 'OnlineStatusBarHooks::setDefaultOptions';
 80+$wgHooks['LanguageGetMagic'][] = 'OnlineStatusBarHooks::magicWordVar';
 81+$wgHooks['BeforePageDisplay'][] = 'OnlineStatusBarHooks::stylePage';
 82+$wgHooks['MagicWordwgVariableIDs'][] = 'OnlineStatusBarHooks::magicWordSet';
 83+$wgHooks['ParserGetVariableValueSwitch'][] = 'OnlineStatusBarHooks::parserGetVariable';
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
@@ -0,0 +1,157 @@
 2+<?php
 3+
 4+/**
 5+ * Hooks for OnlineStatusBar
 6+ *
 7+ * @group Extensions
 8+ */
 9+class OnlineStatusBarHooks {
 10+ /**
 11+ * @param DatabaseUpdate|null $updater
 12+ * @return bool
 13+ */
 14+ public static function ckSchema( $updater = null ) {
 15+ if ( ( $updater === null ) != true ){
 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+ * @return bool
 38+ */
 39+ public static function updateStatus() {
 40+ OnlineStatusBar::UpdateDb();
 41+ return true;
 42+ }
 43+
 44+ /**
 45+ * @param $article Article
 46+ * @param $outputDone bool
 47+ * @param $pcache string
 48+ * @return bool
 49+ */
 50+ public static function renderBar( &$article, &$outputDone, &$pcache ) {
 51+ global $wgOnlineStatusBar_Template, $messages, $wgOnlineStatusBarModes, $wgOut;
 52+ OnlineStatusBar::UpdateStatus();
 53+ $ns = $article->getTitle()->getNamespace();
 54+ if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
 55+ $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
 56+ if ( $user === null ) {
 57+ return true;
 58+ }
 59+ $username = $user->getName();
 60+ if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
 61+ return true;
 62+ }
 63+ if ( OnlineStatusBar::IsValid( $username ) ) {
 64+ $mode = OnlineStatusBar::GetStatus( $username );
 65+ $modetext = $wgOnlineStatusBarModes[$mode];
 66+ $image = OnlineStatusBar::getImageHtml( $mode );
 67+ $text = wfMessage( 'onlinestatusbar-line', $username )->rawParams( $image )->params( $modetext )->escaped();
 68+ $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
 69+ }
 70+ }
 71+ return true;
 72+ }
 73+
 74+ /**
 75+ * @param $user User
 76+ * @paramNireferences array
 77+ * @return bool
 78+ */
 79+ public static function preferencesHook( User $user, array &$preferences ) {
 80+ global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
 81+ $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' );
 82+ $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' );
 83+ $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
 84+ 'options' => array(
 85+ $wgOnlineStatusBarModes['online'] => 'online',
 86+ $wgOnlineStatusBarModes['busy'] => 'busy',
 87+ $wgOnlineStatusBarModes['away'] => 'away',
 88+ $wgOnlineStatusBarModes['hidden'] => 'hidden'
 89+ ),
 90+ );
 91+ return true;
 92+ }
 93+
 94+ /**
 95+ * @param $defaultOptions array
 96+ * @return bool
 97+ */
 98+ public static function setDefaultOptions( &$defaultOptions ) {
 99+ global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled;
 100+ // set defaults
 101+ $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
 102+ $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
 103+ $defaultOptions['OnlineStatusBar_hide'] = false;
 104+ // quit
 105+ return true;
 106+ }
 107+
 108+ /**
 109+ * @param $magicWords array
 110+ * @param $ln string?
 111+ * @return bool
 112+ */
 113+ public static function magicWordVar ( array &$magicWords, $ln ) {
 114+ $magicWords['isonline'] = array ( 0, 'isonline' );
 115+
 116+ return true;
 117+ }
 118+
 119+ /**
 120+ * @param $out OutputPage
 121+ * @param $skin Skin
 122+ * @return bool
 123+ */
 124+ public static function stylePage ( &$out, &$skin ) {
 125+ $out->addModules( 'ext.OnlineStatusBar' );
 126+ return true;
 127+ }
 128+
 129+ /**
 130+ * @param $vars array
 131+ * @return bool
 132+ */
 133+ public static function magicWordSet ( &$vars ) {
 134+ $vars[] = 'isonline';
 135+ return true;
 136+ }
 137+
 138+ /**
 139+ * @param $parser Parser
 140+ * @param $varCache ??
 141+ * @param $index ??
 142+ * @param $ret string?
 143+ * @return bool
 144+ */
 145+ public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
 146+ global $wgOnlineStatusBarModes;
 147+ if( $index == 'isonline' ){
 148+ $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
 149+
 150+ if ( OnlineStatusBar::IsValid($name) != true ) {
 151+ $ret = "unknown";
 152+ return true;
 153+ }
 154+ $ret = $wgOnlineStatusBarModes[OnlineStatusBar::GetStatus( $name )];
 155+ }
 156+ return true;
 157+ }
 158+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r101018svn:eol-style nativejohnduhart18:33, 27 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100996fixed === and == :)petrb16:14, 27 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   06:26, 28 October 2011

svn:eol-style

#Comment by Johnduhart (talk | contribs)   15:53, 28 October 2011

Fixed in r101018

Status & tagging log