MediaWiki  master
SpecialEditWatchlist.php
Go to the documentation of this file.
1 <?php
6 
31 
45  const EDIT_CLEAR = 1;
46  const EDIT_RAW = 2;
47  const EDIT_NORMAL = 3;
48 
49  protected $successMessage;
50 
51  protected $toc;
52 
53  private $badItems = [];
54 
58  private $titleParser;
59 
60  public function __construct() {
61  parent::__construct( 'EditWatchlist', 'editmywatchlist' );
62  }
63 
68  private function initServices() {
69  if ( !$this->titleParser ) {
70  $lang = $this->getContext()->getLanguage();
71  $this->titleParser = new MediaWikiTitleCodec( $lang, GenderCache::singleton() );
72  }
73  }
74 
75  public function doesWrites() {
76  return true;
77  }
78 
84  public function execute( $mode ) {
85  $this->initServices();
86  $this->setHeaders();
87 
88  # Anons don't get a watchlist
89  $this->requireLogin( 'watchlistanontext' );
90 
91  $out = $this->getOutput();
92 
93  $this->checkPermissions();
94  $this->checkReadOnly();
95 
96  $this->outputHeader();
97  $this->outputSubtitle();
98  $out->addModuleStyles( 'mediawiki.special' );
99 
100  # B/C: $mode used to be waaay down the parameter list, and the first parameter
101  # was $wgUser
102  if ( $mode instanceof User ) {
103  $args = func_get_args();
104  if ( count( $args ) >= 4 ) {
105  $mode = $args[3];
106  }
107  }
108  $mode = self::getMode( $this->getRequest(), $mode );
109 
110  switch ( $mode ) {
111  case self::EDIT_RAW:
112  $out->setPageTitle( $this->msg( 'watchlistedit-raw-title' ) );
113  $form = $this->getRawForm();
114  if ( $form->show() ) {
115  $out->addHTML( $this->successMessage );
116  $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
117  }
118  break;
119  case self::EDIT_CLEAR:
120  $out->setPageTitle( $this->msg( 'watchlistedit-clear-title' ) );
121  $form = $this->getClearForm();
122  if ( $form->show() ) {
123  $out->addHTML( $this->successMessage );
124  $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
125  }
126  break;
127 
128  case self::EDIT_NORMAL:
129  default:
130  $this->executeViewEditWatchlist();
131  break;
132  }
133  }
134 
138  protected function outputSubtitle() {
139  $out = $this->getOutput();
140  $out->addSubtitle( $this->msg( 'watchlistfor2', $this->getUser()->getName() )
141  ->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
142  }
143 
148  protected function executeViewEditWatchlist() {
149  $out = $this->getOutput();
150  $out->setPageTitle( $this->msg( 'watchlistedit-normal-title' ) );
151  $form = $this->getNormalForm();
152  if ( $form->show() ) {
153  $out->addHTML( $this->successMessage );
154  $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
155  } elseif ( $this->toc !== false ) {
156  $out->prependHTML( $this->toc );
157  $out->addModules( 'mediawiki.toc' );
158  }
159  }
160 
167  public function getSubpagesForPrefixSearch() {
168  // SpecialWatchlist uses SpecialEditWatchlist::getMode, so new types should be added
169  // here and there - no 'edit' here, because that the default for this page
170  return [
171  'clear',
172  'raw',
173  ];
174  }
175 
183  private function extractTitles( $list ) {
184  $list = explode( "\n", trim( $list ) );
185  if ( !is_array( $list ) ) {
186  return [];
187  }
188 
189  $titles = [];
190 
191  foreach ( $list as $text ) {
192  $text = trim( $text );
193  if ( strlen( $text ) > 0 ) {
194  $title = Title::newFromText( $text );
195  if ( $title instanceof Title && $title->isWatchable() ) {
196  $titles[] = $title;
197  }
198  }
199  }
200 
201  GenderCache::singleton()->doTitlesArray( $titles );
202 
203  $list = [];
205  foreach ( $titles as $title ) {
206  $list[] = $title->getPrefixedText();
207  }
208 
209  return array_unique( $list );
210  }
211 
212  public function submitRaw( $data ) {
213  $wanted = $this->extractTitles( $data['Titles'] );
214  $current = $this->getWatchlist();
215 
216  if ( count( $wanted ) > 0 ) {
217  $toWatch = array_diff( $wanted, $current );
218  $toUnwatch = array_diff( $current, $wanted );
219  $this->watchTitles( $toWatch );
220  $this->unwatchTitles( $toUnwatch );
221  $this->getUser()->invalidateCache();
222 
223  if ( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 ) {
224  $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
225  } else {
226  return false;
227  }
228 
229  if ( count( $toWatch ) > 0 ) {
230  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-added' )
231  ->numParams( count( $toWatch ) )->parse();
232  $this->showTitles( $toWatch, $this->successMessage );
233  }
234 
235  if ( count( $toUnwatch ) > 0 ) {
236  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
237  ->numParams( count( $toUnwatch ) )->parse();
238  $this->showTitles( $toUnwatch, $this->successMessage );
239  }
240  } else {
241  $this->clearWatchlist();
242  $this->getUser()->invalidateCache();
243 
244  if ( count( $current ) > 0 ) {
245  $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
246  } else {
247  return false;
248  }
249 
250  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
251  ->numParams( count( $current ) )->parse();
252  $this->showTitles( $current, $this->successMessage );
253  }
254 
255  return true;
256  }
257 
258  public function submitClear( $data ) {
259  $current = $this->getWatchlist();
260  $this->clearWatchlist();
261  $this->getUser()->invalidateCache();
262  $this->successMessage = $this->msg( 'watchlistedit-clear-done' )->parse();
263  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-clear-removed' )
264  ->numParams( count( $current ) )->parse();
265  $this->showTitles( $current, $this->successMessage );
266 
267  return true;
268  }
269 
279  private function showTitles( $titles, &$output ) {
280  $talk = $this->msg( 'talkpagelinktext' )->escaped();
281  // Do a batch existence check
282  $batch = new LinkBatch();
283  if ( count( $titles ) >= 100 ) {
284  $output = $this->msg( 'watchlistedit-too-many' )->parse();
285  return;
286  }
287  foreach ( $titles as $title ) {
288  if ( !$title instanceof Title ) {
289  $title = Title::newFromText( $title );
290  }
291 
292  if ( $title instanceof Title ) {
293  $batch->addObj( $title );
294  $batch->addObj( $title->getTalkPage() );
295  }
296  }
297 
298  $batch->execute();
299 
300  // Print out the list
301  $output .= "<ul>\n";
302 
303  foreach ( $titles as $title ) {
304  if ( !$title instanceof Title ) {
305  $title = Title::newFromText( $title );
306  }
307 
308  if ( $title instanceof Title ) {
309  $output .= '<li>' .
310  Linker::link( $title ) . ' ' .
311  $this->msg( 'parentheses' )->rawParams(
312  Linker::link( $title->getTalkPage(), $talk )
313  )->escaped() .
314  "</li>\n";
315  }
316  }
317 
318  $output .= "</ul>\n";
319  }
320 
327  private function getWatchlist() {
328  $list = [];
329 
330  $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()->getWatchedItemsForUser(
331  $this->getUser(),
332  [ 'forWrite' => $this->getRequest()->wasPosted() ]
333  );
334 
335  if ( $watchedItems ) {
337  $titles = [];
338  foreach ( $watchedItems as $watchedItem ) {
339  $namespace = $watchedItem->getLinkTarget()->getNamespace();
340  $dbKey = $watchedItem->getLinkTarget()->getDBkey();
341  $title = Title::makeTitleSafe( $namespace, $dbKey );
342 
343  if ( $this->checkTitle( $title, $namespace, $dbKey )
344  && !$title->isTalkPage()
345  ) {
346  $titles[] = $title;
347  }
348  }
349 
350  GenderCache::singleton()->doTitlesArray( $titles );
351 
352  foreach ( $titles as $title ) {
353  $list[] = $title->getPrefixedText();
354  }
355  }
356 
357  $this->cleanupWatchlist();
358 
359  return $list;
360  }
361 
368  protected function getWatchlistInfo() {
369  $titles = [];
370 
371  $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()
372  ->getWatchedItemsForUser( $this->getUser(), [ 'sort' => WatchedItemStore::SORT_ASC ] );
373 
374  $lb = new LinkBatch();
375 
376  foreach ( $watchedItems as $watchedItem ) {
377  $namespace = $watchedItem->getLinkTarget()->getNamespace();
378  $dbKey = $watchedItem->getLinkTarget()->getDBkey();
379  $lb->add( $namespace, $dbKey );
380  if ( !MWNamespace::isTalk( $namespace ) ) {
381  $titles[$namespace][$dbKey] = 1;
382  }
383  }
384 
385  $lb->execute();
386 
387  return $titles;
388  }
389 
398  private function checkTitle( $title, $namespace, $dbKey ) {
399  if ( $title
400  && ( $title->isExternal()
401  || $title->getNamespace() < 0
402  )
403  ) {
404  $title = false; // unrecoverable
405  }
406 
407  if ( !$title
408  || $title->getNamespace() != $namespace
409  || $title->getDBkey() != $dbKey
410  ) {
411  $this->badItems[] = [ $title, $namespace, $dbKey ];
412  }
413 
414  return (bool)$title;
415  }
416 
420  private function cleanupWatchlist() {
421  if ( !count( $this->badItems ) ) {
422  return; // nothing to do
423  }
424 
425  $user = $this->getUser();
426  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
427 
428  foreach ( $this->badItems as $row ) {
429  list( $title, $namespace, $dbKey ) = $row;
430  $action = $title ? 'cleaning up' : 'deleting';
431  wfDebug( "User {$user->getName()} has broken watchlist item ns($namespace):$dbKey, $action.\n" );
432 
433  $store->removeWatch( $user, new TitleValue( (int)$namespace, $dbKey ) );
434 
435  // Can't just do an UPDATE instead of DELETE/INSERT due to unique index
436  if ( $title ) {
437  $user->addWatch( $title );
438  }
439  }
440  }
441 
445  private function clearWatchlist() {
446  $dbw = wfGetDB( DB_MASTER );
447  $dbw->delete(
448  'watchlist',
449  [ 'wl_user' => $this->getUser()->getId() ],
450  __METHOD__
451  );
452  }
453 
459  private function watchTitles( $targets ) {
460  $expandedTargets = [];
461  foreach ( $targets as $target ) {
462  if ( !$target instanceof LinkTarget ) {
463  try {
464  $target = $this->titleParser->parseTitle( $target, NS_MAIN );
465  }
466  catch ( MalformedTitleException $e ) {
467  continue;
468  }
469  }
470 
471  $ns = $target->getNamespace();
472  $dbKey = $target->getDBkey();
473  $expandedTargets[] = new TitleValue( MWNamespace::getSubject( $ns ), $dbKey );
474  $expandedTargets[] = new TitleValue( MWNamespace::getTalk( $ns ), $dbKey );
475  }
476 
477  MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser(
478  $this->getUser(),
479  $expandedTargets
480  );
481  }
482 
491  private function unwatchTitles( $titles ) {
492  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
493 
494  foreach ( $titles as $title ) {
495  if ( !$title instanceof Title ) {
496  $title = Title::newFromText( $title );
497  }
498 
499  if ( $title instanceof Title ) {
500  $store->removeWatch( $this->getUser(), $title->getSubjectPage() );
501  $store->removeWatch( $this->getUser(), $title->getTalkPage() );
502 
503  $page = WikiPage::factory( $title );
504  Hooks::run( 'UnwatchArticleComplete', [ $this->getUser(), &$page ] );
505  }
506  }
507  }
508 
509  public function submitNormal( $data ) {
510  $removed = [];
511 
512  foreach ( $data as $titles ) {
513  $this->unwatchTitles( $titles );
514  $removed = array_merge( $removed, $titles );
515  }
516 
517  if ( count( $removed ) > 0 ) {
518  $this->successMessage = $this->msg( 'watchlistedit-normal-done'
519  )->numParams( count( $removed ) )->parse();
520  $this->showTitles( $removed, $this->successMessage );
521 
522  return true;
523  } else {
524  return false;
525  }
526  }
527 
533  protected function getNormalForm() {
535 
536  $fields = [];
537  $count = 0;
538 
539  // Allow subscribers to manipulate the list of watched pages (or use it
540  // to preload lots of details at once)
541  $watchlistInfo = $this->getWatchlistInfo();
542  Hooks::run(
543  'WatchlistEditorBeforeFormRender',
544  [ &$watchlistInfo ]
545  );
546 
547  foreach ( $watchlistInfo as $namespace => $pages ) {
548  $options = [];
549 
550  foreach ( array_keys( $pages ) as $dbkey ) {
551  $title = Title::makeTitleSafe( $namespace, $dbkey );
552 
553  if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
554  $text = $this->buildRemoveLine( $title );
555  $options[$text] = $title->getPrefixedText();
556  $count++;
557  }
558  }
559 
560  // checkTitle can filter some options out, avoid empty sections
561  if ( count( $options ) > 0 ) {
562  $fields['TitlesNs' . $namespace] = [
563  'class' => 'EditWatchlistCheckboxSeriesField',
564  'options' => $options,
565  'section' => "ns$namespace",
566  ];
567  }
568  }
569  $this->cleanupWatchlist();
570 
571  if ( count( $fields ) > 1 && $count > 30 ) {
572  $this->toc = Linker::tocIndent();
573  $tocLength = 0;
574 
575  foreach ( $fields as $data ) {
576  # strip out the 'ns' prefix from the section name:
577  $ns = substr( $data['section'], 2 );
578 
579  $nsText = ( $ns == NS_MAIN )
580  ? $this->msg( 'blanknamespace' )->escaped()
581  : htmlspecialchars( $wgContLang->getFormattedNsText( $ns ) );
582  $this->toc .= Linker::tocLine( "editwatchlist-{$data['section']}", $nsText,
583  $this->getLanguage()->formatNum( ++$tocLength ), 1 ) . Linker::tocLineEnd();
584  }
585 
586  $this->toc = Linker::tocList( $this->toc );
587  } else {
588  $this->toc = false;
589  }
590 
591  $context = new DerivativeContext( $this->getContext() );
592  $context->setTitle( $this->getPageTitle() ); // Remove subpage
593  $form = new EditWatchlistNormalHTMLForm( $fields, $context );
594  $form->setSubmitTextMsg( 'watchlistedit-normal-submit' );
595  $form->setSubmitDestructive();
596  # Used message keys:
597  # 'accesskey-watchlistedit-normal-submit', 'tooltip-watchlistedit-normal-submit'
598  $form->setSubmitTooltip( 'watchlistedit-normal-submit' );
599  $form->setWrapperLegendMsg( 'watchlistedit-normal-legend' );
600  $form->addHeaderText( $this->msg( 'watchlistedit-normal-explain' )->parse() );
601  $form->setSubmitCallback( [ $this, 'submitNormal' ] );
602 
603  return $form;
604  }
605 
612  private function buildRemoveLine( $title ) {
614 
615  $tools['talk'] = Linker::link(
616  $title->getTalkPage(),
617  $this->msg( 'talkpagelinktext' )->escaped()
618  );
619 
620  if ( $title->exists() ) {
621  $tools['history'] = Linker::linkKnown(
622  $title,
623  $this->msg( 'history_short' )->escaped(),
624  [],
625  [ 'action' => 'history' ]
626  );
627  }
628 
629  if ( $title->getNamespace() == NS_USER && !$title->isSubpage() ) {
630  $tools['contributions'] = Linker::linkKnown(
631  SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
632  $this->msg( 'contributions' )->escaped()
633  );
634  }
635 
636  Hooks::run(
637  'WatchlistEditorBuildRemoveLine',
638  [ &$tools, $title, $title->isRedirect(), $this->getSkin(), &$link ]
639  );
640 
641  if ( $title->isRedirect() ) {
642  // Linker already makes class mw-redirect, so this is redundant
643  $link = '<span class="watchlistredir">' . $link . '</span>';
644  }
645 
646  return $link . ' ' .
647  $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $tools ) )->escaped();
648  }
649 
655  protected function getRawForm() {
656  $titles = implode( $this->getWatchlist(), "\n" );
657  $fields = [
658  'Titles' => [
659  'type' => 'textarea',
660  'label-message' => 'watchlistedit-raw-titles',
661  'default' => $titles,
662  ],
663  ];
664  $context = new DerivativeContext( $this->getContext() );
665  $context->setTitle( $this->getPageTitle( 'raw' ) ); // Reset subpage
666  $form = new HTMLForm( $fields, $context );
667  $form->setSubmitTextMsg( 'watchlistedit-raw-submit' );
668  # Used message keys: 'accesskey-watchlistedit-raw-submit', 'tooltip-watchlistedit-raw-submit'
669  $form->setSubmitTooltip( 'watchlistedit-raw-submit' );
670  $form->setWrapperLegendMsg( 'watchlistedit-raw-legend' );
671  $form->addHeaderText( $this->msg( 'watchlistedit-raw-explain' )->parse() );
672  $form->setSubmitCallback( [ $this, 'submitRaw' ] );
673 
674  return $form;
675  }
676 
682  protected function getClearForm() {
683  $context = new DerivativeContext( $this->getContext() );
684  $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage
685  $form = new HTMLForm( [], $context );
686  $form->setSubmitTextMsg( 'watchlistedit-clear-submit' );
687  # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit'
688  $form->setSubmitTooltip( 'watchlistedit-clear-submit' );
689  $form->setWrapperLegendMsg( 'watchlistedit-clear-legend' );
690  $form->addHeaderText( $this->msg( 'watchlistedit-clear-explain' )->parse() );
691  $form->setSubmitCallback( [ $this, 'submitClear' ] );
692  $form->setSubmitDestructive();
693 
694  return $form;
695  }
696 
705  public static function getMode( $request, $par ) {
706  $mode = strtolower( $request->getVal( 'action', $par ) );
707 
708  switch ( $mode ) {
709  case 'clear':
710  case self::EDIT_CLEAR:
711  return self::EDIT_CLEAR;
712  case 'raw':
713  case self::EDIT_RAW:
714  return self::EDIT_RAW;
715  case 'edit':
716  case self::EDIT_NORMAL:
717  return self::EDIT_NORMAL;
718  default:
719  return false;
720  }
721  }
722 
730  public static function buildTools( $unused ) {
731  global $wgLang;
732 
733  $tools = [];
734  $modes = [
735  'view' => [ 'Watchlist', false ],
736  'edit' => [ 'EditWatchlist', false ],
737  'raw' => [ 'EditWatchlist', 'raw' ],
738  'clear' => [ 'EditWatchlist', 'clear' ],
739  ];
740 
741  foreach ( $modes as $mode => $arr ) {
742  // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw'
743  $tools[] = Linker::linkKnown(
744  SpecialPage::getTitleFor( $arr[0], $arr[1] ),
745  wfMessage( "watchlisttools-{$mode}" )->escaped()
746  );
747  }
748 
749  return Html::rawElement(
750  'span',
751  [ 'class' => 'mw-watchlist-toollinks' ],
752  wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $tools ) )->escaped()
753  );
754  }
755 }
756 
761  public function getLegend( $namespace ) {
762  $namespace = substr( $namespace, 2 );
763 
764  return $namespace == NS_MAIN
765  ? $this->msg( 'blanknamespace' )->escaped()
766  : htmlspecialchars( $this->getContext()->getLanguage()->getFormattedNsText( $namespace ) );
767  }
768 
769  public function getBody() {
770  return $this->displaySection( $this->mFieldTree, '', 'editwatchlist-' );
771  }
772 }
773 
786  function validate( $value, $alldata ) {
787  // Need to call into grandparent to be a good citizen. :)
788  return HTMLFormField::validate( $value, $alldata );
789  }
790 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:101
isRedirect()
Returns whether this Content represents a redirect.
A codec for MediaWiki page titles.
static tocLineEnd()
End a Table Of Contents line.
Definition: Linker.php:1634
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
static tocList($toc, $lang=false)
Wraps the TOC in a table and provides the hide/collapse javascript.
Definition: Linker.php:1646
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:776
getLanguage()
Get the Language object.
Shortcut to construct a special page which is unlisted by default.
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
$context
Definition: load.php:43
getContext()
Gets the context this SpecialPage is executed in.
const NS_MAIN
Definition: Defines.php:69
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
buildRemoveLine($title)
Build the label for a checkbox, with a link to the title, and various additional bits.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:80
const EDIT_CLEAR
Editing modes.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:1980
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
static singleton()
Definition: GenderCache.php:41
if(!isset($args[0])) $lang
getClearForm()
Get a form for clearing the watchlist.
cleanupWatchlist()
Attempts to clean up broken items.
static isTalk($index)
Is the given namespace a talk namespace?
Definition: MWNamespace.php:97
An IContextSource implementation which will inherit context from another source but allow individual ...
extractTitles($list)
Extract a list of titles from a blob of text, returning (prefixed) strings; unwatchable titles are ig...
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
$value
getRawForm()
Get a form for editing the watchlist in "raw" mode.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:256
Represents a title within MediaWiki.
Definition: Title.php:36
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
checkTitle($title, $namespace, $dbKey)
Validates watchlist entry.
getWatchlist()
Prepare a list of titles on a user's watchlist (excluding talk pages) and return an array of (prefixe...
clearWatchlist()
Remove all titles from a user's watchlist.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
if($line===false) $args
Definition: cdb.php:64
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition: hooks.txt:2621
$batch
Definition: linkcache.txt:23
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:47
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:32
Multi-select field.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
showTitles($titles, &$output)
Print out a list of linked titles.
validate($value, $alldata)
Override this function to add specific validation checks on the field input.
getNormalForm()
Get the standard watchlist editing form.
unwatchTitles($titles)
Remove a list of titles from a user's watchlist.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1020
execute($mode)
Main execution point.
Extend HTMLForm purely so we can have a more sane way of getting the section headers.
validate($value, $alldata)
HTMLMultiSelectField throws validation errors if we get input data that doesn't match the data set in...
initServices()
Initialize any services we'll need (unless it has already been provided via a setter).
getContext()
Get the base IContextSource object.
getSkin()
Shortcut to get the skin being used for this instance.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
Object handling generic submission, CSRF protection, layout and other logic for UI forms...
Definition: HTMLForm.php:128
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:527
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
watchTitles($targets)
Add a list of targets to a user's watchlist.
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $title
Definition: hooks.txt:312
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
static getMode($request, $par)
Determine whether we are editing the watchlist, and if so, what kind of editing operation.
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
static tocLine($anchor, $tocline, $tocnumber, $level, $sectionIndex=false)
parameter level defines if we are on an indentation level
Definition: Linker.php:1616
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:203
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition: hooks.txt:1020
displaySection($fields, $sectionName= '', $fieldsetIDPrefix= '', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1572
outputSubtitle()
Renders a subheader on the watchlist page.
static getTalk($index)
Get the talk namespace index for a given namespace.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2458
getName()
Get the name of this Special Page.
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
requireLogin($reasonMsg= 'exception-nologin-text', $titleMsg= 'exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
getLanguage()
Shortcut to get user's language.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
getWatchlistInfo()
Get a list of titles on a user's watchlist, excluding talk pages, and return as a two-dimensional arr...
static buildTools($unused)
Build a set of links for convenient navigation between watchlist viewing and editing modes...
$count
static tocIndent()
Add another level to the Table of Contents.
Definition: Linker.php:1590
const DB_MASTER
Definition: Defines.php:47
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
getRequest()
Get the WebRequest being used for this instance.
executeViewEditWatchlist()
Executes an edit mode for the watchlist view, from which you can manage your watchlist.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
static getSubject($index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
Provides the UI through which users can perform editing operations on their watchlist.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2376
getPageTitle($subpage=false)
Get a self-referential title object.