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