MediaWiki  master
HistoryAction.php
Go to the documentation of this file.
1 <?php
29 
41  const DIR_PREV = 0;
42  const DIR_NEXT = 1;
43 
45  public $message;
46 
47  public function getName() {
48  return 'history';
49  }
50 
51  public function requiresWrite() {
52  return false;
53  }
54 
55  public function requiresUnblock() {
56  return false;
57  }
58 
59  protected function getPageTitle() {
60  return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
61  }
62 
63  protected function getDescription() {
64  // Creation of a subtitle link pointing to [[Special:Log]]
65  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
66  $subtitle = $linkRenderer->makeKnownLink(
67  SpecialPage::getTitleFor( 'Log' ),
68  $this->msg( 'viewpagelogs' )->text(),
69  [],
70  [ 'page' => $this->getTitle()->getPrefixedText() ]
71  );
72 
73  $links = [];
74  // Allow extensions to add more links
75  Hooks::run( 'HistoryPageToolLinks', [ $this->getContext(), $linkRenderer, &$links ] );
76  if ( $links ) {
77  $subtitle .= ''
78  . $this->msg( 'word-separator' )->escaped()
79  . $this->msg( 'parentheses' )
80  ->rawParams( $this->getLanguage()->pipeList( $links ) )
81  ->escaped();
82  }
83  return $subtitle;
84  }
85 
89  public function getArticle() {
90  return $this->page;
91  }
92 
97  private function preCacheMessages() {
98  // Precache various messages
99  if ( !isset( $this->message ) ) {
100  $msgs = [ 'cur', 'last', 'pipe-separator' ];
101  foreach ( $msgs as $msg ) {
102  $this->message[$msg] = $this->msg( $msg )->escaped();
103  }
104  }
105  }
106 
110  function onView() {
111  $out = $this->getOutput();
112  $request = $this->getRequest();
113 
117  if ( $out->checkLastModified( $this->page->getTouched() ) ) {
118  return; // Client cache fresh and headers sent, nothing more to do.
119  }
120 
121  $this->preCacheMessages();
122  $config = $this->context->getConfig();
123 
124  # Fill in the file cache if not set already
125  if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
126  $cache = new HTMLFileCache( $this->getTitle(), 'history' );
127  if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
128  ob_start( [ &$cache, 'saveToFileCache' ] );
129  }
130  }
131 
132  // Setup page variables.
133  $out->setFeedAppendQuery( 'action=history' );
134  $out->addModules( 'mediawiki.action.history' );
135  $out->addModuleStyles( [
136  'mediawiki.action.history.styles',
137  'mediawiki.special.changeslist',
138  ] );
139  if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
140  $out = $this->getOutput();
141  $out->addModuleStyles( [
142  'mediawiki.ui.input',
143  'mediawiki.ui.checkbox',
144  ] );
145  }
146 
147  // Handle atom/RSS feeds.
148  $feedType = $request->getVal( 'feed' );
149  if ( $feedType ) {
150  $this->feed( $feedType );
151 
152  return;
153  }
154 
155  $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
156 
157  // Fail nicely if article doesn't exist.
158  if ( !$this->page->exists() ) {
159  global $wgSend404Code;
160  if ( $wgSend404Code ) {
161  $out->setStatusCode( 404 );
162  }
163  $out->addWikiMsg( 'nohistory' );
164 
165  $dbr = wfGetDB( DB_REPLICA );
166 
167  # show deletion/move log if there is an entry
169  $out,
170  [ 'delete', 'move', 'protect' ],
171  $this->getTitle(),
172  '',
173  [ 'lim' => 10,
174  'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
175  'showIfEmpty' => false,
176  'msgKey' => [ 'moveddeleted-notice' ]
177  ]
178  );
179 
180  return;
181  }
182 
186  $year = $request->getInt( 'year' );
187  $month = $request->getInt( 'month' );
188  $tagFilter = $request->getVal( 'tagfilter' );
189  $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
190 
194  if ( $request->getBool( 'deleted' ) ) {
195  $conds = [ 'rev_deleted != 0' ];
196  } else {
197  $conds = [];
198  }
199  if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
200  $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
201  'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
202  } else {
203  $checkDeleted = '';
204  }
205 
206  // Add the general form
207  $action = htmlspecialchars( wfScript() );
208  $content = Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
209  $content .= Html::hidden( 'action', 'history' ) . "\n";
211  ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
212  $month
213  ) . "\u{00A0}";
214  $content .= $tagSelector ? ( implode( "\u{00A0}", $tagSelector ) . "\u{00A0}" ) : '';
215  $content .= $checkDeleted . Html::submitButton(
216  $this->msg( 'historyaction-submit' )->text(),
217  [],
218  [ 'mw-ui-progressive' ]
219  );
220  $out->addHTML(
221  "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
223  $this->msg( 'history-fieldset-title' )->text(),
224  $content,
225  [ 'id' => 'mw-history-search' ]
226  ) .
227  '</form>'
228  );
229 
230  Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
231 
232  // Create and output the list.
233  $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
234  $out->addHTML(
235  $pager->getNavigationBar() .
236  $pager->getBody() .
237  $pager->getNavigationBar()
238  );
239  $out->preventClickjacking( $pager->getPreventClickjacking() );
240  }
241 
252  function fetchRevisions( $limit, $offset, $direction ) {
253  // Fail if article doesn't exist.
254  if ( !$this->getTitle()->exists() ) {
255  return new FakeResultWrapper( [] );
256  }
257 
258  $dbr = wfGetDB( DB_REPLICA );
259 
260  if ( $direction === self::DIR_PREV ) {
261  list( $dirs, $oper ) = [ "ASC", ">=" ];
262  } else { /* $direction === self::DIR_NEXT */
263  list( $dirs, $oper ) = [ "DESC", "<=" ];
264  }
265 
266  if ( $offset ) {
267  $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
268  } else {
269  $offsets = [];
270  }
271 
272  $page_id = $this->page->getId();
273 
275  return $dbr->select(
276  $revQuery['tables'],
277  $revQuery['fields'],
278  array_merge( [ 'rev_page' => $page_id ], $offsets ),
279  __METHOD__,
280  [
281  'ORDER BY' => "rev_timestamp $dirs",
282  'USE INDEX' => [ 'revision' => 'page_timestamp' ],
283  'LIMIT' => $limit
284  ],
285  $revQuery['joins']
286  );
287  }
288 
294  function feed( $type ) {
295  if ( !FeedUtils::checkFeedOutput( $type ) ) {
296  return;
297  }
298  $request = $this->getRequest();
299 
300  $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
302  $feed = new $feedClasses[$type](
303  $this->getTitle()->getPrefixedText() . ' - ' .
304  $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
305  $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
306  $this->getTitle()->getFullURL( 'action=history' )
307  );
308 
309  // Get a limit on number of feed entries. Provide a sane default
310  // of 10 if none is defined (but limit to $wgFeedLimit max)
311  $limit = $request->getInt( 'limit', 10 );
312  $limit = min(
313  max( $limit, 1 ),
314  $this->context->getConfig()->get( 'FeedLimit' )
315  );
316 
317  $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
318 
319  // Generate feed elements enclosed between header and footer.
320  $feed->outHeader();
321  if ( $items->numRows() ) {
322  foreach ( $items as $row ) {
323  $feed->outItem( $this->feedItem( $row ) );
324  }
325  } else {
326  $feed->outItem( $this->feedEmpty() );
327  }
328  $feed->outFooter();
329  }
330 
331  function feedEmpty() {
332  return new FeedItem(
333  $this->msg( 'nohistory' )->inContentLanguage()->text(),
334  $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
335  $this->getTitle()->getFullURL(),
336  wfTimestamp( TS_MW ),
337  '',
338  $this->getTitle()->getTalkPage()->getFullURL()
339  );
340  }
341 
350  function feedItem( $row ) {
351  $rev = new Revision( $row, 0, $this->getTitle() );
352 
353  $text = FeedUtils::formatDiffRow(
354  $this->getTitle(),
355  $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
356  $rev->getId(),
357  $rev->getTimestamp(),
358  $rev->getComment()
359  );
360  if ( $rev->getComment() == '' ) {
361  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
362  $title = $this->msg( 'history-feed-item-nocomment',
363  $rev->getUserText(),
364  $contLang->timeanddate( $rev->getTimestamp() ),
365  $contLang->date( $rev->getTimestamp() ),
366  $contLang->time( $rev->getTimestamp() )
367  )->inContentLanguage()->text();
368  } else {
369  $title = $rev->getUserText() .
370  $this->msg( 'colon-separator' )->inContentLanguage()->text() .
371  FeedItem::stripComment( $rev->getComment() );
372  }
373 
374  return new FeedItem(
375  $title,
376  $text,
377  $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
378  $rev->getTimestamp(),
379  $rev->getUserText(),
380  $this->getTitle()->getTalkPage()->getFullURL()
381  );
382  }
383 }
384 
393  public $lastRow = false;
394 
395  public $counter, $historyPage, $buttons, $conds;
396 
397  protected $oldIdChecked;
398 
399  protected $preventClickjacking = false;
403  protected $parentLens;
404 
406  protected $showTagEditUI;
407 
409  private $tagFilter;
410 
418  public function __construct(
419  HistoryAction $historyPage,
420  $year = '',
421  $month = '',
422  $tagFilter = '',
423  array $conds = []
424  ) {
425  parent::__construct( $historyPage->getContext() );
426  $this->historyPage = $historyPage;
427  $this->tagFilter = $tagFilter;
428  $this->getDateCond( $year, $month );
429  $this->conds = $conds;
430  $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
431  }
432 
433  // For hook compatibility...
434  function getArticle() {
435  return $this->historyPage->getArticle();
436  }
437 
438  function getSqlComment() {
439  if ( $this->conds ) {
440  return 'history page filtered'; // potentially slow, see CR r58153
441  } else {
442  return 'history page unfiltered';
443  }
444  }
445 
446  function getQueryInfo() {
447  $revQuery = Revision::getQueryInfo( [ 'user' ] );
448  $queryInfo = [
449  'tables' => $revQuery['tables'],
450  'fields' => $revQuery['fields'],
451  'conds' => array_merge(
452  [ 'rev_page' => $this->getWikiPage()->getId() ],
453  $this->conds ),
454  'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
455  'join_conds' => $revQuery['joins'],
456  ];
458  $queryInfo['tables'],
459  $queryInfo['fields'],
460  $queryInfo['conds'],
461  $queryInfo['join_conds'],
462  $queryInfo['options'],
463  $this->tagFilter
464  );
465 
466  // Avoid PHP 7.1 warning of passing $this by reference
467  $historyPager = $this;
468  Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
469 
470  return $queryInfo;
471  }
472 
473  function getIndexField() {
474  return 'rev_timestamp';
475  }
476 
481  function formatRow( $row ) {
482  if ( $this->lastRow ) {
483  $latest = ( $this->counter == 1 && $this->mIsFirst );
484  $firstInList = $this->counter == 1;
485  $this->counter++;
486 
487  $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
488  ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
489  : false;
490 
491  $s = $this->historyLine(
492  $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
493  } else {
494  $s = '';
495  }
496  $this->lastRow = $row;
497 
498  return $s;
499  }
500 
501  protected function doBatchLookups() {
502  if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
503  return;
504  }
505 
506  # Do a link batch query
507  $this->mResult->seek( 0 );
508  $batch = new LinkBatch();
509  $revIds = [];
510  foreach ( $this->mResult as $row ) {
511  if ( $row->rev_parent_id ) {
512  $revIds[] = $row->rev_parent_id;
513  }
514  if ( $row->user_name !== null ) {
515  $batch->add( NS_USER, $row->user_name );
516  $batch->add( NS_USER_TALK, $row->user_name );
517  } else { # for anons or usernames of imported revisions
518  $batch->add( NS_USER, $row->rev_user_text );
519  $batch->add( NS_USER_TALK, $row->rev_user_text );
520  }
521  }
522  $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
523  $batch->execute();
524  $this->mResult->seek( 0 );
525  }
526 
532  protected function getStartBody() {
533  $this->lastRow = false;
534  $this->counter = 1;
535  $this->oldIdChecked = 0;
536 
537  $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
538  $s = Html::openElement( 'form', [ 'action' => wfScript(),
539  'id' => 'mw-history-compare' ] ) . "\n";
540  $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
541  $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
542  $s .= Html::hidden( 'type', 'revision' ) . "\n";
543 
544  // Button container stored in $this->buttons for re-use in getEndBody()
545  $this->buttons = '<div>';
546  $className = 'historysubmit mw-history-compareselectedversions-button';
547  $attrs = [ 'class' => $className ]
548  + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
549  $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
550  $attrs
551  ) . "\n";
552 
553  $user = $this->getUser();
554  $actionButtons = '';
555  if ( $user->isAllowed( 'deleterevision' ) ) {
556  $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
557  }
558  if ( $this->showTagEditUI ) {
559  $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
560  }
561  if ( $actionButtons ) {
562  $this->buttons .= Xml::tags( 'div', [ 'class' =>
563  'mw-history-revisionactions' ], $actionButtons );
564  }
565 
566  if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
567  $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
568  }
569 
570  $this->buttons .= '</div>';
571 
572  $s .= $this->buttons;
573  $s .= '<ul id="pagehistory">' . "\n";
574 
575  return $s;
576  }
577 
578  private function getRevisionButton( $name, $msg ) {
579  $this->preventClickjacking();
580  # Note T22966, <button> is non-standard in IE<8
581  $element = Html::element(
582  'button',
583  [
584  'type' => 'submit',
585  'name' => $name,
586  'value' => '1',
587  'class' => "historysubmit mw-history-$name-button",
588  ],
589  $this->msg( $msg )->text()
590  ) . "\n";
591  return $element;
592  }
593 
594  protected function getEndBody() {
595  if ( $this->lastRow ) {
596  $latest = $this->counter == 1 && $this->mIsFirst;
597  $firstInList = $this->counter == 1;
598  if ( $this->mIsBackwards ) {
599  # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
600  if ( $this->mOffset == '' ) {
601  $next = null;
602  } else {
603  $next = 'unknown';
604  }
605  } else {
606  # The next row is the past-the-end row
607  $next = $this->mPastTheEndRow;
608  }
609  $this->counter++;
610 
611  $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
612  ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
613  : false;
614 
615  $s = $this->historyLine(
616  $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
617  } else {
618  $s = '';
619  }
620  $s .= "</ul>\n";
621  # Add second buttons only if there is more than one rev
622  if ( $this->getNumRows() > 2 ) {
623  $s .= $this->buttons;
624  }
625  $s .= '</form>';
626 
627  return $s;
628  }
629 
637  function submitButton( $message, $attributes = [] ) {
638  # Disable submit button if history has 1 revision only
639  if ( $this->getNumRows() > 1 ) {
640  return Html::submitButton( $message, $attributes );
641  } else {
642  return '';
643  }
644  }
645 
660  function historyLine( $row, $next, $notificationtimestamp = false,
661  $latest = false, $firstInList = false ) {
662  $rev = new Revision( $row, 0, $this->getTitle() );
663 
664  if ( is_object( $next ) ) {
665  $prevRev = new Revision( $next, 0, $this->getTitle() );
666  } else {
667  $prevRev = null;
668  }
669 
670  $curlink = $this->curLink( $rev, $latest );
671  $lastlink = $this->lastLink( $rev, $next );
672  $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
673  $histLinks = Html::rawElement(
674  'span',
675  [ 'class' => 'mw-history-histlinks' ],
676  $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
677  );
678 
679  $diffButtons = $this->diffButtons( $rev, $firstInList );
680  $s = $histLinks . $diffButtons;
681 
682  $link = $this->revLink( $rev );
683  $classes = [];
684 
685  $del = '';
686  $user = $this->getUser();
687  $canRevDelete = $user->isAllowed( 'deleterevision' );
688  // Show checkboxes for each revision, to allow for revision deletion and
689  // change tags
690  if ( $canRevDelete || $this->showTagEditUI ) {
691  $this->preventClickjacking();
692  // If revision was hidden from sysops and we don't need the checkbox
693  // for anything else, disable it
694  if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
695  $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
696  // Otherwise, enable the checkbox...
697  } else {
698  $del = Xml::check( 'showhiderevisions', false,
699  [ 'name' => 'ids[' . $rev->getId() . ']' ] );
700  }
701  // User can only view deleted revisions...
702  } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
703  // If revision was hidden from sysops, disable the link
704  if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
705  $del = Linker::revDeleteLinkDisabled( false );
706  // Otherwise, show the link...
707  } else {
708  $query = [ 'type' => 'revision',
709  'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
710  $del .= Linker::revDeleteLink( $query,
711  $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
712  }
713  }
714  if ( $del ) {
715  $s .= " $del ";
716  }
717 
718  $lang = $this->getLanguage();
719  $dirmark = $lang->getDirMark();
720 
721  $s .= " $link";
722  $s .= $dirmark;
723  $s .= " <span class='history-user'>" .
724  Linker::revUserTools( $rev, true ) . "</span>";
725  $s .= $dirmark;
726 
727  if ( $rev->isMinor() ) {
728  $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
729  }
730 
731  # Sometimes rev_len isn't populated
732  if ( $rev->getSize() !== null ) {
733  # Size is always public data
734  $prevSize = $this->parentLens[$row->rev_parent_id] ?? 0;
735  $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
736  $fSize = Linker::formatRevisionSize( $rev->getSize() );
737  $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
738  }
739 
740  # Text following the character difference is added just before running hooks
741  $s2 = Linker::revComment( $rev, false, true );
742 
743  if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
744  $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
745  $classes[] = 'mw-history-line-updated';
746  }
747 
748  $tools = [];
749 
750  # Rollback and undo links
751  if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
752  if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
753  // Get a rollback link without the brackets
754  $rollbackLink = Linker::generateRollback(
755  $rev,
756  $this->getContext(),
757  [ 'verify', 'noBrackets' ]
758  );
759  if ( $rollbackLink ) {
760  $this->preventClickjacking();
761  $tools[] = $rollbackLink;
762  }
763  }
764 
765  if ( !$rev->isDeleted( Revision::DELETED_TEXT )
766  && !$prevRev->isDeleted( Revision::DELETED_TEXT )
767  ) {
768  # Create undo tooltip for the first (=latest) line only
769  $undoTooltip = $latest
770  ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
771  : [];
772  $undolink = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
773  $this->getTitle(),
774  $this->msg( 'editundo' )->text(),
775  $undoTooltip,
776  [
777  'action' => 'edit',
778  'undoafter' => $prevRev->getId(),
779  'undo' => $rev->getId()
780  ]
781  );
782  $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
783  }
784  }
785  // Allow extension to add their own links here
786  Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
787 
788  if ( $tools ) {
789  $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
790  }
791 
792  # Tags
793  list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
794  $row->ts_tags,
795  'history',
796  $this->getContext()
797  );
798  $classes = array_merge( $classes, $newClasses );
799  if ( $tagSummary !== '' ) {
800  $s2 .= " $tagSummary";
801  }
802 
803  # Include separator between character difference and following text
804  if ( $s2 !== '' ) {
805  $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
806  }
807 
808  $attribs = [ 'data-mw-revid' => $rev->getId() ];
809 
810  Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes, &$attribs ] );
811  $attribs = array_filter( $attribs,
812  [ Sanitizer::class, 'isReservedDataAttribute' ],
813  ARRAY_FILTER_USE_KEY
814  );
815 
816  if ( $classes ) {
817  $attribs['class'] = implode( ' ', $classes );
818  }
819 
820  return Xml::tags( 'li', $attribs, $s ) . "\n";
821  }
822 
829  function revLink( $rev ) {
830  $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
831  if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
832  $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
833  $this->getTitle(),
834  $date,
835  [ 'class' => 'mw-changeslist-date' ],
836  [ 'oldid' => $rev->getId() ]
837  );
838  } else {
839  $link = htmlspecialchars( $date );
840  }
841  if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
842  $link = "<span class=\"history-deleted\">$link</span>";
843  }
844 
845  return $link;
846  }
847 
855  function curLink( $rev, $latest ) {
856  $cur = $this->historyPage->message['cur'];
857  if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
858  return $cur;
859  } else {
860  return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
861  $this->getTitle(),
862  new HtmlArmor( $cur ),
863  [],
864  [
865  'diff' => $this->getWikiPage()->getLatest(),
866  'oldid' => $rev->getId()
867  ]
868  );
869  }
870  }
871 
881  function lastLink( $prevRev, $next ) {
882  $last = $this->historyPage->message['last'];
883 
884  if ( $next === null ) {
885  # Probably no next row
886  return $last;
887  }
888 
889  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
890  if ( $next === 'unknown' ) {
891  # Next row probably exists but is unknown, use an oldid=prev link
892  return $linkRenderer->makeKnownLink(
893  $this->getTitle(),
894  new HtmlArmor( $last ),
895  [],
896  [
897  'diff' => $prevRev->getId(),
898  'oldid' => 'prev'
899  ]
900  );
901  }
902 
903  $nextRev = new Revision( $next );
904 
905  if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
906  || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
907  ) {
908  return $last;
909  }
910 
911  return $linkRenderer->makeKnownLink(
912  $this->getTitle(),
913  new HtmlArmor( $last ),
914  [],
915  [
916  'diff' => $prevRev->getId(),
917  'oldid' => $next->rev_id
918  ]
919  );
920  }
921 
930  function diffButtons( $rev, $firstInList ) {
931  if ( $this->getNumRows() > 1 ) {
932  $id = $rev->getId();
933  $radio = [ 'type' => 'radio', 'value' => $id ];
935  if ( $firstInList ) {
936  $first = Xml::element( 'input',
937  array_merge( $radio, [
938  'style' => 'visibility:hidden',
939  'name' => 'oldid',
940  'id' => 'mw-oldid-null' ] )
941  );
942  $checkmark = [ 'checked' => 'checked' ];
943  } else {
944  # Check visibility of old revisions
945  if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
946  $radio['disabled'] = 'disabled';
947  $checkmark = []; // We will check the next possible one
948  } elseif ( !$this->oldIdChecked ) {
949  $checkmark = [ 'checked' => 'checked' ];
950  $this->oldIdChecked = $id;
951  } else {
952  $checkmark = [];
953  }
954  $first = Xml::element( 'input',
955  array_merge( $radio, $checkmark, [
956  'name' => 'oldid',
957  'id' => "mw-oldid-$id" ] ) );
958  $checkmark = [];
959  }
960  $second = Xml::element( 'input',
961  array_merge( $radio, $checkmark, [
962  'name' => 'diff',
963  'id' => "mw-diff-$id" ] ) );
964 
965  return $first . $second;
966  } else {
967  return '';
968  }
969  }
970 
975  function preventClickjacking( $enable = true ) {
976  $this->preventClickjacking = $enable;
977  }
978 
984  return $this->preventClickjacking;
985  }
986 
987 }
Class for generating clickable toggle links for a list of checkboxes.
Definition: ListToggle.php:31
getRevisionButton( $name, $msg)
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 stripComment( $text)
Quickie hack...
Definition: Feed.php:223
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:728
lastLink( $prevRev, $next)
Create a diff-to-previous link for this revision for this page.
__construct(HistoryAction $historyPage, $year='', $month='', $tagFilter='', array $conds=[])
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
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:209
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1598
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
feed( $type)
Output a subscription feed listing recent edits to this page.
getStartBody()
Creates begin of history list with a submit button.
static formatRevisionSize( $size)
Definition: Linker.php:1513
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: Action.php:395
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:248
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 noclasses 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 and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1995
static dateMenu( $year, $month)
Definition: Xml.php:169
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
database rows
Definition: globals.txt:10
static useFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Check if pages can be cached for this request/user.
if(!isset( $args[0])) $lang
static revUserTools( $rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1065
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:219
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing &#39;/&#39;...
Definition: Html.php:252
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Efficient paging for SQL queries.
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:554
Page view caching in the file system.
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 formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='')
Really format a diff for the newsfeed.
Definition: FeedUtils.php:108
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:238
target page
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1736
static exists( $name)
Check if a given action is recognised, even if it&#39;s disabled.
Definition: Action.php:171
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
$batch
Definition: linkcache.txt:23
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3042
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static submitButton( $contents, array $attrs, array $modifiers=[])
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enab...
Definition: Html.php:186
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
$last
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
feedItem( $row)
Generate a FeedItem object from a given revision table row Borrows Recent Changes&#39; feed generation fu...
onView()
Print the history page for an article.
preCacheMessages()
As we use the same small set of messages in various methods and that they are called often...
static flag( $flag, IContextSource $context=null)
Make an "<abbr>" element for a given change flag.
In both all secondary updates will be triggered handle like object that caches derived data representing a and can trigger updates of cached copies of that e g in the links the and the CDN layer DerivedPageDataUpdater is used by PageUpdater when creating new revisions
Definition: pageupdater.txt:78
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:611
bool $showTagEditUI
Whether to show the tag editing UI.
preventClickjacking( $enable=true)
This is called if a write operation is possible from the generated HTML.
$cache
Definition: mcc.php:33
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
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 noclasses 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 and may include noclasses after processing & $attribs
Definition: hooks.txt:1995
const DELETED_RESTRICTED
Definition: Revision.php:51
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:935
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:527
getContext()
Get the IContextSource in use here.
Definition: Action.php:180
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
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1779
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition: Feed.php:38
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 showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
getPreventClickjacking()
Get the "prevent clickjacking" flag.
$page
Page on which we&#39;re performing the action.
Definition: Action.php:46
const DELETED_TEXT
Definition: Revision.php:48
An action which just does something, without showing a form first.
This class handles printing the history page for an article.
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
historyLine( $row, $next, $notificationtimestamp=false, $latest=false, $firstInList=false)
Returns a row from the history printout.
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 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:780
submitButton( $message, $attributes=[])
Creates a submit button.
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
fetchRevisions( $limit, $offset, $direction)
Fetch an array of revisions, specified by a given limit, offset and direction.
Overloads the relevant methods of the real ResultsWrapper so it doesn&#39;t go anywhere near an actual da...
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:801
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2123
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 message
Definition: hooks.txt:2164
$revQuery
array $message
Array of message keys and strings.
revLink( $rev)
Create a link to view this revision of the page.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
static checkFeedOutput( $type)
Check whether feeds can be used and that $type is a valid feed type.
Definition: FeedUtils.php:56
diffButtons( $rev, $firstInList)
Create radio buttons for page history.
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:93
static revComment(Revision $rev, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision&#39;s comment block, if the current user is allowed to view it...
Definition: Linker.php:1488
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
const DB_REPLICA
Definition: defines.php:25
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:421
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2164
$wgSend404Code
Some web hosts attempt to rewrite all responses with a 404 (not found) status code, mangling or hiding MediaWiki&#39;s output.
static buildTagFilterSelector( $selected='', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
Definition: ChangeTags.php:830
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:258
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:199
$content
Definition: pageupdater.txt:72
const NS_USER_TALK
Definition: Defines.php:67
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:2625
curLink( $rev, $latest)
Create a diff-to-current link for this revision for this page.
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:325
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1486
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1654
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2145
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.