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  return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
66  SpecialPage::getTitleFor( 'Log' ),
67  $this->msg( 'viewpagelogs' )->text(),
68  [],
69  [ 'page' => $this->getTitle()->getPrefixedText() ]
70  );
71  }
72 
76  public function getArticle() {
77  return $this->page;
78  }
79 
84  private function preCacheMessages() {
85  // Precache various messages
86  if ( !isset( $this->message ) ) {
87  $msgs = [ 'cur', 'last', 'pipe-separator' ];
88  foreach ( $msgs as $msg ) {
89  $this->message[$msg] = $this->msg( $msg )->escaped();
90  }
91  }
92  }
93 
97  function onView() {
98  $out = $this->getOutput();
99  $request = $this->getRequest();
100 
104  if ( $out->checkLastModified( $this->page->getTouched() ) ) {
105  return; // Client cache fresh and headers sent, nothing more to do.
106  }
107 
108  $this->preCacheMessages();
109  $config = $this->context->getConfig();
110 
111  # Fill in the file cache if not set already
112  if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
113  $cache = new HTMLFileCache( $this->getTitle(), 'history' );
114  if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
115  ob_start( [ &$cache, 'saveToFileCache' ] );
116  }
117  }
118 
119  // Setup page variables.
120  $out->setFeedAppendQuery( 'action=history' );
121  $out->addModules( 'mediawiki.action.history' );
122  $out->addModuleStyles( [
123  'mediawiki.action.history.styles',
124  'mediawiki.special.changeslist',
125  ] );
126  if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
127  $out = $this->getOutput();
128  $out->addModuleStyles( [
129  'mediawiki.ui.input',
130  'mediawiki.ui.checkbox',
131  ] );
132  }
133 
134  // Handle atom/RSS feeds.
135  $feedType = $request->getVal( 'feed' );
136  if ( $feedType ) {
137  $this->feed( $feedType );
138 
139  return;
140  }
141 
142  $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
143 
144  // Fail nicely if article doesn't exist.
145  if ( !$this->page->exists() ) {
147  if ( $wgSend404Code ) {
148  $out->setStatusCode( 404 );
149  }
150  $out->addWikiMsg( 'nohistory' );
151 
152  $dbr = wfGetDB( DB_REPLICA );
153 
154  # show deletion/move log if there is an entry
156  $out,
157  [ 'delete', 'move', 'protect' ],
158  $this->getTitle(),
159  '',
160  [ 'lim' => 10,
161  'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
162  'showIfEmpty' => false,
163  'msgKey' => [ 'moveddeleted-notice' ]
164  ]
165  );
166 
167  return;
168  }
169 
173  $year = $request->getInt( 'year' );
174  $month = $request->getInt( 'month' );
175  $tagFilter = $request->getVal( 'tagfilter' );
176  $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
177 
181  if ( $request->getBool( 'deleted' ) ) {
182  $conds = [ 'rev_deleted != 0' ];
183  } else {
184  $conds = [];
185  }
186  if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
187  $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
188  'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
189  } else {
190  $checkDeleted = '';
191  }
192 
193  // Add the general form
194  $action = htmlspecialchars( wfScript() );
195  $content = Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
196  $content .= Html::hidden( 'action', 'history' ) . "\n";
197  $content .= Xml::dateMenu(
198  ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
199  $month
200  ) . '&#160;';
201  $content .= $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '';
202  $content .= $checkDeleted . Html::submitButton(
203  $this->msg( 'historyaction-submit' )->text(),
204  [],
205  [ 'mw-ui-progressive' ]
206  );
207  $out->addHTML(
208  "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
210  $this->msg( 'history-fieldset-title' )->text(),
211  $content,
212  [ 'id' => 'mw-history-search' ]
213  ) .
214  '</form>'
215  );
216 
217  Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
218 
219  // Create and output the list.
220  $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
221  $out->addHTML(
222  $pager->getNavigationBar() .
223  $pager->getBody() .
224  $pager->getNavigationBar()
225  );
226  $out->preventClickjacking( $pager->getPreventClickjacking() );
227  }
228 
239  function fetchRevisions( $limit, $offset, $direction ) {
240  // Fail if article doesn't exist.
241  if ( !$this->getTitle()->exists() ) {
242  return new FakeResultWrapper( [] );
243  }
244 
245  $dbr = wfGetDB( DB_REPLICA );
246 
247  if ( $direction === self::DIR_PREV ) {
248  list( $dirs, $oper ) = [ "ASC", ">=" ];
249  } else { /* $direction === self::DIR_NEXT */
250  list( $dirs, $oper ) = [ "DESC", "<=" ];
251  }
252 
253  if ( $offset ) {
254  $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
255  } else {
256  $offsets = [];
257  }
258 
259  $page_id = $this->page->getId();
260 
262  return $dbr->select(
263  $revQuery['tables'],
264  $revQuery['fields'],
265  array_merge( [ 'rev_page' => $page_id ], $offsets ),
266  __METHOD__,
267  [
268  'ORDER BY' => "rev_timestamp $dirs",
269  'USE INDEX' => [ 'revision' => 'page_timestamp' ],
270  'LIMIT' => $limit
271  ],
272  $revQuery['joins']
273  );
274  }
275 
281  function feed( $type ) {
282  if ( !FeedUtils::checkFeedOutput( $type ) ) {
283  return;
284  }
285  $request = $this->getRequest();
286 
287  $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
289  $feed = new $feedClasses[$type](
290  $this->getTitle()->getPrefixedText() . ' - ' .
291  $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
292  $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
293  $this->getTitle()->getFullURL( 'action=history' )
294  );
295 
296  // Get a limit on number of feed entries. Provide a sane default
297  // of 10 if none is defined (but limit to $wgFeedLimit max)
298  $limit = $request->getInt( 'limit', 10 );
299  $limit = min(
300  max( $limit, 1 ),
301  $this->context->getConfig()->get( 'FeedLimit' )
302  );
303 
304  $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
305 
306  // Generate feed elements enclosed between header and footer.
307  $feed->outHeader();
308  if ( $items->numRows() ) {
309  foreach ( $items as $row ) {
310  $feed->outItem( $this->feedItem( $row ) );
311  }
312  } else {
313  $feed->outItem( $this->feedEmpty() );
314  }
315  $feed->outFooter();
316  }
317 
318  function feedEmpty() {
319  return new FeedItem(
320  $this->msg( 'nohistory' )->inContentLanguage()->text(),
321  $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
322  $this->getTitle()->getFullURL(),
323  wfTimestamp( TS_MW ),
324  '',
325  $this->getTitle()->getTalkPage()->getFullURL()
326  );
327  }
328 
337  function feedItem( $row ) {
338  $rev = new Revision( $row, 0, $this->getTitle() );
339 
340  $text = FeedUtils::formatDiffRow(
341  $this->getTitle(),
342  $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
343  $rev->getId(),
344  $rev->getTimestamp(),
345  $rev->getComment()
346  );
347  if ( $rev->getComment() == '' ) {
349  $title = $this->msg( 'history-feed-item-nocomment',
350  $rev->getUserText(),
351  $wgContLang->timeanddate( $rev->getTimestamp() ),
352  $wgContLang->date( $rev->getTimestamp() ),
353  $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
354  } else {
355  $title = $rev->getUserText() .
356  $this->msg( 'colon-separator' )->inContentLanguage()->text() .
357  FeedItem::stripComment( $rev->getComment() );
358  }
359 
360  return new FeedItem(
361  $title,
362  $text,
363  $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
364  $rev->getTimestamp(),
365  $rev->getUserText(),
366  $this->getTitle()->getTalkPage()->getFullURL()
367  );
368  }
369 }
370 
379  public $lastRow = false;
380 
382 
383  protected $oldIdChecked;
384 
385  protected $preventClickjacking = false;
389  protected $parentLens;
390 
392  protected $showTagEditUI;
393 
395  private $tagFilter;
396 
404  function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
405  parent::__construct( $historyPage->getContext() );
406  $this->historyPage = $historyPage;
407  $this->tagFilter = $tagFilter;
408  $this->getDateCond( $year, $month );
409  $this->conds = $conds;
410  $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
411  }
412 
413  // For hook compatibility...
414  function getArticle() {
415  return $this->historyPage->getArticle();
416  }
417 
418  function getSqlComment() {
419  if ( $this->conds ) {
420  return 'history page filtered'; // potentially slow, see CR r58153
421  } else {
422  return 'history page unfiltered';
423  }
424  }
425 
426  function getQueryInfo() {
427  $revQuery = Revision::getQueryInfo( [ 'user' ] );
428  $queryInfo = [
429  'tables' => $revQuery['tables'],
430  'fields' => $revQuery['fields'],
431  'conds' => array_merge(
432  [ 'rev_page' => $this->getWikiPage()->getId() ],
433  $this->conds ),
434  'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
435  'join_conds' => $revQuery['joins'],
436  ];
438  $queryInfo['tables'],
439  $queryInfo['fields'],
440  $queryInfo['conds'],
441  $queryInfo['join_conds'],
442  $queryInfo['options'],
443  $this->tagFilter
444  );
445 
446  // Avoid PHP 7.1 warning of passing $this by reference
447  $historyPager = $this;
448  Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
449 
450  return $queryInfo;
451  }
452 
453  function getIndexField() {
454  return 'rev_timestamp';
455  }
456 
461  function formatRow( $row ) {
462  if ( $this->lastRow ) {
463  $latest = ( $this->counter == 1 && $this->mIsFirst );
464  $firstInList = $this->counter == 1;
465  $this->counter++;
466 
467  $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
468  ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
469  : false;
470 
471  $s = $this->historyLine(
472  $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
473  } else {
474  $s = '';
475  }
476  $this->lastRow = $row;
477 
478  return $s;
479  }
480 
481  function doBatchLookups() {
482  if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
483  return;
484  }
485 
486  # Do a link batch query
487  $this->mResult->seek( 0 );
488  $batch = new LinkBatch();
489  $revIds = [];
490  foreach ( $this->mResult as $row ) {
491  if ( $row->rev_parent_id ) {
492  $revIds[] = $row->rev_parent_id;
493  }
494  if ( !is_null( $row->user_name ) ) {
495  $batch->add( NS_USER, $row->user_name );
496  $batch->add( NS_USER_TALK, $row->user_name );
497  } else { # for anons or usernames of imported revisions
498  $batch->add( NS_USER, $row->rev_user_text );
499  $batch->add( NS_USER_TALK, $row->rev_user_text );
500  }
501  }
502  $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
503  $batch->execute();
504  $this->mResult->seek( 0 );
505  }
506 
512  function getStartBody() {
513  $this->lastRow = false;
514  $this->counter = 1;
515  $this->oldIdChecked = 0;
516 
517  $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
518  $s = Html::openElement( 'form', [ 'action' => wfScript(),
519  'id' => 'mw-history-compare' ] ) . "\n";
520  $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
521  $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
522  $s .= Html::hidden( 'type', 'revision' ) . "\n";
523 
524  // Button container stored in $this->buttons for re-use in getEndBody()
525  $this->buttons = '<div>';
526  $className = 'historysubmit mw-history-compareselectedversions-button';
527  $attrs = [ 'class' => $className ]
528  + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
529  $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
530  $attrs
531  ) . "\n";
532 
533  $user = $this->getUser();
534  $actionButtons = '';
535  if ( $user->isAllowed( 'deleterevision' ) ) {
536  $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
537  }
538  if ( $this->showTagEditUI ) {
539  $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
540  }
541  if ( $actionButtons ) {
542  $this->buttons .= Xml::tags( 'div', [ 'class' =>
543  'mw-history-revisionactions' ], $actionButtons );
544  }
545 
546  if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
547  $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
548  }
549 
550  $this->buttons .= '</div>';
551 
552  $s .= $this->buttons;
553  $s .= '<ul id="pagehistory">' . "\n";
554 
555  return $s;
556  }
557 
558  private function getRevisionButton( $name, $msg ) {
559  $this->preventClickjacking();
560  # Note bug #20966, <button> is non-standard in IE<8
561  $element = Html::element(
562  'button',
563  [
564  'type' => 'submit',
565  'name' => $name,
566  'value' => '1',
567  'class' => "historysubmit mw-history-$name-button",
568  ],
569  $this->msg( $msg )->text()
570  ) . "\n";
571  return $element;
572  }
573 
574  function getEndBody() {
575  if ( $this->lastRow ) {
576  $latest = $this->counter == 1 && $this->mIsFirst;
577  $firstInList = $this->counter == 1;
578  if ( $this->mIsBackwards ) {
579  # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
580  if ( $this->mOffset == '' ) {
581  $next = null;
582  } else {
583  $next = 'unknown';
584  }
585  } else {
586  # The next row is the past-the-end row
587  $next = $this->mPastTheEndRow;
588  }
589  $this->counter++;
590 
591  $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
592  ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
593  : false;
594 
595  $s = $this->historyLine(
596  $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
597  } else {
598  $s = '';
599  }
600  $s .= "</ul>\n";
601  # Add second buttons only if there is more than one rev
602  if ( $this->getNumRows() > 2 ) {
603  $s .= $this->buttons;
604  }
605  $s .= '</form>';
606 
607  return $s;
608  }
609 
617  function submitButton( $message, $attributes = [] ) {
618  # Disable submit button if history has 1 revision only
619  if ( $this->getNumRows() > 1 ) {
620  return Html::submitButton( $message, $attributes );
621  } else {
622  return '';
623  }
624  }
625 
640  function historyLine( $row, $next, $notificationtimestamp = false,
641  $latest = false, $firstInList = false ) {
642  $rev = new Revision( $row, 0, $this->getTitle() );
643 
644  if ( is_object( $next ) ) {
645  $prevRev = new Revision( $next, 0, $this->getTitle() );
646  } else {
647  $prevRev = null;
648  }
649 
650  $curlink = $this->curLink( $rev, $latest );
651  $lastlink = $this->lastLink( $rev, $next );
652  $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
653  $histLinks = Html::rawElement(
654  'span',
655  [ 'class' => 'mw-history-histlinks' ],
656  $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
657  );
658 
659  $diffButtons = $this->diffButtons( $rev, $firstInList );
660  $s = $histLinks . $diffButtons;
661 
662  $link = $this->revLink( $rev );
663  $classes = [];
664 
665  $del = '';
666  $user = $this->getUser();
667  $canRevDelete = $user->isAllowed( 'deleterevision' );
668  // Show checkboxes for each revision, to allow for revision deletion and
669  // change tags
670  if ( $canRevDelete || $this->showTagEditUI ) {
671  $this->preventClickjacking();
672  // If revision was hidden from sysops and we don't need the checkbox
673  // for anything else, disable it
674  if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
675  $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
676  // Otherwise, enable the checkbox...
677  } else {
678  $del = Xml::check( 'showhiderevisions', false,
679  [ 'name' => 'ids[' . $rev->getId() . ']' ] );
680  }
681  // User can only view deleted revisions...
682  } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
683  // If revision was hidden from sysops, disable the link
684  if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
685  $del = Linker::revDeleteLinkDisabled( false );
686  // Otherwise, show the link...
687  } else {
688  $query = [ 'type' => 'revision',
689  'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
690  $del .= Linker::revDeleteLink( $query,
691  $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
692  }
693  }
694  if ( $del ) {
695  $s .= " $del ";
696  }
697 
698  $lang = $this->getLanguage();
699  $dirmark = $lang->getDirMark();
700 
701  $s .= " $link";
702  $s .= $dirmark;
703  $s .= " <span class='history-user'>" .
704  Linker::revUserTools( $rev, true ) . "</span>";
705  $s .= $dirmark;
706 
707  if ( $rev->isMinor() ) {
708  $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
709  }
710 
711  # Sometimes rev_len isn't populated
712  if ( $rev->getSize() !== null ) {
713  # Size is always public data
714  $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
715  ? $this->parentLens[$row->rev_parent_id]
716  : 0;
717  $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
718  $fSize = Linker::formatRevisionSize( $rev->getSize() );
719  $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
720  }
721 
722  # Text following the character difference is added just before running hooks
723  $s2 = Linker::revComment( $rev, false, true );
724 
725  if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
726  $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
727  $classes[] = 'mw-history-line-updated';
728  }
729 
730  $tools = [];
731 
732  # Rollback and undo links
733  if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
734  if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
735  // Get a rollback link without the brackets
736  $rollbackLink = Linker::generateRollback(
737  $rev,
738  $this->getContext(),
739  [ 'verify', 'noBrackets' ]
740  );
741  if ( $rollbackLink ) {
742  $this->preventClickjacking();
743  $tools[] = $rollbackLink;
744  }
745  }
746 
747  if ( !$rev->isDeleted( Revision::DELETED_TEXT )
748  && !$prevRev->isDeleted( Revision::DELETED_TEXT )
749  ) {
750  # Create undo tooltip for the first (=latest) line only
751  $undoTooltip = $latest
752  ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
753  : [];
754  $undolink = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
755  $this->getTitle(),
756  $this->msg( 'editundo' )->text(),
757  $undoTooltip,
758  [
759  'action' => 'edit',
760  'undoafter' => $prevRev->getId(),
761  'undo' => $rev->getId()
762  ]
763  );
764  $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
765  }
766  }
767  // Allow extension to add their own links here
768  Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
769 
770  if ( $tools ) {
771  $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
772  }
773 
774  # Tags
775  list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
776  $row->ts_tags,
777  'history',
778  $this->getContext()
779  );
780  $classes = array_merge( $classes, $newClasses );
781  if ( $tagSummary !== '' ) {
782  $s2 .= " $tagSummary";
783  }
784 
785  # Include separator between character difference and following text
786  if ( $s2 !== '' ) {
787  $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
788  }
789 
790  $attribs = [ 'data-mw-revid' => $rev->getId() ];
791 
792  Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes, &$attribs ] );
793  $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
794 
795  if ( $classes ) {
796  $attribs['class'] = implode( ' ', $classes );
797  }
798 
799  return Xml::tags( 'li', $attribs, $s ) . "\n";
800  }
801 
808  function revLink( $rev ) {
809  $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
810  if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
811  $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
812  $this->getTitle(),
813  $date,
814  [ 'class' => 'mw-changeslist-date' ],
815  [ 'oldid' => $rev->getId() ]
816  );
817  } else {
818  $link = htmlspecialchars( $date );
819  }
820  if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
821  $link = "<span class=\"history-deleted\">$link</span>";
822  }
823 
824  return $link;
825  }
826 
834  function curLink( $rev, $latest ) {
835  $cur = $this->historyPage->message['cur'];
836  if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
837  return $cur;
838  } else {
839  return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
840  $this->getTitle(),
841  $cur,
842  [],
843  [
844  'diff' => $this->getWikiPage()->getLatest(),
845  'oldid' => $rev->getId()
846  ]
847  );
848  }
849  }
850 
860  function lastLink( $prevRev, $next ) {
861  $last = $this->historyPage->message['last'];
862 
863  if ( $next === null ) {
864  # Probably no next row
865  return $last;
866  }
867 
868  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
869  if ( $next === 'unknown' ) {
870  # Next row probably exists but is unknown, use an oldid=prev link
871  return $linkRenderer->makeKnownLink(
872  $this->getTitle(),
873  $last,
874  [],
875  [
876  'diff' => $prevRev->getId(),
877  'oldid' => 'prev'
878  ]
879  );
880  }
881 
882  $nextRev = new Revision( $next );
883 
884  if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
885  || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
886  ) {
887  return $last;
888  }
889 
890  return $linkRenderer->makeKnownLink(
891  $this->getTitle(),
892  $last,
893  [],
894  [
895  'diff' => $prevRev->getId(),
896  'oldid' => $next->rev_id
897  ]
898  );
899  }
900 
909  function diffButtons( $rev, $firstInList ) {
910  if ( $this->getNumRows() > 1 ) {
911  $id = $rev->getId();
912  $radio = [ 'type' => 'radio', 'value' => $id ];
914  if ( $firstInList ) {
915  $first = Xml::element( 'input',
916  array_merge( $radio, [
917  'style' => 'visibility:hidden',
918  'name' => 'oldid',
919  'id' => 'mw-oldid-null' ] )
920  );
921  $checkmark = [ 'checked' => 'checked' ];
922  } else {
923  # Check visibility of old revisions
924  if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
925  $radio['disabled'] = 'disabled';
926  $checkmark = []; // We will check the next possible one
927  } elseif ( !$this->oldIdChecked ) {
928  $checkmark = [ 'checked' => 'checked' ];
929  $this->oldIdChecked = $id;
930  } else {
931  $checkmark = [];
932  }
933  $first = Xml::element( 'input',
934  array_merge( $radio, $checkmark, [
935  'name' => 'oldid',
936  'id' => "mw-oldid-$id" ] ) );
937  $checkmark = [];
938  }
939  $second = Xml::element( 'input',
940  array_merge( $radio, $checkmark, [
941  'name' => 'diff',
942  'id' => "mw-diff-$id" ] ) );
943 
944  return $first . $second;
945  } else {
946  return '';
947  }
948  }
949 
954  function preventClickjacking( $enable = true ) {
955  $this->preventClickjacking = $enable;
956  }
957 
964  }
965 
966 }
Class for generating clickable toggle links for a list of checkboxes.
Definition: ListToggle.php:31
addHelpLink($to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: Action.php:388
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
static revComment(Revision $rev, $local=false, $isPublic=false)
Wrap and format the given revision's comment block, if the current user is allowed to view it...
Definition: Linker.php:1480
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
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:790
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:207
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:1623
static checkFeedOutput($type)
Check whether feeds can be used and that $type is a valid feed type.
Definition: FeedUtils.php:56
getStartBody()
Creates begin of history list with a submit button.
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static element($element, $attribs=null, $contents= '', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:246
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
curLink($rev, $latest)
Create a diff-to-current link for this revision for this page.
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
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:2019
static buildTagFilterSelector($selected= '', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
Definition: ChangeTags.php:791
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
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
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:217
static formatRevisionSize($size)
Definition: Linker.php:1503
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:790
Efficient paging for SQL queries.
bool stdClass $lastRow
submitButton($message, $attributes=[])
Creates a submit button.
Page view caching in the file system.
historyLine($row, $next, $notificationtimestamp=false, $latest=false, $firstInList=false)
Returns a row from the history printout.
preventClickjacking($enable=true)
This is called if a write operation is possible from the generated HTML.
static exists($name)
Check if a given action is recognised, even if it's disabled.
Definition: Action.php:169
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 tooltipAndAccesskeyAttribs($name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2135
static check($name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:324
target page
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static stripComment($text)
Quickie hack...
Definition: Feed.php:223
lastLink($prevRev, $next)
Create a diff-to-previous link for this revision for this page.
static showLogExtract(&$out, $types=[], $page= '', $user= '', $param=[])
Show log extract.
static getLocalInstance($ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
static getQueryInfo($options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:492
$batch
Definition: linkcache.txt:23
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3038
$mIsFirst
True if the current result set is the first one.
Definition: IndexPager.php:114
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.
static fieldset($legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:610
onView()
Print the history page for an article.
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
preCacheMessages()
As we use the same small set of messages in various methods and that they are called often...
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 message
Definition: hooks.txt:2187
static formatSummaryRow($tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:91
__construct($historyPage, $year= '', $month= '', $tagFilter= '', $conds=[])
bool $showTagEditUI
Whether to show the tag editing UI.
static dateMenu($year, $month)
Definition: Xml.php:168
static showCharacterDifference($old, $new, IContextSource $context=null)
Show formatted char difference.
getContext()
Get the base IContextSource object.
$cache
Definition: mcc.php:33
static revDeleteLinkDisabled($delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2116
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:2019
const DELETED_RESTRICTED
Definition: Revision.php:50
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:941
getContext()
Get the IContextSource in use here.
Definition: Action.php:178
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
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
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:1799
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition: Feed.php:38
revLink($rev)
Create a link to view this revision of the page.
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
getPreventClickjacking()
Get the "prevent clickjacking" flag.
$page
Page on which we're performing the action.
Definition: Action.php:44
const DELETED_TEXT
Definition: Revision.php:47
An action which just does something, without showing a form first.
feedItem($row)
Generate a FeedItem object from a given revision table row Borrows Recent Changes' feed generation fu...
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
static tags($element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
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:185
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
static generateRollback($rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1706
diffButtons($rev, $firstInList)
Create radio buttons for page history.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
$revQuery
array $message
Array of message keys and strings.
fetchRevisions($limit, $offset, $direction)
Fetch an array of revisions, specified by a given limit, offset and direction.
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
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
static flag($flag, IContextSource $context=null)
Make an "" element for a given change flag.
wfArrayFilterByKey(array $arr, callable $callback)
Like array_filter with ARRAY_FILTER_USE_KEY, but works pre-5.6.
static getParentLengths($db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:519
msg($key)
Get a Message object with context set Parameters are the same as wfMessage()
static checkLabel($label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:420
static formatDiffRow($title, $oldid, $newid, $timestamp, $comment, $actiontext= '')
Really format a diff for the newsfeed.
Definition: FeedUtils.php:108
const DB_REPLICA
Definition: defines.php:25
getRevisionButton($name, $msg)
feed($type)
Output a subscription feed listing recent edits to this page.
msg($key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
$wgSend404Code
Some web hosts attempt to rewrite all responses with a 404 (not found) status code, mangling or hiding MediaWiki's output.
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:197
const NS_USER_TALK
Definition: Defines.php:68
static revUserTools($rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1070
getWikiPage()
Get the WikiPage object.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
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:2636
static revDeleteLink($query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2094
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag= '')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:736
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:244
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1681
getDateCond($year, $month, $day=-1)
Set and return the mOffset timestamp such that we can get all revisions with a timestamp up to the sp...
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:555