r101018 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101017‎ | r101018 | r101019 >
Date:18:33, 27 October 2011
Author:johnduhart
Status:resolved (Comments)
Tags:
Comment:
svn:eol-style native
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php (modified) (history)
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.i18n.php
@@ -25,6 +25,10 @@
2626 'prefs-onlinestatus' => 'Online status',
2727 // Message in config
2828 'onlinestatusbar-hide' => 'Do you want to hide the status bar in order to use just the magic word? (For advanced users)',
 29+ 'onlinestatusbar-status-online' => 'On-line',
 30+ 'onlinestatusbar-status-busy' => 'Busy',
 31+ 'onlinestatusbar-status-away' => 'Away',
 32+ 'onlinestatusbar-status-offline' => 'Offline',
2933 );
3034
3135 $messages['qqq'] = array(
Index: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
@@ -1,179 +1,179 @@
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 ){
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, $wgOnlineStatusBarDefaultIpUsers, $wgOnlineStatusBarModes, $wgOut;
52 - OnlineStatusBar::UpdateStatus();
53 - $anon = false;
54 - $ns = $article->getTitle()->getNamespace();
55 - if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
56 - $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
57 - $userName = $article->getTitle()->getBaseText();
58 - if ( User::isIP ( $userName ) != true && $user == null ) {
59 - return true;
60 - }
61 - if ( User::isIP ( $userName ) && $user == null && $wgOnlineStatusBarDefaultIpUsers ) {
62 - // it's anon user and we want to track them
63 - $sanitizedusername = $userName;
64 - $anon = true;
65 - } else if ( $user != null ) {
66 - // Fix capitalisation issues
67 - $sanitizedusername = $user->getName();
68 - } else {
69 - return true;
70 - }
71 - if ( $anon == false )
72 - {
73 - //we don't want to check this
74 - if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
75 - return true;
76 - }
77 - }
78 - if ( OnlineStatusBar::IsValid( $userName ) ) {
79 - $mode = OnlineStatusBar::GetStatus( $userName );
80 - $modetext = $wgOnlineStatusBarModes[$mode];
81 - $image = OnlineStatusBar::getImageHtml( $mode );
82 - $text = wfMessage( 'onlinestatusbar-line', $userName )->rawParams( $image )->params( $modetext )->escaped();
83 - $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
84 - }
85 - }
86 - return true;
87 - }
88 -
89 - /**
90 - * @param $user User
91 - * @paramNireferences array
92 - * @return bool
93 - */
94 - public static function preferencesHook( User $user, array &$preferences ) {
95 - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
96 - $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' );
97 - $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' );
98 - $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
99 - 'options' => array(
100 - $wgOnlineStatusBarModes['online'] => 'online',
101 - $wgOnlineStatusBarModes['busy'] => 'busy',
102 - $wgOnlineStatusBarModes['away'] => 'away',
103 - $wgOnlineStatusBarModes['hidden'] => 'hidden'
104 - ),
105 - );
106 - return true;
107 - }
108 -
109 - /**
110 - * @param $defaultOptions array
111 - * @return bool
112 - */
113 - public static function setDefaultOptions( &$defaultOptions ) {
114 - global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled;
115 - // set defaults
116 - $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
117 - $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
118 - $defaultOptions['OnlineStatusBar_hide'] = false;
119 - // quit
120 - return true;
121 - }
122 -
123 - /**
124 - * @param $magicWords array
125 - * @param $ln string?
126 - * @return bool
127 - */
128 - public static function magicWordVar ( array &$magicWords, $ln ) {
129 - $magicWords['isonline'] = array ( 0, 'isonline' );
130 - return true;
131 - }
132 -
133 - /**
134 - * @param $out OutputPage
135 - * @param $skin Skin
136 - * @return bool
137 - */
138 - public static function stylePage ( &$out, &$skin ) {
139 - $out->addModules( 'ext.OnlineStatusBar' );
140 - return true;
141 - }
142 -
143 - /**
144 - * @param $vars array
145 - * @return bool
146 - */
147 - public static function magicWordSet ( &$vars ) {
148 - $vars[] = 'isonline';
149 - return true;
150 - }
151 -
152 - /**
153 - * @param $parser Parser
154 - * @param $varCache ??
155 - * @param $index ??
156 - * @param $ret string?
157 - * @return bool
158 - */
159 - public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
160 - global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline;
161 - if( $index == 'isonline' ){
162 - $ns = $parser->getTitle()->getNamespace();
163 - if ( ( $ns != NS_USER_TALK ) && ( $ns != NS_USER ) ) {
164 - $ret = "unknown";
165 - return true;
166 - }
167 - $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
168 -
169 - if ( OnlineStatusBar::IsValid($name) != true ) {
170 - $ret = "unknown";
171 - return true;
172 - }
173 - $ret = OnlineStatusBar::GetStatus( $name );
174 - if ( $ret == "hidden" ) {
175 - $ret = $wgOnlineStatusBarDefaultOffline;
176 - }
177 - }
178 - return true;
179 - }
180 -}
 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 ){
 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, $wgOnlineStatusBarDefaultIpUsers, $wgOnlineStatusBarModes, $wgOut;
 52+ OnlineStatusBar::UpdateStatus();
 53+ $anon = false;
 54+ $ns = $article->getTitle()->getNamespace();
 55+ if ( ( $ns == NS_USER_TALK ) || ( $ns == NS_USER ) ) {
 56+ $user = OnlineStatusBar::GetOwnerFromTitle ( $article->getTitle() );
 57+ $userName = $article->getTitle()->getBaseText();
 58+ if ( User::isIP ( $userName ) != true && $user == null ) {
 59+ return true;
 60+ }
 61+ if ( User::isIP ( $userName ) && $user == null && $wgOnlineStatusBarDefaultIpUsers ) {
 62+ // it's anon user and we want to track them
 63+ $sanitizedusername = $userName;
 64+ $anon = true;
 65+ } else if ( $user != null ) {
 66+ // Fix capitalisation issues
 67+ $sanitizedusername = $user->getName();
 68+ } else {
 69+ return true;
 70+ }
 71+ if ( $anon == false )
 72+ {
 73+ //we don't want to check this
 74+ if ( $user->getOption ( "OnlineStatusBar_hide" ) == true ) {
 75+ return true;
 76+ }
 77+ }
 78+ if ( OnlineStatusBar::IsValid( $userName ) ) {
 79+ $mode = OnlineStatusBar::GetStatus( $userName );
 80+ $modetext = $wgOnlineStatusBarModes[$mode];
 81+ $image = OnlineStatusBar::getImageHtml( $mode );
 82+ $text = wfMessage( 'onlinestatusbar-line', $userName )->rawParams( $image )->params( $modetext )->escaped();
 83+ $wgOut->addHtml( OnlineStatusBar::Get_Html( $text, $mode ) );
 84+ }
 85+ }
 86+ return true;
 87+ }
 88+
 89+ /**
 90+ * @param $user User
 91+ * @paramNireferences array
 92+ * @return bool
 93+ */
 94+ public static function preferencesHook( User $user, array &$preferences ) {
 95+ global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled, $wgOnlineStatusBarModes;
 96+ $preferences['OnlineStatusBar_active'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-used', 'section' => 'misc/onlinestatus' );
 97+ $preferences['OnlineStatusBar_hide'] = array( 'type' => 'toggle', 'label-message' => 'onlinestatusbar-hide', 'section' => 'misc/onlinestatus' );
 98+ $preferences['OnlineStatusBar_status'] = array( 'type' => 'radio', 'label-message' => 'onlinestatusbar-status', 'section' => 'misc/onlinestatus',
 99+ 'options' => array(
 100+ $wgOnlineStatusBarModes['online'] => 'online',
 101+ $wgOnlineStatusBarModes['busy'] => 'busy',
 102+ $wgOnlineStatusBarModes['away'] => 'away',
 103+ $wgOnlineStatusBarModes['hidden'] => 'hidden'
 104+ ),
 105+ );
 106+ return true;
 107+ }
 108+
 109+ /**
 110+ * @param $defaultOptions array
 111+ * @return bool
 112+ */
 113+ public static function setDefaultOptions( &$defaultOptions ) {
 114+ global $wgOnlineStatusBarDefaultOnline, $wgOnlineStatusBarDefaultEnabled;
 115+ // set defaults
 116+ $defaultOptions['OnlineStatusBar_status'] = $wgOnlineStatusBarDefaultOnline;
 117+ $defaultOptions['OnlineStatusBar_active'] = $wgOnlineStatusBarDefaultEnabled;
 118+ $defaultOptions['OnlineStatusBar_hide'] = false;
 119+ // quit
 120+ return true;
 121+ }
 122+
 123+ /**
 124+ * @param $magicWords array
 125+ * @param $ln string?
 126+ * @return bool
 127+ */
 128+ public static function magicWordVar ( array &$magicWords, $ln ) {
 129+ $magicWords['isonline'] = array ( 0, 'isonline' );
 130+ return true;
 131+ }
 132+
 133+ /**
 134+ * @param $out OutputPage
 135+ * @param $skin Skin
 136+ * @return bool
 137+ */
 138+ public static function stylePage ( &$out, &$skin ) {
 139+ $out->addModules( 'ext.OnlineStatusBar' );
 140+ return true;
 141+ }
 142+
 143+ /**
 144+ * @param $vars array
 145+ * @return bool
 146+ */
 147+ public static function magicWordSet ( &$vars ) {
 148+ $vars[] = 'isonline';
 149+ return true;
 150+ }
 151+
 152+ /**
 153+ * @param $parser Parser
 154+ * @param $varCache ??
 155+ * @param $index ??
 156+ * @param $ret string?
 157+ * @return bool
 158+ */
 159+ public static function parserGetVariable ( &$parser, &$varCache, &$index, &$ret ){
 160+ global $wgOnlineStatusBarModes, $wgOnlineStatusBarDefaultOffline;
 161+ if( $index == 'isonline' ){
 162+ $ns = $parser->getTitle()->getNamespace();
 163+ if ( ( $ns != NS_USER_TALK ) && ( $ns != NS_USER ) ) {
 164+ $ret = "unknown";
 165+ return true;
 166+ }
 167+ $name = OnlineStatusBar::GetOwnerFromTitle ( $parser->getTitle() )->getName();
 168+
 169+ if ( OnlineStatusBar::IsValid($name) != true ) {
 170+ $ret = "unknown";
 171+ return true;
 172+ }
 173+ $ret = OnlineStatusBar::GetStatus( $name );
 174+ if ( $ret == "hidden" ) {
 175+ $ret = $wgOnlineStatusBarDefaultOffline;
 176+ }
 177+ }
 178+ return true;
 179+ }
 180+}
Property changes on: trunk/extensions/OnlineStatusBar/OnlineStatusBarHooks.php
___________________________________________________________________
Added: svn:eol-style
181181 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r101020Remove file that was committed by accident in 101018johnduhart18:37, 27 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100997Moved hooks into their own class...johnduhart16:20, 27 October 2011

Comments

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

Ah, same request for you, please use the r12345678 phrase in your messages :)

Status & tagging log