Index: trunk/phase3/includes/specials/SpecialEditWatchlist.php |
— | — | @@ -28,32 +28,33 @@ |
29 | 29 | * @param $mode int |
30 | 30 | */ |
31 | 31 | public function execute( $mode ) { |
32 | | - global $wgUser, $wgOut, $wgRequest; |
33 | 32 | if( wfReadOnly() ) { |
34 | | - $wgOut->readOnlyPage(); |
| 33 | + throw new ReadOnlyError; |
35 | 34 | return; |
36 | 35 | } |
37 | 36 | |
| 37 | + $out = $this->getOutput(); |
| 38 | + |
38 | 39 | # Anons don't get a watchlist |
39 | | - if( $wgUser->isAnon() ) { |
40 | | - $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); |
41 | | - $llink = $this->getSkin()->linkKnown( |
| 40 | + if( $this->getUser()->isAnon() ) { |
| 41 | + $out->setPageTitle( wfMsg( 'watchnologin' ) ); |
| 42 | + $llink = Linker::linkKnown( |
42 | 43 | SpecialPage::getTitleFor( 'Userlogin' ), |
43 | 44 | wfMsgHtml( 'loginreqlink' ), |
44 | 45 | array(), |
45 | 46 | array( 'returnto' => $this->getTitle()->getPrefixedText() ) |
46 | 47 | ); |
47 | | - $wgOut->addWikiMsgArray( 'watchlistanontext', array( $llink ), array( 'replaceafter' ) ); |
| 48 | + $out->addHTML( wfMessage( 'watchlistanontext' )->rawParam( $llink )->parse() ); |
48 | 49 | return; |
49 | 50 | } |
50 | 51 | |
51 | 52 | $sub = wfMsgExt( |
52 | 53 | 'watchlistfor2', |
53 | 54 | array( 'parseinline', 'replaceafter' ), |
54 | | - $wgUser->getName(), |
55 | | - SpecialEditWatchlist::buildTools( $this->getSkin() ) |
| 55 | + $this->getUser()->getName(), |
| 56 | + SpecialEditWatchlist::buildTools( null ) |
56 | 57 | ); |
57 | | - $wgOut->setSubtitle( $sub ); |
| 58 | + $out->setSubtitle( $sub ); |
58 | 59 | |
59 | 60 | # B/C: $mode used to be waaay down the parameter list, and the first parameter |
60 | 61 | # was $wgUser |
— | — | @@ -63,7 +64,7 @@ |
64 | 65 | $mode = $args[3]; |
65 | 66 | } |
66 | 67 | } |
67 | | - $mode = self::getMode( $wgRequest, $mode ); |
| 68 | + $mode = self::getMode( $this->getRequest(), $mode ); |
68 | 69 | |
69 | 70 | switch( $mode ) { |
70 | 71 | case self::EDIT_CLEAR: |
— | — | @@ -71,21 +72,21 @@ |
72 | 73 | // Pass on to the raw editor, from which it's very easy to clear. |
73 | 74 | |
74 | 75 | case self::EDIT_RAW: |
75 | | - $wgOut->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) ); |
76 | | - $form = $this->getRawForm( $wgUser ); |
| 76 | + $out->setPageTitle( wfMsg( 'watchlistedit-raw-title' ) ); |
| 77 | + $form = $this->getRawForm(); |
77 | 78 | if( $form->show() ){ |
78 | | - $wgOut->addHTML( $this->successMessage ); |
79 | | - $wgOut->returnToMain(); |
| 79 | + $out->addHTML( $this->successMessage ); |
| 80 | + $out->returnToMain(); |
80 | 81 | } |
81 | 82 | break; |
82 | 83 | |
83 | 84 | case self::EDIT_NORMAL: |
84 | 85 | default: |
85 | | - $wgOut->setPageTitle( wfMsg( 'watchlistedit-normal-title' ) ); |
86 | | - $form = $this->getNormalForm( $wgUser ); |
| 86 | + $out->setPageTitle( wfMsg( 'watchlistedit-normal-title' ) ); |
| 87 | + $form = $this->getNormalForm(); |
87 | 88 | if( $form->show() ){ |
88 | | - $wgOut->addHTML( $this->successMessage ); |
89 | | - $wgOut->returnToMain(); |
| 89 | + $out->addHTML( $this->successMessage ); |
| 90 | + $out->returnToMain(); |
90 | 91 | } |
91 | 92 | break; |
92 | 93 | } |
— | — | @@ -117,16 +118,15 @@ |
118 | 119 | } |
119 | 120 | |
120 | 121 | public function submitRaw( $data ){ |
121 | | - global $wgUser, $wgLang; |
122 | 122 | $wanted = $this->extractTitles( $data['Titles'] ); |
123 | | - $current = $this->getWatchlist( $wgUser ); |
| 123 | + $current = $this->getWatchlist(); |
124 | 124 | |
125 | 125 | if( count( $wanted ) > 0 ) { |
126 | 126 | $toWatch = array_diff( $wanted, $current ); |
127 | 127 | $toUnwatch = array_diff( $current, $wanted ); |
128 | | - $this->watchTitles( $toWatch, $wgUser ); |
129 | | - $this->unwatchTitles( $toUnwatch, $wgUser ); |
130 | | - $wgUser->invalidateCache(); |
| 128 | + $this->watchTitles( $toWatch ); |
| 129 | + $this->unwatchTitles( $toUnwatch ); |
| 130 | + $this->getUser()->invalidateCache(); |
131 | 131 | |
132 | 132 | if( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 ){ |
133 | 133 | $this->successMessage = wfMessage( 'watchlistedit-raw-done' )->parse(); |
— | — | @@ -137,26 +137,26 @@ |
138 | 138 | if( count( $toWatch ) > 0 ) { |
139 | 139 | $this->successMessage .= wfMessage( |
140 | 140 | 'watchlistedit-raw-added', |
141 | | - $wgLang->formatNum( count( $toWatch ) ) |
| 141 | + $this->getLang()->formatNum( count( $toWatch ) ) |
142 | 142 | ); |
143 | | - $this->showTitles( $toWatch, $this->successMessage, $this->getSkin() ); |
| 143 | + $this->showTitles( $toWatch, $this->successMessage ); |
144 | 144 | } |
145 | 145 | |
146 | 146 | if( count( $toUnwatch ) > 0 ) { |
147 | 147 | $this->successMessage .= wfMessage( |
148 | 148 | 'watchlistedit-raw-removed', |
149 | | - $wgLang->formatNum( count( $toUnwatch ) ) |
| 149 | + $this->getLang()->formatNum( count( $toUnwatch ) ) |
150 | 150 | ); |
151 | | - $this->showTitles( $toUnwatch, $this->successMessage, $this->getSkin() ); |
| 151 | + $this->showTitles( $toUnwatch, $this->successMessage ); |
152 | 152 | } |
153 | 153 | } else { |
154 | | - $this->clearWatchlist( $wgUser ); |
155 | | - $wgUser->invalidateCache(); |
| 154 | + $this->clearWatchlist(); |
| 155 | + $this->getLang()->invalidateCache(); |
156 | 156 | $this->successMessage .= wfMessage( |
157 | 157 | 'watchlistedit-raw-removed', |
158 | | - $wgLang->formatNum( count( $current ) ) |
| 158 | + $this->getLang()->formatNum( count( $current ) ) |
159 | 159 | ); |
160 | | - $this->showTitles( $current, $this->successMessage, $this->getSkin() ); |
| 160 | + $this->showTitles( $current, $this->successMessage ); |
161 | 161 | } |
162 | 162 | return true; |
163 | 163 | } |
— | — | @@ -169,9 +169,8 @@ |
170 | 170 | * |
171 | 171 | * @param $titles array of strings, or Title objects |
172 | 172 | * @param $output String |
173 | | - * @param $skin Skin |
174 | 173 | */ |
175 | | - private function showTitles( $titles, &$output, $skin ) { |
| 174 | + private function showTitles( $titles, &$output ) { |
176 | 175 | $talk = wfMsgHtml( 'talkpagelinktext' ); |
177 | 176 | // Do a batch existence check |
178 | 177 | $batch = new LinkBatch(); |
— | — | @@ -193,8 +192,8 @@ |
194 | 193 | } |
195 | 194 | if( $title instanceof Title ) { |
196 | 195 | $output .= "<li>" |
197 | | - . $skin->link( $title ) |
198 | | - . ' (' . $skin->link( $title->getTalkPage(), $talk ) |
| 196 | + . Linker::link( $title ) |
| 197 | + . ' (' . Linker::link( $title->getTalkPage(), $talk ) |
199 | 198 | . ")</li>\n"; |
200 | 199 | } |
201 | 200 | } |
— | — | @@ -202,33 +201,19 @@ |
203 | 202 | } |
204 | 203 | |
205 | 204 | /** |
206 | | - * Count the number of titles on a user's watchlist, excluding talk pages |
207 | | - * |
208 | | - * @param $user User |
209 | | - * @return int |
210 | | - */ |
211 | | - private function countWatchlist( $user ) { |
212 | | - $dbr = wfGetDB( DB_MASTER ); |
213 | | - $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->getId() ), __METHOD__ ); |
214 | | - $row = $dbr->fetchObject( $res ); |
215 | | - return ceil( $row->count / 2 ); // Paranoia |
216 | | - } |
217 | | - |
218 | | - /** |
219 | 205 | * Prepare a list of titles on a user's watchlist (excluding talk pages) |
220 | 206 | * and return an array of (prefixed) strings |
221 | 207 | * |
222 | | - * @param $user User |
223 | 208 | * @return array |
224 | 209 | */ |
225 | | - private function getWatchlist( $user ) { |
| 210 | + private function getWatchlist() { |
226 | 211 | $list = array(); |
227 | 212 | $dbr = wfGetDB( DB_MASTER ); |
228 | 213 | $res = $dbr->select( |
229 | 214 | 'watchlist', |
230 | 215 | '*', |
231 | 216 | array( |
232 | | - 'wl_user' => $user->getId(), |
| 217 | + 'wl_user' => $this->getUser()->getId(), |
233 | 218 | ), |
234 | 219 | __METHOD__ |
235 | 220 | ); |
— | — | @@ -248,10 +233,9 @@ |
249 | 234 | * and return as a two-dimensional array with namespace, title and |
250 | 235 | * redirect status |
251 | 236 | * |
252 | | - * @param $user User |
253 | 237 | * @return array |
254 | 238 | */ |
255 | | - private function getWatchlistInfo( $user ) { |
| 239 | + private function getWatchlistInfo() { |
256 | 240 | $titles = array(); |
257 | 241 | $dbr = wfGetDB( DB_MASTER ); |
258 | 242 | |
— | — | @@ -265,7 +249,7 @@ |
266 | 250 | 'page_is_redirect', |
267 | 251 | 'page_latest' |
268 | 252 | ), |
269 | | - array( 'wl_user' => $user->getId() ), |
| 253 | + array( 'wl_user' => $this->getUser()->getId() ), |
270 | 254 | __METHOD__, |
271 | 255 | array( 'ORDER BY' => 'wl_namespace, wl_title' ), |
272 | 256 | array( 'page' => array( |
— | — | @@ -296,33 +280,13 @@ |
297 | 281 | } |
298 | 282 | |
299 | 283 | /** |
300 | | - * Show a message indicating the number of items on the user's watchlist, |
301 | | - * and return this count for additional checking |
302 | | - * |
303 | | - * @param $output OutputPage |
304 | | - * @param $user User |
305 | | - * @return int |
306 | | - */ |
307 | | - private function showItemCount( $output, $user ) { |
308 | | - if( ( $count = $this->countWatchlist( $user ) ) > 0 ) { |
309 | | - $output->addHTML( wfMsgExt( 'watchlistedit-numitems', 'parse', |
310 | | - $GLOBALS['wgLang']->formatNum( $count ) ) ); |
311 | | - } else { |
312 | | - $output->addHTML( wfMsgExt( 'watchlistedit-noitems', 'parse' ) ); |
313 | | - } |
314 | | - return $count; |
315 | | - } |
316 | | - |
317 | | - /** |
318 | 284 | * Remove all titles from a user's watchlist |
319 | | - * |
320 | | - * @param $user User |
321 | 285 | */ |
322 | | - private function clearWatchlist( $user ) { |
| 286 | + private function clearWatchlist() { |
323 | 287 | $dbw = wfGetDB( DB_MASTER ); |
324 | 288 | $dbw->delete( |
325 | 289 | 'watchlist', |
326 | | - array( 'wl_user' => $user->getId() ), |
| 290 | + array( 'wl_user' => $this->getUser()->getId() ), |
327 | 291 | __METHOD__ |
328 | 292 | ); |
329 | 293 | } |
— | — | @@ -334,9 +298,8 @@ |
335 | 299 | * is preferred, since Titles are very memory-heavy |
336 | 300 | * |
337 | 301 | * @param $titles Array of strings, or Title objects |
338 | | - * @param $user User |
339 | 302 | */ |
340 | | - private function watchTitles( $titles, $user ) { |
| 303 | + private function watchTitles( $titles ) { |
341 | 304 | $dbw = wfGetDB( DB_MASTER ); |
342 | 305 | $rows = array(); |
343 | 306 | foreach( $titles as $title ) { |
— | — | @@ -345,13 +308,13 @@ |
346 | 309 | } |
347 | 310 | if( $title instanceof Title ) { |
348 | 311 | $rows[] = array( |
349 | | - 'wl_user' => $user->getId(), |
| 312 | + 'wl_user' => $this->getUser()->getId(), |
350 | 313 | 'wl_namespace' => ( $title->getNamespace() & ~1 ), |
351 | 314 | 'wl_title' => $title->getDBkey(), |
352 | 315 | 'wl_notificationtimestamp' => null, |
353 | 316 | ); |
354 | 317 | $rows[] = array( |
355 | | - 'wl_user' => $user->getId(), |
| 318 | + 'wl_user' => $this->getUser()->getId(), |
356 | 319 | 'wl_namespace' => ( $title->getNamespace() | 1 ), |
357 | 320 | 'wl_title' => $title->getDBkey(), |
358 | 321 | 'wl_notificationtimestamp' => null, |
— | — | @@ -368,9 +331,8 @@ |
369 | 332 | * is preferred, since Titles are very memory-heavy |
370 | 333 | * |
371 | 334 | * @param $titles Array of strings, or Title objects |
372 | | - * @param $user User |
373 | 335 | */ |
374 | | - private function unwatchTitles( $titles, $user ) { |
| 336 | + private function unwatchTitles( $titles ) { |
375 | 337 | $dbw = wfGetDB( DB_MASTER ); |
376 | 338 | foreach( $titles as $title ) { |
377 | 339 | if( !$title instanceof Title ) { |
— | — | @@ -380,7 +342,7 @@ |
381 | 343 | $dbw->delete( |
382 | 344 | 'watchlist', |
383 | 345 | array( |
384 | | - 'wl_user' => $user->getId(), |
| 346 | + 'wl_user' => $this->getUser()->getId(), |
385 | 347 | 'wl_namespace' => ( $title->getNamespace() & ~1 ), |
386 | 348 | 'wl_title' => $title->getDBkey(), |
387 | 349 | ), |
— | — | @@ -389,34 +351,32 @@ |
390 | 352 | $dbw->delete( |
391 | 353 | 'watchlist', |
392 | 354 | array( |
393 | | - 'wl_user' => $user->getId(), |
| 355 | + 'wl_user' => $this->getUser()->getId(), |
394 | 356 | 'wl_namespace' => ( $title->getNamespace() | 1 ), |
395 | 357 | 'wl_title' => $title->getDBkey(), |
396 | 358 | ), |
397 | 359 | __METHOD__ |
398 | 360 | ); |
399 | | - $article = new Article($title); |
400 | | - wfRunHooks('UnwatchArticleComplete',array(&$user,&$article)); |
| 361 | + $article = new Article( $title, 0 ); |
| 362 | + wfRunHooks( 'UnwatchArticleComplete', array( $this->getUser(), &$article ) ); |
401 | 363 | } |
402 | 364 | } |
403 | 365 | } |
404 | 366 | |
405 | 367 | public function submitNormal( $data ) { |
406 | | - global $wgUser; |
407 | 368 | $removed = array(); |
408 | 369 | |
409 | 370 | foreach( $data as $titles ) { |
410 | | - $this->unwatchTitles( $titles, $wgUser ); |
| 371 | + $this->unwatchTitles( $titles ); |
411 | 372 | $removed += $titles; |
412 | 373 | } |
413 | 374 | |
414 | 375 | if( count( $removed ) > 0 ) { |
415 | | - global $wgLang; |
416 | 376 | $this->successMessage = wfMessage( |
417 | 377 | 'watchlistedit-normal-done', |
418 | | - $wgLang->formatNum( count( $removed ) ) |
| 378 | + $this->getLang()->formatNum( count( $removed ) ) |
419 | 379 | ); |
420 | | - $this->showTitles( $removed, $this->successMessage, $this->getSkin() ); |
| 380 | + $this->showTitles( $removed, $this->successMessage ); |
421 | 381 | return true; |
422 | 382 | } else { |
423 | 383 | return false; |
— | — | @@ -426,15 +386,14 @@ |
427 | 387 | /** |
428 | 388 | * Get the standard watchlist editing form |
429 | 389 | * |
430 | | - * @param $user User |
431 | 390 | * @return HTMLForm |
432 | 391 | */ |
433 | | - protected function getNormalForm( $user ){ |
| 392 | + protected function getNormalForm(){ |
434 | 393 | global $wgContLang; |
435 | | - $skin = $user->getSkin(); |
| 394 | + |
436 | 395 | $fields = array(); |
437 | 396 | |
438 | | - foreach( $this->getWatchlistInfo( $user ) as $namespace => $pages ){ |
| 397 | + foreach( $this->getWatchlistInfo() as $namespace => $pages ){ |
439 | 398 | |
440 | 399 | $namespace == NS_MAIN |
441 | 400 | ? wfMsgHtml( 'blanknamespace' ) |
— | — | @@ -448,7 +407,7 @@ |
449 | 408 | |
450 | 409 | foreach( $pages as $dbkey => $redirect ){ |
451 | 410 | $title = Title::makeTitleSafe( $namespace, $dbkey ); |
452 | | - $text = $this->buildRemoveLine( $title, $redirect, $skin ); |
| 411 | + $text = $this->buildRemoveLine( $title, $redirect ); |
453 | 412 | $fields['TitlesNs'.$namespace]['options'][$text] = $title->getEscapedText(); |
454 | 413 | } |
455 | 414 | } |
— | — | @@ -467,49 +426,41 @@ |
468 | 427 | * |
469 | 428 | * @param $title Title |
470 | 429 | * @param $redirect bool |
471 | | - * @param $skin Skin |
472 | 430 | * @return string |
473 | 431 | */ |
474 | | - private function buildRemoveLine( $title, $redirect, $skin ) { |
475 | | - global $wgLang; |
476 | | - |
477 | | - $link = $skin->link( $title ); |
| 432 | + private function buildRemoveLine( $title, $redirect ) { |
| 433 | + $link = Linker::link( $title ); |
478 | 434 | if( $redirect ) { |
479 | 435 | $link = '<span class="watchlistredir">' . $link . '</span>'; |
480 | 436 | } |
481 | | - $tools[] = $skin->link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ); |
| 437 | + $tools[] = Linker::link( $title->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) ); |
482 | 438 | if( $title->exists() ) { |
483 | | - $tools[] = $skin->link( |
| 439 | + $tools[] = Linker::linkKnown( |
484 | 440 | $title, |
485 | 441 | wfMsgHtml( 'history_short' ), |
486 | 442 | array(), |
487 | | - array( 'action' => 'history' ), |
488 | | - array( 'known', 'noclasses' ) |
| 443 | + array( 'action' => 'history' ) |
489 | 444 | ); |
490 | 445 | } |
491 | 446 | if( $title->getNamespace() == NS_USER && !$title->isSubpage() ) { |
492 | | - $tools[] = $skin->link( |
| 447 | + $tools[] = Linker::linkKnown( |
493 | 448 | SpecialPage::getTitleFor( 'Contributions', $title->getText() ), |
494 | | - wfMsgHtml( 'contributions' ), |
495 | | - array(), |
496 | | - array(), |
497 | | - array( 'known', 'noclasses' ) |
| 449 | + wfMsgHtml( 'contributions' ) |
498 | 450 | ); |
499 | 451 | } |
500 | 452 | |
501 | | - wfRunHooks( 'WatchlistEditorBuildRemoveLine', array( &$tools, $title, $redirect, $skin ) ); |
| 453 | + wfRunHooks( 'WatchlistEditorBuildRemoveLine', array( &$tools, $title, $redirect, $this->getSkin() ) ); |
502 | 454 | |
503 | | - return $link . " (" . $wgLang->pipeList( $tools ) . ")"; |
| 455 | + return $link . " (" . $this->getLang()->pipeList( $tools ) . ")"; |
504 | 456 | } |
505 | 457 | |
506 | 458 | /** |
507 | 459 | * Get a form for editing the watchlist in "raw" mode |
508 | 460 | * |
509 | | - * @param $user User |
510 | 461 | * @return HTMLForm |
511 | 462 | */ |
512 | | - protected function getRawForm( $user ){ |
513 | | - $titles = implode( array_map( 'htmlspecialchars', $this->getWatchlist( $user ) ), "\n" ); |
| 463 | + protected function getRawForm(){ |
| 464 | + $titles = implode( array_map( 'htmlspecialchars', $this->getWatchlist() ), "\n" ); |
514 | 465 | $fields = array( |
515 | 466 | 'Titles' => array( |
516 | 467 | 'type' => 'textarea', |
— | — | @@ -560,10 +511,10 @@ |
561 | 512 | * Build a set of links for convenient navigation |
562 | 513 | * between watchlist viewing and editing modes |
563 | 514 | * |
564 | | - * @param $skin Skin to use |
| 515 | + * @param $unused Unused |
565 | 516 | * @return string |
566 | 517 | */ |
567 | | - public static function buildTools( $skin ) { |
| 518 | + public static function buildTools( $unused ) { |
568 | 519 | global $wgLang; |
569 | 520 | |
570 | 521 | $tools = array(); |
— | — | @@ -574,7 +525,7 @@ |
575 | 526 | ); |
576 | 527 | foreach( $modes as $mode => $arr ) { |
577 | 528 | // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw' |
578 | | - $tools[] = $skin->linkKnown( |
| 529 | + $tools[] = Linker::linkKnown( |
579 | 530 | SpecialPage::getTitleFor( $arr[0], $arr[1] ), |
580 | 531 | wfMsgHtml( "watchlisttools-{$mode}" ) |
581 | 532 | ); |
— | — | @@ -593,10 +544,9 @@ |
594 | 545 | */ |
595 | 546 | class EditWatchlistNormalHTMLForm extends HTMLForm { |
596 | 547 | public function getLegend( $namespace ){ |
597 | | - global $wgLang; |
598 | 548 | $namespace = substr( $namespace, 2 ); |
599 | 549 | return $namespace == NS_MAIN |
600 | 550 | ? wfMsgHtml( 'blanknamespace' ) |
601 | | - : htmlspecialchars( $wgLang->getFormattedNsText( $namespace ) ); |
| 551 | + : htmlspecialchars( $this->getContext()->getLang()->getFormattedNsText( $namespace ) ); |
602 | 552 | } |
603 | 553 | } |