MediaWiki REL1_29
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(
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
153
154 # show deletion/move log if there is an entry
156 $out,
157 [ 'delete', 'move' ],
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 $out->addHTML(
196 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
197 Xml::fieldset(
198 $this->msg( 'history-fieldset-title' )->text(),
199 false,
200 [ 'id' => 'mw-history-search' ]
201 ) .
202 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
203 Html::hidden( 'action', 'history' ) . "\n" .
204 Xml::dateMenu(
205 ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
206 $month
207 ) . '&#160;' .
208 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
209 $checkDeleted .
210 Html::submitButton(
211 $this->msg( 'historyaction-submit' )->text(),
212 [],
213 [ 'mw-ui-progressive' ]
214 ) . "\n" .
215 '</fieldset></form>'
216 );
217
218 Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
219
220 // Create and output the list.
221 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
222 $out->addHTML(
223 $pager->getNavigationBar() .
224 $pager->getBody() .
225 $pager->getNavigationBar()
226 );
227 $out->preventClickjacking( $pager->getPreventClickjacking() );
228 }
229
240 function fetchRevisions( $limit, $offset, $direction ) {
241 // Fail if article doesn't exist.
242 if ( !$this->getTitle()->exists() ) {
243 return new FakeResultWrapper( [] );
244 }
245
247
248 if ( $direction === self::DIR_PREV ) {
249 list( $dirs, $oper ) = [ "ASC", ">=" ];
250 } else { /* $direction === self::DIR_NEXT */
251 list( $dirs, $oper ) = [ "DESC", "<=" ];
252 }
253
254 if ( $offset ) {
255 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
256 } else {
257 $offsets = [];
258 }
259
260 $page_id = $this->page->getId();
261
262 return $dbr->select( 'revision',
264 array_merge( [ 'rev_page' => $page_id ], $offsets ),
265 __METHOD__,
266 [ 'ORDER BY' => "rev_timestamp $dirs",
267 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
268 );
269 }
270
276 function feed( $type ) {
278 return;
279 }
280 $request = $this->getRequest();
281
282 $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
284 $feed = new $feedClasses[$type](
285 $this->getTitle()->getPrefixedText() . ' - ' .
286 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
287 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
288 $this->getTitle()->getFullURL( 'action=history' )
289 );
290
291 // Get a limit on number of feed entries. Provide a sane default
292 // of 10 if none is defined (but limit to $wgFeedLimit max)
293 $limit = $request->getInt( 'limit', 10 );
294 $limit = min(
295 max( $limit, 1 ),
296 $this->context->getConfig()->get( 'FeedLimit' )
297 );
298
299 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
300
301 // Generate feed elements enclosed between header and footer.
302 $feed->outHeader();
303 if ( $items->numRows() ) {
304 foreach ( $items as $row ) {
305 $feed->outItem( $this->feedItem( $row ) );
306 }
307 } else {
308 $feed->outItem( $this->feedEmpty() );
309 }
310 $feed->outFooter();
311 }
312
313 function feedEmpty() {
314 return new FeedItem(
315 $this->msg( 'nohistory' )->inContentLanguage()->text(),
316 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
317 $this->getTitle()->getFullURL(),
318 wfTimestamp( TS_MW ),
319 '',
320 $this->getTitle()->getTalkPage()->getFullURL()
321 );
322 }
323
332 function feedItem( $row ) {
333 $rev = new Revision( $row );
334 $rev->setTitle( $this->getTitle() );
336 $this->getTitle(),
337 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
338 $rev->getId(),
339 $rev->getTimestamp(),
340 $rev->getComment()
341 );
342 if ( $rev->getComment() == '' ) {
344 $title = $this->msg( 'history-feed-item-nocomment',
345 $rev->getUserText(),
346 $wgContLang->timeanddate( $rev->getTimestamp() ),
347 $wgContLang->date( $rev->getTimestamp() ),
348 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
349 } else {
350 $title = $rev->getUserText() .
351 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
352 FeedItem::stripComment( $rev->getComment() );
353 }
354
355 return new FeedItem(
356 $title,
357 $text,
358 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
359 $rev->getTimestamp(),
360 $rev->getUserText(),
361 $this->getTitle()->getTalkPage()->getFullURL()
362 );
363 }
364}
365
374 public $lastRow = false;
375
377
378 protected $oldIdChecked;
379
380 protected $preventClickjacking = false;
384 protected $parentLens;
385
387 protected $showTagEditUI;
388
396 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
397 parent::__construct( $historyPage->getContext() );
398 $this->historyPage = $historyPage;
399 $this->tagFilter = $tagFilter;
400 $this->getDateCond( $year, $month );
401 $this->conds = $conds;
402 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
403 }
404
405 // For hook compatibility...
406 function getArticle() {
407 return $this->historyPage->getArticle();
408 }
409
410 function getSqlComment() {
411 if ( $this->conds ) {
412 return 'history page filtered'; // potentially slow, see CR r58153
413 } else {
414 return 'history page unfiltered';
415 }
416 }
417
418 function getQueryInfo() {
419 $queryInfo = [
420 'tables' => [ 'revision', 'user' ],
421 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
422 'conds' => array_merge(
423 [ 'rev_page' => $this->getWikiPage()->getId() ],
424 $this->conds ),
425 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
426 'join_conds' => [ 'user' => Revision::userJoinCond() ],
427 ];
429 $queryInfo['tables'],
430 $queryInfo['fields'],
431 $queryInfo['conds'],
432 $queryInfo['join_conds'],
433 $queryInfo['options'],
434 $this->tagFilter
435 );
436
437 // Avoid PHP 7.1 warning of passing $this by reference
438 $historyPager = $this;
439 Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
440
441 return $queryInfo;
442 }
443
444 function getIndexField() {
445 return 'rev_timestamp';
446 }
447
452 function formatRow( $row ) {
453 if ( $this->lastRow ) {
454 $latest = ( $this->counter == 1 && $this->mIsFirst );
455 $firstInList = $this->counter == 1;
456 $this->counter++;
457
458 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
459 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
460 : false;
461
462 $s = $this->historyLine(
463 $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
464 } else {
465 $s = '';
466 }
467 $this->lastRow = $row;
468
469 return $s;
470 }
471
472 function doBatchLookups() {
473 if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
474 return;
475 }
476
477 # Do a link batch query
478 $this->mResult->seek( 0 );
479 $batch = new LinkBatch();
480 $revIds = [];
481 foreach ( $this->mResult as $row ) {
482 if ( $row->rev_parent_id ) {
483 $revIds[] = $row->rev_parent_id;
484 }
485 if ( !is_null( $row->user_name ) ) {
486 $batch->add( NS_USER, $row->user_name );
487 $batch->add( NS_USER_TALK, $row->user_name );
488 } else { # for anons or usernames of imported revisions
489 $batch->add( NS_USER, $row->rev_user_text );
490 $batch->add( NS_USER_TALK, $row->rev_user_text );
491 }
492 }
493 $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
494 $batch->execute();
495 $this->mResult->seek( 0 );
496 }
497
503 function getStartBody() {
504 $this->lastRow = false;
505 $this->counter = 1;
506 $this->oldIdChecked = 0;
507
508 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
509 $s = Html::openElement( 'form', [ 'action' => wfScript(),
510 'id' => 'mw-history-compare' ] ) . "\n";
511 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
512 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
513 $s .= Html::hidden( 'type', 'revision' ) . "\n";
514
515 // Button container stored in $this->buttons for re-use in getEndBody()
516 $this->buttons = '<div>';
517 $className = 'historysubmit mw-history-compareselectedversions-button';
518 $attrs = [ 'class' => $className ]
519 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
520 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
521 $attrs
522 ) . "\n";
523
524 $user = $this->getUser();
525 $actionButtons = '';
526 if ( $user->isAllowed( 'deleterevision' ) ) {
527 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
528 }
529 if ( $this->showTagEditUI ) {
530 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
531 }
532 if ( $actionButtons ) {
533 $this->buttons .= Xml::tags( 'div', [ 'class' =>
534 'mw-history-revisionactions' ], $actionButtons );
535 }
536
537 if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
538 $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
539 }
540
541 $this->buttons .= '</div>';
542
544 $s .= '<ul id="pagehistory">' . "\n";
545
546 return $s;
547 }
548
549 private function getRevisionButton( $name, $msg ) {
550 $this->preventClickjacking();
551 # Note bug #20966, <button> is non-standard in IE<8
552 $element = Html::element(
553 'button',
554 [
555 'type' => 'submit',
556 'name' => $name,
557 'value' => '1',
558 'class' => "historysubmit mw-history-$name-button",
559 ],
560 $this->msg( $msg )->text()
561 ) . "\n";
562 return $element;
563 }
564
565 function getEndBody() {
566 if ( $this->lastRow ) {
567 $latest = $this->counter == 1 && $this->mIsFirst;
568 $firstInList = $this->counter == 1;
569 if ( $this->mIsBackwards ) {
570 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
571 if ( $this->mOffset == '' ) {
572 $next = null;
573 } else {
574 $next = 'unknown';
575 }
576 } else {
577 # The next row is the past-the-end row
578 $next = $this->mPastTheEndRow;
579 }
580 $this->counter++;
581
582 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
583 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
584 : false;
585
586 $s = $this->historyLine(
587 $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
588 } else {
589 $s = '';
590 }
591 $s .= "</ul>\n";
592 # Add second buttons only if there is more than one rev
593 if ( $this->getNumRows() > 2 ) {
595 }
596 $s .= '</form>';
597
598 return $s;
599 }
600
608 function submitButton( $message, $attributes = [] ) {
609 # Disable submit button if history has 1 revision only
610 if ( $this->getNumRows() > 1 ) {
611 return Html::submitButton( $message, $attributes );
612 } else {
613 return '';
614 }
615 }
616
631 function historyLine( $row, $next, $notificationtimestamp = false,
632 $latest = false, $firstInList = false ) {
633 $rev = new Revision( $row );
634 $rev->setTitle( $this->getTitle() );
635
636 if ( is_object( $next ) ) {
637 $prevRev = new Revision( $next );
638 $prevRev->setTitle( $this->getTitle() );
639 } else {
640 $prevRev = null;
641 }
642
643 $curlink = $this->curLink( $rev, $latest );
644 $lastlink = $this->lastLink( $rev, $next );
645 $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
646 $histLinks = Html::rawElement(
647 'span',
648 [ 'class' => 'mw-history-histlinks' ],
649 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
650 );
651
652 $diffButtons = $this->diffButtons( $rev, $firstInList );
653 $s = $histLinks . $diffButtons;
654
655 $link = $this->revLink( $rev );
656 $classes = [];
657
658 $del = '';
659 $user = $this->getUser();
660 $canRevDelete = $user->isAllowed( 'deleterevision' );
661 // Show checkboxes for each revision, to allow for revision deletion and
662 // change tags
663 if ( $canRevDelete || $this->showTagEditUI ) {
664 $this->preventClickjacking();
665 // If revision was hidden from sysops and we don't need the checkbox
666 // for anything else, disable it
667 if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
668 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
669 // Otherwise, enable the checkbox...
670 } else {
671 $del = Xml::check( 'showhiderevisions', false,
672 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
673 }
674 // User can only view deleted revisions...
675 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
676 // If revision was hidden from sysops, disable the link
677 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
678 $del = Linker::revDeleteLinkDisabled( false );
679 // Otherwise, show the link...
680 } else {
681 $query = [ 'type' => 'revision',
682 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
684 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
685 }
686 }
687 if ( $del ) {
688 $s .= " $del ";
689 }
690
691 $lang = $this->getLanguage();
692 $dirmark = $lang->getDirMark();
693
694 $s .= " $link";
695 $s .= $dirmark;
696 $s .= " <span class='history-user'>" .
697 Linker::revUserTools( $rev, true ) . "</span>";
698 $s .= $dirmark;
699
700 if ( $rev->isMinor() ) {
701 $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
702 }
703
704 # Sometimes rev_len isn't populated
705 if ( $rev->getSize() !== null ) {
706 # Size is always public data
707 $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
708 ? $this->parentLens[$row->rev_parent_id]
709 : 0;
710 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
711 $fSize = Linker::formatRevisionSize( $rev->getSize() );
712 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
713 }
714
715 # Text following the character difference is added just before running hooks
716 $s2 = Linker::revComment( $rev, false, true );
717
718 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
719 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
720 $classes[] = 'mw-history-line-updated';
721 }
722
723 $tools = [];
724
725 # Rollback and undo links
726 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
727 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
728 // Get a rollback link without the brackets
729 $rollbackLink = Linker::generateRollback(
730 $rev,
731 $this->getContext(),
732 [ 'verify', 'noBrackets' ]
733 );
734 if ( $rollbackLink ) {
735 $this->preventClickjacking();
736 $tools[] = $rollbackLink;
737 }
738 }
739
740 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
741 && !$prevRev->isDeleted( Revision::DELETED_TEXT )
742 ) {
743 # Create undo tooltip for the first (=latest) line only
744 $undoTooltip = $latest
745 ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
746 : [];
747 $undolink = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
748 $this->getTitle(),
749 $this->msg( 'editundo' )->text(),
750 $undoTooltip,
751 [
752 'action' => 'edit',
753 'undoafter' => $prevRev->getId(),
754 'undo' => $rev->getId()
755 ]
756 );
757 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
758 }
759 }
760 // Allow extension to add their own links here
761 Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
762
763 if ( $tools ) {
764 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
765 }
766
767 # Tags
768 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
769 $row->ts_tags,
770 'history',
771 $this->getContext()
772 );
773 $classes = array_merge( $classes, $newClasses );
774 if ( $tagSummary !== '' ) {
775 $s2 .= " $tagSummary";
776 }
777
778 # Include separator between character difference and following text
779 if ( $s2 !== '' ) {
780 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
781 }
782
783 Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
784
785 $attribs = [];
786 if ( $classes ) {
787 $attribs['class'] = implode( ' ', $classes );
788 }
789
790 return Xml::tags( 'li', $attribs, $s ) . "\n";
791 }
792
799 function revLink( $rev ) {
800 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
801 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
802 $link = MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
803 $this->getTitle(),
804 $date,
805 [ 'class' => 'mw-changeslist-date' ],
806 [ 'oldid' => $rev->getId() ]
807 );
808 } else {
809 $link = htmlspecialchars( $date );
810 }
811 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
812 $link = "<span class=\"history-deleted\">$link</span>";
813 }
814
815 return $link;
816 }
817
825 function curLink( $rev, $latest ) {
826 $cur = $this->historyPage->message['cur'];
827 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
828 return $cur;
829 } else {
830 return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
831 $this->getTitle(),
832 $cur,
833 [],
834 [
835 'diff' => $this->getWikiPage()->getLatest(),
836 'oldid' => $rev->getId()
837 ]
838 );
839 }
840 }
841
851 function lastLink( $prevRev, $next ) {
852 $last = $this->historyPage->message['last'];
853
854 if ( $next === null ) {
855 # Probably no next row
856 return $last;
857 }
858
859 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
860 if ( $next === 'unknown' ) {
861 # Next row probably exists but is unknown, use an oldid=prev link
862 return $linkRenderer->makeKnownLink(
863 $this->getTitle(),
864 $last,
865 [],
866 [
867 'diff' => $prevRev->getId(),
868 'oldid' => 'prev'
869 ]
870 );
871 }
872
873 $nextRev = new Revision( $next );
874
875 if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
876 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
877 ) {
878 return $last;
879 }
880
881 return $linkRenderer->makeKnownLink(
882 $this->getTitle(),
883 $last,
884 [],
885 [
886 'diff' => $prevRev->getId(),
887 'oldid' => $next->rev_id
888 ]
889 );
890 }
891
900 function diffButtons( $rev, $firstInList ) {
901 if ( $this->getNumRows() > 1 ) {
902 $id = $rev->getId();
903 $radio = [ 'type' => 'radio', 'value' => $id ];
905 if ( $firstInList ) {
906 $first = Xml::element( 'input',
907 array_merge( $radio, [
908 'style' => 'visibility:hidden',
909 'name' => 'oldid',
910 'id' => 'mw-oldid-null' ] )
911 );
912 $checkmark = [ 'checked' => 'checked' ];
913 } else {
914 # Check visibility of old revisions
915 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
916 $radio['disabled'] = 'disabled';
917 $checkmark = []; // We will check the next possible one
918 } elseif ( !$this->oldIdChecked ) {
919 $checkmark = [ 'checked' => 'checked' ];
920 $this->oldIdChecked = $id;
921 } else {
922 $checkmark = [];
923 }
924 $first = Xml::element( 'input',
925 array_merge( $radio, $checkmark, [
926 'name' => 'oldid',
927 'id' => "mw-oldid-$id" ] ) );
928 $checkmark = [];
929 }
930 $second = Xml::element( 'input',
931 array_merge( $radio, $checkmark, [
932 'name' => 'diff',
933 'id' => "mw-diff-$id" ] ) );
934
935 return $first . $second;
936 } else {
937 return '';
938 }
939 }
940
945 function preventClickjacking( $enable = true ) {
946 $this->preventClickjacking = $enable;
947 }
948
956
957}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgSend404Code
Some web hosts attempt to rewrite all responses with a 404 (not found) status code,...
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:256
$page
Page on which we're performing the action.
Definition Action.php:44
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition Action.php:390
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:246
getContext()
Get the IContextSource in use here.
Definition Action.php:178
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:207
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:217
static exists( $name)
Check if a given action is recognised, even if it's disabled.
Definition Action.php:169
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:197
static buildTagFilterSelector( $selected='', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
static showTagEditingUI(User $user)
Indicate whether change tag editing UI is relevant.
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
static showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
static flag( $flag, IContextSource $context=null)
Make an "<abbr>" element for a given change flag.
getUser()
Get the User object.
getConfig()
Get the Config object.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getTitle()
Get the Title object.
getOutput()
Get the OutputPage object.
getWikiPage()
Get the WikiPage object.
getLanguage()
Get the Language object.
getContext()
Get the base IContextSource object.
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition Feed.php:38
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition Feed.php:180
static checkFeedOutput( $type)
Check whether feeds can be used and that $type is a valid feed type.
Definition FeedUtils.php:56
static formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='')
Really format a diff for the newsfeed.
An action which just does something, without showing a form first.
Page view caching in the file system.
static useFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Check if pages can be cached for this request/user.
This class handles printing the history page for an article.
onView()
Print the history page for an article.
feed( $type)
Output a subscription feed listing recent edits to this page.
preCacheMessages()
As we use the same small set of messages in various methods and that they are called often,...
array $message
Array of message keys and strings.
getName()
Return the name of the action this object responds to.
requiresWrite()
Whether this action requires the wiki not to be locked.
getPageTitle()
Returns the name that goes in the <h1> page title.
fetchRevisions( $limit, $offset, $direction)
Fetch an array of revisions, specified by a given limit, offset and direction.
feedItem( $row)
Generate a FeedItem object from a given revision table row Borrows Recent Changes' feed generation fu...
getDescription()
Returns the description that goes below the <h1> tag.
requiresUnblock()
Whether this action can still be executed by a blocked user.
preventClickjacking( $enable=true)
This is called if a write operation is possible from the generated HTML.
getRevisionButton( $name, $msg)
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
lastLink( $prevRev, $next)
Create a diff-to-previous link for this revision for this page.
__construct( $historyPage, $year='', $month='', $tagFilter='', $conds=[])
getEndBody()
Hook into getBody() for the end of the list.
diffButtons( $rev, $firstInList)
Create radio buttons for page history.
submitButton( $message, $attributes=[])
Creates a submit button.
historyLine( $row, $next, $notificationtimestamp=false, $latest=false, $firstInList=false)
Returns a row from the history printout.
revLink( $rev)
Create a link to view this revision of the page.
bool $showTagEditUI
Whether to show the tag editing UI.
getSqlComment()
Get some text to go in brackets in the "function name" part of the SQL comment.
curLink( $rev, $latest)
Create a diff-to-current link for this revision for this page.
getPreventClickjacking()
Get the "prevent clickjacking" flag.
getIndexField()
This function should be overridden to return the name of the index fi- eld.
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
getStartBody()
Creates begin of history list with a submit button.
bool stdClass $lastRow
$mIsFirst
True if the current result set is the first one.
getNumRows()
Get the number of rows in the result set.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition Linker.php:1677
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2080
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:1464
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition Linker.php:2098
static revUserTools( $rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition Linker.php:1055
static formatRevisionSize( $size)
Definition Linker.php:1487
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2058
Class for generating clickable toggle links for a list of checkboxes.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
MediaWikiServices is the service locator for the application scope of MediaWiki.
IndexPager with a formatted navigation bar.
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...
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition Revision.php:429
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition Revision.php:448
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition Revision.php:536
const DELETED_TEXT
Definition Revision.php:90
const DELETED_RESTRICTED
Definition Revision.php:93
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition Revision.php:546
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,...
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Result wrapper for grabbing data queried from an IDatabase object.
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
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:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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:18
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
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
const NS_USER
Definition Defines.php:64
const NS_USER_TALK
Definition Defines.php:65
the array() calling protocol came about after MediaWiki 1.4rc1.
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:249
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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 please use GetContentModels hook to make them known to core 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:1143
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:2114
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
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 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:2604
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2723
if the prop value should be in the metadata multi language array format
Definition hooks.txt:1637
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:864
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:2937
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
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:1975
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 my talk page
Definition hooks.txt:2579
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:1601
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:2007
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:1751
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:37
$batch
Definition linkcache.txt:23
$cache
Definition mcc.php:33
$last
const DB_REPLICA
Definition defines.php:25
if(!isset( $args[0])) $lang