Index: trunk/phase3/includes/specials/SpecialWatchlist.php |
— | — | @@ -26,8 +26,8 @@ |
27 | 27 | /** |
28 | 28 | * Constructor |
29 | 29 | */ |
30 | | - public function __construct(){ |
31 | | - parent::__construct( 'Watchlist' ); |
| 30 | + public function __construct( $page = 'Watchlist' ){ |
| 31 | + parent::__construct( $page ); |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
— | — | @@ -35,47 +35,51 @@ |
36 | 36 | * @param $par Parameter passed to the page |
37 | 37 | */ |
38 | 38 | function execute( $par ) { |
39 | | - global $wgUser, $wgOut, $wgLang, $wgRequest; |
40 | 39 | global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; |
41 | 40 | |
| 41 | + $user = $this->getUser(); |
| 42 | + $output = $this->getOutput(); |
| 43 | + |
42 | 44 | // Add feed links |
43 | | - $wlToken = $wgUser->getOption( 'watchlisttoken' ); |
| 45 | + $wlToken = $user->getOption( 'watchlisttoken' ); |
44 | 46 | if ( !$wlToken ) { |
45 | 47 | $wlToken = sha1( mt_rand() . microtime( true ) ); |
46 | | - $wgUser->setOption( 'watchlisttoken', $wlToken ); |
47 | | - $wgUser->saveSettings(); |
| 48 | + $user->setOption( 'watchlisttoken', $wlToken ); |
| 49 | + $user->saveSettings(); |
48 | 50 | } |
49 | 51 | |
50 | 52 | $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev', |
51 | | - 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ) ); |
| 53 | + 'wlowner' => $user->getName(), 'wltoken' => $wlToken ) ); |
52 | 54 | |
53 | | - $skin = $this->getSkin(); |
54 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 55 | + $output->setRobotPolicy( 'noindex,nofollow' ); |
55 | 56 | |
56 | 57 | # Anons don't get a watchlist |
57 | | - if( $wgUser->isAnon() ) { |
58 | | - $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); |
59 | | - $llink = $skin->linkKnown( |
| 58 | + if( $user->isAnon() ) { |
| 59 | + $output->setPageTitle( wfMsg( 'watchnologin' ) ); |
| 60 | + $llink = Linker::linkKnown( |
60 | 61 | SpecialPage::getTitleFor( 'Userlogin' ), |
61 | 62 | wfMsgHtml( 'loginreqlink' ), |
62 | 63 | array(), |
63 | 64 | array( 'returnto' => $this->getTitle()->getPrefixedText() ) |
64 | 65 | ); |
65 | | - $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) ); |
| 66 | + $output->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) ); |
66 | 67 | return; |
67 | 68 | } |
68 | 69 | |
69 | | - $wgOut->setPageTitle( wfMsg( 'watchlist' ) ); |
| 70 | + $this->setHeaders(); |
| 71 | + $this->outputHeader(); |
70 | 72 | |
71 | 73 | $sub = wfMsgExt( |
72 | 74 | 'watchlistfor2', |
73 | 75 | array( 'parseinline', 'replaceafter' ), |
74 | | - $wgUser->getName(), |
75 | | - SpecialEditWatchlist::buildTools( $skin ) |
| 76 | + $user->getName(), |
| 77 | + SpecialEditWatchlist::buildTools( $this->getSkin() ) |
76 | 78 | ); |
77 | | - $wgOut->setSubtitle( $sub ); |
| 79 | + $output->setSubtitle( $sub ); |
78 | 80 | |
79 | | - $mode = SpecialEditWatchlist::getMode( $wgRequest, $par ); |
| 81 | + $request = $this->getRequest(); |
| 82 | + |
| 83 | + $mode = SpecialEditWatchlist::getMode( $request, $par ); |
80 | 84 | if( $mode !== false ) { |
81 | 85 | # TODO: localise? |
82 | 86 | switch( $mode ){ |
— | — | @@ -89,28 +93,33 @@ |
90 | 94 | $mode = null; |
91 | 95 | } |
92 | 96 | $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode ); |
93 | | - $wgOut->redirect( $title->getLocalUrl() ); |
| 97 | + $output->redirect( $title->getLocalUrl() ); |
94 | 98 | return; |
95 | 99 | } |
96 | 100 | |
97 | | - $uid = $wgUser->getId(); |
98 | | - if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $wgRequest->getVal( 'reset' ) && |
99 | | - $wgRequest->wasPosted() ) |
| 101 | + if( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) && |
| 102 | + $request->wasPosted() ) |
100 | 103 | { |
101 | | - $wgUser->clearAllNotifications( $uid ); |
102 | | - $wgOut->redirect( $this->getTitle()->getFullUrl() ); |
| 104 | + $user->clearAllNotifications(); |
| 105 | + $output->redirect( $this->getTitle()->getFullUrl() ); |
103 | 106 | return; |
104 | 107 | } |
105 | 108 | |
| 109 | + $nitems = $this->countItems(); |
| 110 | + if ( $nitems == 0 ) { |
| 111 | + $output->addWikiMsg( 'nowatchlist' ); |
| 112 | + return; |
| 113 | + } |
| 114 | + |
106 | 115 | // @TODO: use FormOptions! |
107 | 116 | $defaults = array( |
108 | | - /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */ |
109 | | - /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ), |
110 | | - /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ), |
111 | | - /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ), |
112 | | - /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ), |
113 | | - /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ), |
114 | | - /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ), |
| 117 | + /* float */ 'days' => floatval( $user->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */ |
| 118 | + /* bool */ 'hideMinor' => (int)$user->getBoolOption( 'watchlisthideminor' ), |
| 119 | + /* bool */ 'hideBots' => (int)$user->getBoolOption( 'watchlisthidebots' ), |
| 120 | + /* bool */ 'hideAnons' => (int)$user->getBoolOption( 'watchlisthideanons' ), |
| 121 | + /* bool */ 'hideLiu' => (int)$user->getBoolOption( 'watchlisthideliu' ), |
| 122 | + /* bool */ 'hidePatrolled' => (int)$user->getBoolOption( 'watchlisthidepatrolled' ), |
| 123 | + /* bool */ 'hideOwn' => (int)$user->getBoolOption( 'watchlisthideown' ), |
115 | 124 | /* ? */ 'namespace' => 'all', |
116 | 125 | /* ? */ 'invert' => false, |
117 | 126 | ); |
— | — | @@ -122,30 +131,30 @@ |
123 | 132 | |
124 | 133 | # Extract variables from the request, falling back to user preferences or |
125 | 134 | # other default values if these don't exist |
126 | | - $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) ); |
127 | | - $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' ); |
128 | | - $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' ); |
129 | | - $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanons' ); |
130 | | - $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' ); |
131 | | - $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' ); |
132 | | - $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' ); |
| 135 | + $prefs['days'] = floatval( $user->getOption( 'watchlistdays' ) ); |
| 136 | + $prefs['hideminor'] = $user->getBoolOption( 'watchlisthideminor' ); |
| 137 | + $prefs['hidebots'] = $user->getBoolOption( 'watchlisthidebots' ); |
| 138 | + $prefs['hideanons'] = $user->getBoolOption( 'watchlisthideanons' ); |
| 139 | + $prefs['hideliu'] = $user->getBoolOption( 'watchlisthideliu' ); |
| 140 | + $prefs['hideown' ] = $user->getBoolOption( 'watchlisthideown' ); |
| 141 | + $prefs['hidepatrolled' ] = $user->getBoolOption( 'watchlisthidepatrolled' ); |
133 | 142 | |
134 | 143 | # Get query variables |
135 | 144 | $values = array(); |
136 | | - $values['days'] = $wgRequest->getVal( 'days', $prefs['days'] ); |
137 | | - $values['hideMinor'] = (int)$wgRequest->getBool( 'hideMinor', $prefs['hideminor'] ); |
138 | | - $values['hideBots'] = (int)$wgRequest->getBool( 'hideBots' , $prefs['hidebots'] ); |
139 | | - $values['hideAnons'] = (int)$wgRequest->getBool( 'hideAnons', $prefs['hideanons'] ); |
140 | | - $values['hideLiu'] = (int)$wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] ); |
141 | | - $values['hideOwn'] = (int)$wgRequest->getBool( 'hideOwn' , $prefs['hideown'] ); |
142 | | - $values['hidePatrolled'] = (int)$wgRequest->getBool( 'hidePatrolled', $prefs['hidepatrolled'] ); |
| 145 | + $values['days'] = $request->getVal( 'days', $prefs['days'] ); |
| 146 | + $values['hideMinor'] = (int)$request->getBool( 'hideMinor', $prefs['hideminor'] ); |
| 147 | + $values['hideBots'] = (int)$request->getBool( 'hideBots' , $prefs['hidebots'] ); |
| 148 | + $values['hideAnons'] = (int)$request->getBool( 'hideAnons', $prefs['hideanons'] ); |
| 149 | + $values['hideLiu'] = (int)$request->getBool( 'hideLiu' , $prefs['hideliu'] ); |
| 150 | + $values['hideOwn'] = (int)$request->getBool( 'hideOwn' , $prefs['hideown'] ); |
| 151 | + $values['hidePatrolled'] = (int)$request->getBool( 'hidePatrolled', $prefs['hidepatrolled'] ); |
143 | 152 | foreach( $this->customFilters as $key => $params ) { |
144 | | - $values[$key] = (int)$wgRequest->getBool( $key ); |
| 153 | + $values[$key] = (int)$request->getBool( $key ); |
145 | 154 | } |
146 | 155 | |
147 | 156 | # Get namespace value, if supplied, and prepare a WHERE fragment |
148 | | - $nameSpace = $wgRequest->getIntOrNull( 'namespace' ); |
149 | | - $invert = $wgRequest->getIntOrNull( 'invert' ); |
| 157 | + $nameSpace = $request->getIntOrNull( 'namespace' ); |
| 158 | + $invert = $request->getIntOrNull( 'invert' ); |
150 | 159 | if ( !is_null( $nameSpace ) ) { |
151 | 160 | $nameSpace = intval( $nameSpace ); // paranioa |
152 | 161 | if ( $invert ) { |
— | — | @@ -160,15 +169,6 @@ |
161 | 170 | $values['namespace'] = $nameSpace; |
162 | 171 | $values['invert'] = $invert; |
163 | 172 | |
164 | | - $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
165 | | - $recentchanges = $dbr->tableName( 'recentchanges' ); |
166 | | - |
167 | | - $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)', |
168 | | - array( 'wl_user' => $uid ), __METHOD__ ); |
169 | | - // Adjust for page X, talk:page X, which are both stored separately, |
170 | | - // but treated together |
171 | | - $nitems = floor( $watchlistCount / 2 ); |
172 | | - |
173 | 173 | if( is_null( $values['days'] ) || !is_numeric( $values['days'] ) ) { |
174 | 174 | $big = 1000; /* The magical big */ |
175 | 175 | if( $nitems > $big ) { |
— | — | @@ -187,10 +187,7 @@ |
188 | 188 | wfAppendToArrayIfNotDefault( $name, $values[$name], $defaults, $nondefaults ); |
189 | 189 | } |
190 | 190 | |
191 | | - if( $nitems == 0 ) { |
192 | | - $wgOut->addWikiMsg( 'nowatchlist' ); |
193 | | - return; |
194 | | - } |
| 191 | + $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
195 | 192 | |
196 | 193 | # Possible where conditions |
197 | 194 | $conds = array(); |
— | — | @@ -207,9 +204,10 @@ |
208 | 205 | |
209 | 206 | # Up estimate of watched items by 15% to compensate for talk pages... |
210 | 207 | |
| 208 | + |
211 | 209 | # Toggles |
212 | 210 | if( $values['hideOwn'] ) { |
213 | | - $conds[] = "rc_user != $uid"; |
| 211 | + $conds[] = 'rc_user != ' . $user->getId(); |
214 | 212 | } |
215 | 213 | if( $values['hideBots'] ) { |
216 | 214 | $conds[] = 'rc_bot = 0'; |
— | — | @@ -223,7 +221,7 @@ |
224 | 222 | if( $values['hideAnons'] ) { |
225 | 223 | $conds[] = 'rc_user != 0'; |
226 | 224 | } |
227 | | - if ( $wgUser->useRCPatrol() && $values['hidePatrolled'] ) { |
| 225 | + if ( $user->useRCPatrol() && $values['hidePatrolled'] ) { |
228 | 226 | $conds[] = 'rc_patrolled != 1'; |
229 | 227 | } |
230 | 228 | if ( $nameSpaceClause ) { |
— | — | @@ -231,8 +229,8 @@ |
232 | 230 | } |
233 | 231 | |
234 | 232 | # Toggle watchlist content (all recent edits or just the latest) |
235 | | - if( $wgUser->getOption( 'extendwatchlist' ) ) { |
236 | | - $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) ); |
| 233 | + if( $user->getOption( 'extendwatchlist' ) ) { |
| 234 | + $limitWatchlist = intval( $user->getOption( 'wllimit' ) ); |
237 | 235 | $usePage = false; |
238 | 236 | } else { |
239 | 237 | # Top log Ids for a page are not stored |
— | — | @@ -244,16 +242,18 @@ |
245 | 243 | # Show a message about slave lag, if applicable |
246 | 244 | $lag = $dbr->getLag(); |
247 | 245 | if( $lag > 0 ) { |
248 | | - $wgOut->showLagWarning( $lag ); |
| 246 | + $output->showLagWarning( $lag ); |
249 | 247 | } |
250 | 248 | |
| 249 | + $lang = $this->getLang(); |
| 250 | + |
251 | 251 | # Create output form |
252 | 252 | $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) ); |
253 | 253 | |
254 | 254 | # Show watchlist header |
255 | | - $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) ); |
| 255 | + $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $lang->formatNum( $nitems ) ); |
256 | 256 | |
257 | | - if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { |
| 257 | + if( $user->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { |
258 | 258 | $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n"; |
259 | 259 | } |
260 | 260 | if( $wgShowUpdatedMarker ) { |
— | — | @@ -268,9 +268,9 @@ |
269 | 269 | $form .= '<hr />'; |
270 | 270 | |
271 | 271 | $tables = array( 'recentchanges', 'watchlist' ); |
272 | | - $fields = array( "{$recentchanges}.*" ); |
| 272 | + $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' ); |
273 | 273 | $join_conds = array( |
274 | | - 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"), |
| 274 | + 'watchlist' => array('INNER JOIN',"wl_user='{$user->getId()}' AND wl_namespace=rc_namespace AND wl_title=rc_title"), |
275 | 275 | ); |
276 | 276 | $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); |
277 | 277 | if( $wgShowUpdatedMarker ) { |
— | — | @@ -280,7 +280,7 @@ |
281 | 281 | $options['LIMIT'] = $limitWatchlist; |
282 | 282 | } |
283 | 283 | |
284 | | - $rollbacker = $wgUser->isAllowed('rollback'); |
| 284 | + $rollbacker = $user->isAllowed('rollback'); |
285 | 285 | if ( $usePage || $rollbacker ) { |
286 | 286 | $tables[] = 'page'; |
287 | 287 | $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id'); |
— | — | @@ -301,23 +301,21 @@ |
302 | 302 | if( $values['days'] >= 1 ) { |
303 | 303 | $timestamp = wfTimestampNow(); |
304 | 304 | $wlInfo = wfMsgExt( 'rcnote', 'parseinline', |
305 | | - $wgLang->formatNum( $numRows ), |
306 | | - $wgLang->formatNum( $values['days'] ), |
307 | | - $wgLang->timeAndDate( $timestamp, true ), |
308 | | - $wgLang->date( $timestamp, true ), |
309 | | - $wgLang->time( $timestamp, true ) |
| 305 | + $lang->formatNum( $numRows ), |
| 306 | + $lang->formatNum( $values['days'] ), |
| 307 | + $lang->timeAndDate( $timestamp, true ), |
| 308 | + $lang->date( $timestamp, true ), |
| 309 | + $lang->time( $timestamp, true ) |
310 | 310 | ) . '<br />'; |
311 | 311 | } elseif( $values['days'] > 0 ) { |
312 | 312 | $wlInfo = wfMsgExt( 'wlnote', 'parseinline', |
313 | | - $wgLang->formatNum( $numRows ), |
314 | | - $wgLang->formatNum( round( $values['days'] * 24 ) ) |
| 313 | + $lang->formatNum( $numRows ), |
| 314 | + $lang->formatNum( round( $values['days'] * 24 ) ) |
315 | 315 | ) . '<br />'; |
316 | 316 | } |
317 | 317 | |
318 | | - $cutofflinks = "\n" . self::cutoffLinks( $values['days'], 'Watchlist', $nondefaults ) . "<br />\n"; |
| 318 | + $cutofflinks = "\n" . $this->cutoffLinks( $values['days'], $nondefaults ) . "<br />\n"; |
319 | 319 | |
320 | | - $thisTitle = SpecialPage::getTitleFor( 'Watchlist' ); |
321 | | - |
322 | 320 | # Spit out some control panel links |
323 | 321 | $filters = array( |
324 | 322 | 'hideMinor' => 'rcshowhideminor', |
— | — | @@ -331,20 +329,20 @@ |
332 | 330 | $filters[$key] = $params['msg']; |
333 | 331 | } |
334 | 332 | // Disable some if needed |
335 | | - if ( !$wgUser->useNPPatrol() ) { |
| 333 | + if ( !$user->useNPPatrol() ) { |
336 | 334 | unset( $filters['hidePatrolled'] ); |
337 | 335 | } |
338 | 336 | |
339 | 337 | $links = array(); |
340 | 338 | foreach( $filters as $name => $msg ) { |
341 | | - $links[] = self::showHideLink( $nondefaults, $msg, $name, $values[$name] ); |
| 339 | + $links[] = $this->showHideLink( $nondefaults, $msg, $name, $values[$name] ); |
342 | 340 | } |
343 | 341 | |
344 | 342 | # Namespace filter and put the whole form together. |
345 | 343 | $form .= $wlInfo; |
346 | 344 | $form .= $cutofflinks; |
347 | | - $form .= $wgLang->pipeList( $links ); |
348 | | - $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) ); |
| 345 | + $form .= $lang->pipeList( $links ); |
| 346 | + $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) ); |
349 | 347 | $form .= '<hr /><p>'; |
350 | 348 | $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '; |
351 | 349 | $form .= Xml::namespaceSelector( $nameSpace, '' ) . ' '; |
— | — | @@ -358,11 +356,11 @@ |
359 | 357 | } |
360 | 358 | $form .= Xml::closeElement( 'form' ); |
361 | 359 | $form .= Xml::closeElement( 'fieldset' ); |
362 | | - $wgOut->addHTML( $form ); |
| 360 | + $output->addHTML( $form ); |
363 | 361 | |
364 | 362 | # If there's nothing to show, stop here |
365 | 363 | if( $numRows == 0 ) { |
366 | | - $wgOut->addWikiMsg( 'watchnochange' ); |
| 364 | + $output->addWikiMsg( 'watchnochange' ); |
367 | 365 | return; |
368 | 366 | } |
369 | 367 | |
— | — | @@ -382,7 +380,7 @@ |
383 | 381 | $linkBatch->execute(); |
384 | 382 | $dbr->dataSeek( $res, 0 ); |
385 | 383 | |
386 | | - $list = ChangesList::newFromUser( $wgUser ); |
| 384 | + $list = ChangesList::newFromUser( $this->getUser() ); |
387 | 385 | $list->setWatchlistDivs(); |
388 | 386 | |
389 | 387 | $s = $list->beginRecentChangesList(); |
— | — | @@ -398,7 +396,7 @@ |
399 | 397 | $updated = false; |
400 | 398 | } |
401 | 399 | |
402 | | - if ( $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) { |
| 400 | + if ( $wgRCShowWatchingUsers && $user->getOption( 'shownumberswatching' ) ) { |
403 | 401 | $rc->numberofWatchingusers = $dbr->selectField( 'watchlist', |
404 | 402 | 'COUNT(*)', |
405 | 403 | array( |
— | — | @@ -414,48 +412,36 @@ |
415 | 413 | } |
416 | 414 | $s .= $list->endRecentChangesList(); |
417 | 415 | |
418 | | - $wgOut->addHTML( $s ); |
| 416 | + $output->addHTML( $s ); |
419 | 417 | } |
420 | 418 | |
421 | | - public static function showHideLink( $options, $message, $name, $value ) { |
422 | | - global $wgUser; |
423 | | - |
| 419 | + protected function showHideLink( $options, $message, $name, $value ) { |
424 | 420 | $showLinktext = wfMsgHtml( 'show' ); |
425 | 421 | $hideLinktext = wfMsgHtml( 'hide' ); |
426 | | - $title = SpecialPage::getTitleFor( 'Watchlist' ); |
427 | | - $skin = $wgUser->getSkin(); |
428 | 422 | |
429 | 423 | $label = $value ? $showLinktext : $hideLinktext; |
430 | 424 | $options[$name] = 1 - (int) $value; |
431 | 425 | |
432 | | - return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) ); |
| 426 | + return wfMsgHtml( $message, Linker::linkKnown( $this->getTitle(), $label, array(), $options ) ); |
433 | 427 | } |
434 | 428 | |
435 | | - public static function hoursLink( $h, $page, $options = array() ) { |
436 | | - global $wgUser, $wgLang, $wgContLang; |
437 | | - |
438 | | - $sk = $wgUser->getSkin(); |
439 | | - $title = Title::newFromText( $wgContLang->specialPage( $page ) ); |
| 429 | + protected function hoursLink( $h, $options = array() ) { |
440 | 430 | $options['days'] = ( $h / 24.0 ); |
441 | 431 | |
442 | | - return $sk->linkKnown( |
443 | | - $title, |
444 | | - $wgLang->formatNum( $h ), |
| 432 | + return Linker::linkKnown( |
| 433 | + $this->getTitle(), |
| 434 | + $this->getLang()->formatNum( $h ), |
445 | 435 | array(), |
446 | 436 | $options |
447 | 437 | ); |
448 | 438 | } |
449 | 439 | |
450 | | - public static function daysLink( $d, $page, $options = array() ) { |
451 | | - global $wgUser, $wgLang, $wgContLang; |
452 | | - |
453 | | - $sk = $wgUser->getSkin(); |
454 | | - $title = Title::newFromText( $wgContLang->specialPage( $page ) ); |
| 440 | + protected function daysLink( $d, $options = array() ) { |
455 | 441 | $options['days'] = $d; |
456 | | - $message = ( $d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ); |
| 442 | + $message = ( $d ? $this->getLang()->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ); |
457 | 443 | |
458 | | - return $sk->linkKnown( |
459 | | - $title, |
| 444 | + return Linker::linkKnown( |
| 445 | + $this->getTitle(), |
460 | 446 | $message, |
461 | 447 | array(), |
462 | 448 | $options |
— | — | @@ -467,47 +453,38 @@ |
468 | 454 | * |
469 | 455 | * @return string |
470 | 456 | */ |
471 | | - protected static function cutoffLinks( $days, $page = 'Watchlist', $options = array() ) { |
472 | | - global $wgLang; |
473 | | - |
| 457 | + protected function cutoffLinks( $days, $options = array() ) { |
474 | 458 | $hours = array( 1, 2, 6, 12 ); |
475 | 459 | $days = array( 1, 3, 7 ); |
476 | 460 | $i = 0; |
477 | 461 | foreach( $hours as $h ) { |
478 | | - $hours[$i++] = self::hoursLink( $h, $page, $options ); |
| 462 | + $hours[$i++] = $this->hoursLink( $h, $options ); |
479 | 463 | } |
480 | 464 | $i = 0; |
481 | 465 | foreach( $days as $d ) { |
482 | | - $days[$i++] = self::daysLink( $d, $page, $options ); |
| 466 | + $days[$i++] = $this->daysLink( $d, $options ); |
483 | 467 | } |
484 | 468 | return wfMsgExt('wlshowlast', |
485 | 469 | array('parseinline', 'replaceafter'), |
486 | | - $wgLang->pipeList( $hours ), |
487 | | - $wgLang->pipeList( $days ), |
488 | | - self::daysLink( 0, $page, $options ) ); |
| 470 | + $this->getLang()->pipeList( $hours ), |
| 471 | + $this->getLang()->pipeList( $days ), |
| 472 | + $this->daysLink( 0, $options ) ); |
489 | 473 | } |
490 | 474 | |
491 | 475 | /** |
492 | 476 | * Count the number of items on a user's watchlist |
493 | 477 | * |
494 | | - * @param $user User object |
495 | | - * @param $talk Boolean: include talk pages |
496 | 478 | * @return Integer |
497 | 479 | */ |
498 | | - protected static function countItems( &$user, $talk = true ) { |
| 480 | + protected function countItems() { |
499 | 481 | $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
500 | 482 | |
501 | 483 | # Fetch the raw count |
502 | 484 | $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', |
503 | | - array( 'wl_user' => $user->mId ), __METHOD__ ); |
| 485 | + array( 'wl_user' => $this->getUser()->getId() ), __METHOD__ ); |
504 | 486 | $row = $dbr->fetchObject( $res ); |
505 | 487 | $count = $row->count; |
506 | 488 | |
507 | | - # Halve to remove talk pages if needed |
508 | | - if( !$talk ) { |
509 | | - $count = floor( $count / 2 ); |
510 | | - } |
511 | | - |
512 | | - return( $count ); |
| 489 | + return floor( $count / 2 ); |
513 | 490 | } |
514 | 491 | } |
Index: trunk/extensions/InterwikiIntegration/SpecialInterwikiWatchlist.php |
— | — | @@ -62,9 +62,21 @@ |
63 | 63 | $sub .= '<br />' . WatchlistEditor::buildTools( $wgUser->getSkin() ); |
64 | 64 | $wgOut->setSubtitle( $sub ); |
65 | 65 | |
66 | | - if( ( $mode = WatchlistEditor::getMode( $wgRequest, $par ) ) !== false ) { |
67 | | - $editor = new WatchlistEditor(); |
68 | | - $editor->execute( $wgUser, $wgOut, $wgRequest, $mode ); |
| 66 | + $mode = SpecialEditWatchlist::getMode( $this->getRequest(), $par ); |
| 67 | + if( $mode !== false ) { |
| 68 | + # TODO: localise? |
| 69 | + switch( $mode ){ |
| 70 | + case SpecialEditWatchlist::EDIT_CLEAR: |
| 71 | + $mode = 'clear'; |
| 72 | + break; |
| 73 | + case SpecialEditWatchlist::EDIT_RAW: |
| 74 | + $mode = 'raw'; |
| 75 | + break; |
| 76 | + default: |
| 77 | + $mode = null; |
| 78 | + } |
| 79 | + $title = SpecialPage::getTitleFor( 'EditWatchlist', $mode ); |
| 80 | + $wgOut->redirect( $title->getLocalUrl() ); |
69 | 81 | return; |
70 | 82 | } |
71 | 83 | |
— | — | @@ -72,7 +84,7 @@ |
73 | 85 | if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && |
74 | 86 | $wgRequest->wasPosted() ) |
75 | 87 | { |
76 | | - $wgUser->clearAllNotifications( $uid ); |
| 88 | + $wgUser->clearAllNotifications(); |
77 | 89 | $wgOut->redirect( $specialTitle->getFullUrl() ); |
78 | 90 | return; |
79 | 91 | } |
— | — | @@ -127,11 +139,7 @@ |
128 | 140 | $dbr = wfGetDB( DB_SLAVE, 'integration_watchlist' ); |
129 | 141 | $recentchanges = $dbr->tableName( 'integration_recentchanges' ); |
130 | 142 | |
131 | | - $watchlistCount = $dbr->selectField( 'integration_watchlist', 'COUNT(*)', |
132 | | - array( 'integration_wl_user' => $uid ), __METHOD__ ); |
133 | | - // Adjust for page X, talk:page X, which are both stored separately, |
134 | | - // but treated together |
135 | | - $nitems = floor($watchlistCount / 2); |
| 143 | + $nitems = $this->countItems(); |
136 | 144 | |
137 | 145 | if( is_null($days) || !is_numeric($days) ) { |
138 | 146 | $big = 1000; /* The magical big */ |
— | — | @@ -282,26 +290,24 @@ |
283 | 291 | ) . '<br />'; |
284 | 292 | } |
285 | 293 | |
286 | | - $cutofflinks = "\n" . self::cutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n"; |
287 | | - |
288 | | - $thisTitle = SpecialPage::getTitleFor( 'Watchlist' ); |
289 | | - |
| 294 | + $cutofflinks = "\n" . $this->cutoffLinks( $days, $nondefaults ) . "<br />\n"; |
| 295 | + |
290 | 296 | # Spit out some control panel links |
291 | | - $links[] = self::showHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); |
292 | | - $links[] = self::showHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); |
293 | | - $links[] = self::showHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons ); |
294 | | - $links[] = self::showHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); |
295 | | - $links[] = self::showHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); |
| 297 | + $links[] = $this->showHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); |
| 298 | + $links[] = $this->showHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); |
| 299 | + $links[] = $this->showHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons ); |
| 300 | + $links[] = $this->showHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); |
| 301 | + $links[] = $this->showHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); |
296 | 302 | |
297 | 303 | if( $wgUser->useRCPatrol() ) { |
298 | | - $links[] = self::showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); |
| 304 | + $links[] = $this->showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); |
299 | 305 | } |
300 | 306 | |
301 | 307 | # Namespace filter and put the whole form together. |
302 | 308 | $form .= $wlInfo; |
303 | 309 | $form .= $cutofflinks; |
304 | 310 | $form .= $wgLang->pipeList( $links ); |
305 | | - $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) ); |
| 311 | + $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'mw-watchlist-form-namespaceselector' ) ); |
306 | 312 | $form .= '<hr /><p>'; |
307 | 313 | $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '; |
308 | 314 | $form .= Xml::namespaceSelector( $nameSpace, '' ) . ' '; |
— | — | @@ -385,23 +391,18 @@ |
386 | 392 | /** |
387 | 393 | * Count the number of items on a user's watchlist |
388 | 394 | * |
389 | | - * @param $talk Include talk pages |
390 | 395 | * @return integer |
391 | 396 | */ |
392 | | - function countItems( &$user, $talk = true ) { |
| 397 | + function countItems() { |
393 | 398 | $dbr = wfGetDB( DB_SLAVE, 'integration_watchlist' ); |
394 | | - |
| 399 | + |
395 | 400 | # Fetch the raw count |
396 | 401 | $res = $dbr->select( 'integration_watchlist', 'COUNT(*) AS count', |
397 | | - array( 'integration_wl_user' => $user->mId ), __METHOD__ ); |
| 402 | + array( 'integration_wl_user' => $this->getUser()->getId() ), __METHOD__ ); |
398 | 403 | $row = $dbr->fetchObject( $res ); |
399 | 404 | $count = $row->count; |
400 | 405 | $dbr->freeResult( $res ); |
401 | | - |
402 | | - # Halve to remove talk pages if needed |
403 | | - if( !$talk ) |
404 | | - $count = floor( $count / 2 ); |
405 | | - |
406 | | - return( $count ); |
| 406 | + |
| 407 | + return floor( $count / 2 ); |
407 | 408 | } |
408 | | -} |
\ No newline at end of file |
| 409 | +} |