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