MediaWiki  1.28.1
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 
154  protected function executeViewEditWatchlist() {
155  $out = $this->getOutput();
156  $out->setPageTitle( $this->msg( 'watchlistedit-normal-title' ) );
157  $form = $this->getNormalForm();
158  if ( $form->show() ) {
159  $out->addHTML( $this->successMessage );
160  $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
161  } elseif ( $this->toc !== false ) {
162  $out->prependHTML( $this->toc );
163  $out->addModules( 'mediawiki.toc' );
164  }
165  }
166 
173  public function getSubpagesForPrefixSearch() {
174  // SpecialWatchlist uses SpecialEditWatchlist::getMode, so new types should be added
175  // here and there - no 'edit' here, because that the default for this page
176  return [
177  'clear',
178  'raw',
179  ];
180  }
181 
189  private function extractTitles( $list ) {
190  $list = explode( "\n", trim( $list ) );
191  if ( !is_array( $list ) ) {
192  return [];
193  }
194 
195  $titles = [];
196 
197  foreach ( $list as $text ) {
198  $text = trim( $text );
199  if ( strlen( $text ) > 0 ) {
200  $title = Title::newFromText( $text );
201  if ( $title instanceof Title && $title->isWatchable() ) {
202  $titles[] = $title;
203  }
204  }
205  }
206 
207  MediaWikiServices::getInstance()->getGenderCache()->doTitlesArray( $titles );
208 
209  $list = [];
211  foreach ( $titles as $title ) {
212  $list[] = $title->getPrefixedText();
213  }
214 
215  return array_unique( $list );
216  }
217 
218  public function submitRaw( $data ) {
219  $wanted = $this->extractTitles( $data['Titles'] );
220  $current = $this->getWatchlist();
221 
222  if ( count( $wanted ) > 0 ) {
223  $toWatch = array_diff( $wanted, $current );
224  $toUnwatch = array_diff( $current, $wanted );
225  $this->watchTitles( $toWatch );
226  $this->unwatchTitles( $toUnwatch );
227  $this->getUser()->invalidateCache();
228 
229  if ( count( $toWatch ) > 0 || count( $toUnwatch ) > 0 ) {
230  $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
231  } else {
232  return false;
233  }
234 
235  if ( count( $toWatch ) > 0 ) {
236  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-added' )
237  ->numParams( count( $toWatch ) )->parse();
238  $this->showTitles( $toWatch, $this->successMessage );
239  }
240 
241  if ( count( $toUnwatch ) > 0 ) {
242  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
243  ->numParams( count( $toUnwatch ) )->parse();
244  $this->showTitles( $toUnwatch, $this->successMessage );
245  }
246  } else {
247  $this->clearWatchlist();
248  $this->getUser()->invalidateCache();
249 
250  if ( count( $current ) > 0 ) {
251  $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse();
252  } else {
253  return false;
254  }
255 
256  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' )
257  ->numParams( count( $current ) )->parse();
258  $this->showTitles( $current, $this->successMessage );
259  }
260 
261  return true;
262  }
263 
264  public function submitClear( $data ) {
265  $current = $this->getWatchlist();
266  $this->clearWatchlist();
267  $this->getUser()->invalidateCache();
268  $this->successMessage = $this->msg( 'watchlistedit-clear-done' )->parse();
269  $this->successMessage .= ' ' . $this->msg( 'watchlistedit-clear-removed' )
270  ->numParams( count( $current ) )->parse();
271  $this->showTitles( $current, $this->successMessage );
272 
273  return true;
274  }
275 
285  private function showTitles( $titles, &$output ) {
286  $talk = $this->msg( 'talkpagelinktext' )->text();
287  // Do a batch existence check
288  $batch = new LinkBatch();
289  if ( count( $titles ) >= 100 ) {
290  $output = $this->msg( 'watchlistedit-too-many' )->parse();
291  return;
292  }
293  foreach ( $titles as $title ) {
294  if ( !$title instanceof Title ) {
295  $title = Title::newFromText( $title );
296  }
297 
298  if ( $title instanceof Title ) {
299  $batch->addObj( $title );
300  $batch->addObj( $title->getTalkPage() );
301  }
302  }
303 
304  $batch->execute();
305 
306  // Print out the list
307  $output .= "<ul>\n";
308 
309  $linkRenderer = $this->getLinkRenderer();
310  foreach ( $titles as $title ) {
311  if ( !$title instanceof Title ) {
312  $title = Title::newFromText( $title );
313  }
314 
315  if ( $title instanceof Title ) {
316  $output .= '<li>' .
317  $linkRenderer->makeLink( $title ) . ' ' .
318  $this->msg( 'parentheses' )->rawParams(
319  $linkRenderer->makeLink( $title->getTalkPage(), $talk )
320  )->escaped() .
321  "</li>\n";
322  }
323  }
324 
325  $output .= "</ul>\n";
326  }
327 
334  private function getWatchlist() {
335  $list = [];
336 
337  $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()->getWatchedItemsForUser(
338  $this->getUser(),
339  [ 'forWrite' => $this->getRequest()->wasPosted() ]
340  );
341 
342  if ( $watchedItems ) {
344  $titles = [];
345  foreach ( $watchedItems as $watchedItem ) {
346  $namespace = $watchedItem->getLinkTarget()->getNamespace();
347  $dbKey = $watchedItem->getLinkTarget()->getDBkey();
348  $title = Title::makeTitleSafe( $namespace, $dbKey );
349 
350  if ( $this->checkTitle( $title, $namespace, $dbKey )
351  && !$title->isTalkPage()
352  ) {
353  $titles[] = $title;
354  }
355  }
356 
357  MediaWikiServices::getInstance()->getGenderCache()->doTitlesArray( $titles );
358 
359  foreach ( $titles as $title ) {
360  $list[] = $title->getPrefixedText();
361  }
362  }
363 
364  $this->cleanupWatchlist();
365 
366  return $list;
367  }
368 
375  protected function getWatchlistInfo() {
376  $titles = [];
377 
378  $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()
379  ->getWatchedItemsForUser( $this->getUser(), [ 'sort' => WatchedItemStore::SORT_ASC ] );
380 
381  $lb = new LinkBatch();
382 
383  foreach ( $watchedItems as $watchedItem ) {
384  $namespace = $watchedItem->getLinkTarget()->getNamespace();
385  $dbKey = $watchedItem->getLinkTarget()->getDBkey();
386  $lb->add( $namespace, $dbKey );
387  if ( !MWNamespace::isTalk( $namespace ) ) {
388  $titles[$namespace][$dbKey] = 1;
389  }
390  }
391 
392  $lb->execute();
393 
394  return $titles;
395  }
396 
405  private function checkTitle( $title, $namespace, $dbKey ) {
406  if ( $title
407  && ( $title->isExternal()
408  || $title->getNamespace() < 0
409  )
410  ) {
411  $title = false; // unrecoverable
412  }
413 
414  if ( !$title
415  || $title->getNamespace() != $namespace
416  || $title->getDBkey() != $dbKey
417  ) {
418  $this->badItems[] = [ $title, $namespace, $dbKey ];
419  }
420 
421  return (bool)$title;
422  }
423 
427  private function cleanupWatchlist() {
428  if ( !count( $this->badItems ) ) {
429  return; // nothing to do
430  }
431 
432  $user = $this->getUser();
435  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
436  foreach ( $badItems as $row ) {
437  list( $title, $namespace, $dbKey ) = $row;
438  $action = $title ? 'cleaning up' : 'deleting';
439  wfDebug( "User {$user->getName()} has broken watchlist item " .
440  "ns($namespace):$dbKey, $action.\n" );
441 
442  $store->removeWatch( $user, new TitleValue( (int)$namespace, $dbKey ) );
443  // Can't just do an UPDATE instead of DELETE/INSERT due to unique index
444  if ( $title ) {
445  $user->addWatch( $title );
446  }
447  }
448  } );
449  }
450 
454  private function clearWatchlist() {
455  $dbw = wfGetDB( DB_MASTER );
456  $dbw->delete(
457  'watchlist',
458  [ 'wl_user' => $this->getUser()->getId() ],
459  __METHOD__
460  );
461  }
462 
468  private function watchTitles( $targets ) {
469  $expandedTargets = [];
470  foreach ( $targets as $target ) {
471  if ( !$target instanceof LinkTarget ) {
472  try {
473  $target = $this->titleParser->parseTitle( $target, NS_MAIN );
474  }
475  catch ( MalformedTitleException $e ) {
476  continue;
477  }
478  }
479 
480  $ns = $target->getNamespace();
481  $dbKey = $target->getDBkey();
482  $expandedTargets[] = new TitleValue( MWNamespace::getSubject( $ns ), $dbKey );
483  $expandedTargets[] = new TitleValue( MWNamespace::getTalk( $ns ), $dbKey );
484  }
485 
486  MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser(
487  $this->getUser(),
488  $expandedTargets
489  );
490  }
491 
500  private function unwatchTitles( $titles ) {
501  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
502 
503  foreach ( $titles as $title ) {
504  if ( !$title instanceof Title ) {
505  $title = Title::newFromText( $title );
506  }
507 
508  if ( $title instanceof Title ) {
509  $store->removeWatch( $this->getUser(), $title->getSubjectPage() );
510  $store->removeWatch( $this->getUser(), $title->getTalkPage() );
511 
512  $page = WikiPage::factory( $title );
513  Hooks::run( 'UnwatchArticleComplete', [ $this->getUser(), &$page ] );
514  }
515  }
516  }
517 
518  public function submitNormal( $data ) {
519  $removed = [];
520 
521  foreach ( $data as $titles ) {
522  $this->unwatchTitles( $titles );
523  $removed = array_merge( $removed, $titles );
524  }
525 
526  if ( count( $removed ) > 0 ) {
527  $this->successMessage = $this->msg( 'watchlistedit-normal-done'
528  )->numParams( count( $removed ) )->parse();
529  $this->showTitles( $removed, $this->successMessage );
530 
531  return true;
532  } else {
533  return false;
534  }
535  }
536 
542  protected function getNormalForm() {
544 
545  $fields = [];
546  $count = 0;
547 
548  // Allow subscribers to manipulate the list of watched pages (or use it
549  // to preload lots of details at once)
550  $watchlistInfo = $this->getWatchlistInfo();
551  Hooks::run(
552  'WatchlistEditorBeforeFormRender',
553  [ &$watchlistInfo ]
554  );
555 
556  foreach ( $watchlistInfo as $namespace => $pages ) {
557  $options = [];
558 
559  foreach ( array_keys( $pages ) as $dbkey ) {
560  $title = Title::makeTitleSafe( $namespace, $dbkey );
561 
562  if ( $this->checkTitle( $title, $namespace, $dbkey ) ) {
563  $text = $this->buildRemoveLine( $title );
564  $options[$text] = $title->getPrefixedText();
565  $count++;
566  }
567  }
568 
569  // checkTitle can filter some options out, avoid empty sections
570  if ( count( $options ) > 0 ) {
571  $fields['TitlesNs' . $namespace] = [
572  'class' => 'EditWatchlistCheckboxSeriesField',
573  'options' => $options,
574  'section' => "ns$namespace",
575  ];
576  }
577  }
578  $this->cleanupWatchlist();
579 
580  if ( count( $fields ) > 1 && $count > 30 ) {
581  $this->toc = Linker::tocIndent();
582  $tocLength = 0;
583 
584  foreach ( $fields as $data ) {
585  # strip out the 'ns' prefix from the section name:
586  $ns = substr( $data['section'], 2 );
587 
588  $nsText = ( $ns == NS_MAIN )
589  ? $this->msg( 'blanknamespace' )->escaped()
590  : htmlspecialchars( $wgContLang->getFormattedNsText( $ns ) );
591  $this->toc .= Linker::tocLine( "editwatchlist-{$data['section']}", $nsText,
592  $this->getLanguage()->formatNum( ++$tocLength ), 1 ) . Linker::tocLineEnd();
593  }
594 
595  $this->toc = Linker::tocList( $this->toc );
596  } else {
597  $this->toc = false;
598  }
599 
600  $context = new DerivativeContext( $this->getContext() );
601  $context->setTitle( $this->getPageTitle() ); // Remove subpage
602  $form = new EditWatchlistNormalHTMLForm( $fields, $context );
603  $form->setSubmitTextMsg( 'watchlistedit-normal-submit' );
604  $form->setSubmitDestructive();
605  # Used message keys:
606  # 'accesskey-watchlistedit-normal-submit', 'tooltip-watchlistedit-normal-submit'
607  $form->setSubmitTooltip( 'watchlistedit-normal-submit' );
608  $form->setWrapperLegendMsg( 'watchlistedit-normal-legend' );
609  $form->addHeaderText( $this->msg( 'watchlistedit-normal-explain' )->parse() );
610  $form->setSubmitCallback( [ $this, 'submitNormal' ] );
611 
612  return $form;
613  }
614 
621  private function buildRemoveLine( $title ) {
622  $linkRenderer = $this->getLinkRenderer();
623  $link = $linkRenderer->makeLink( $title );
624 
625  $tools['talk'] = $linkRenderer->makeLink(
626  $title->getTalkPage(),
627  $this->msg( 'talkpagelinktext' )->text()
628  );
629 
630  if ( $title->exists() ) {
631  $tools['history'] = $linkRenderer->makeKnownLink(
632  $title,
633  $this->msg( 'history_short' )->text(),
634  [],
635  [ 'action' => 'history' ]
636  );
637  }
638 
639  if ( $title->getNamespace() == NS_USER && !$title->isSubpage() ) {
640  $tools['contributions'] = $linkRenderer->makeKnownLink(
641  SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
642  $this->msg( 'contributions' )->text()
643  );
644  }
645 
646  Hooks::run(
647  'WatchlistEditorBuildRemoveLine',
648  [ &$tools, $title, $title->isRedirect(), $this->getSkin(), &$link ]
649  );
650 
651  if ( $title->isRedirect() ) {
652  // Linker already makes class mw-redirect, so this is redundant
653  $link = '<span class="watchlistredir">' . $link . '</span>';
654  }
655 
656  return $link . ' ' .
657  $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $tools ) )->escaped();
658  }
659 
665  protected function getRawForm() {
666  $titles = implode( $this->getWatchlist(), "\n" );
667  $fields = [
668  'Titles' => [
669  'type' => 'textarea',
670  'label-message' => 'watchlistedit-raw-titles',
671  'default' => $titles,
672  ],
673  ];
674  $context = new DerivativeContext( $this->getContext() );
675  $context->setTitle( $this->getPageTitle( 'raw' ) ); // Reset subpage
676  $form = new HTMLForm( $fields, $context );
677  $form->setSubmitTextMsg( 'watchlistedit-raw-submit' );
678  # Used message keys: 'accesskey-watchlistedit-raw-submit', 'tooltip-watchlistedit-raw-submit'
679  $form->setSubmitTooltip( 'watchlistedit-raw-submit' );
680  $form->setWrapperLegendMsg( 'watchlistedit-raw-legend' );
681  $form->addHeaderText( $this->msg( 'watchlistedit-raw-explain' )->parse() );
682  $form->setSubmitCallback( [ $this, 'submitRaw' ] );
683 
684  return $form;
685  }
686 
692  protected function getClearForm() {
693  $context = new DerivativeContext( $this->getContext() );
694  $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage
695  $form = new HTMLForm( [], $context );
696  $form->setSubmitTextMsg( 'watchlistedit-clear-submit' );
697  # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit'
698  $form->setSubmitTooltip( 'watchlistedit-clear-submit' );
699  $form->setWrapperLegendMsg( 'watchlistedit-clear-legend' );
700  $form->addHeaderText( $this->msg( 'watchlistedit-clear-explain' )->parse() );
701  $form->setSubmitCallback( [ $this, 'submitClear' ] );
702  $form->setSubmitDestructive();
703 
704  return $form;
705  }
706 
715  public static function getMode( $request, $par ) {
716  $mode = strtolower( $request->getVal( 'action', $par ) );
717 
718  switch ( $mode ) {
719  case 'clear':
720  case self::EDIT_CLEAR:
721  return self::EDIT_CLEAR;
722  case 'raw':
723  case self::EDIT_RAW:
724  return self::EDIT_RAW;
725  case 'edit':
726  case self::EDIT_NORMAL:
727  return self::EDIT_NORMAL;
728  default:
729  return false;
730  }
731  }
732 
741  public static function buildTools( $lang, LinkRenderer $linkRenderer = null ) {
742  if ( !$lang instanceof Language ) {
743  // back-compat where the first parameter was $unused
744  global $wgLang;
745  $lang = $wgLang;
746  }
747  if ( !$linkRenderer ) {
748  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
749  }
750 
751  $tools = [];
752  $modes = [
753  'view' => [ 'Watchlist', false ],
754  'edit' => [ 'EditWatchlist', false ],
755  'raw' => [ 'EditWatchlist', 'raw' ],
756  'clear' => [ 'EditWatchlist', 'clear' ],
757  ];
758 
759  foreach ( $modes as $mode => $arr ) {
760  // can use messages 'watchlisttools-view', 'watchlisttools-edit', 'watchlisttools-raw'
761  $tools[] = $linkRenderer->makeKnownLink(
762  SpecialPage::getTitleFor( $arr[0], $arr[1] ),
763  wfMessage( "watchlisttools-{$mode}" )->text()
764  );
765  }
766 
767  return Html::rawElement(
768  'span',
769  [ 'class' => 'mw-watchlist-toollinks' ],
770  wfMessage( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped()
771  );
772  }
773 }
774 
779  public function getLegend( $namespace ) {
780  $namespace = substr( $namespace, 2 );
781 
782  return $namespace == NS_MAIN
783  ? $this->msg( 'blanknamespace' )->escaped()
784  : htmlspecialchars( $this->getContext()->getLanguage()->getFormattedNsText( $namespace ) );
785  }
786 
787  public function getBody() {
788  return $this->displaySection( $this->mFieldTree, '', 'editwatchlist-' );
789  }
790 }
791 
804  function validate( $value, $alldata ) {
805  // Need to call into grandparent to be a good citizen. :)
806  return HTMLFormField::validate( $value, $alldata );
807  }
808 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:115
static tocLineEnd()
End a Table Of Contents line.
Definition: Linker.php:1633
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:1645
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:802
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:50
getContext()
Gets the context this SpecialPage is executed in.
const NS_MAIN
Definition: Defines.php:56
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 If you don't need a full Title object...
Definition: SpecialPage.php:82
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:2102
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
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:262
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.
const DB_MASTER
Definition: defines.php:23
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
$batch
Definition: linkcache.txt:23
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2889
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.
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 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
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:1046
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:535
watchTitles($targets)
Add a list of targets to a user's watchlist.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
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:1615
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
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
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:1046
displaySection($fields, $sectionName= '', $fieldsetIDPrefix= '', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1617
outputSubtitle()
Renders a subheader on the watchlist page.
static getTalk($index)
Get the talk namespace index for a given namespace.
static buildTools($lang, LinkRenderer $linkRenderer=null)
Build a set of links for convenient navigation between watchlist viewing and editing modes...
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:2573
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...
$count
static tocIndent()
Add another level to the Table of Contents.
Definition: Linker.php:1589
static addCallableUpdate($callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
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:2491
getPageTitle($subpage=false)
Get a self-referential title object.
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:66