29use MediaWiki\Debug\DeprecationHelper;
83 use DeprecationHelper;
91 private const DIFF_VERSION =
'1.41';
119 private $mOldRevisionRecord;
129 private $mNewRevisionRecord;
160 private $mOldContent;
167 private $mNewContent;
173 private $mRevisionsIdsLoaded =
false;
176 protected $mRevisionsLoaded =
false;
179 protected $mTextLoaded = 0;
189 protected $isContentOverridden =
false;
192 protected $mCacheHit =
false;
195 private $cacheHitKey =
null;
203 public $enableDebugComment =
false;
208 protected $mReducedLineNumbers =
false;
211 protected $mMarkPatrolledLink =
null;
214 protected $unhide =
false;
217 protected $mRefreshCache =
false;
228 protected $isSlotDiffRenderer =
false;
234 private $slotDiffOptions = [];
240 private $extraQueryParams = [];
259 private $revisionLoadErrors = [];
269 public function __construct( $context =
null, $old = 0, $new = 0, $rcid = 0,
270 $refreshCache =
false, $unhide =
false
276 wfDebug(
"DifferenceEngine old '$old' new '$new' rcid '$rcid'" );
278 $this->mOldid = $old;
279 $this->mNewid = $new;
280 $this->mRefreshCache = $refreshCache;
281 $this->unhide = $unhide;
283 $services = MediaWikiServices::getInstance();
284 $this->linkRenderer = $services->getLinkRenderer();
285 $this->contentHandlerFactory = $services->getContentHandlerFactory();
286 $this->revisionStore = $services->getRevisionStore();
287 $this->archivedRevisionLookup = $services->getArchivedRevisionLookup();
288 $this->hookRunner =
new HookRunner( $services->getHookContainer() );
289 $this->wikiPageFactory = $services->getWikiPageFactory();
290 $this->userOptionsLookup = $services->getUserOptionsLookup();
291 $this->commentFormatter = $services->getCommentFormatter();
292 $this->dbProvider = $services->getConnectionProvider();
293 $this->userGroupManager = $services->getUserGroupManager();
294 $this->userEditTracker = $services->getUserEditTracker();
295 $this->userIdentityUtils = $services->getUserIdentityUtils();
304 if ( $this->isSlotDiffRenderer ) {
305 throw new LogicException( __METHOD__ .
' called in slot diff renderer mode' );
308 if ( $this->slotDiffRenderers ===
null ) {
314 $this->slotDiffRenderers = [];
315 foreach ( $slotContents as $role => $contents ) {
316 if ( $contents[
'new'] && $contents[
'old']
317 && $contents[
'new']->equals( $contents[
'old'] )
322 $handler = ( $contents[
'new'] ?: $contents[
'old'] )->getContentHandler();
323 $this->slotDiffRenderers[$role] = $handler->getSlotDiffRenderer(
325 $this->slotDiffOptions + [
326 'contentLanguage' => $this->
getDiffLang()->getCode(),
333 return $this->slotDiffRenderers;
343 $this->isSlotDiffRenderer =
true;
352 if ( $this->isContentOverridden ) {
354 SlotRecord::MAIN => [
'old' => $this->mOldContent,
'new' => $this->mNewContent ]
360 $newSlots = $this->mNewRevisionRecord->getPrimarySlots()->getSlots();
361 $oldSlots = $this->mOldRevisionRecord ?
362 $this->mOldRevisionRecord->getPrimarySlots()->getSlots() :
368 $roles = array_keys( array_merge( $newSlots, $oldSlots ) );
371 foreach ( $roles as $role ) {
373 'old' => $this->loadSingleSlot(
374 $oldSlots[$role] ??
null,
377 'new' => $this->loadSingleSlot(
378 $newSlots[$role] ??
null,
384 if ( isset( $slots[SlotRecord::MAIN] ) ) {
385 $slots = [ SlotRecord::MAIN => $slots[SlotRecord::MAIN] ] + $slots;
397 private function loadSingleSlot( ?
SlotRecord $slot,
string $which ) {
404 $this->addRevisionLoadError( $which );
414 private function addRevisionLoadError( $which ) {
415 $this->revisionLoadErrors[] = $this->
msg( $which ===
'new'
416 ?
'difference-bad-new-revision' :
'difference-bad-old-revision'
427 return $this->revisionLoadErrors;
434 private function hasNewRevisionLoadError() {
435 foreach ( $this->revisionLoadErrors as $error ) {
436 if ( $error->getKey() ===
'difference-bad-new-revision' ) {
446 return parent::getTitle() ?: Title::makeTitle(
NS_SPECIAL,
'BadTitle/DifferenceEngine' );
456 $this->mReducedLineNumbers = $value;
465 # Default language in which the diff text is written.
467 return $this->mDiffLang;
477 return $this->
getTitle()->getPageLanguage();
484 return $this->mCacheHit;
495 $this->loadRevisionIds();
497 return $this->mOldid;
507 $this->loadRevisionIds();
509 return $this->mNewid;
519 return $this->mOldRevisionRecord ?:
null;
528 return $this->mNewRevisionRecord;
540 if ( $this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
541 $revRecord = $this->archivedRevisionLookup->getArchivedRevisionRecord(
null, $id );
543 $title = Title::newFromPageIdentity( $revRecord->
getPage() );
545 return SpecialPage::getTitleFor(
'Undelete' )->getFullURL( [
546 'target' => $title->getPrefixedText(),
565 return "[$link $id]";
571 private function showMissingRevision() {
572 $out = $this->getOutput();
575 if ( $this->mOldid && ( !$this->mOldRevisionRecord || !$this->mOldContent ) ) {
576 $missing[] = $this->deletedIdMarker( $this->mOldid );
578 if ( !$this->mNewRevisionRecord || !$this->mNewContent ) {
582 $out->setPageTitleMsg( $this->
msg(
'errorpagetitle' ) );
583 $msg = $this->
msg(
'difference-missing-revision' )
584 ->params( $this->
getLanguage()->listToText( $missing ) )
585 ->numParams( count( $missing ) )
587 $out->addHTML( $msg );
598 $this->mNewRevisionRecord &&
599 $this->mNewRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT )
602 $this->mOldRevisionRecord &&
603 $this->mOldRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT )
615 $permStatus = PermissionStatus::newEmpty();
616 if ( $this->mNewPage ) {
617 $performer->
authorizeRead(
'read', $this->mNewPage, $permStatus );
619 if ( $this->mOldPage ) {
620 $performer->
authorizeRead(
'read', $this->mOldPage, $permStatus );
622 return $permStatus->toLegacyErrorArray();
632 ( $this->mOldRevisionRecord &&
633 $this->mOldRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) ||
634 ( $this->mNewRevisionRecord &&
635 $this->mNewRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) )
645 private function getUserEditCount( $user ): string {
646 $editCount = $this->userEditTracker->getUserEditCount( $user );
647 if ( $editCount ===
null ) {
651 return Html::rawElement(
'div', [
652 'class' =>
'mw-diff-usereditcount',
668 if ( !$this->userIdentityUtils->isNamed( $user ) ) {
671 $userGroups = $this->userGroupManager->getUserGroups( $user );
672 $userGroupLinks = [];
673 foreach ( $userGroups as $group ) {
674 $userGroupLinks[] = UserGroupMembership::getLinkHTML( $group, $this->
getContext() );
676 return Html::rawElement(
'div', [
677 'class' =>
'mw-diff-userroles',
678 ], $this->getLanguage()->commaList( $userGroupLinks ) );
687 private function getUserMetaData( ?
UserIdentity $user ) {
691 return Html::rawElement(
'div', [
692 'class' =>
'mw-diff-usermetadata',
693 ], $this->getUserRoles( $user ) . $this->getUserEditCount( $user ) );
708 $this->loadRevisionData();
710 if ( $this->mOldRevisionRecord && !$this->mOldRevisionRecord->userCan(
711 RevisionRecord::DELETED_TEXT,
719 return !$this->mNewRevisionRecord || $this->mNewRevisionRecord->userCan(
720 RevisionRecord::DELETED_TEXT,
733 return $this->hasDeletedRevision() && ( !$this->unhide ||
734 !$this->isUserAllowedToSeeRevisions( $performer ) );
741 # Allow frames except in certain special cases
742 $out = $this->getOutput();
743 $out->getMetadata()->setPreventClickjacking(
false );
744 $out->setRobotPolicy(
'noindex,nofollow' );
747 $this->hookRunner->onDifferenceEngineShowDiffPage( $out );
749 if ( !$this->loadRevisionData() ) {
750 if ( $this->hookRunner->onDifferenceEngineShowDiffPageMaybeShowMissingRevision( $this ) ) {
751 $this->showMissingRevision();
756 $user = $this->getUser();
757 $permErrors = $this->getPermissionErrors( $this->getAuthority() );
764 $query = $this->extraQueryParams;
765 # Carry over 'diffonly' param via navigation links
766 if ( $diffOnly != MediaWikiServices::getInstance()
767 ->getUserOptionsLookup()->getBoolOption( $user,
'diffonly' )
769 $query[
'diffonly'] = $diffOnly;
771 # Cascade unhide param in links for easy deletion browsing
772 if ( $this->unhide ) {
773 $query[
'unhide'] = 1;
776 # Check if one of the revisions is deleted/suppressed
777 $deleted = $this->hasDeletedRevision();
778 $suppressed = $this->hasSuppressedRevision();
779 $allowed = $this->isUserAllowedToSeeRevisions( $this->getAuthority() );
784 # mOldRevisionRecord is false if the difference engine is called with a "vague" query for
785 # a diff between a version V and its previous version V' AND the version V
786 # is the first version of that article. In that case, V' does not exist.
787 if ( $this->mOldRevisionRecord ===
false ) {
788 if ( $this->mNewPage ) {
789 $out->setPageTitleMsg(
790 $this->msg(
'difference-title' )->plaintextParams( $this->mNewPage->getPrefixedText() )
796 $this->hookRunner->onDifferenceEngineOldHeaderNoOldRev( $oldHeader );
798 $this->hookRunner->onDifferenceEngineViewHeader( $this );
800 if ( !$this->mOldPage || !$this->mNewPage ) {
803 } elseif ( $this->mNewPage->equals( $this->mOldPage ) ) {
804 $out->setPageTitleMsg(
805 $this->msg(
'difference-title' )->plaintextParams( $this->mNewPage->getPrefixedText() )
809 $out->setPageTitleMsg( $this->msg(
'difference-title-multipage' )->plaintextParams(
810 $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText() ) );
811 $out->addSubtitle( $this->msg(
'difference-multipage' ) );
815 if ( $samePage && $this->mNewPage &&
816 $this->getAuthority()->probablyCan(
'edit', $this->mNewPage )
818 if ( $this->mNewRevisionRecord->isCurrent() &&
819 $this->getAuthority()->probablyCan(
'rollback', $this->mNewPage )
821 $rollbackLink = Linker::generateRollback(
822 $this->mNewRevisionRecord,
826 if ( $rollbackLink ) {
827 $out->getMetadata()->setPreventClickjacking(
true );
828 $rollback =
"\u{00A0}\u{00A0}\u{00A0}" . $rollbackLink;
832 if ( $this->userCanEdit( $this->mOldRevisionRecord ) &&
833 $this->userCanEdit( $this->mNewRevisionRecord )
835 $undoLink = $this->linkRenderer->makeKnownLink(
837 $this->msg(
'editundo' )->text(),
838 [
'title' => Linker::titleAttrib(
'undo' ) ],
841 'undoafter' => $this->mOldid,
842 'undo' => $this->mNewid
845 $revisionTools[
'mw-diff-undo'] = $undoLink;
848 # Make "previous revision link"
849 $hasPrevious = $samePage && $this->mOldPage &&
850 $this->revisionStore->getPreviousRevision( $this->mOldRevisionRecord );
851 if ( $hasPrevious ) {
852 $prevlinkQuery = [
'diff' =>
'prev',
'oldid' => $this->mOldid ] + $query;
853 $prevlink = $this->linkRenderer->makeKnownLink(
855 $this->msg(
'previousdiff' )->text(),
856 [
'id' =>
'differences-prevlink' ],
859 $breadCrumbs .= $this->linkRenderer->makeKnownLink(
861 $this->msg(
'previousdiff' )->text(),
863 'class' =>
'mw-diff-revision-history-link-previous'
868 $prevlink =
"\u{00A0}";
871 if ( $this->mOldRevisionRecord->isMinor() ) {
872 $oldminor = ChangesList::flag(
'minor' );
877 $oldRevRecord = $this->mOldRevisionRecord;
879 $ldel = $this->revisionDeleteLink( $oldRevRecord );
880 $oldRevisionHeader = $this->getRevisionHeader( $oldRevRecord,
'complete' );
882 $oldRevComment = $this->commentFormatter
884 $oldRevRecord, $user, !$diffOnly, !$this->unhide,
false
887 if ( $oldRevComment ===
'' ) {
888 $defaultComment = $this->msg(
'changeslist-nocomment' )->escaped();
889 $oldRevComment =
"<span class=\"comment mw-comment-none\">$defaultComment</span>";
892 $oldHeader =
'<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader .
'</strong></div>' .
893 '<div id="mw-diff-otitle2">' .
894 Linker::revUserTools( $oldRevRecord, !$this->unhide ) .
895 $this->getUserMetaData( $oldRevRecord->getUser() ) .
897 '<div id="mw-diff-otitle3">' . $oldminor . $oldRevComment . $ldel .
'</div>' .
898 '<div id="mw-diff-otitle5">' . $oldChangeTags[0] .
'</div>' .
899 '<div id="mw-diff-otitle4">' . $prevlink .
'</div>';
902 $this->hookRunner->onDifferenceEngineOldHeader(
903 $this, $oldHeader, $prevlink, $oldminor, $diffOnly, $ldel, $this->unhide );
906 $out->addJsConfigVars( [
907 'wgDiffOldId' => $this->mOldid,
908 'wgDiffNewId' => $this->mNewid,
911 # Make "next revision link"
912 # Skip next link on the top revision
913 if ( $samePage && $this->mNewPage && !$this->mNewRevisionRecord->isCurrent() ) {
914 $nextlinkQuery = [
'diff' =>
'next',
'oldid' => $this->mNewid ] + $query;
915 $nextlink = $this->linkRenderer->makeKnownLink(
917 $this->msg(
'nextdiff' )->text(),
918 [
'id' =>
'differences-nextlink' ],
921 $breadCrumbs .= $this->linkRenderer->makeKnownLink(
923 $this->msg(
'nextdiff' )->text(),
925 'class' =>
'mw-diff-revision-history-link-next'
930 $nextlink =
"\u{00A0}";
933 if ( $this->mNewRevisionRecord->isMinor() ) {
934 $newminor = ChangesList::flag(
'minor' );
939 # Handle RevisionDelete links...
940 $rdel = $this->revisionDeleteLink( $this->mNewRevisionRecord );
942 # Allow extensions to define their own revision tools
943 $this->hookRunner->onDiffTools(
944 $this->mNewRevisionRecord,
946 $this->mOldRevisionRecord ?:
null,
950 $formattedRevisionTools = [];
952 foreach ( $revisionTools as $key => $tool ) {
953 $toolClass = is_string( $key ) ? $key :
'mw-diff-tool';
954 $element = Html::rawElement(
956 [
'class' => $toolClass ],
959 $formattedRevisionTools[] = $element;
962 $newRevRecord = $this->mNewRevisionRecord;
964 $newRevisionHeader = $this->getRevisionHeader( $newRevRecord,
'complete' ) .
965 ' ' . implode(
' ', $formattedRevisionTools );
967 $newRevComment = $this->commentFormatter->formatRevision(
968 $newRevRecord, $user, !$diffOnly, !$this->unhide,
false
971 if ( $newRevComment ===
'' ) {
972 $defaultComment = $this->msg(
'changeslist-nocomment' )->escaped();
973 $newRevComment =
"<span class=\"comment mw-comment-none\">$defaultComment</span>";
976 $newHeader =
'<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader .
'</strong></div>' .
977 '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $newRevRecord, !$this->unhide ) .
979 $this->getUserMetaData( $newRevRecord->getUser() ) .
981 '<div id="mw-diff-ntitle3">' . $newminor . $newRevComment . $rdel .
'</div>' .
982 '<div id="mw-diff-ntitle5">' . $newChangeTags[0] .
'</div>' .
983 '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() .
'</div>';
986 $this->hookRunner->onDifferenceEngineNewHeader( $this, $newHeader,
987 $formattedRevisionTools, $nextlink, $rollback, $newminor, $diffOnly,
988 $rdel, $this->unhide );
991 Html::rawElement(
'div', [
992 'class' =>
'mw-diff-revision-history-links'
995 # If the diff cannot be shown due to a deleted revision, then output
996 # the diff header and links to unhide (if available)...
997 if ( $this->shouldBeHiddenFromUser( $this->getAuthority() ) ) {
998 $this->showDiffStyle();
999 $multi = $this->getMultiNotice();
1000 $out->addHTML( $this->addHeader(
'', $oldHeader, $newHeader, $multi ) );
1002 # Give explanation for why revision is not visible
1003 $msg = [ $suppressed ?
'rev-suppressed-no-diff' :
'rev-deleted-no-diff' ];
1005 # Give explanation and add a link to view the diff...
1006 $query = $this->getRequest()->appendQueryValue(
'unhide',
'1' );
1008 $suppressed ?
'rev-suppressed-unhide-diff' :
'rev-deleted-unhide-diff',
1009 $this->
getTitle()->getFullURL( $query )
1012 $out->addHTML( Html::warningBox( $this->msg( ...$msg )->parse(),
'plainlinks' ) );
1013 # Otherwise, output a regular diff...
1015 # Add deletion notice if the user is viewing deleted content
1018 $msg = $suppressed ?
'rev-suppressed-diff-view' :
'rev-deleted-diff-view';
1019 $notice = Html::warningBox( $this->msg( $msg )->parse(),
'plainlinks' );
1022 # Add an error if the content can't be loaded
1023 $this->getSlotContents();
1024 foreach ( $this->getRevisionLoadErrors() as $msg ) {
1025 $notice .= Html::warningBox( $msg->parse() );
1029 if ( $this->getTextDiffer()->hasFormat(
'inline' ) ) {
1033 $this->showTablePrefixes();
1034 $this->showDiff( $oldHeader, $newHeader, $notice );
1036 $this->renderNewRevision();
1040 if ( $this->hookRunner->onDifferenceEngineRenderRevisionShowFinalPatrolLink() ) {
1041 # Add redundant patrol link on bottom...
1042 $out->addHTML( $this->markPatrolledLink() );
1050 private function showTablePrefixes() {
1052 foreach ( $this->getSlotDiffRenderers() as $slotDiffRenderer ) {
1053 $parts += $slotDiffRenderer->getTablePrefix( $this->getContext(), $this->mNewPage );
1056 if ( count( array_filter( $parts ) ) > 0 ) {
1057 $language = $this->getLanguage();
1059 'class' =>
'mw-diff-table-prefix',
1060 'dir' => $language->getDir(),
1061 'lang' => $language->getCode(),
1063 $this->getOutput()->addHTML(
1064 Html::rawElement(
'div', $attrs, implode(
'', $parts ) ) );
1080 if ( $this->mMarkPatrolledLink ===
null ) {
1081 $linkInfo = $this->getMarkPatrolledLinkInfo();
1083 if ( !$linkInfo || !$this->mNewPage ) {
1084 $this->mMarkPatrolledLink =
'';
1086 $patrolLinkClass =
'patrollink';
1087 $this->mMarkPatrolledLink =
' <span class="' . $patrolLinkClass .
'" data-mw="interface">[' .
1088 $this->linkRenderer->makeKnownLink(
1090 $this->msg(
'markaspatrolleddiff' )->text(),
1093 'action' =>
'markpatrolled',
1094 'rcid' => $linkInfo[
'rcid'],
1098 $this->hookRunner->onDifferenceEngineMarkPatrolledLink( $this,
1099 $this->mMarkPatrolledLink, $linkInfo[
'rcid'] );
1102 return $this->mMarkPatrolledLink;
1113 $user = $this->getUser();
1114 $config = $this->getConfig();
1119 $config->get( MainConfigNames::UseRCPatrol ) &&
1121 $this->getAuthority()->probablyCan(
'patrol', $this->mNewPage ) &&
1124 RecentChange::isInRCLifespan( $this->mNewRevisionRecord->getTimestamp(), 21600 )
1127 $change = RecentChange::newFromConds(
1129 'rc_this_oldid' => $this->mNewid,
1130 'rc_patrolled' => RecentChange::PRC_UNPATROLLED
1135 if ( $change && !$change->getPerformerIdentity()->equals( $user ) ) {
1136 $rcid = $change->getAttribute(
'rc_id' );
1147 $this->hookRunner->onDifferenceEngineMarkPatrolledRCID( $rcid, $this, $change, $user );
1151 $this->getOutput()->getMetadata()->setPreventClickjacking(
true );
1152 $this->getOutput()->addModules(
'mediawiki.misc-authed-curate' );
1154 return [
'rcid' => $rcid ];
1167 private function revisionDeleteLink(
RevisionRecord $revRecord ) {
1168 $link = Linker::getRevDeleteLink(
1169 $this->getAuthority(),
1173 if ( $link !==
'' ) {
1174 $link =
"\u{00A0}\u{00A0}\u{00A0}" . $link .
' ';
1186 if ( $this->isContentOverridden ) {
1190 throw new LogicException(
1192 .
' is not supported after calling setContent(). Use setRevisions() instead.'
1196 $out = $this->getOutput();
1197 $revHeader = $this->getRevisionHeader( $this->mNewRevisionRecord );
1198 # Add "current version as of X" title
1199 $out->addHTML(
"<hr class='diff-hr' id='mw-oldid' />
1200 <h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
1201 # Page content may be handled by a hooked call instead...
1202 if ( $this->hookRunner->onArticleContentOnDiff( $this, $out ) ) {
1203 $this->loadNewText();
1204 if ( !$this->mNewPage ) {
1210 if ( $this->hasNewRevisionLoadError() ) {
1215 $out->setRevisionId( $this->mNewid );
1216 $out->setRevisionIsCurrent( $this->mNewRevisionRecord->isCurrent() );
1217 $out->setRevisionTimestamp( $this->mNewRevisionRecord->getTimestamp() );
1218 $out->setArticleFlag(
true );
1220 if ( !$this->hookRunner->onArticleRevisionViewCustom(
1221 $this->mNewRevisionRecord, $this->mNewPage, $this->mOldid, $out )
1227 if ( $this->
getTitle()->equals( $this->mNewPage ) ) {
1231 $wikiPage = $this->getWikiPage();
1234 $wikiPage = $this->wikiPageFactory->newFromTitle( $this->mNewPage );
1237 $parserOptions = $wikiPage->makeParserOptions( $this->getContext() );
1238 $parserOptions->setRenderReason(
'diff-page' );
1240 $parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
1241 $status = $parserOutputAccess->getParserOutput(
1244 $this->mNewRevisionRecord,
1246 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK |
1248 ParserOutputAccess::OPT_LINKS_UPDATE
1250 if ( $status->isOK() ) {
1251 $parserOutput = $status->getValue();
1253 if ( $this->hookRunner->onDifferenceEngineRenderRevisionAddParserOutput(
1254 $this, $out, $parserOutput, $wikiPage )
1256 $out->addParserOutput( $parserOutput, [
1257 'enableSectionEditLinks' => $this->mNewRevisionRecord->isCurrent()
1258 && $this->getAuthority()->probablyCan(
1260 $this->mNewRevisionRecord->getPage()
1262 'absoluteURLs' => $this->slotDiffOptions[
'expand-url'] ??
false
1268 $out->parseAsInterface(
1269 $status->getWikiText(
false,
false, $this->getLanguage() )
1288 public function showDiff( $otitle, $ntitle, $notice =
'' ) {
1290 $this->hookRunner->onDifferenceEngineShowDiff( $this );
1292 $diff = $this->getDiff( $otitle, $ntitle, $notice );
1293 if ( $diff ===
false ) {
1294 $this->showMissingRevision();
1298 $this->showDiffStyle();
1299 if ( $this->slotDiffOptions[
'expand-url'] ??
false ) {
1300 $diff = Linker::expandLocalLinks( $diff );
1302 $this->getOutput()->addHTML( $diff );
1310 if ( !$this->isSlotDiffRenderer ) {
1311 $this->getOutput()->addModules(
'mediawiki.diff' );
1312 $this->getOutput()->addModuleStyles( [
1313 'mediawiki.interface.helpers.styles',
1314 'mediawiki.diff.styles'
1316 foreach ( $this->getSlotDiffRenderers() as $slotDiffRenderer ) {
1317 $slotDiffRenderer->addModules( $this->getOutput() );
1331 public function getDiff( $otitle, $ntitle, $notice =
'' ) {
1332 $body = $this->getDiffBody();
1333 if ( $body ===
false ) {
1337 $multi = $this->getMultiNotice();
1339 if ( $body ===
'' ) {
1340 $notice .=
'<div class="mw-diff-empty">' .
1341 $this->msg(
'diff-empty' )->parse() .
1345 if ( $this->cacheHitKey !==
null ) {
1346 $body .=
"\n<!-- diff cache key " . htmlspecialchars( $this->cacheHitKey ) .
" -->\n";
1349 return $this->addHeader( $body, $otitle, $ntitle, $multi, $notice );
1352 private function incrementStats(
string $cacheStatus ): void {
1354 $stats->getCounter(
'diff_cache_total' )
1355 ->setLabel(
'status', $cacheStatus )
1356 ->copyToStatsdAt(
'diff_cache.' . $cacheStatus )
1366 $this->mCacheHit =
true;
1368 if ( !$this->isContentOverridden ) {
1369 if ( !$this->loadRevisionData() ) {
1371 } elseif ( $this->mOldRevisionRecord &&
1372 !$this->mOldRevisionRecord->userCan(
1373 RevisionRecord::DELETED_TEXT,
1374 $this->getAuthority()
1378 } elseif ( $this->mNewRevisionRecord &&
1379 !$this->mNewRevisionRecord->userCan(
1380 RevisionRecord::DELETED_TEXT,
1381 $this->getAuthority()
1386 if ( $this->mOldRevisionRecord ===
false || (
1387 $this->mOldRevisionRecord &&
1388 $this->mNewRevisionRecord &&
1389 $this->mOldRevisionRecord->getId() &&
1390 $this->mOldRevisionRecord->getId() == $this->mNewRevisionRecord->getId()
1392 if ( $this->hookRunner->onDifferenceEngineShowEmptyOldContent( $this ) ) {
1400 $services = MediaWikiServices::getInstance();
1401 $cache = $services->getMainWANObjectCache();
1402 $stats = $services->getStatsdDataFactory();
1403 if ( $this->mOldid && $this->mNewid ) {
1404 $key = $cache->makeKey( ...$this->getDiffBodyCacheKeyParams() );
1407 if ( !$this->mRefreshCache ) {
1408 $difftext = $cache->get( $key );
1409 if ( is_string( $difftext ) ) {
1410 $this->incrementStats(
'hit' );
1411 $difftext = $this->localiseDiff( $difftext );
1412 $this->cacheHitKey = $key;
1417 $this->mCacheHit =
false;
1418 $this->cacheHitKey =
null;
1421 if ( !$this->loadText() ) {
1428 $slotContents = $this->getSlotContents();
1429 foreach ( $this->getSlotDiffRenderers() as $role => $slotDiffRenderer ) {
1431 $slotDiff = $slotDiffRenderer->getDiff( $slotContents[$role][
'old'],
1432 $slotContents[$role][
'new'] );
1436 if ( $slotDiff && $role !== SlotRecord::MAIN ) {
1439 $difftext .= $this->getSlotHeader( $slotTitle );
1441 $difftext .= $slotDiff;
1445 if ( !$this->hookRunner->onAbortDiffCache( $this ) ) {
1446 $this->incrementStats(
'uncacheable' );
1447 } elseif ( $key !==
false ) {
1448 $this->incrementStats(
'miss' );
1449 $cache->set( $key, $difftext, 7 * 86400 );
1451 $this->incrementStats(
'uncacheable' );
1454 $difftext = $this->localiseDiff( $difftext );
1466 $diffRenderers = $this->getSlotDiffRenderers();
1467 if ( !isset( $diffRenderers[$role] ) ) {
1471 $slotContents = $this->getSlotContents();
1473 $slotDiff = $diffRenderers[$role]->getDiff( $slotContents[$role][
'old'],
1474 $slotContents[$role][
'new'] );
1478 if ( $slotDiff ===
'' ) {
1482 if ( $role !== SlotRecord::MAIN ) {
1485 $slotDiff = $this->getSlotHeader( $slotTitle ) . $slotDiff;
1488 return $this->localiseDiff( $slotDiff );
1500 $columnCount = $this->mOldRevisionRecord ? 4 : 2;
1501 $userLang = $this->getLanguage()->getHtmlCode();
1502 return Html::rawElement(
'tr', [
'class' =>
'mw-diff-slot-header',
'lang' => $userLang ],
1503 Html::element(
'th', [
'colspan' => $columnCount ], $headerText ) );
1514 $columnCount = $this->mOldRevisionRecord ? 4 : 2;
1515 $userLang = $this->getLanguage()->getHtmlCode();
1516 return Html::rawElement(
'tr', [
'class' =>
'mw-diff-slot-error',
'lang' => $userLang ],
1517 Html::rawElement(
'td', [
'colspan' => $columnCount ], $errorText ) );
1534 if ( !$this->mOldid || !$this->mNewid ) {
1535 throw new BadMethodCallException(
'mOldid and mNewid must be set to get diff cache key.' );
1541 "old-{$this->mOldid}",
1542 "rev-{$this->mNewid}"
1546 if ( !$this->isSlotDiffRenderer ) {
1547 foreach ( $this->getSlotDiffRenderers() as $slotDiffRenderer ) {
1548 $extraKeys = array_merge( $extraKeys, $slotDiffRenderer->getExtraCacheKeys() );
1551 ksort( $extraKeys );
1552 return array_merge(
$params, array_values( $extraKeys ) );
1566 $this->mOldid = 123456789;
1567 $this->mNewid = 987654321;
1570 $params = $this->getDiffBodyCacheKeyParams();
1580 if ( array_slice(
$params, 0, count( $standardParams ) ) === $standardParams ) {
1598 $validatedOptions = [];
1599 if ( isset( $options[
'diff-type'] )
1600 && $this->getTextDiffer()->hasFormat( $options[
'diff-type'] )
1602 $validatedOptions[
'diff-type'] = $options[
'diff-type'];
1604 if ( !empty( $options[
'expand-url'] ) ) {
1605 $validatedOptions[
'expand-url'] =
true;
1607 if ( !empty( $options[
'inline-toggle'] ) ) {
1608 $validatedOptions[
'inline-toggle'] =
true;
1610 $this->slotDiffOptions = $validatedOptions;
1621 $this->extraQueryParams =
$params;
1638 $slotDiffRenderer = $new->
getContentHandler()->getSlotDiffRenderer( $this->getContext() );
1641 && $this->isSlotDiffRenderer
1647 throw new LogicException( get_class( $this ) .
': could not maintain backwards compatibility. '
1648 .
'Please use a SlotDiffRenderer.' );
1650 return $slotDiffRenderer->getDiff( $old, $new ) . $this->getDebugString();
1666 $slotDiffRenderer = $this->contentHandlerFactory
1668 ->getSlotDiffRenderer( $this->getContext() );
1672 throw new LogicException(
'The slot diff renderer for text content should be a '
1673 .
'TextSlotDiffRenderer subclass' );
1675 return $slotDiffRenderer->getTextDiff( $otext, $ntext ) . $this->getDebugString();
1685 $differenceEngine =
new self;
1686 $engine = $differenceEngine->getTextDiffer()->getEngineForFormat(
'table' );
1687 if ( $engine ===
'external' ) {
1688 return MediaWikiServices::getInstance()->getMainConfig()
1689 ->get( MainConfigNames::ExternalDiffEngine );
1703 protected function debug( $generator =
"internal" ) {
1704 if ( !$this->enableDebugComment ) {
1707 $data = [ $generator ];
1708 if ( $this->getConfig()->
get( MainConfigNames::ShowHostnames ) ) {
1713 return "<!-- diff generator: " .
1714 implode(
" ", array_map(
"htmlspecialchars", $data ) ) .
1721 private function getDebugString() {
1722 $engine = self::getEngine();
1723 if ( $engine ===
'wikidiff2' ) {
1724 return $this->debug(
'wikidiff2' );
1725 } elseif ( $engine ===
'php' ) {
1726 return $this->debug(
'native PHP' );
1728 return $this->debug(
"external $engine" );
1738 private function localiseDiff( $text ) {
1739 return $this->getTextDiffer()->localize( $this->getTextDiffFormat(), $text );
1751 return preg_replace_callback(
'/<!--LINE (\d+)-->/',
1753 if (
$matches[1] ===
'1' && $this->mReducedLineNumbers ) {
1756 return $this->msg(
'lineno' )->numParams(
$matches[1] )->escaped();
1768 !$this->mOldRevisionRecord || !$this->mNewRevisionRecord
1769 || !$this->mOldPage || !$this->mNewPage
1770 || !$this->mOldPage->equals( $this->mNewPage )
1771 || $this->mOldRevisionRecord->getId() ===
null
1772 || $this->mNewRevisionRecord->getId() ===
null
1774 || $this->mNewPage->getArticleID() !== $this->mOldRevisionRecord->getPageId()
1775 || $this->mNewPage->getArticleID() !== $this->mNewRevisionRecord->getPageId()
1780 if ( $this->mOldRevisionRecord->getTimestamp() > $this->mNewRevisionRecord->getTimestamp() ) {
1781 $oldRevRecord = $this->mNewRevisionRecord;
1782 $newRevRecord = $this->mOldRevisionRecord;
1784 $oldRevRecord = $this->mOldRevisionRecord;
1785 $newRevRecord = $this->mNewRevisionRecord;
1791 $revisionIdList = $this->revisionStore->getRevisionIdsBetween(
1792 $this->mNewPage->getArticleID(),
1798 if ( count( $revisionIdList ) > 0 ) {
1799 foreach ( $revisionIdList as $revisionId ) {
1800 $revision = $this->revisionStore->getRevisionById( $revisionId );
1801 if ( $revision->getUser( RevisionRecord::FOR_THIS_USER, $this->getAuthority() ) ) {
1806 if ( $nEdits > 0 && $nEdits <= 1000 ) {
1808 $newRevUserForGender =
'[HIDDEN]';
1811 $users = $this->revisionStore->getAuthorsBetween(
1812 $this->mNewPage->getArticleID(),
1818 $numUsers = count( $users );
1820 $newRevUser = $newRevRecord->getUser( RevisionRecord::RAW );
1821 $newRevUserText = $newRevUser ? $newRevUser->getName() :
'';
1822 $newRevUserSafe = $newRevRecord->getUser(
1823 RevisionRecord::FOR_THIS_USER,
1824 $this->getAuthority()
1826 $newRevUserForGender = $newRevUserSafe ? $newRevUserSafe->getName() :
'[HIDDEN]';
1827 if ( $numUsers == 1 && $users[0]->getName() == $newRevUserText ) {
1830 }
catch ( InvalidArgumentException $e ) {
1834 return self::intermediateEditsMsg( $nEdits, $numUsers, $limit, $newRevUserForGender );
1851 if ( $numUsers === 0 ) {
1852 $msg =
'diff-multi-sameuser';
1854 ->numParams( $numEdits, $numUsers )
1855 ->params( $lastUser )
1857 } elseif ( $numUsers > $limit ) {
1858 $msg =
'diff-multi-manyusers';
1861 $msg =
'diff-multi-otherusers';
1864 return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
1872 if ( !$revRecord->
userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
1889 $lang = $this->getLanguage();
1890 $user = $this->getUser();
1892 $timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
1893 $dateofrev = $lang->userDate( $revtimestamp, $user );
1894 $timeofrev = $lang->userTime( $revtimestamp, $user );
1897 $rev->
isCurrent() ?
'currentrev-asof' :
'revisionasof',
1903 if ( $complete !==
'complete' ) {
1909 if ( $this->userCanEdit( $rev ) ) {
1910 $header = $this->linkRenderer->makeKnownLink(
1914 [
'oldid' => $rev->
getId() ]
1916 $editQuery = [
'action' =>
'edit' ];
1918 $editQuery[
'oldid'] = $rev->
getId();
1921 $key = $this->getAuthority()->probablyCan(
'edit', $rev->
getPage() ) ?
'editold' :
'viewsourceold';
1922 $msg = $this->msg( $key )->text();
1923 $editLink = $this->linkRenderer->makeKnownLink( $title, $msg, [], $editQuery );
1924 $header .=
' ' . Html::rawElement(
1926 [
'class' =>
'mw-diff-edit' ],
1934 $header .= Html::element(
'span',
1936 'class' =>
'mw-diff-timestamp',
1937 'data-timestamp' =>
wfTimestamp( TS_ISO_8601, $revtimestamp ),
1941 if ( $rev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1942 return Html::rawElement(
1944 [
'class' => Linker::getRevisionDeletedClass( $rev ) ],
1964 public function addHeader( $diff, $otitle, $ntitle, $multi =
'', $notice =
'' ) {
1967 $header = Html::openElement(
'table', [
1973 'diff-type-' . $this->getTextDiffFormat(),
1977 'diff-contentalign-' . $this->getDiffLang()->alignStart(),
1982 'diff-editfont-' . $this->userOptionsLookup->getOption(
1987 'data-mw' =>
'interface',
1989 $userLang = htmlspecialchars( $this->getLanguage()->getHtmlCode() );
1991 if ( !$diff && !$otitle ) {
1993 <tr class=\"diff-title\" lang=\"{$userLang}\">
1994 <td class=\"diff-ntitle\">{$ntitle}</td>
2000 <col class=\"diff-marker\" />
2001 <col class=\"diff-content\" />
2002 <col class=\"diff-marker\" />
2003 <col class=\"diff-content\" />";
2010 if ( $otitle || $ntitle ) {
2012 $deletedClass =
'diff-side-deleted';
2013 $addedClass =
'diff-side-added';
2015 <tr class=\"diff-title\" lang=\"{$userLang}\">
2016 <td colspan=\"$colspan\" class=\"diff-otitle {$deletedClass}\">{$otitle}</td>
2017 <td colspan=\"$colspan\" class=\"diff-ntitle {$addedClass}\">{$ntitle}</td>
2022 if ( $multi !=
'' ) {
2023 $header .=
"<tr><td colspan=\"{$multiColspan}\" " .
2024 "class=\"diff-multi\" lang=\"{$userLang}\">{$multi}</td></tr>";
2026 if ( $notice !=
'' ) {
2027 $header .=
"<tr><td colspan=\"{$multiColspan}\" " .
2028 "class=\"diff-notice\" lang=\"{$userLang}\">{$notice}</td></tr>";
2031 return $header . $diff .
"</table>";
2042 $this->mOldContent = $oldContent;
2043 $this->mNewContent = $newContent;
2045 $this->mTextLoaded = 2;
2046 $this->mRevisionsLoaded =
true;
2047 $this->isContentOverridden =
true;
2048 $this->slotDiffRenderers =
null;
2059 if ( $oldRevision ) {
2060 $this->mOldRevisionRecord = $oldRevision;
2061 $this->mOldid = $oldRevision->
getId();
2065 $this->mOldContent = $oldRevision->
getContent( SlotRecord::MAIN,
2066 RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
2067 if ( !$this->mOldContent ) {
2068 $this->addRevisionLoadError(
'old' );
2071 $this->mOldPage =
null;
2072 $this->mOldRevisionRecord = $this->mOldid =
false;
2074 $this->mNewRevisionRecord = $newRevision;
2075 $this->mNewid = $newRevision->
getId();
2077 $this->mNewContent = $newRevision->
getContent( SlotRecord::MAIN,
2078 RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
2079 if ( !$this->mNewContent ) {
2080 $this->addRevisionLoadError(
'new' );
2083 $this->mRevisionsIdsLoaded = $this->mRevisionsLoaded =
true;
2084 $this->mTextLoaded = $oldRevision ? 2 : 1;
2085 $this->isContentOverridden =
false;
2086 $this->slotDiffRenderers =
null;
2096 $this->mDiffLang = $lang;
2112 if ( $new ===
'prev' ) {
2114 $newid = intval( $old );
2116 $newRev = $this->revisionStore->getRevisionById( $newid );
2118 $oldRev = $this->revisionStore->getPreviousRevision( $newRev );
2120 $oldid = $oldRev->getId();
2123 } elseif ( $new ===
'next' ) {
2125 $oldid = intval( $old );
2127 $oldRev = $this->revisionStore->getRevisionById( $oldid );
2129 $newRev = $this->revisionStore->getNextRevision( $oldRev );
2131 $newid = $newRev->getId();
2135 $oldid = intval( $old );
2136 $newid = intval( $new );
2140 return [ $oldid, $newid ];
2143 private function loadRevisionIds() {
2144 if ( $this->mRevisionsIdsLoaded ) {
2148 $this->mRevisionsIdsLoaded =
true;
2150 $old = $this->mOldid;
2151 $new = $this->mNewid;
2153 [ $this->mOldid, $this->mNewid ] = self::mapDiffPrevNext( $old, $new );
2154 if ( $new ===
'next' && $this->mNewid ===
false ) {
2155 # if no result, NewId points to the newest old revision. The only newer
2156 # revision is cur, which is "0".
2160 $this->hookRunner->onNewDifferenceEngine(
2162 $this->
getTitle(), $this->mOldid, $this->mNewid, $old, $new );
2179 if ( $this->mRevisionsLoaded ) {
2180 return $this->isContentOverridden ||
2181 ( $this->mOldRevisionRecord !==
null && $this->mNewRevisionRecord !== null );
2185 $this->mRevisionsLoaded =
true;
2187 $this->loadRevisionIds();
2190 if ( $this->mNewid ) {
2191 $this->mNewRevisionRecord = $this->revisionStore->getRevisionById( $this->mNewid );
2193 $this->mNewRevisionRecord = $this->revisionStore->getRevisionByTitle( $this->
getTitle() );
2201 $this->mNewid = $this->mNewRevisionRecord->getId();
2202 $this->mNewPage = $this->mNewid ?
2203 Title::newFromLinkTarget( $this->mNewRevisionRecord->getPageAsLinkTarget() ) :
2207 $this->mOldRevisionRecord =
false;
2208 if ( $this->mOldid ) {
2209 $this->mOldRevisionRecord = $this->revisionStore->getRevisionById( $this->mOldid );
2210 } elseif ( $this->mOldid === 0 ) {
2211 $revRecord = $this->revisionStore->getPreviousRevision( $this->mNewRevisionRecord );
2213 $this->mOldid = $revRecord ? $revRecord->
getId() :
false;
2214 $this->mOldRevisionRecord = $revRecord ??
false;
2217 if ( $this->mOldRevisionRecord ===
null ) {
2221 if ( $this->mOldRevisionRecord && $this->mOldRevisionRecord->getId() ) {
2222 $this->mOldPage = Title::newFromLinkTarget(
2223 $this->mOldRevisionRecord->getPageAsLinkTarget()
2226 $this->mOldPage =
null;
2230 $dbr = $this->dbProvider->getReplicaDatabase();
2231 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
2232 if ( $this->mOldid !==
false ) {
2233 $tagIds = $dbr->newSelectQueryBuilder()
2234 ->select(
'ct_tag_id' )
2235 ->from(
'change_tag' )
2236 ->where( [
'ct_rev_id' => $this->mOldid ] )
2237 ->caller( __METHOD__ )->fetchFieldValues();
2239 foreach ( $tagIds as $tagId ) {
2241 $tags[] = $changeTagDefStore->getName( (
int)$tagId );
2246 $this->mOldTags = implode(
',', $tags );
2248 $this->mOldTags =
false;
2251 $tagIds = $dbr->newSelectQueryBuilder()
2252 ->select(
'ct_tag_id' )
2253 ->from(
'change_tag' )
2254 ->where( [
'ct_rev_id' => $this->mNewid ] )
2255 ->caller( __METHOD__ )->fetchFieldValues();
2257 foreach ( $tagIds as $tagId ) {
2259 $tags[] = $changeTagDefStore->getName( (
int)$tagId );
2264 $this->mNewTags = implode(
',', $tags );
2278 if ( $this->mTextLoaded == 2 ) {
2279 return $this->loadRevisionData() &&
2280 ( $this->mOldRevisionRecord ===
false || $this->mOldContent )
2281 && $this->mNewContent;
2285 $this->mTextLoaded = 2;
2287 if ( !$this->loadRevisionData() ) {
2291 if ( $this->mOldRevisionRecord ) {
2292 $this->mOldContent = $this->mOldRevisionRecord->getContent(
2294 RevisionRecord::FOR_THIS_USER,
2295 $this->getAuthority()
2297 if ( $this->mOldContent ===
null ) {
2302 $this->mNewContent = $this->mNewRevisionRecord->getContent(
2304 RevisionRecord::FOR_THIS_USER,
2305 $this->getAuthority()
2307 $this->hookRunner->onDifferenceEngineLoadTextAfterNewContentIsLoaded( $this );
2308 if ( $this->mNewContent ===
null ) {
2321 if ( $this->mTextLoaded >= 1 ) {
2322 return $this->loadRevisionData();
2325 $this->mTextLoaded = 1;
2327 if ( !$this->loadRevisionData() ) {
2331 $this->mNewContent = $this->mNewRevisionRecord->getContent(
2333 RevisionRecord::FOR_THIS_USER,
2334 $this->getAuthority()
2337 $this->hookRunner->onDifferenceEngineAfterLoadNewText( $this );
2348 if ( $this->textDiffer ===
null ) {
2350 $this->getContext(),
2351 $this->getDiffLang(),
2352 $this->getConfig()->
get( MainConfigNames::DiffEngine ),
2353 $this->getConfig()->
get( MainConfigNames::ExternalDiffEngine ),
2354 $this->getConfig()->
get( MainConfigNames::Wikidiff2Options )
2357 return $this->textDiffer;
2367 return $this->getTextDiffer()->getFormats();
2377 return $this->slotDiffOptions[
'diff-type'] ??
'table';
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfHostname()
Get host name of the current machine, for use in error reporting.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
bool $enableDebugComment
Set this to true to add debug info to the HTML output.
bool $unhide
Show rev_deleted content if allowed.
bool $isContentOverridden
Was the content overridden via setContent()? If the content was overridden, most internal state (e....
getExtraCacheKeys()
Implements DifferenceEngineSlotDiffRenderer::getExtraCacheKeys().
markAsSlotDiffRenderer()
Mark this DifferenceEngine as a slot renderer (as opposed to a page renderer).
getSlotHeader( $headerText)
Get a slot header for inclusion in a diff body (as a table row).
setSlotDiffOptions( $options)
hasDeletedRevision()
Checks whether one of the given Revisions was deleted.
int $mTextLoaded
How many text blobs have been loaded, 0, 1 or 2?
deletedIdMarker( $id)
Build a wikitext link toward a deleted revision, if viewable.
SlotDiffRenderer[] null $slotDiffRenderers
DifferenceEngine classes for the slots, keyed by role name.
getDiffBodyForRole( $role)
Get the diff table body for one slot, without header.
getTextDiffer()
Get the TextDiffer which will be used for rendering text.
getDefaultLanguage()
Get the language to use if none has been set by setTextLanguage().
getOldid()
Get the ID of old revision (left pane) of the diff.
setRevisions(?RevisionRecord $oldRevision, RevisionRecord $newRevision)
Use specified text instead of loading from the database.
bool $isSlotDiffRenderer
Temporary hack for B/C while slot diff related methods of DifferenceEngine are being deprecated.
generateTextDiffBody( $otext, $ntext)
Generate a diff, no caching.
loadNewText()
Load the text of the new revision, not the old one.
showDiffPage( $diffOnly=false)
loadText()
Load the text of the revisions, as well as revision data.
int string false null $mNewid
Revision ID for the new revision.
mapDiffPrevNext( $old, $new)
Maps a revision pair definition as accepted by DifferenceEngine constructor to a pair of actual integ...
getPermissionErrors(Authority $performer)
Get the permission errors associated with the revisions for the current diff.
getDiffBody()
Get the diff table body, without header.
getTitle()
1.18 to override Title|null
loadRevisionData()
Load revision metadata for the specified revisions.
static getEngine()
Process DiffEngine config and get a sensible, usable engine.
bool $mRevisionsLoaded
Have the revisions been loaded.
getNewRevision()
Get the right side of the diff.
showDiff( $otitle, $ntitle, $notice='')
Get the diff text, send it to the OutputPage object Returns false if the diff could not be generated,...
getTextDiffFormat()
Get the selected text diff format.
localiseLineNumbers( $text)
Replace a common convention for language-independent line numbers with the text in the user's languag...
getSlotContents()
Get the old and new content objects for all slots.
string $mMarkPatrolledLink
Link to action=markpatrolled.
deletedLink( $id)
Look up a special:Undelete link to the given deleted revision id, as a workaround for being unable to...
bool $mReducedLineNumbers
If true, line X is not displayed when X is 1, for example to increase readability and conserve space ...
__construct( $context=null, $old=0, $new=0, $rcid=0, $refreshCache=false, $unhide=false)
Title null $mNewPage
Title of new revision or null if the new revision does not exist or does not belong to a page.
bool $mCacheHit
Was the diff fetched from cache?
getMultiNotice()
If there are revisions between the ones being compared, return a note saying so.
isUserAllowedToSeeRevisions(Authority $performer)
Checks whether the current user has permission for accessing the revisions of the diff.
int false null $mOldid
Revision ID for the old revision.
debug( $generator="internal")
Generate a debug comment indicating diff generating time, server node, and generator backend.
addHeader( $diff, $otitle, $ntitle, $multi='', $notice='')
Add the header to a diff body.
bool $mRefreshCache
Refresh the diff cache.
LinkRenderer $linkRenderer
getDiffBodyCacheKeyParams()
Get the cache key parameters.
getDiff( $otitle, $ntitle, $notice='')
Get complete diff table, including header.
setExtraQueryParams( $params)
Set query parameters to append to diff page links.
static intermediateEditsMsg( $numEdits, $numUsers, $limit, $lastUser='[HIDDEN]')
Get a notice about how many intermediate edits and users there are.
getNewid()
Get the ID of new revision (right pane) of the diff.
renderNewRevision()
Show the new revision of the page.
setContent(Content $oldContent, Content $newContent)
Use specified text instead of loading from the database.
setTextLanguage(Language $lang)
Set the language in which the diff text is written.
generateContentDiffBody(Content $old, Content $new)
Generate a diff, no caching.
getSlotError( $errorText)
Get an error message for inclusion in a diff body (as a table row).
shouldBeHiddenFromUser(Authority $performer)
Checks whether the diff should be hidden from the current user This is based on whether the user is a...
getRevisionHeader(RevisionRecord $rev, $complete='')
Get a header for a specified revision.
getMarkPatrolledLinkInfo()
Returns an array of meta data needed to build a "mark as patrolled" link and adds a JS module to the ...
setReducedLineNumbers( $value=true)
Set reduced line numbers mode.
getSupportedFormats()
Get the list of supported text diff formats.
Title null $mOldPage
Title of old revision or null if the old revision does not exist or does not belong to a page.
getDiffLang()
Get the language in which the diff text is written.
showDiffStyle()
Add style sheets for diff display.
markPatrolledLink()
Build a link to mark a change as patrolled.
getRevisionLoadErrors()
If errors were encountered while loading the revision contents, this will return an array of Messages...
hasSuppressedRevision()
Checks whether one of the given Revisions was suppressed.
getOldRevision()
Get the left side of the diff.
Exception thrown when trying to render a diff between two content types which cannot be compared (thi...
getMessageObject()
Return a Message object for this exception.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
A TextDiffer which acts as a container for other TextDiffers, and dispatches requests to them.
A class containing constants representing the names of configuration variables.
Service for getting rendered output of a given page.
Service for creating WikiPage objects.
Parent class for all special pages.
Show an error when a user tries to do something they do not have the necessary permissions for.
Renders a diff for a single slot (that is, a diff between two content objects).
Renders a slot diff by doing a text diff on the native representation.
Base interface for representing page content.
getContentHandler()
Convenience method that returns the ContentHandler singleton for handling the content model that this...
Interface for objects which can provide a MediaWiki context on request.