Merge "Fixed IDE errors due to SquidUpdate::newFromTitles"
[lhc/web/wiklou.git] / includes / specials / SpecialEditWatchlist.php
1 <?php
2 /**
3 * @defgroup Watchlist Users watchlist handling
4 */
5
6 /**
7 * Implements Special:EditWatchlist
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 * @ingroup SpecialPage
26 * @ingroup Watchlist
27 */
28
29 /**
30 * Provides the UI through which users can perform editing
31 * operations on their watchlist
32 *
33 * @ingroup SpecialPage
34 * @ingroup Watchlist
35 * @author Rob Church <robchur@gmail.com>
36 */
37 class SpecialEditWatchlist extends UnlistedSpecialPage {
38 /**
39 * Editing modes. EDIT_CLEAR is no longer used; the "Clear" link scared people
40 * too much. Now it's passed on to the raw editor, from which it's very easy to clear.
41 */
42 const EDIT_CLEAR = 1;
43 const EDIT_RAW = 2;
44 const EDIT_NORMAL = 3;
45
46 protected $successMessage;
47
48 protected $toc;
49
50 private $badItems = array();
51
52 public function __construct() {
53 parent::__construct( 'EditWatchlist', 'editmywatchlist' );
54 }
55
56 /**
57 * Main execution point
58 *
59 * @param int $mode
60 */
61 public function execute( $mode ) {
62 $this->setHeaders();
63
64 # Anons don't get a watchlist
65 $this->requireLogin( 'watchlistanontext' );
66
67 $out = $this->getOutput();
68
69 $this->checkPermissions();
70 $this->checkReadOnly();
71
72 $this->outputHeader();
73 $this->outputSubtitle();
74 $out->addModuleStyles( 'mediawiki.special' );
75
76 # B/C: $mode used to be waaay down the parameter list, and the first parameter
77 # was $wgUser
78 if ( $mode instanceof User ) {
79 $args = func_get_args();
80 if ( count( $args ) >= 4 ) {
81 $mode = $args[3];
82 }
83 }
84 $mode = self::getMode( $this->getRequest(), $mode );
85
86 switch ( $mode ) {
87 case self::EDIT_RAW:
88 $out->setPageTitle( $this->msg( 'watchlistedit-raw-title' ) );
89 $form = $this->getRawForm();
90 if ( $form->show() ) {
91 $out->addHTML( $this->successMessage );
92 $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
93 }
94 break;
95 case self::EDIT_CLEAR:
96 $out->setPageTitle( $this->msg( 'watchlistedit-clear-title' ) );
97 $form = $this->getClearForm();
98 if ( $form->show() ) {
99 $out->addHTML( $this->successMessage );
100 $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
101 }
102 break;
103
104 case self::EDIT_NORMAL:
105 default:
106 $this->executeViewEditWatchlist();
107 break;
108 }
109 }
110
111 /**
112 * Renders a subheader on the watchlist page.
113 */
114 protected function outputSubtitle() {
115 $out = $this->getOutput();
116 $out->addSubtitle( $this->msg( 'watchlistfor2', $this->getUser()->getName() )
117 ->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
118 }
119
120 /**
121 * Executes an edit mode for the watchlist view, from which you can manage your watchlist
122 *
123 */
124 protected function executeViewEditWatchlist() {
125 $out = $this->getOutput();
126 $out->setPageTitle( $this->msg( 'watchlistedit-normal-title' ) );
127 $form = $this->getNormalForm();
128 if ( $form->show() ) {
129 $out->addHTML( $this->successMessage );
130 $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
131 } elseif ( $this->toc !== false ) {
132 $out->prependHTML( $this->toc );
133 $out->addModules( 'mediawiki.toc' );
134 }
135 }
136
137 /**
138 * Return an array of subpages that this special page will accept.
139 *
140 * @see also SpecialWatchlist::getSubpagesForPrefixSearch
141 * @return string[] subpages
142 */
143 public function getSubpagesForPrefixSearch() {
144 // SpecialWatchlist uses SpecialEditWatchlist::getMode, so new types should be added
145 // here and there - no 'edit' here, because that the default for this page
146 return array(
147 'clear',
148 'raw',
149 );
150 }
151
152 /**
153 * Extract a list of titles from a blob of text, returning
154 * (prefixed) strings; unwatchable titles are ignored
155 *
156 * @param string $list
157 * @return array
158 */
159 private function extractTitles( $list ) {
160 $list = explode( "\n", trim( $list ) );
161 if ( !is_array( $list ) ) {
162 return array();
163 }
164
165 $titles = array();
166
167 foreach ( $list as $text ) {
168 $text = trim( $text );
169 if ( strlen( $text ) > 0 ) {
170 $title = Title::newFromText( $text );
171 if ( $title instanceof Title && $title->isWatchable() ) {
172 $titles[] = $title;
173 }
174 }
175 }
176
177 GenderCache::singleton()->doTitlesArray( $titles );
178
179 $list = array();
180 /** @var Title $title */
181 foreach ( $titles as $title ) {
182 $list[] = $title->getPrefixedText();
183 }
184
185 return array_unique( $list );
186 }
187
188 public function submitRaw( $data ) {
189 $wanted = $this->extractTitles( $data['Titles'] );
190 $current = $this->getWatchlist();
191
192 if ( count( $wanted ) > 0 ) {
193 $toWatch = array_diff( $wanted, $current );
194 $toUnwatch = array_diff( $current, $wanted );
195 $this->watchTitles( $toWatch );
196 $this->unwatchTitles( $toUnwatch );
197 $this->getUser()->invalidateCache();
198
199 if ( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 ) {
200 $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
201 } else {
202 return false;
203 }
204
205 if ( count( $toWatch ) > 0 ) {
206 $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-added' )
207 ->numParams( count( $toWatch ) )->parse();
208 $this->showTitles( $toWatch, $this->successMessage );
209 }
210
211 if ( count( $toUnwatch ) > 0 ) {
212 $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
213 ->numParams( count( $toUnwatch ) )->parse();
214 $this->showTitles( $toUnwatch, $this->successMessage );
215 }
216 } else {
217 $this->clearWatchlist();
218 $this->getUser()->invalidateCache();
219
220 if ( count( $current ) > 0 ) {
221 $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
222 } else {
223 return false;
224 }
225
226 $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
227 ->numParams( count( $current ) )->parse();
228 $this->showTitles( $current, $this->successMessage );
229 }
230
231 return true;
232 }
233
234 public function submitClear( $data ) {
235 $current = $this->getWatchlist();
236 $this->clearWatchlist();
237 $this->getUser()->invalidateCache();
238 $this->successMessage = $this->msg( 'watchlistedit-clear-done' )->parse();
239 $this->successMessage .= ' ' . $this->msg( 'watchlistedit-clear-removed' )
240 ->numParams( count( $current ) )->parse();
241 $this->showTitles( $current, $this->successMessage );
242
243 return true;
244 }
245
246 /**
247 * Print out a list of linked titles
248 *
249 * $titles can be an array of strings or Title objects; the former
250 * is preferred, since Titles are very memory-heavy
251 *
252 * @param array $titles Array of strings, or Title objects
253 * @param string $output
254 */
255 private function showTitles( $titles, &$output ) {
256 $talk = $this->msg( 'talkpagelinktext' )->escaped();
257 // Do a batch existence check
258 $batch = new LinkBatch();
259 if ( count( $titles ) >= 100 ) {
260 $output = $this->msg( 'watchlistedit-too-many' )->parse();
261 return;
262 }
263 foreach ( $titles as $title ) {
264 if ( !$title instanceof Title ) {
265 $title = Title::newFromText( $title );
266 }
267
268 if ( $title instanceof Title ) {
269 $batch->addObj( $title );
270 $batch->addObj( $title->getTalkPage() );
271 }
272 }
273
274 $batch->execute();
275
276 // Print out the list
277 $output .= "<ul>\n";
278
279 foreach ( $titles as $title ) {
280 if ( !$title instanceof Title ) {
281 $title = Title::newFromText( $title );
282 }
283
284 if ( $title instanceof Title ) {
285 $output .= "<li>"
286 . Linker::link( $title )
287 . ' (' . Linker::link( $title->getTalkPage(), $talk )
288 . ")</li>\n";
289 }
290 }
291
292 $output .= "</ul>\n";
293 }
294
295 /**
296 * Prepare a list of titles on a user's watchlist (excluding talk pages)
297 * and return an array of (prefixed) strings
298 *
299 * @return array
300 */
301 private function getWatchlist() {
302 $list = array();
303
304 $index = $this->getRequest()->wasPosted() ? DB_MASTER : DB_SLAVE;
305 $dbr = wfGetDB( $index );
306
307 $res = $dbr->select(
308 'watchlist',
309 array(
310 'wl_namespace', 'wl_title'
311 ), array(
312 'wl_user' => $this->getUser()->getId(),
313 ),
314 __METHOD__
315 );
316
317 if ( $res->numRows() > 0 ) {
318 /** @var Title[] $titles */
319 $titles = array();
320 foreach ( $res as $row ) {
321 $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
322
323 if ( $this->checkTitle( $title, $row->wl_namespace, $row->wl_title )
324 && !$title->isTalkPage()
325 ) {
326 $titles[] = $title;
327 }
328 }
329 $res->free();
330
331 GenderCache::singleton()->doTitlesArray( $titles );
332
333 foreach ( $titles as $title ) {
334 $list[] = $title->getPrefixedText();
335 }
336 }
337
338 $this->cleanupWatchlist();
339
340 return $list;
341 }
342
343 /**
344 * Get a list of titles on a user's watchlist, excluding talk pages,
345 * and return as a two-dimensional array with namespace and title.
346 *
347 * @return array
348 */
349 protected function getWatchlistInfo() {
350 $titles = array();
351 $dbr = wfGetDB( DB_SLAVE );
352
353 $res = $dbr->select(
354 array( 'watchlist' ),
355 array( 'wl_namespace', 'wl_title' ),
356 array( 'wl_user' => $this->getUser()->getId() ),
357 __METHOD__,
358 array( 'ORDER BY' => array( 'wl_namespace', 'wl_title' ) )
359 );
360
361 $lb = new LinkBatch();
362
363 foreach ( $res as $row ) {
364 $lb->add( $row->wl_namespace, $row->wl_title );
365 if ( !MWNamespace::isTalk( $row->wl_namespace ) ) {
366 $titles[$row->wl_namespace][$row->wl_title] = 1;
367 }
368 }
369
370 $lb->execute();
371
372 return $titles;
373 }
374
375 /**
376 * Validates watchlist entry
377 *
378 * @param Title $title
379 * @param int $namespace
380 * @param string $dbKey
381 * @return bool Whether this item is valid
382 */
383 private function checkTitle( $title, $namespace, $dbKey ) {
384 if ( $title
385 && ( $title->isExternal()
386 || $title->getNamespace() < 0
387 )
388 ) {
389 $title = false; // unrecoverable
390 }
391
392 if ( !$title
393 || $title->getNamespace() != $namespace
394 || $title->getDBkey() != $dbKey
395 ) {
396 $this->badItems[] = array( $title, $namespace, $dbKey );
397 }
398
399 return (bool)$title;
400 }
401
402 /**
403 * Attempts to clean up broken items
404 */
405 private function cleanupWatchlist() {
406 if ( !count( $this->badItems ) ) {
407 return; // nothing to do
408 }
409
410 $dbw = wfGetDB( DB_MASTER );
411 $user = $this->getUser();
412
413 foreach ( $this->badItems as $row ) {
414 list( $title, $namespace, $dbKey ) = $row;
415 $action = $title ? 'cleaning up' : 'deleting';
416 wfDebug( "User {$user->getName()} has broken watchlist item ns($namespace):$dbKey, $action.\n" );
417
418 $dbw->delete( 'watchlist',
419 array(
420 'wl_user' => $user->getId(),
421 'wl_namespace' => $namespace,
422 'wl_title' => $dbKey,
423 ),
424 __METHOD__
425 );
426
427 // Can't just do an UPDATE instead of DELETE/INSERT due to unique index
428 if ( $title ) {
429 $user->addWatch( $title );
430 }
431 }
432 }
433
434 /**
435 * Remove all titles from a user's watchlist
436 */
437 private function clearWatchlist() {
438 $dbw = wfGetDB( DB_MASTER );
439 $dbw->delete(
440 'watchlist',
441 array( 'wl_user' => $this->getUser()->getId() ),
442 __METHOD__
443 );
444 }
445
446 /**
447 * Add a list of titles to a user's watchlist
448 *
449 * $titles can be an array of strings or Title objects; the former
450 * is preferred, since Titles are very memory-heavy
451 *
452 * @param array $titles Array of strings, or Title objects
453 */
454 private function watchTitles( $titles ) {
455 $dbw = wfGetDB( DB_MASTER );
456 $rows = array();
457
458 foreach ( $titles as $title ) {
459 if ( !$title instanceof Title ) {
460 $title = Title::newFromText( $title );
461 }
462
463 if ( $title instanceof Title ) {
464 $rows[] = array(
465 'wl_user' => $this->getUser()->getId(),
466 'wl_namespace' => MWNamespace::getSubject( $title->getNamespace() ),
467 'wl_title' => $title->getDBkey(),
468 'wl_notificationtimestamp' => null,
469 );
470 $rows[] = array(
471 'wl_user' => $this->getUser()->getId(),
472 'wl_namespace' => MWNamespace::getTalk( $title->getNamespace() ),
473 'wl_title' => $title->getDBkey(),
474 'wl_notificationtimestamp' => null,
475 );
476 }
477 }
478
479 $dbw->insert( 'watchlist', $rows, __METHOD__, 'IGNORE' );
480 }
481
482 /**
483 * Remove a list of titles from a user's watchlist
484 *
485 * $titles can be an array of strings or Title objects; the former
486 * is preferred, since Titles are very memory-heavy
487 *
488 * @param array $titles Array of strings, or Title objects
489 */
490 private function unwatchTitles( $titles ) {
491 $dbw = wfGetDB( DB_MASTER );
492
493 foreach ( $titles as $title ) {
494 if ( !$title instanceof Title ) {
495 $title = Title::newFromText( $title );
496 }
497
498 if ( $title instanceof Title ) {
499 $dbw->delete(
500 'watchlist',
501 array(
502 'wl_user' => $this->getUser()->getId(),
503 'wl_namespace' => MWNamespace::getSubject( $title->getNamespace() ),
504 'wl_title' => $title->getDBkey(),
505 ),
506 __METHOD__
507 );
508
509 $dbw->delete(
510 'watchlist',
511 array(
512 'wl_user' => $this->getUser()->getId(),
513 'wl_namespace' => MWNamespace::getTalk( $title->getNamespace() ),
514 'wl_title' => $title->getDBkey(),
515 ),
516 __METHOD__
517 );
518
519 $page = WikiPage::factory( $title );
520 Hooks::run( 'UnwatchArticleComplete', array( $this->getUser(), &$page ) );
521 }
522 }
523 }
524
525 public function submitNormal( $data ) {
526 $removed = array();
527
528 foreach ( $data as $titles ) {
529 $this->unwatchTitles( $titles );
530 $removed = array_merge( $removed, $titles );
531 }
532
533 if ( count( $removed ) > 0 ) {
534 $this->successMessage = $this->msg( 'watchlistedit-normal-done'
535 )->numParams( count( $removed ) )->parse();
536 $this->showTitles( $removed, $this->successMessage );
537
538 return true;
539 } else {
540 return false;
541 }
542 }
543
544 /**
545 * Get the standard watchlist editing form
546 *
547 * @return HTMLForm
548 */
549 protected function getNormalForm() {
550 global $wgContLang;
551
552 $fields = array();
553 $count = 0;
554
555 // Allow subscribers to manipulate the list of watched pages (or use it
556 // to preload lots of details at once)
557 $watchlistInfo = $this->getWatchlistInfo();
558 Hooks::run(
559 'WatchlistEditorBeforeFormRender',
560 array( &$watchlistInfo )
561 );
562
563 foreach ( $watchlistInfo as $namespace => $pages ) {
564 $options = array();
565
566 foreach ( array_keys( $pages ) as $dbkey ) {
567 $title = Title::makeTitleSafe( $namespace, $dbkey );
568
569 if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
570 $text = $this->buildRemoveLine( $title );
571 $options[$text] = $title->getPrefixedText();
572 $count++;
573 }
574 }
575
576 // checkTitle can filter some options out, avoid empty sections
577 if ( count( $options ) > 0 ) {
578 $fields['TitlesNs' . $namespace] = array(
579 'class' => 'EditWatchlistCheckboxSeriesField',
580 'options' => $options,
581 'section' => "ns$namespace",
582 );
583 }
584 }
585 $this->cleanupWatchlist();
586
587 if ( count( $fields ) > 1 && $count > 30 ) {
588 $this->toc = Linker::tocIndent();
589 $tocLength = 0;
590
591 foreach ( $fields as $data ) {
592 # strip out the 'ns' prefix from the section name:
593 $ns = substr( $data['section'], 2 );
594
595 $nsText = ( $ns == NS_MAIN )
596 ? $this->msg( 'blanknamespace' )->escaped()
597 : htmlspecialchars( $wgContLang->getFormattedNsText( $ns ) );
598 $this->toc .= Linker::tocLine( "editwatchlist-{$data['section']}", $nsText,
599 $this->getLanguage()->formatNum( ++$tocLength ), 1 ) . Linker::tocLineEnd();
600 }
601
602 $this->toc = Linker::tocList( $this->toc );
603 } else {
604 $this->toc = false;
605 }
606
607 $context = new DerivativeContext( $this->getContext() );
608 $context->setTitle( $this->getPageTitle() ); // Remove subpage
609 $form = new EditWatchlistNormalHTMLForm( $fields, $context );
610 $form->setSubmitTextMsg( 'watchlistedit-normal-submit' );
611 $form->setSubmitDestructive();
612 # Used message keys:
613 # 'accesskey-watchlistedit-normal-submit', 'tooltip-watchlistedit-normal-submit'
614 $form->setSubmitTooltip( 'watchlistedit-normal-submit' );
615 $form->setWrapperLegendMsg( 'watchlistedit-normal-legend' );
616 $form->addHeaderText( $this->msg( 'watchlistedit-normal-explain' )->parse() );
617 $form->setSubmitCallback( array( $this, 'submitNormal' ) );
618
619 return $form;
620 }
621
622 /**
623 * Build the label for a checkbox, with a link to the title, and various additional bits
624 *
625 * @param Title $title
626 * @return string
627 */
628 private function buildRemoveLine( $title ) {
629 $link = Linker::link( $title );
630
631 $tools['talk'] = Linker::link(
632 $title->getTalkPage(),
633 $this->msg( 'talkpagelinktext' )->escaped()
634 );
635
636 if ( $title->exists() ) {
637 $tools['history'] = Linker::linkKnown(
638 $title,
639 $this->msg( 'history_short' )->escaped(),
640 array(),
641 array( 'action' => 'history' )
642 );
643 }
644
645 if ( $title->getNamespace() == NS_USER && !$title->isSubpage() ) {
646 $tools['contributions'] = Linker::linkKnown(
647 SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
648 $this->msg( 'contributions' )->escaped()
649 );
650 }
651
652 Hooks::run(
653 'WatchlistEditorBuildRemoveLine',
654 array( &$tools, $title, $title->isRedirect(), $this->getSkin(), &$link )
655 );
656
657 if ( $title->isRedirect() ) {
658 // Linker already makes class mw-redirect, so this is redundant
659 $link = '<span class="watchlistredir">' . $link . '</span>';
660 }
661
662 return $link . " (" . $this->getLanguage()->pipeList( $tools ) . ")";
663 }
664
665 /**
666 * Get a form for editing the watchlist in "raw" mode
667 *
668 * @return HTMLForm
669 */
670 protected function getRawForm() {
671 $titles = implode( $this->getWatchlist(), "\n" );
672 $fields = array(
673 'Titles' => array(
674 'type' => 'textarea',
675 'label-message' => 'watchlistedit-raw-titles',
676 'default' => $titles,
677 ),
678 );
679 $context = new DerivativeContext( $this->getContext() );
680 $context->setTitle( $this->getPageTitle( 'raw' ) ); // Reset subpage
681 $form = new HTMLForm( $fields, $context );
682 $form->setSubmitTextMsg( 'watchlistedit-raw-submit' );
683 # Used message keys: 'accesskey-watchlistedit-raw-submit', 'tooltip-watchlistedit-raw-submit'
684 $form->setSubmitTooltip( 'watchlistedit-raw-submit' );
685 $form->setWrapperLegendMsg( 'watchlistedit-raw-legend' );
686 $form->addHeaderText( $this->msg( 'watchlistedit-raw-explain' )->parse() );
687 $form->setSubmitCallback( array( $this, 'submitRaw' ) );
688
689 return $form;
690 }
691
692 /**
693 * Get a form for clearing the watchlist
694 *
695 * @return HTMLForm
696 */
697 protected function getClearForm() {
698 $context = new DerivativeContext( $this->getContext() );
699 $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage
700 $form = new HTMLForm( array(), $context );
701 $form->setSubmitTextMsg( 'watchlistedit-clear-submit' );
702 # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit'
703 $form->setSubmitTooltip( 'watchlistedit-clear-submit' );
704 $form->setWrapperLegendMsg( 'watchlistedit-clear-legend' );
705 $form->addHeaderText( $this->msg( 'watchlistedit-clear-explain' )->parse() );
706 $form->setSubmitCallback( array( $this, 'submitClear' ) );
707 $form->setSubmitDestructive();
708
709 return $form;
710 }
711
712 /**
713 * Determine whether we are editing the watchlist, and if so, what
714 * kind of editing operation
715 *
716 * @param WebRequest $request
717 * @param string $par
718 * @return int
719 */
720 public static function getMode( $request, $par ) {
721 $mode = strtolower( $request->getVal( 'action', $par ) );
722
723 switch ( $mode ) {
724 case 'clear':
725 case self::EDIT_CLEAR:
726 return self::EDIT_CLEAR;
727 case 'raw':
728 case self::EDIT_RAW:
729 return self::EDIT_RAW;
730 case 'edit':
731 case self::EDIT_NORMAL:
732 return self::EDIT_NORMAL;
733 default:
734 return false;
735 }
736 }
737
738 /**
739 * Build a set of links for convenient navigation
740 * between watchlist viewing and editing modes
741 *
742 * @param null $unused
743 * @return string
744 */
745 public static function buildTools( $unused ) {
746 global $wgLang;
747
748 $tools = array();
749 $modes = array(
750 'view' => array( 'Watchlist', false ),
751 'edit' => array( 'EditWatchlist', false ),
752 'raw' => array( 'EditWatchlist', 'raw' ),
753 'clear' => array( 'EditWatchlist', 'clear' ),
754 );
755
756 foreach ( $modes as $mode => $arr ) {
757 // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw'
758 $tools[] = Linker::linkKnown(
759 SpecialPage::getTitleFor( $arr[0], $arr[1] ),
760 wfMessage( "watchlisttools-{$mode}" )->escaped()
761 );
762 }
763
764 return Html::rawElement(
765 'span',
766 array( 'class' => 'mw-watchlist-toollinks' ),
767 wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $tools ) )->escaped()
768 );
769 }
770 }
771
772 /**
773 * Extend HTMLForm purely so we can have a more sane way of getting the section headers
774 */
775 class EditWatchlistNormalHTMLForm extends HTMLForm {
776 public function getLegend( $namespace ) {
777 $namespace = substr( $namespace, 2 );
778
779 return $namespace == NS_MAIN
780 ? $this->msg( 'blanknamespace' )->escaped()
781 : htmlspecialchars( $this->getContext()->getLanguage()->getFormattedNsText( $namespace ) );
782 }
783
784 public function getBody() {
785 return $this->displaySection( $this->mFieldTree, '', 'editwatchlist-' );
786 }
787 }
788
789 class EditWatchlistCheckboxSeriesField extends HTMLMultiSelectField {
790 /**
791 * HTMLMultiSelectField throws validation errors if we get input data
792 * that doesn't match the data set in the form setup. This causes
793 * problems if something gets removed from the watchlist while the
794 * form is open (bug 32126), but we know that invalid items will
795 * be harmless so we can override it here.
796 *
797 * @param string $value The value the field was submitted with
798 * @param array $alldata The data collected from the form
799 * @return bool|string Bool true on success, or String error to display.
800 */
801 function validate( $value, $alldata ) {
802 // Need to call into grandparent to be a good citizen. :)
803 return HTMLFormField::validate( $value, $alldata );
804 }
805 }