MediaWiki  1.28.1
HistoryAction.php
Go to the documentation of this file.
1 <?php
37  const DIR_PREV = 0;
38  const DIR_NEXT = 1;
39 
41  public $message;
42 
43  public function getName() {
44  return 'history';
45  }
46 
47  public function requiresWrite() {
48  return false;
49  }
50 
51  public function requiresUnblock() {
52  return false;
53  }
54 
55  protected function getPageTitle() {
56  return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
57  }
58 
59  protected function getDescription() {
60  // Creation of a subtitle link pointing to [[Special:Log]]
61  return Linker::linkKnown(
62  SpecialPage::getTitleFor( 'Log' ),
63  $this->msg( 'viewpagelogs' )->escaped(),
64  [],
65  [ 'page' => $this->getTitle()->getPrefixedText() ]
66  );
67  }
68 
72  public function getArticle() {
73  return $this->page;
74  }
75 
80  private function preCacheMessages() {
81  // Precache various messages
82  if ( !isset( $this->message ) ) {
83  $msgs = [ 'cur', 'last', 'pipe-separator' ];
84  foreach ( $msgs as $msg ) {
85  $this->message[$msg] = $this->msg( $msg )->escaped();
86  }
87  }
88  }
89 
93  function onView() {
94  $out = $this->getOutput();
95  $request = $this->getRequest();
96 
100  if ( $out->checkLastModified( $this->page->getTouched() ) ) {
101  return; // Client cache fresh and headers sent, nothing more to do.
102  }
103 
104  $this->preCacheMessages();
105  $config = $this->context->getConfig();
106 
107  # Fill in the file cache if not set already
108  if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
109  $cache = new HTMLFileCache( $this->getTitle(), 'history' );
110  if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
111  ob_start( [ &$cache, 'saveToFileCache' ] );
112  }
113  }
114 
115  // Setup page variables.
116  $out->setFeedAppendQuery( 'action=history' );
117  $out->addModules( 'mediawiki.action.history' );
118  $out->addModuleStyles( [
119  'mediawiki.action.history.styles',
120  'mediawiki.special.changeslist',
121  ] );
122  if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
123  $out = $this->getOutput();
124  $out->addModuleStyles( [
125  'mediawiki.ui.input',
126  'mediawiki.ui.checkbox',
127  ] );
128  }
129 
130  // Handle atom/RSS feeds.
131  $feedType = $request->getVal( 'feed' );
132  if ( $feedType ) {
133  $this->feed( $feedType );
134 
135  return;
136  }
137 
138  $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
139 
140  // Fail nicely if article doesn't exist.
141  if ( !$this->page->exists() ) {
143  if ( $wgSend404Code ) {
144  $out->setStatusCode( 404 );
145  }
146  $out->addWikiMsg( 'nohistory' );
147  # show deletion/move log if there is an entry
149  $out,
150  [ 'delete', 'move' ],
151  $this->getTitle(),
152  '',
153  [ 'lim' => 10,
154  'conds' => [ "log_action != 'revision'" ],
155  'showIfEmpty' => false,
156  'msgKey' => [ 'moveddeleted-notice' ]
157  ]
158  );
159 
160  return;
161  }
162 
166  $year = $request->getInt( 'year' );
167  $month = $request->getInt( 'month' );
168  $tagFilter = $request->getVal( 'tagfilter' );
169  $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
170 
174  if ( $request->getBool( 'deleted' ) ) {
175  $conds = [ 'rev_deleted != 0' ];
176  } else {
177  $conds = [];
178  }
179  if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
180  $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
181  'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
182  } else {
183  $checkDeleted = '';
184  }
185 
186  // Add the general form
187  $action = htmlspecialchars( wfScript() );
188  $out->addHTML(
189  "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
191  $this->msg( 'history-fieldset-title' )->text(),
192  false,
193  [ 'id' => 'mw-history-search' ]
194  ) .
195  Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
196  Html::hidden( 'action', 'history' ) . "\n" .
198  ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
199  $month
200  ) . '&#160;' .
201  ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
202  $checkDeleted .
204  $this->msg( 'historyaction-submit' )->text(),
205  [],
206  [ 'mw-ui-progressive' ]
207  ) . "\n" .
208  '</fieldset></form>'
209  );
210 
211  Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
212 
213  // Create and output the list.
214  $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
215  $out->addHTML(
216  $pager->getNavigationBar() .
217  $pager->getBody() .
218  $pager->getNavigationBar()
219  );
220  $out->preventClickjacking( $pager->getPreventClickjacking() );
221 
222  }
223 
234  function fetchRevisions( $limit, $offset, $direction ) {
235  // Fail if article doesn't exist.
236  if ( !$this->getTitle()->exists() ) {
237  return new FakeResultWrapper( [] );
238  }
239 
240  $dbr = wfGetDB( DB_REPLICA );
241 
242  if ( $direction === self::DIR_PREV ) {
243  list( $dirs, $oper ) = [ "ASC", ">=" ];
244  } else { /* $direction === self::DIR_NEXT */
245  list( $dirs, $oper ) = [ "DESC", "<=" ];
246  }
247 
248  if ( $offset ) {
249  $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
250  } else {
251  $offsets = [];
252  }
253 
254  $page_id = $this->page->getId();
255 
256  return $dbr->select( 'revision',
258  array_merge( [ 'rev_page' => $page_id ], $offsets ),
259  __METHOD__,
260  [ 'ORDER BY' => "rev_timestamp $dirs",
261  'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
262  );
263  }
264 
270  function feed( $type ) {
271  if ( !FeedUtils::checkFeedOutput( $type ) ) {
272  return;
273  }
274  $request = $this->getRequest();
275 
276  $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
278  $feed = new $feedClasses[$type](
279  $this->getTitle()->getPrefixedText() . ' - ' .
280  $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
281  $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
282  $this->getTitle()->getFullURL( 'action=history' )
283  );
284 
285  // Get a limit on number of feed entries. Provide a sane default
286  // of 10 if none is defined (but limit to $wgFeedLimit max)
287  $limit = $request->getInt( 'limit', 10 );
288  $limit = min(
289  max( $limit, 1 ),
290  $this->context->getConfig()->get( 'FeedLimit' )
291  );
292 
293  $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
294 
295  // Generate feed elements enclosed between header and footer.
296  $feed->outHeader();
297  if ( $items->numRows() ) {
298  foreach ( $items as $row ) {
299  $feed->outItem( $this->feedItem( $row ) );
300  }
301  } else {
302  $feed->outItem( $this->feedEmpty() );
303  }
304  $feed->outFooter();
305  }
306 
307  function feedEmpty() {
308  return new FeedItem(
309  $this->msg( 'nohistory' )->inContentLanguage()->text(),
310  $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
311  $this->getTitle()->getFullURL(),
312  wfTimestamp( TS_MW ),
313  '',
314  $this->getTitle()->getTalkPage()->getFullURL()
315  );
316  }
317 
326  function feedItem( $row ) {
327  $rev = new Revision( $row );
328  $rev->setTitle( $this->getTitle() );
329  $text = FeedUtils::formatDiffRow(
330  $this->getTitle(),
331  $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
332  $rev->getId(),
333  $rev->getTimestamp(),
334  $rev->getComment()
335  );
336  if ( $rev->getComment() == '' ) {
338  $title = $this->msg( 'history-feed-item-nocomment',
339  $rev->getUserText(),
340  $wgContLang->timeanddate( $rev->getTimestamp() ),
341  $wgContLang->date( $rev->getTimestamp() ),
342  $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
343  } else {
344  $title = $rev->getUserText() .
345  $this->msg( 'colon-separator' )->inContentLanguage()->text() .
346  FeedItem::stripComment( $rev->getComment() );
347  }
348 
349  return new FeedItem(
350  $title,
351  $text,
352  $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
353  $rev->getTimestamp(),
354  $rev->getUserText(),
355  $this->getTitle()->getTalkPage()->getFullURL()
356  );
357  }
358 }
359 
368  public $lastRow = false;
369 
371 
372  protected $oldIdChecked;
373 
374  protected $preventClickjacking = false;
378  protected $parentLens;
379 
381  protected $showTagEditUI;
382 
390  function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
391  parent::__construct( $historyPage->getContext() );
392  $this->historyPage = $historyPage;
393  $this->tagFilter = $tagFilter;
394  $this->getDateCond( $year, $month );
395  $this->conds = $conds;
396  $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
397  }
398 
399  // For hook compatibility...
400  function getArticle() {
401  return $this->historyPage->getArticle();
402  }
403 
404  function getSqlComment() {
405  if ( $this->conds ) {
406  return 'history page filtered'; // potentially slow, see CR r58153
407  } else {
408  return 'history page unfiltered';
409  }
410  }
411 
412  function getQueryInfo() {
413  $queryInfo = [
414  'tables' => [ 'revision', 'user' ],
415  'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
416  'conds' => array_merge(
417  [ 'rev_page' => $this->getWikiPage()->getId() ],
418  $this->conds ),
419  'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
420  'join_conds' => [ 'user' => Revision::userJoinCond() ],
421  ];
423  $queryInfo['tables'],
424  $queryInfo['fields'],
425  $queryInfo['conds'],
426  $queryInfo['join_conds'],
427  $queryInfo['options'],
428  $this->tagFilter
429  );
430  Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$this, &$queryInfo ] );
431 
432  return $queryInfo;
433  }
434 
435  function getIndexField() {
436  return 'rev_timestamp';
437  }
438 
443  function formatRow( $row ) {
444  if ( $this->lastRow ) {
445  $latest = ( $this->counter == 1 && $this->mIsFirst );
446  $firstInList = $this->counter == 1;
447  $this->counter++;
448 
449  $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
450  ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
451  : false;
452 
453  $s = $this->historyLine(
454  $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
455  } else {
456  $s = '';
457  }
458  $this->lastRow = $row;
459 
460  return $s;
461  }
462 
463  function doBatchLookups() {
464  if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
465  return;
466  }
467 
468  # Do a link batch query
469  $this->mResult->seek( 0 );
470  $batch = new LinkBatch();
471  $revIds = [];
472  foreach ( $this->mResult as $row ) {
473  if ( $row->rev_parent_id ) {
474  $revIds[] = $row->rev_parent_id;
475  }
476  if ( !is_null( $row->user_name ) ) {
477  $batch->add( NS_USER, $row->user_name );
478  $batch->add( NS_USER_TALK, $row->user_name );
479  } else { # for anons or usernames of imported revisions
480  $batch->add( NS_USER, $row->rev_user_text );
481  $batch->add( NS_USER_TALK, $row->rev_user_text );
482  }
483  }
484  $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
485  $batch->execute();
486  $this->mResult->seek( 0 );
487  }
488 
494  function getStartBody() {
495  $this->lastRow = false;
496  $this->counter = 1;
497  $this->oldIdChecked = 0;
498 
499  $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
500  $s = Html::openElement( 'form', [ 'action' => wfScript(),
501  'id' => 'mw-history-compare' ] ) . "\n";
502  $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
503  $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
504  $s .= Html::hidden( 'type', 'revision' ) . "\n";
505 
506  // Button container stored in $this->buttons for re-use in getEndBody()
507  $this->buttons = '<div>';
508  $className = 'historysubmit mw-history-compareselectedversions-button';
509  $attrs = [ 'class' => $className ]
510  + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
511  $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
512  $attrs
513  ) . "\n";
514 
515  $user = $this->getUser();
516  $actionButtons = '';
517  if ( $user->isAllowed( 'deleterevision' ) ) {
518  $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
519  }
520  if ( $this->showTagEditUI ) {
521  $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
522  }
523  if ( $actionButtons ) {
524  $this->buttons .= Xml::tags( 'div', [ 'class' =>
525  'mw-history-revisionactions' ], $actionButtons );
526  }
527 
528  if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
529  $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
530  }
531 
532  $this->buttons .= '</div>';
533 
534  $s .= $this->buttons;
535  $s .= '<ul id="pagehistory">' . "\n";
536 
537  return $s;
538  }
539 
540  private function getRevisionButton( $name, $msg ) {
541  $this->preventClickjacking();
542  # Note bug #20966, <button> is non-standard in IE<8
543  $element = Html::element(
544  'button',
545  [
546  'type' => 'submit',
547  'name' => $name,
548  'value' => '1',
549  'class' => "historysubmit mw-history-$name-button",
550  ],
551  $this->msg( $msg )->text()
552  ) . "\n";
553  return $element;
554  }
555 
556  function getEndBody() {
557  if ( $this->lastRow ) {
558  $latest = $this->counter == 1 && $this->mIsFirst;
559  $firstInList = $this->counter == 1;
560  if ( $this->mIsBackwards ) {
561  # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
562  if ( $this->mOffset == '' ) {
563  $next = null;
564  } else {
565  $next = 'unknown';
566  }
567  } else {
568  # The next row is the past-the-end row
569  $next = $this->mPastTheEndRow;
570  }
571  $this->counter++;
572 
573  $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
574  ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
575  : false;
576 
577  $s = $this->historyLine(
578  $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
579  } else {
580  $s = '';
581  }
582  $s .= "</ul>\n";
583  # Add second buttons only if there is more than one rev
584  if ( $this->getNumRows() > 2 ) {
585  $s .= $this->buttons;
586  }
587  $s .= '</form>';
588 
589  return $s;
590  }
591 
599  function submitButton( $message, $attributes = [] ) {
600  # Disable submit button if history has 1 revision only
601  if ( $this->getNumRows() > 1 ) {
602  return Html::submitButton( $message, $attributes );
603  } else {
604  return '';
605  }
606  }
607 
622  function historyLine( $row, $next, $notificationtimestamp = false,
623  $latest = false, $firstInList = false ) {
624  $rev = new Revision( $row );
625  $rev->setTitle( $this->getTitle() );
626 
627  if ( is_object( $next ) ) {
628  $prevRev = new Revision( $next );
629  $prevRev->setTitle( $this->getTitle() );
630  } else {
631  $prevRev = null;
632  }
633 
634  $curlink = $this->curLink( $rev, $latest );
635  $lastlink = $this->lastLink( $rev, $next );
636  $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
637  $histLinks = Html::rawElement(
638  'span',
639  [ 'class' => 'mw-history-histlinks' ],
640  $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
641  );
642 
643  $diffButtons = $this->diffButtons( $rev, $firstInList );
644  $s = $histLinks . $diffButtons;
645 
646  $link = $this->revLink( $rev );
647  $classes = [];
648 
649  $del = '';
650  $user = $this->getUser();
651  $canRevDelete = $user->isAllowed( 'deleterevision' );
652  // Show checkboxes for each revision, to allow for revision deletion and
653  // change tags
654  if ( $canRevDelete || $this->showTagEditUI ) {
655  $this->preventClickjacking();
656  // If revision was hidden from sysops and we don't need the checkbox
657  // for anything else, disable it
658  if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
659  $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
660  // Otherwise, enable the checkbox...
661  } else {
662  $del = Xml::check( 'showhiderevisions', false,
663  [ 'name' => 'ids[' . $rev->getId() . ']' ] );
664  }
665  // User can only view deleted revisions...
666  } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
667  // If revision was hidden from sysops, disable the link
668  if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
669  $del = Linker::revDeleteLinkDisabled( false );
670  // Otherwise, show the link...
671  } else {
672  $query = [ 'type' => 'revision',
673  'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
674  $del .= Linker::revDeleteLink( $query,
675  $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
676  }
677  }
678  if ( $del ) {
679  $s .= " $del ";
680  }
681 
682  $lang = $this->getLanguage();
683  $dirmark = $lang->getDirMark();
684 
685  $s .= " $link";
686  $s .= $dirmark;
687  $s .= " <span class='history-user'>" .
688  Linker::revUserTools( $rev, true ) . "</span>";
689  $s .= $dirmark;
690 
691  if ( $rev->isMinor() ) {
692  $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
693  }
694 
695  # Sometimes rev_len isn't populated
696  if ( $rev->getSize() !== null ) {
697  # Size is always public data
698  $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
699  ? $this->parentLens[$row->rev_parent_id]
700  : 0;
701  $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
702  $fSize = Linker::formatRevisionSize( $rev->getSize() );
703  $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
704  }
705 
706  # Text following the character difference is added just before running hooks
707  $s2 = Linker::revComment( $rev, false, true );
708 
709  if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
710  $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
711  $classes[] = 'mw-history-line-updated';
712  }
713 
714  $tools = [];
715 
716  # Rollback and undo links
717  if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
718  if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
719  // Get a rollback link without the brackets
720  $rollbackLink = Linker::generateRollback(
721  $rev,
722  $this->getContext(),
723  [ 'verify', 'noBrackets' ]
724  );
725  if ( $rollbackLink ) {
726  $this->preventClickjacking();
727  $tools[] = $rollbackLink;
728  }
729  }
730 
731  if ( !$rev->isDeleted( Revision::DELETED_TEXT )
732  && !$prevRev->isDeleted( Revision::DELETED_TEXT )
733  ) {
734  # Create undo tooltip for the first (=latest) line only
735  $undoTooltip = $latest
736  ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
737  : [];
738  $undolink = Linker::linkKnown(
739  $this->getTitle(),
740  $this->msg( 'editundo' )->escaped(),
741  $undoTooltip,
742  [
743  'action' => 'edit',
744  'undoafter' => $prevRev->getId(),
745  'undo' => $rev->getId()
746  ]
747  );
748  $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
749  }
750  }
751  // Allow extension to add their own links here
752  Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
753 
754  if ( $tools ) {
755  $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
756  }
757 
758  # Tags
759  list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
760  $row->ts_tags,
761  'history',
762  $this->getContext()
763  );
764  $classes = array_merge( $classes, $newClasses );
765  if ( $tagSummary !== '' ) {
766  $s2 .= " $tagSummary";
767  }
768 
769  # Include separator between character difference and following text
770  if ( $s2 !== '' ) {
771  $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
772  }
773 
774  Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
775 
776  $attribs = [];
777  if ( $classes ) {
778  $attribs['class'] = implode( ' ', $classes );
779  }
780 
781  return Xml::tags( 'li', $attribs, $s ) . "\n";
782  }
783 
790  function revLink( $rev ) {
791  $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
792  $date = htmlspecialchars( $date );
793  if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
795  $this->getTitle(),
796  $date,
797  [ 'class' => 'mw-changeslist-date' ],
798  [ 'oldid' => $rev->getId() ]
799  );
800  } else {
801  $link = $date;
802  }
803  if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
804  $link = "<span class=\"history-deleted\">$link</span>";
805  }
806 
807  return $link;
808  }
809 
817  function curLink( $rev, $latest ) {
818  $cur = $this->historyPage->message['cur'];
819  if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
820  return $cur;
821  } else {
822  return Linker::linkKnown(
823  $this->getTitle(),
824  $cur,
825  [],
826  [
827  'diff' => $this->getWikiPage()->getLatest(),
828  'oldid' => $rev->getId()
829  ]
830  );
831  }
832  }
833 
843  function lastLink( $prevRev, $next ) {
844  $last = $this->historyPage->message['last'];
845 
846  if ( $next === null ) {
847  # Probably no next row
848  return $last;
849  }
850 
851  if ( $next === 'unknown' ) {
852  # Next row probably exists but is unknown, use an oldid=prev link
853  return Linker::linkKnown(
854  $this->getTitle(),
855  $last,
856  [],
857  [
858  'diff' => $prevRev->getId(),
859  'oldid' => 'prev'
860  ]
861  );
862  }
863 
864  $nextRev = new Revision( $next );
865 
866  if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
867  || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
868  ) {
869  return $last;
870  }
871 
872  return Linker::linkKnown(
873  $this->getTitle(),
874  $last,
875  [],
876  [
877  'diff' => $prevRev->getId(),
878  'oldid' => $next->rev_id
879  ]
880  );
881  }
882 
891  function diffButtons( $rev, $firstInList ) {
892  if ( $this->getNumRows() > 1 ) {
893  $id = $rev->getId();
894  $radio = [ 'type' => 'radio', 'value' => $id ];
896  if ( $firstInList ) {
897  $first = Xml::element( 'input',
898  array_merge( $radio, [
899  'style' => 'visibility:hidden',
900  'name' => 'oldid',
901  'id' => 'mw-oldid-null' ] )
902  );
903  $checkmark = [ 'checked' => 'checked' ];
904  } else {
905  # Check visibility of old revisions
906  if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
907  $radio['disabled'] = 'disabled';
908  $checkmark = []; // We will check the next possible one
909  } elseif ( !$this->oldIdChecked ) {
910  $checkmark = [ 'checked' => 'checked' ];
911  $this->oldIdChecked = $id;
912  } else {
913  $checkmark = [];
914  }
915  $first = Xml::element( 'input',
916  array_merge( $radio, $checkmark, [
917  'name' => 'oldid',
918  'id' => "mw-oldid-$id" ] ) );
919  $checkmark = [];
920  }
921  $second = Xml::element( 'input',
922  array_merge( $radio, $checkmark, [
923  'name' => 'diff',
924  'id' => "mw-diff-$id" ] ) );
925 
926  return $first . $second;
927  } else {
928  return '';
929  }
930  }
931 
936  function preventClickjacking( $enable = true ) {
937  $this->preventClickjacking = $enable;
938  }
939 
946  }
947 
948 }
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:390
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:1550
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:802
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:1555
getLanguage()
Get the Language object.
static checkFeedOutput($type)
Check whether feeds can be used and that $type is a valid feed type.
Definition: FeedUtils.php:56
static buildTagFilterSelector($selected= '', $ooui=false)
Build a text box to select a change tag.
Definition: ChangeTags.php:672
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
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:246
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
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
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:217
static formatRevisionSize($size)
Definition: Linker.php:1573
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:758
IndexPager with a formatted navigation bar.
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
static check($name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:324
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:180
getTitle()
Get the Title object.
static tooltipAndAccesskeyAttribs($name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2182
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)
$batch
Definition: linkcache.txt:23
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2889
$mIsFirst
True if the current result set is the first one.
Definition: IndexPager.php:111
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:32
$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:578
msg()
Get a Message object with context set Parameters are the same as wfMessage()
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:247
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:2094
static formatSummaryRow($tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:50
__construct($historyPage, $year= '', $month= '', $tagFilter= '', $conds=[])
bool $showTagEditUI
Whether to show the tag editing UI.
getConfig()
Get the Config object.
static dateMenu($year, $month)
Definition: Xml.php:167
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:2164
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:442
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: defines.php:11
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:1936
const DELETED_RESTRICTED
Definition: Revision.php:88
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
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:131
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:1721
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
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
const DELETED_TEXT
Definition: Revision.php:85
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:629
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
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
static generateRollback($rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1761
diffButtons($rev, $firstInList)
Create radio buttons for page history.
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 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 to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1046
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
static flag($flag, IContextSource $context=null)
Make an "" element for a given change flag.
static getParentLengths($db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:540
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:107
const DB_REPLICA
Definition: defines.php:22
getRevisionButton($name, $msg)
feed($type)
Output a subscription feed listing recent edits to this page.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:423
$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:59
static revUserTools($rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1141
getWikiPage()
Get the WikiPage object.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:229
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:530
getUser()
Get the User object.
static revDeleteLink($query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2142
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 one of or reset my talk page
Definition: hooks.txt:2491
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 one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1610
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:552
getOutput()
Get the OutputPage object.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300