MediaWiki  master
SpecialEditWatchlist.php
Go to the documentation of this file.
1 <?php
32 
46  const EDIT_CLEAR = 1;
47  const EDIT_RAW = 2;
48  const EDIT_NORMAL = 3;
49 
50  protected $successMessage;
51 
52  protected $toc;
53 
54  private $badItems = [];
55 
59  private $titleParser;
60 
61  public function __construct() {
62  parent::__construct( 'EditWatchlist', 'editmywatchlist' );
63  }
64 
69  private function initServices() {
70  if ( !$this->titleParser ) {
71  $this->titleParser = MediaWikiServices::getInstance()->getTitleParser();
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(
142  self::buildTools(
143  $this->getLanguage(),
144  $this->getLinkRenderer()
145  )
146  )
147  );
148  }
149 
153  protected function executeViewEditWatchlist() {
154  $out = $this->getOutput();
155  $out->setPageTitle( $this->msg( 'watchlistedit-normal-title' ) );
156  $form = $this->getNormalForm();
157  if ( $form->show() ) {
158  $out->addHTML( $this->successMessage );
159  $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
160  } elseif ( $this->toc !== false ) {
161  $out->prependHTML( $this->toc );
162  $out->addModuleStyles( 'mediawiki.toc.styles' );
163  }
164  }
165 
172  public function getSubpagesForPrefixSearch() {
173  // SpecialWatchlist uses SpecialEditWatchlist::getMode, so new types should be added
174  // here and there - no 'edit' here, because that the default for this page
175  return [
176  'clear',
177  'raw',
178  ];
179  }
180 
188  private function extractTitles( $list ) {
189  $list = explode( "\n", trim( $list ) );
190  if ( !is_array( $list ) ) {
191  return [];
192  }
193 
194  $titles = [];
195 
196  foreach ( $list as $text ) {
197  $text = trim( $text );
198  if ( strlen( $text ) > 0 ) {
199  $title = Title::newFromText( $text );
200  if ( $title instanceof Title && $title->isWatchable() ) {
201  $titles[] = $title;
202  }
203  }
204  }
205 
206  MediaWikiServices::getInstance()->getGenderCache()->doTitlesArray( $titles );
207 
208  $list = [];
210  foreach ( $titles as $title ) {
211  $list[] = $title->getPrefixedText();
212  }
213 
214  return array_unique( $list );
215  }
216 
217  public function submitRaw( $data ) {
218  $wanted = $this->extractTitles( $data['Titles'] );
219  $current = $this->getWatchlist();
220 
221  if ( count( $wanted ) > 0 ) {
222  $toWatch = array_diff( $wanted, $current );
223  $toUnwatch = array_diff( $current, $wanted );
224  $this->watchTitles( $toWatch );
225  $this->unwatchTitles( $toUnwatch );
226  $this->getUser()->invalidateCache();
227 
228  if ( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 ) {
229  $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
230  } else {
231  return false;
232  }
233 
234  if ( count( $toWatch ) > 0 ) {
235  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-added' )
236  ->numParams( count( $toWatch ) )->parse();
237  $this->showTitles( $toWatch, $this->successMessage );
238  }
239 
240  if ( count( $toUnwatch ) > 0 ) {
241  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
242  ->numParams( count( $toUnwatch ) )->parse();
243  $this->showTitles( $toUnwatch, $this->successMessage );
244  }
245  } else {
246 
247  if ( count( $current ) === 0 ) {
248  return false;
249  }
250 
251  $this->clearUserWatchedItems( $current, 'raw' );
252  $this->showTitles( $current, $this->successMessage );
253  }
254 
255  return true;
256  }
257 
258  public function submitClear( $data ) {
259  $current = $this->getWatchlist();
260  $this->clearUserWatchedItems( $current, 'clear' );
261  $this->showTitles( $current, $this->successMessage );
262  return true;
263  }
264 
269  private function clearUserWatchedItems( $current, $messageFor ) {
270  $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
271  if ( $watchedItemStore->clearUserWatchedItems( $this->getUser() ) ) {
272  $this->successMessage = $this->msg( 'watchlistedit-' . $messageFor . '-done' )->parse();
273  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-' . $messageFor . '-removed' )
274  ->numParams( count( $current ) )->parse();
275  $this->getUser()->invalidateCache();
276  } else {
277  $watchedItemStore->clearUserWatchedItemsUsingJobQueue( $this->getUser() );
278  $this->successMessage = $this->msg( 'watchlistedit-clear-jobqueue' )->parse();
279  }
280  }
281 
291  private function showTitles( $titles, &$output ) {
292  $talk = $this->msg( 'talkpagelinktext' )->text();
293  // Do a batch existence check
294  $batch = new LinkBatch();
295  if ( count( $titles ) >= 100 ) {
296  $output = $this->msg( 'watchlistedit-too-many' )->parse();
297  return;
298  }
299  foreach ( $titles as $title ) {
300  if ( !$title instanceof Title ) {
301  $title = Title::newFromText( $title );
302  }
303 
304  if ( $title instanceof Title ) {
305  $batch->addObj( $title );
306  $batch->addObj( $title->getTalkPage() );
307  }
308  }
309 
310  $batch->execute();
311 
312  // Print out the list
313  $output .= "<ul>\n";
314 
315  $linkRenderer = $this->getLinkRenderer();
316  foreach ( $titles as $title ) {
317  if ( !$title instanceof Title ) {
318  $title = Title::newFromText( $title );
319  }
320 
321  if ( $title instanceof Title ) {
322  $output .= '<li>' .
323  $linkRenderer->makeLink( $title ) . ' ' .
324  $this->msg( 'parentheses' )->rawParams(
325  $linkRenderer->makeLink( $title->getTalkPage(), $talk )
326  )->escaped() .
327  "</li>\n";
328  }
329  }
330 
331  $output .= "</ul>\n";
332  }
333 
340  private function getWatchlist() {
341  $list = [];
342 
343  $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()->getWatchedItemsForUser(
344  $this->getUser(),
345  [ 'forWrite' => $this->getRequest()->wasPosted() ]
346  );
347 
348  if ( $watchedItems ) {
350  $titles = [];
351  foreach ( $watchedItems as $watchedItem ) {
352  $namespace = $watchedItem->getLinkTarget()->getNamespace();
353  $dbKey = $watchedItem->getLinkTarget()->getDBkey();
354  $title = Title::makeTitleSafe( $namespace, $dbKey );
355 
356  if ( $this->checkTitle( $title, $namespace, $dbKey )
357  && !$title->isTalkPage()
358  ) {
359  $titles[] = $title;
360  }
361  }
362 
363  MediaWikiServices::getInstance()->getGenderCache()->doTitlesArray( $titles );
364 
365  foreach ( $titles as $title ) {
366  $list[] = $title->getPrefixedText();
367  }
368  }
369 
370  $this->cleanupWatchlist();
371 
372  return $list;
373  }
374 
381  protected function getWatchlistInfo() {
382  $titles = [];
383 
384  $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()
385  ->getWatchedItemsForUser( $this->getUser(), [ 'sort' => WatchedItemStore::SORT_ASC ] );
386 
387  $lb = new LinkBatch();
388 
389  foreach ( $watchedItems as $watchedItem ) {
390  $namespace = $watchedItem->getLinkTarget()->getNamespace();
391  $dbKey = $watchedItem->getLinkTarget()->getDBkey();
392  $lb->add( $namespace, $dbKey );
393  if ( !MWNamespace::isTalk( $namespace ) ) {
394  $titles[$namespace][$dbKey] = 1;
395  }
396  }
397 
398  $lb->execute();
399 
400  return $titles;
401  }
402 
411  private function checkTitle( $title, $namespace, $dbKey ) {
412  if ( $title
413  && ( $title->isExternal()
414  || $title->getNamespace() < 0
415  )
416  ) {
417  $title = false; // unrecoverable
418  }
419 
420  if ( !$title
421  || $title->getNamespace() != $namespace
422  || $title->getDBkey() != $dbKey
423  ) {
424  $this->badItems[] = [ $title, $namespace, $dbKey ];
425  }
426 
427  return (bool)$title;
428  }
429 
433  private function cleanupWatchlist() {
434  if ( $this->badItems === [] ) {
435  return; // nothing to do
436  }
437 
438  $user = $this->getUser();
441  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
442  foreach ( $badItems as $row ) {
443  list( $title, $namespace, $dbKey ) = $row;
444  $action = $title ? 'cleaning up' : 'deleting';
445  wfDebug( "User {$user->getName()} has broken watchlist item " .
446  "ns($namespace):$dbKey, $action.\n" );
447 
448  $store->removeWatch( $user, new TitleValue( (int)$namespace, $dbKey ) );
449  // Can't just do an UPDATE instead of DELETE/INSERT due to unique index
450  if ( $title ) {
451  $user->addWatch( $title );
452  }
453  }
454  } );
455  }
456 
465  private function watchTitles( array $targets ) {
466  return MediaWikiServices::getInstance()->getWatchedItemStore()
467  ->addWatchBatchForUser( $this->getUser(), $this->getExpandedTargets( $targets ) )
468  && $this->runWatchUnwatchCompleteHook( 'Watch', $targets );
469  }
470 
483  private function unwatchTitles( array $targets ) {
484  return MediaWikiServices::getInstance()->getWatchedItemStore()
485  ->removeWatchBatchForUser( $this->getUser(), $this->getExpandedTargets( $targets ) )
486  && $this->runWatchUnwatchCompleteHook( 'Unwatch', $targets );
487  }
488 
497  private function runWatchUnwatchCompleteHook( $action, $targets ) {
498  foreach ( $targets as $target ) {
499  $title = $target instanceof TitleValue ?
500  Title::newFromTitleValue( $target ) :
501  Title::newFromText( $target );
502  $page = WikiPage::factory( $title );
503  Hooks::run( $action . 'ArticleComplete', [ $this->getUser(), &$page ] );
504  }
505  return true;
506  }
507 
512  private function getExpandedTargets( array $targets ) {
513  $expandedTargets = [];
514  foreach ( $targets as $target ) {
515  if ( !$target instanceof LinkTarget ) {
516  try {
517  $target = $this->titleParser->parseTitle( $target, NS_MAIN );
518  }
519  catch ( MalformedTitleException $e ) {
520  continue;
521  }
522  }
523 
524  $ns = $target->getNamespace();
525  $dbKey = $target->getDBkey();
526  $expandedTargets[] = new TitleValue( MWNamespace::getSubject( $ns ), $dbKey );
527  $expandedTargets[] = new TitleValue( MWNamespace::getTalk( $ns ), $dbKey );
528  }
529  return $expandedTargets;
530  }
531 
532  public function submitNormal( $data ) {
533  $removed = [];
534 
535  foreach ( $data as $titles ) {
536  $this->unwatchTitles( $titles );
537  $removed = array_merge( $removed, $titles );
538  }
539 
540  if ( count( $removed ) > 0 ) {
541  $this->successMessage = $this->msg( 'watchlistedit-normal-done'
542  )->numParams( count( $removed ) )->parse();
543  $this->showTitles( $removed, $this->successMessage );
544 
545  return true;
546  } else {
547  return false;
548  }
549  }
550 
556  protected function getNormalForm() {
557  $fields = [];
558  $count = 0;
559 
560  // Allow subscribers to manipulate the list of watched pages (or use it
561  // to preload lots of details at once)
562  $watchlistInfo = $this->getWatchlistInfo();
563  Hooks::run(
564  'WatchlistEditorBeforeFormRender',
565  [ &$watchlistInfo ]
566  );
567 
568  foreach ( $watchlistInfo as $namespace => $pages ) {
569  $options = [];
570 
571  foreach ( array_keys( $pages ) as $dbkey ) {
572  $title = Title::makeTitleSafe( $namespace, $dbkey );
573 
574  if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
575  $text = $this->buildRemoveLine( $title );
576  $options[$text] = $title->getPrefixedText();
577  $count++;
578  }
579  }
580 
581  // checkTitle can filter some options out, avoid empty sections
582  if ( count( $options ) > 0 ) {
583  $fields['TitlesNs' . $namespace] = [
585  'options' => $options,
586  'section' => "ns$namespace",
587  ];
588  }
589  }
590  $this->cleanupWatchlist();
591 
592  if ( count( $fields ) > 1 && $count > 30 ) {
593  $this->toc = Linker::tocIndent();
594  $tocLength = 0;
595  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
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( $contLang->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 
634  private function buildRemoveLine( $title ) {
635  $linkRenderer = $this->getLinkRenderer();
636  $link = $linkRenderer->makeLink( $title );
637 
638  $tools['talk'] = $linkRenderer->makeLink(
639  $title->getTalkPage(),
640  $this->msg( 'talkpagelinktext' )->text()
641  );
642 
643  if ( $title->exists() ) {
644  $tools['history'] = $linkRenderer->makeKnownLink(
645  $title,
646  $this->msg( 'history_small' )->text(),
647  [],
648  [ 'action' => 'history' ]
649  );
650  }
651 
652  if ( $title->getNamespace() == NS_USER && !$title->isSubpage() ) {
653  $tools['contributions'] = $linkRenderer->makeKnownLink(
654  SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
655  $this->msg( 'contribslink' )->text()
656  );
657  }
658 
659  Hooks::run(
660  'WatchlistEditorBuildRemoveLine',
661  [ &$tools, $title, $title->isRedirect(), $this->getSkin(), &$link ]
662  );
663 
664  if ( $title->isRedirect() ) {
665  // Linker already makes class mw-redirect, so this is redundant
666  $link = '<span class="watchlistredir">' . $link . '</span>';
667  }
668 
669  return $link . ' ' .
670  $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $tools ) )->escaped();
671  }
672 
678  protected function getRawForm() {
679  $titles = implode( "\n", $this->getWatchlist() );
680  $fields = [
681  'Titles' => [
682  'type' => 'textarea',
683  'label-message' => 'watchlistedit-raw-titles',
684  'default' => $titles,
685  ],
686  ];
687  $context = new DerivativeContext( $this->getContext() );
688  $context->setTitle( $this->getPageTitle( 'raw' ) ); // Reset subpage
689  $form = new OOUIHTMLForm( $fields, $context );
690  $form->setSubmitTextMsg( 'watchlistedit-raw-submit' );
691  # Used message keys: 'accesskey-watchlistedit-raw-submit', 'tooltip-watchlistedit-raw-submit'
692  $form->setSubmitTooltip( 'watchlistedit-raw-submit' );
693  $form->setWrapperLegendMsg( 'watchlistedit-raw-legend' );
694  $form->addHeaderText( $this->msg( 'watchlistedit-raw-explain' )->parse() );
695  $form->setSubmitCallback( [ $this, 'submitRaw' ] );
696 
697  return $form;
698  }
699 
705  protected function getClearForm() {
706  $context = new DerivativeContext( $this->getContext() );
707  $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage
708  $form = new OOUIHTMLForm( [], $context );
709  $form->setSubmitTextMsg( 'watchlistedit-clear-submit' );
710  # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit'
711  $form->setSubmitTooltip( 'watchlistedit-clear-submit' );
712  $form->setWrapperLegendMsg( 'watchlistedit-clear-legend' );
713  $form->addHeaderText( $this->msg( 'watchlistedit-clear-explain' )->parse() );
714  $form->setSubmitCallback( [ $this, 'submitClear' ] );
715  $form->setSubmitDestructive();
716 
717  return $form;
718  }
719 
728  public static function getMode( $request, $par ) {
729  $mode = strtolower( $request->getVal( 'action', $par ) );
730 
731  switch ( $mode ) {
732  case 'clear':
733  case self::EDIT_CLEAR:
734  return self::EDIT_CLEAR;
735  case 'raw':
736  case self::EDIT_RAW:
737  return self::EDIT_RAW;
738  case 'edit':
739  case self::EDIT_NORMAL:
740  return self::EDIT_NORMAL;
741  default:
742  return false;
743  }
744  }
745 
754  public static function buildTools( $lang, LinkRenderer $linkRenderer = null ) {
755  if ( !$lang instanceof Language ) {
756  // back-compat where the first parameter was $unused
757  global $wgLang;
758  $lang = $wgLang;
759  }
760  if ( !$linkRenderer ) {
761  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
762  }
763 
764  $tools = [];
765  $modes = [
766  'view' => [ 'Watchlist', false ],
767  'edit' => [ 'EditWatchlist', false ],
768  'raw' => [ 'EditWatchlist', 'raw' ],
769  'clear' => [ 'EditWatchlist', 'clear' ],
770  ];
771 
772  foreach ( $modes as $mode => $arr ) {
773  // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw'
774  $tools[] = $linkRenderer->makeKnownLink(
775  SpecialPage::getTitleFor( $arr[0], $arr[1] ),
776  wfMessage( "watchlisttools-{$mode}" )->text()
777  );
778  }
779 
780  return Html::rawElement(
781  'span',
782  [ 'class' => 'mw-watchlist-toollinks' ],
783  wfMessage( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped()
784  );
785  }
786 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
static tocLineEnd()
End a Table Of Contents line.
Definition: Linker.php:1612
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
runWatchUnwatchCompleteHook( $action, $targets)
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Shortcut to construct a special page which is unlisted by default.
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
getContext()
Gets the context this SpecialPage is executed in.
const NS_MAIN
Definition: Defines.php:64
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:2159
if(!isset( $args[0])) $lang
getClearForm()
Get a form for clearing the watchlist.
cleanupWatchlist()
Attempts to clean up broken items.
static getSubject( $index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
Definition: MWNamespace.php:76
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
An IContextSource implementation which will inherit context from another source but allow individual ...
static getMode( $request, $par)
Determine whether we are editing the watchlist, and if so, what kind of editing operation.
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
static buildTools( $lang, LinkRenderer $linkRenderer=null)
Build a set of links for convenient navigation between watchlist viewing and editing modes...
static isTalk( $index)
Is the given namespace a talk namespace?
Definition: MWNamespace.php:55
getOutput()
Get the OutputPage being used for this instance.
execute( $mode)
Main execution point.
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
getWatchlist()
Prepare a list of titles on a user&#39;s watchlist (excluding talk pages) and return an array of (prefixe...
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2217
if( $line===false) $args
Definition: cdb.php:64
$batch
Definition: linkcache.txt:23
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3050
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:48
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
getExpandedTargets(array $targets)
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
clearUserWatchedItems( $current, $messageFor)
$wgLang
Definition: Setup.php:875
Class that generates HTML links for pages.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead 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 unset offset - wrap String Wrap the message in html(usually something like "&lt
unwatchTitles(array $targets)
Remove a list of titles from a user&#39;s watchlist.
getNormalForm()
Get the standard watchlist editing form.
checkTitle( $title, $namespace, $dbKey)
Validates watchlist entry.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Extend OOUIHTMLForm purely so we can have a more sane way of getting the section headers.
initServices()
Initialize any services we&#39;ll need (unless it has already been provided via a setter).
showTitles( $titles, &$output)
Print out a list of linked titles.
static tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex=false)
parameter level defines if we are on an indentation level
Definition: Linker.php:1588
getSkin()
Shortcut to get the skin being used for this instance.
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 & $options
Definition: hooks.txt:1982
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
extractTitles( $list)
Extract a list of titles from a blob of text, returning (prefixed) strings; unwatchable titles are ig...
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:82
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
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
outputSubtitle()
Renders a subheader on the watchlist page.
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
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
static getTalk( $index)
Get the talk namespace index for a given namespace.
Definition: MWNamespace.php:65
getUser()
Shortcut to get the User executing this instance.
Compact stacked vertical format for forms, implemented using OOUI widgets.
getLanguage()
Shortcut to get user&#39;s language.
msg( $key)
Wrapper around wfMessage that sets the current context.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2633
getWatchlistInfo()
Get a list of titles on a user&#39;s watchlist, excluding talk pages, and return as a two-dimensional arr...
static tocIndent()
Add another level to the Table of Contents.
Definition: Linker.php:1562
static tocList( $toc, $lang=null)
Wraps the TOC in a table and provides the hide/collapse javascript.
Definition: Linker.php:1625
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.
buildRemoveLine( $title)
Build the label for a checkbox, with a link to the title, and various additional bits.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
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 all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2633
static newFromTitleValue(TitleValue $titleValue, $forceClone='')
Returns a Title given a TitleValue.
Definition: Title.php:256
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getPageTitle( $subpage=false)
Get a self-referential title object.
watchTitles(array $targets)
Add a list of targets to a user&#39;s watchlist.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:66
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319