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