MediaWiki REL1_27
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(
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 $useFileCache = $config->get( 'UseFileCache' );
109 if ( $useFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) {
110 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
111 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
112 ob_start( [ &$cache, 'saveToFileCache' ] );
113 }
114 }
115
116 // Setup page variables.
117 $out->setFeedAppendQuery( 'action=history' );
118 $out->addModules( 'mediawiki.action.history' );
119 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
120 $out = $this->getOutput();
121 $out->addModuleStyles( [
122 'mediawiki.ui.input',
123 'mediawiki.ui.checkbox',
124 ] );
125 }
126
127 // Handle atom/RSS feeds.
128 $feedType = $request->getVal( 'feed' );
129 if ( $feedType ) {
130 $this->feed( $feedType );
131
132 return;
133 }
134
135 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
136
137 // Fail nicely if article doesn't exist.
138 if ( !$this->page->exists() ) {
139 $out->addWikiMsg( 'nohistory' );
140 # show deletion/move log if there is an entry
142 $out,
143 [ 'delete', 'move' ],
144 $this->getTitle(),
145 '',
146 [ 'lim' => 10,
147 'conds' => [ "log_action != 'revision'" ],
148 'showIfEmpty' => false,
149 'msgKey' => [ 'moveddeleted-notice' ]
150 ]
151 );
152
153 return;
154 }
155
159 $year = $request->getInt( 'year' );
160 $month = $request->getInt( 'month' );
161 $tagFilter = $request->getVal( 'tagfilter' );
162 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
163
167 if ( $request->getBool( 'deleted' ) ) {
168 $conds = [ 'rev_deleted != 0' ];
169 } else {
170 $conds = [];
171 }
172 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
173 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
174 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
175 } else {
176 $checkDeleted = '';
177 }
178
179 // Add the general form
180 $action = htmlspecialchars( wfScript() );
181 $out->addHTML(
182 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
184 $this->msg( 'history-fieldset-title' )->text(),
185 false,
186 [ 'id' => 'mw-history-search' ]
187 ) .
188 Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n" .
189 Html::hidden( 'action', 'history' ) . "\n" .
191 ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
192 $month
193 ) . '&#160;' .
194 ( $tagSelector ? ( implode( '&#160;', $tagSelector ) . '&#160;' ) : '' ) .
195 $checkDeleted .
197 $this->msg( 'historyaction-submit' )->text(),
198 [],
199 [ 'mw-ui-progressive' ]
200 ) . "\n" .
201 '</fieldset></form>'
202 );
203
204 Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
205
206 // Create and output the list.
207 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
208 $out->addHTML(
209 $pager->getNavigationBar() .
210 $pager->getBody() .
211 $pager->getNavigationBar()
212 );
213 $out->preventClickjacking( $pager->getPreventClickjacking() );
214
215 }
216
227 function fetchRevisions( $limit, $offset, $direction ) {
228 // Fail if article doesn't exist.
229 if ( !$this->getTitle()->exists() ) {
230 return new FakeResultWrapper( [] );
231 }
232
233 $dbr = wfGetDB( DB_SLAVE );
234
235 if ( $direction === self::DIR_PREV ) {
236 list( $dirs, $oper ) = [ "ASC", ">=" ];
237 } else { /* $direction === self::DIR_NEXT */
238 list( $dirs, $oper ) = [ "DESC", "<=" ];
239 }
240
241 if ( $offset ) {
242 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
243 } else {
244 $offsets = [];
245 }
246
247 $page_id = $this->page->getId();
248
249 return $dbr->select( 'revision',
251 array_merge( [ 'rev_page' => $page_id ], $offsets ),
252 __METHOD__,
253 [ 'ORDER BY' => "rev_timestamp $dirs",
254 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit ]
255 );
256 }
257
263 function feed( $type ) {
265 return;
266 }
267 $request = $this->getRequest();
268
269 $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
271 $feed = new $feedClasses[$type](
272 $this->getTitle()->getPrefixedText() . ' - ' .
273 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
274 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
275 $this->getTitle()->getFullURL( 'action=history' )
276 );
277
278 // Get a limit on number of feed entries. Provide a sane default
279 // of 10 if none is defined (but limit to $wgFeedLimit max)
280 $limit = $request->getInt( 'limit', 10 );
281 $limit = min(
282 max( $limit, 1 ),
283 $this->context->getConfig()->get( 'FeedLimit' )
284 );
285
286 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
287
288 // Generate feed elements enclosed between header and footer.
289 $feed->outHeader();
290 if ( $items->numRows() ) {
291 foreach ( $items as $row ) {
292 $feed->outItem( $this->feedItem( $row ) );
293 }
294 } else {
295 $feed->outItem( $this->feedEmpty() );
296 }
297 $feed->outFooter();
298 }
299
300 function feedEmpty() {
301 return new FeedItem(
302 $this->msg( 'nohistory' )->inContentLanguage()->text(),
303 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
304 $this->getTitle()->getFullURL(),
306 '',
307 $this->getTitle()->getTalkPage()->getFullURL()
308 );
309 }
310
319 function feedItem( $row ) {
320 $rev = new Revision( $row );
321 $rev->setTitle( $this->getTitle() );
323 $this->getTitle(),
324 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
325 $rev->getId(),
326 $rev->getTimestamp(),
327 $rev->getComment()
328 );
329 if ( $rev->getComment() == '' ) {
331 $title = $this->msg( 'history-feed-item-nocomment',
332 $rev->getUserText(),
333 $wgContLang->timeanddate( $rev->getTimestamp() ),
334 $wgContLang->date( $rev->getTimestamp() ),
335 $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
336 } else {
337 $title = $rev->getUserText() .
338 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
339 FeedItem::stripComment( $rev->getComment() );
340 }
341
342 return new FeedItem(
343 $title,
344 $text,
345 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
346 $rev->getTimestamp(),
347 $rev->getUserText(),
348 $this->getTitle()->getTalkPage()->getFullURL()
349 );
350 }
351}
352
361 public $lastRow = false;
362
364
365 protected $oldIdChecked;
366
367 protected $preventClickjacking = false;
371 protected $parentLens;
372
374 protected $showTagEditUI;
375
383 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = [] ) {
384 parent::__construct( $historyPage->getContext() );
385 $this->historyPage = $historyPage;
386 $this->tagFilter = $tagFilter;
387 $this->getDateCond( $year, $month );
388 $this->conds = $conds;
389 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
390 }
391
392 // For hook compatibility...
393 function getArticle() {
394 return $this->historyPage->getArticle();
395 }
396
397 function getSqlComment() {
398 if ( $this->conds ) {
399 return 'history page filtered'; // potentially slow, see CR r58153
400 } else {
401 return 'history page unfiltered';
402 }
403 }
404
405 function getQueryInfo() {
406 $queryInfo = [
407 'tables' => [ 'revision', 'user' ],
408 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
409 'conds' => array_merge(
410 [ 'rev_page' => $this->getWikiPage()->getId() ],
411 $this->conds ),
412 'options' => [ 'USE INDEX' => [ 'revision' => 'page_timestamp' ] ],
413 'join_conds' => [ 'user' => Revision::userJoinCond() ],
414 ];
416 $queryInfo['tables'],
417 $queryInfo['fields'],
418 $queryInfo['conds'],
419 $queryInfo['join_conds'],
420 $queryInfo['options'],
421 $this->tagFilter
422 );
423
424 // Avoid PHP 7.1 warning of passing $this by reference
425 $historyPager = $this;
426 Hooks::run( 'PageHistoryPager::getQueryInfo', [ &$historyPager, &$queryInfo ] );
427
428 return $queryInfo;
429 }
430
431 function getIndexField() {
432 return 'rev_timestamp';
433 }
434
439 function formatRow( $row ) {
440 if ( $this->lastRow ) {
441 $latest = ( $this->counter == 1 && $this->mIsFirst );
442 $firstInList = $this->counter == 1;
443 $this->counter++;
444
445 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
446 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
447 : false;
448
449 $s = $this->historyLine(
450 $this->lastRow, $row, $notifTimestamp, $latest, $firstInList );
451 } else {
452 $s = '';
453 }
454 $this->lastRow = $row;
455
456 return $s;
457 }
458
459 function doBatchLookups() {
460 if ( !Hooks::run( 'PageHistoryPager::doBatchLookups', [ $this, $this->mResult ] ) ) {
461 return;
462 }
463
464 # Do a link batch query
465 $this->mResult->seek( 0 );
466 $batch = new LinkBatch();
467 $revIds = [];
468 foreach ( $this->mResult as $row ) {
469 if ( $row->rev_parent_id ) {
470 $revIds[] = $row->rev_parent_id;
471 }
472 if ( !is_null( $row->user_name ) ) {
473 $batch->add( NS_USER, $row->user_name );
474 $batch->add( NS_USER_TALK, $row->user_name );
475 } else { # for anons or usernames of imported revisions
476 $batch->add( NS_USER, $row->rev_user_text );
477 $batch->add( NS_USER_TALK, $row->rev_user_text );
478 }
479 }
480 $this->parentLens = Revision::getParentLengths( $this->mDb, $revIds );
481 $batch->execute();
482 $this->mResult->seek( 0 );
483 }
484
490 function getStartBody() {
491 $this->lastRow = false;
492 $this->counter = 1;
493 $this->oldIdChecked = 0;
494
495 $this->getOutput()->wrapWikiMsg( "<div class='mw-history-legend'>\n$1\n</div>", 'histlegend' );
496 $s = Html::openElement( 'form', [ 'action' => wfScript(),
497 'id' => 'mw-history-compare' ] ) . "\n";
498 $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
499 $s .= Html::hidden( 'action', 'historysubmit' ) . "\n";
500 $s .= Html::hidden( 'type', 'revision' ) . "\n";
501
502 // Button container stored in $this->buttons for re-use in getEndBody()
503 $this->buttons = '<div>';
504 $className = 'historysubmit mw-history-compareselectedversions-button';
505 $attrs = [ 'class' => $className ]
506 + Linker::tooltipAndAccesskeyAttribs( 'compareselectedversions' );
507 $this->buttons .= $this->submitButton( $this->msg( 'compareselectedversions' )->text(),
508 $attrs
509 ) . "\n";
510
511 $user = $this->getUser();
512 $actionButtons = '';
513 if ( $user->isAllowed( 'deleterevision' ) ) {
514 $actionButtons .= $this->getRevisionButton( 'revisiondelete', 'showhideselectedversions' );
515 }
516 if ( $this->showTagEditUI ) {
517 $actionButtons .= $this->getRevisionButton( 'editchangetags', 'history-edit-tags' );
518 }
519 if ( $actionButtons ) {
520 $this->buttons .= Xml::tags( 'div', [ 'class' =>
521 'mw-history-revisionactions' ], $actionButtons );
522 }
523
524 if ( $user->isAllowed( 'deleterevision' ) || $this->showTagEditUI ) {
525 $this->buttons .= ( new ListToggle( $this->getOutput() ) )->getHTML();
526 }
527
528 $this->buttons .= '</div>';
529
531 $s .= '<ul id="pagehistory">' . "\n";
532
533 return $s;
534 }
535
536 private function getRevisionButton( $name, $msg ) {
537 $this->preventClickjacking();
538 # Note bug #20966, <button> is non-standard in IE<8
539 $element = Html::element(
540 'button',
541 [
542 'type' => 'submit',
543 'name' => $name,
544 'value' => '1',
545 'class' => "historysubmit mw-history-$name-button",
546 ],
547 $this->msg( $msg )->text()
548 ) . "\n";
549 return $element;
550 }
551
552 function getEndBody() {
553 if ( $this->lastRow ) {
554 $latest = $this->counter == 1 && $this->mIsFirst;
555 $firstInList = $this->counter == 1;
556 if ( $this->mIsBackwards ) {
557 # Next row is unknown, but for UI reasons, probably exists if an offset has been specified
558 if ( $this->mOffset == '' ) {
559 $next = null;
560 } else {
561 $next = 'unknown';
562 }
563 } else {
564 # The next row is the past-the-end row
565 $next = $this->mPastTheEndRow;
566 }
567 $this->counter++;
568
569 $notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
570 ? $this->getTitle()->getNotificationTimestamp( $this->getUser() )
571 : false;
572
573 $s = $this->historyLine(
574 $this->lastRow, $next, $notifTimestamp, $latest, $firstInList );
575 } else {
576 $s = '';
577 }
578 $s .= "</ul>\n";
579 # Add second buttons only if there is more than one rev
580 if ( $this->getNumRows() > 2 ) {
582 }
583 $s .= '</form>';
584
585 return $s;
586 }
587
595 function submitButton( $message, $attributes = [] ) {
596 # Disable submit button if history has 1 revision only
597 if ( $this->getNumRows() > 1 ) {
598 return Html::submitButton( $message, $attributes );
599 } else {
600 return '';
601 }
602 }
603
618 function historyLine( $row, $next, $notificationtimestamp = false,
619 $latest = false, $firstInList = false ) {
620 $rev = new Revision( $row );
621 $rev->setTitle( $this->getTitle() );
622
623 if ( is_object( $next ) ) {
624 $prevRev = new Revision( $next );
625 $prevRev->setTitle( $this->getTitle() );
626 } else {
627 $prevRev = null;
628 }
629
630 $curlink = $this->curLink( $rev, $latest );
631 $lastlink = $this->lastLink( $rev, $next );
632 $curLastlinks = $curlink . $this->historyPage->message['pipe-separator'] . $lastlink;
633 $histLinks = Html::rawElement(
634 'span',
635 [ 'class' => 'mw-history-histlinks' ],
636 $this->msg( 'parentheses' )->rawParams( $curLastlinks )->escaped()
637 );
638
639 $diffButtons = $this->diffButtons( $rev, $firstInList );
640 $s = $histLinks . $diffButtons;
641
642 $link = $this->revLink( $rev );
643 $classes = [];
644
645 $del = '';
646 $user = $this->getUser();
647 $canRevDelete = $user->isAllowed( 'deleterevision' );
648 // Show checkboxes for each revision, to allow for revision deletion and
649 // change tags
650 if ( $canRevDelete || $this->showTagEditUI ) {
651 $this->preventClickjacking();
652 // If revision was hidden from sysops and we don't need the checkbox
653 // for anything else, disable it
654 if ( !$this->showTagEditUI && !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
655 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
656 // Otherwise, enable the checkbox...
657 } else {
658 $del = Xml::check( 'showhiderevisions', false,
659 [ 'name' => 'ids[' . $rev->getId() . ']' ] );
660 }
661 // User can only view deleted revisions...
662 } elseif ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) {
663 // If revision was hidden from sysops, disable the link
664 if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
665 $del = Linker::revDeleteLinkDisabled( false );
666 // Otherwise, show the link...
667 } else {
668 $query = [ 'type' => 'revision',
669 'target' => $this->getTitle()->getPrefixedDBkey(), 'ids' => $rev->getId() ];
671 $rev->isDeleted( Revision::DELETED_RESTRICTED ), false );
672 }
673 }
674 if ( $del ) {
675 $s .= " $del ";
676 }
677
678 $lang = $this->getLanguage();
679 $dirmark = $lang->getDirMark();
680
681 $s .= " $link";
682 $s .= $dirmark;
683 $s .= " <span class='history-user'>" .
684 Linker::revUserTools( $rev, true ) . "</span>";
685 $s .= $dirmark;
686
687 if ( $rev->isMinor() ) {
688 $s .= ' ' . ChangesList::flag( 'minor', $this->getContext() );
689 }
690
691 # Sometimes rev_len isn't populated
692 if ( $rev->getSize() !== null ) {
693 # Size is always public data
694 $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
695 ? $this->parentLens[$row->rev_parent_id]
696 : 0;
697 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
698 $fSize = Linker::formatRevisionSize( $rev->getSize() );
699 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . "$fSize $sDiff";
700 }
701
702 # Text following the character difference is added just before running hooks
703 $s2 = Linker::revComment( $rev, false, true );
704
705 if ( $notificationtimestamp && ( $row->rev_timestamp >= $notificationtimestamp ) ) {
706 $s2 .= ' <span class="updatedmarker">' . $this->msg( 'updatedmarker' )->escaped() . '</span>';
707 $classes[] = 'mw-history-line-updated';
708 }
709
710 $tools = [];
711
712 # Rollback and undo links
713 if ( $prevRev && $this->getTitle()->quickUserCan( 'edit', $user ) ) {
714 if ( $latest && $this->getTitle()->quickUserCan( 'rollback', $user ) ) {
715 // Get a rollback link without the brackets
716 $rollbackLink = Linker::generateRollback(
717 $rev,
718 $this->getContext(),
719 [ 'verify', 'noBrackets' ]
720 );
721 if ( $rollbackLink ) {
722 $this->preventClickjacking();
723 $tools[] = $rollbackLink;
724 }
725 }
726
727 if ( !$rev->isDeleted( Revision::DELETED_TEXT )
728 && !$prevRev->isDeleted( Revision::DELETED_TEXT )
729 ) {
730 # Create undo tooltip for the first (=latest) line only
731 $undoTooltip = $latest
732 ? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
733 : [];
734 $undolink = Linker::linkKnown(
735 $this->getTitle(),
736 $this->msg( 'editundo' )->escaped(),
737 $undoTooltip,
738 [
739 'action' => 'edit',
740 'undoafter' => $prevRev->getId(),
741 'undo' => $rev->getId()
742 ]
743 );
744 $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>";
745 }
746 }
747 // Allow extension to add their own links here
748 Hooks::run( 'HistoryRevisionTools', [ $rev, &$tools, $prevRev, $user ] );
749
750 if ( $tools ) {
751 $s2 .= ' ' . $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $tools ) )->escaped();
752 }
753
754 # Tags
755 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
756 $row->ts_tags,
757 'history',
758 $this->getContext()
759 );
760 $classes = array_merge( $classes, $newClasses );
761 if ( $tagSummary !== '' ) {
762 $s2 .= " $tagSummary";
763 }
764
765 # Include separator between character difference and following text
766 if ( $s2 !== '' ) {
767 $s .= ' <span class="mw-changeslist-separator">. .</span> ' . $s2;
768 }
769
770 Hooks::run( 'PageHistoryLineEnding', [ $this, &$row, &$s, &$classes ] );
771
772 $attribs = [];
773 if ( $classes ) {
774 $attribs['class'] = implode( ' ', $classes );
775 }
776
777 return Xml::tags( 'li', $attribs, $s ) . "\n";
778 }
779
786 function revLink( $rev ) {
787 $date = $this->getLanguage()->userTimeAndDate( $rev->getTimestamp(), $this->getUser() );
788 $date = htmlspecialchars( $date );
789 if ( $rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
791 $this->getTitle(),
792 $date,
793 [ 'class' => 'mw-changeslist-date' ],
794 [ 'oldid' => $rev->getId() ]
795 );
796 } else {
797 $link = $date;
798 }
799 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
800 $link = "<span class=\"history-deleted\">$link</span>";
801 }
802
803 return $link;
804 }
805
813 function curLink( $rev, $latest ) {
814 $cur = $this->historyPage->message['cur'];
815 if ( $latest || !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
816 return $cur;
817 } else {
818 return Linker::linkKnown(
819 $this->getTitle(),
820 $cur,
821 [],
822 [
823 'diff' => $this->getWikiPage()->getLatest(),
824 'oldid' => $rev->getId()
825 ]
826 );
827 }
828 }
829
839 function lastLink( $prevRev, $next ) {
840 $last = $this->historyPage->message['last'];
841
842 if ( $next === null ) {
843 # Probably no next row
844 return $last;
845 }
846
847 if ( $next === 'unknown' ) {
848 # Next row probably exists but is unknown, use an oldid=prev link
849 return Linker::linkKnown(
850 $this->getTitle(),
851 $last,
852 [],
853 [
854 'diff' => $prevRev->getId(),
855 'oldid' => 'prev'
856 ]
857 );
858 }
859
860 $nextRev = new Revision( $next );
861
862 if ( !$prevRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
863 || !$nextRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
864 ) {
865 return $last;
866 }
867
868 return Linker::linkKnown(
869 $this->getTitle(),
870 $last,
871 [],
872 [
873 'diff' => $prevRev->getId(),
874 'oldid' => $next->rev_id
875 ]
876 );
877 }
878
887 function diffButtons( $rev, $firstInList ) {
888 if ( $this->getNumRows() > 1 ) {
889 $id = $rev->getId();
890 $radio = [ 'type' => 'radio', 'value' => $id ];
892 if ( $firstInList ) {
893 $first = Xml::element( 'input',
894 array_merge( $radio, [
895 'style' => 'visibility:hidden',
896 'name' => 'oldid',
897 'id' => 'mw-oldid-null' ] )
898 );
899 $checkmark = [ 'checked' => 'checked' ];
900 } else {
901 # Check visibility of old revisions
902 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
903 $radio['disabled'] = 'disabled';
904 $checkmark = []; // We will check the next possible one
905 } elseif ( !$this->oldIdChecked ) {
906 $checkmark = [ 'checked' => 'checked' ];
907 $this->oldIdChecked = $id;
908 } else {
909 $checkmark = [];
910 }
911 $first = Xml::element( 'input',
912 array_merge( $radio, $checkmark, [
913 'name' => 'oldid',
914 'id' => "mw-oldid-$id" ] ) );
915 $checkmark = [];
916 }
917 $second = Xml::element( 'input',
918 array_merge( $radio, $checkmark, [
919 'name' => 'diff',
920 'id' => "mw-diff-$id" ] ) );
921
922 return $first . $second;
923 } else {
924 return '';
925 }
926 }
927
932 function preventClickjacking( $enable = true ) {
933 $this->preventClickjacking = $enable;
934 }
935
943
944}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
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='', $fullForm=false, Title $title=null, $ooui=false)
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.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
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:55
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)
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
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:230
static submitButton( $contents, array $attrs, array $modifiers=[])
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enab...
Definition Html.php:186
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition Html.php:210
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition Html.php:248
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition Html.php:759
$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:31
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition Linker.php:1859
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2320
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:1656
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition Linker.php:2337
static revUserTools( $rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition Linker.php:1252
static formatRevisionSize( $size)
Definition Linker.php:1678
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition Linker.php:264
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition Linker.php:2299
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)
IndexPager with a formatted navigation bar.
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition Revision.php:410
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition Revision.php:429
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition Revision.php:517
const DELETED_TEXT
Definition Revision.php:76
const DELETED_RESTRICTED
Definition Revision.php:79
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition Revision.php:527
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition Xml.php:324
static dateMenu( $year, $month)
Definition Xml.php:167
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition Xml.php:420
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition Xml.php:131
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition Xml.php:39
static fieldset( $legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition Xml.php:578
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:72
const NS_USER_TALK
Definition Defines.php:73
const DB_SLAVE
Definition Defines.php:47
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
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:1819
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:2413
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:944
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2530
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:1081
if the prop value should be in the metadata multi language array format
Definition hooks.txt:1483
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:846
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:2388
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 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:1927
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition hooks.txt:2692
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
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:1458
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:1597
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
if(!isset( $args[0])) $lang