28use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
55use Wikimedia\NonSerializable\NonSerializableTrait;
68 use ProtectedHookAccessorTrait;
69 use NonSerializableTrait;
97 private $fetchResult =
null;
111 protected $viewIsRenderAction =
false;
121 private $revisionStore;
126 private $userNameUtils;
131 private $userOptionsLookup;
134 private $commentFormatter;
137 private $wikiPageFactory;
140 private $jobQueueGroup;
143 private $archivedRevisionLookup;
156 private $mRevisionRecord =
null;
163 $this->mOldId = $oldId;
164 $this->mPage = $this->
newPage( $title );
166 $services = MediaWikiServices::getInstance();
167 $this->linkRenderer = $services->getLinkRenderer();
168 $this->revisionStore = $services->getRevisionStore();
169 $this->userNameUtils = $services->getUserNameUtils();
170 $this->userOptionsLookup = $services->getUserOptionsLookup();
171 $this->commentFormatter = $services->getCommentFormatter();
172 $this->wikiPageFactory = $services->getWikiPageFactory();
173 $this->jobQueueGroup = $services->getJobQueueGroup();
174 $this->archivedRevisionLookup = $services->getArchivedRevisionLookup();
175 $this->dbProvider = $services->getConnectionProvider();
176 $this->blockStore = $services->getDatabaseBlockStore();
193 $t = Title::newFromID( $id );
194 return $t ===
null ? null :
new static( $t );
207 $title = Title::makeTitle(
NS_FILE, $title->getDBkey() );
211 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
213 ->onArticleFromTitle( $title, $page, $context );
215 switch ( $title->getNamespace() ) {
226 $page->setContext( $context );
239 $article = self::newFromTitle( $page->
getTitle(), $context );
240 $article->mPage = $page;
250 return $this->mRedirectedFrom;
259 $this->mRedirectedFrom = $from;
268 return $this->mPage->getTitle();
282 $this->mRedirectedFrom =
null; #
Title object if set
283 $this->mRedirectUrl =
false;
284 $this->mRevisionRecord =
null;
285 $this->fetchResult =
null;
289 $this->mPage->clear();
300 if ( $this->mOldId ===
null ) {
301 $this->mOldId = $this->getOldIDFromRequest();
304 return $this->mOldId;
313 $this->mRedirectUrl =
false;
316 $oldid = $request->getIntOrNull(
'oldid' );
318 if ( $oldid ===
null ) {
322 if ( $oldid !== 0 ) {
323 # Load the given revision and check whether the page is another one.
324 # In that case, update this instance to reflect the change.
325 if ( $oldid === $this->mPage->getLatest() ) {
326 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
328 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
329 if ( $this->mRevisionRecord !==
null ) {
330 $revPageId = $this->mRevisionRecord->getPageId();
332 if ( $this->mPage->getId() !== $revPageId ) {
333 $this->mPage = $this->wikiPageFactory->newFromID( $revPageId );
339 $oldRev = $this->mRevisionRecord;
340 if ( $request->getRawVal(
'direction' ) ===
'next' ) {
343 $nextRev = $this->revisionStore->getNextRevision( $oldRev );
345 $nextid = $nextRev->getId();
350 $this->mRevisionRecord =
null;
352 $this->mRedirectUrl = $this->
getTitle()->getFullURL(
'redirect=no' );
354 } elseif ( $request->getRawVal(
'direction' ) ===
'prev' ) {
357 $prevRev = $this->revisionStore->getPreviousRevision( $oldRev );
359 $previd = $prevRev->getId();
364 $this->mRevisionRecord =
null;
381 if ( $this->fetchResult ) {
382 return $this->mRevisionRecord;
385 $oldid = $this->getOldID();
388 if ( !$this->mRevisionRecord ) {
390 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
392 if ( !$this->mRevisionRecord ) {
393 wfDebug( __METHOD__ .
" failed to find page data for title " .
394 $this->
getTitle()->getPrefixedText() );
397 $this->fetchResult = Status::newFatal(
'noarticletext' );
401 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
403 if ( !$this->mRevisionRecord ) {
404 wfDebug( __METHOD__ .
" failed to load revision, rev_id $oldid" );
406 $this->fetchResult = Status::newFatal( $this->getMissingRevisionMsg( $oldid ) );
412 if ( !$this->mRevisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getContext()->getAuthority() ) ) {
413 wfDebug( __METHOD__ .
" failed to retrieve content of revision " . $this->mRevisionRecord->getId() );
417 $this->fetchResult =
new Status;
418 $title = $this->
getTitle()->getPrefixedDBkey();
420 if ( $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
421 $this->fetchResult->
fatal(
'rev-suppressed-text' );
423 $this->fetchResult->fatal(
'rev-deleted-text-permission', $title );
429 $this->fetchResult = Status::newGood( $this->mRevisionRecord );
430 return $this->mRevisionRecord;
439 # If no oldid, this is the current version.
440 if ( $this->getOldID() == 0 ) {
444 return $this->mPage->exists() &&
445 $this->mRevisionRecord &&
446 $this->mRevisionRecord->isCurrent();
458 if ( $this->fetchResult && $this->fetchResult->isOK() ) {
460 $rev = $this->fetchResult->getValue();
461 return $rev->
getId();
463 return $this->mPage->getLatest();
473 $useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache );
475 # Get variables from query string
476 # As side effect this will load the revision and update the title
477 # in a revision ID is passed in the request, so this should remain
478 # the first call of this method even if $oldid is used way below.
479 $oldid = $this->getOldID();
481 $authority = $context->getAuthority();
482 # Another check in case getOldID() is altering the title
483 $permissionStatus = PermissionStatus::newEmpty();
485 ->authorizeRead(
'read', $this->
getTitle(), $permissionStatus )
487 wfDebug( __METHOD__ .
": denied on secondary read check" );
492 # getOldID() may as well want us to redirect somewhere else
493 if ( $this->mRedirectUrl ) {
494 $outputPage->
redirect( $this->mRedirectUrl );
495 wfDebug( __METHOD__ .
": redirecting due to oldid" );
500 # If we got diff in the query, we want to see a diff page instead of the article.
501 if ( $context->getRequest()->getCheck(
'diff' ) ) {
502 wfDebug( __METHOD__ .
": showing diff page" );
503 $this->showDiffPage();
508 # Set page title (may be overridden from ParserOutput if title conversion is enabled or DISPLAYTITLE is used)
510 str_replace(
'_',
' ', $this->
getTitle()->getNsText() ),
516 # Allow frames by default
519 $parserOptions = $this->getParserOptions();
522 # Allow extensions to vary parser options used for article rendering
523 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
524 ->onArticleParserOptions( $this, $parserOptions );
525 # Render printable version, use printable version cache
528 $poOptions[
'enableSectionEditLinks'] =
false;
531 $outputPage->
msg(
'printableversion-deprecated-warning' )->escaped()
534 } elseif ( $this->viewIsRenderAction || !$this->isCurrent() ||
535 !$authority->probablyCan(
'edit', $this->getTitle() )
537 $poOptions[
'enableSectionEditLinks'] =
false;
540 # Try client and file cache
541 if ( $oldid === 0 && $this->mPage->checkTouched() ) {
542 # Try to stream the output from file cache
543 if ( $useFileCache && $this->tryFileCache() ) {
544 wfDebug( __METHOD__ .
": done file cache" );
545 # tell wgOut that output is taken care of
547 $this->mPage->doViewUpdates( $authority, $oldid );
553 $this->showRedirectedFromHeader();
554 $this->showNamespaceHeader();
556 if ( $this->viewIsRenderAction ) {
557 $poOptions += [
'absoluteURLs' => true ];
559 $poOptions += [
'includeDebugInfo' => true ];
563 $this->generateContentOutput( $authority, $parserOptions, $oldid, $outputPage, $poOptions );
566 $this->showViewError(
wfMessage(
'badrevision' )->text() );
573 # For the main page, overwrite the <title> element with the con-
574 # tents of 'pagetitle-view-mainpage' instead of the default (if
576 # This message always exists because it is in the i18n files
577 if ( $this->
getTitle()->isMainPage() ) {
578 $msg = $context->msg(
'pagetitle-view-mainpage' )->inContentLanguage();
579 if ( !$msg->isDisabled() ) {
584 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
585 # This could use getTouched(), but that could be scary for major template edits.
586 $outputPage->
adaptCdnTTL( $this->mPage->getTimestamp(), ExpirationAwareness::TTL_DAY );
588 $this->showViewFooter();
589 $this->mPage->doViewUpdates( $authority, $oldid, $this->fetchRevisionRecord() );
591 # Load the postEdit module if the user just saved this revision
592 # See also EditPage::setPostEditCookie
593 $request = $context->getRequest();
594 $cookieKey = EditPage::POST_EDIT_COOKIE_KEY_PREFIX . $this->getRevIdFetched();
595 $postEdit = $request->getCookie( $cookieKey );
597 # Clear the cookie. This also prevents caching of the response.
598 $request->response()->clearCookie( $cookieKey );
600 $outputPage->
addModules(
'mediawiki.action.view.postEdit' );
601 if ( $this->
getContext()->getConfig()->
get(
'EnableEditRecovery' )
602 && $this->userOptionsLookup->getOption( $this->getContext()->getUser(),
'editrecovery' )
604 $outputPage->
addModules(
'mediawiki.editRecovery.postEdit' );
621 private function generateContentOutput(
628 # Should the parser cache be used?
629 $useParserCache = true;
631 $parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
634 $this->getHookRunner()->onArticleViewHeader( $this, $outputDone, $useParserCache );
637 $pOutput = $outputDone;
641 $this->doOutputMetaData( $pOutput, $outputPage );
647 if ( !$this->mPage->exists() ) {
648 wfDebug( __METHOD__ .
": showing missing article" );
649 $this->showMissingArticle();
650 $this->mPage->doViewUpdates( $performer );
656 if ( $useParserCache && !$oldid ) {
657 $pOutput = $parserOutputAccess->getCachedParserOutput(
661 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
665 $this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions );
666 $this->doOutputMetaData( $pOutput, $outputPage );
671 $rev = $this->fetchRevisionRecord();
672 if ( !$this->fetchResult->isOK() ) {
673 $this->showViewError( $this->fetchResult->getWikiText(
674 false,
false, $this->getContext()->getLanguage()
679 # Are we looking at an old revision
681 $this->setOldSubtitle( $oldid );
683 if ( !$this->showDeletedRevisionHeader() ) {
684 wfDebug( __METHOD__ .
": cannot view deleted revision" );
691 if ( $useParserCache ) {
692 $pOutput = $parserOutputAccess->getCachedParserOutput(
696 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
700 $this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions );
701 $this->doOutputMetaData( $pOutput, $outputPage );
707 # Ensure that UI elements requiring revision ID have
708 # the correct version information. (This may be overwritten after creation of ParserOutput)
711 # Preload timestamp to avoid a DB hit
714 # Pages containing custom CSS or JavaScript get special treatment
715 if ( $this->
getTitle()->isSiteConfigPage() || $this->
getTitle()->isUserConfigPage() ) {
716 $dir = $this->
getContext()->getLanguage()->getDir();
717 $lang = $this->
getContext()->getLanguage()->getHtmlCode();
720 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
724 } elseif ( !$this->getHookRunner()->onArticleRevisionViewCustom(
732 $this->doOutputMetaData( $pOutput, $outputPage );
736 # Run the parse, protected by a pool counter
737 wfDebug( __METHOD__ .
": doing uncached parse" );
742 $opt |= ParserOutputAccess::OPT_NO_CHECK_CACHE;
745 $opt |= ParserOutputAccess::OPT_NO_AUDIENCE_CHECK;
748 $opt |= ParserOutputAccess::OPT_FOR_ARTICLE_VIEW;
753 $opt |= ParserOutputAccess::OPT_LINKS_UPDATE;
755 if ( !$rev->
getId() || !$useParserCache ) {
757 $opt |= ParserOutputAccess::OPT_NO_CACHE;
760 $renderStatus = $parserOutputAccess->getParserOutput(
782 if ( $oldid === 0 || $oldid === $this->getPage()->getLatest() ) {
783 $parsoidCacheWarmingEnabled = $this->
getContext()->getConfig()
784 ->get( MainConfigNames::ParsoidCacheConfig )[
'WarmParsoidParserCache'];
786 if ( $parsoidCacheWarmingEnabled ) {
789 $this->getPage()->toPageRecord(),
790 [
'causeAction' =>
'view' ]
792 $this->jobQueueGroup->lazyPush( $parsoidJobSpec );
796 $this->doOutputFromRenderStatus(
803 if ( !$renderStatus->
isOK() ) {
807 $pOutput = $renderStatus->
getValue();
808 $this->doOutputMetaData( $pOutput, $outputPage );
817 # Adjust title for main page & pages with displaytitle
819 $this->adjustDisplayTitle( $pOutput );
831 # Check for any __NOINDEX__ tags on the page using $pOutput
832 $policy = $this->getRobotPolicy(
'view', $pOutput ?: null );
836 $this->mParserOutput = $pOutput;
844 private function doOutputFromParserCache(
849 # Ensure that UI elements requiring revision ID have
850 # the correct version information.
855 # Preload timestamp to avoid a DB hit
857 if ( $cachedTimestamp !==
null ) {
859 $this->mPage->setTimestamp( $cachedTimestamp );
869 private function doOutputFromRenderStatus(
876 if ( !$renderStatus->
isOK() ) {
878 false,
'view-pool-error', $context->getLanguage()
883 $pOutput = $renderStatus->
getValue();
886 if ( $renderStatus->
hasMessage(
'view-pool-dirty-output' ) ) {
887 $outputPage->
lowerCdnMaxage( $context->getConfig()->get( MainConfigNames::CdnMaxageStale ) );
889 $staleReason = $renderStatus->
hasMessage(
'view-pool-contention' )
890 ? $context->msg(
'view-pool-contention' )->escaped()
891 : $context->msg(
'view-pool-timeout' )->escaped();
892 $outputPage->
addHTML(
"<!-- parser cache is expired, " .
893 "sending anyway due to $staleReason-->\n" );
897 if ( $cachedId !==
null ) {
905 if ( $this->getRevisionRedirectTarget( $rev ) ) {
906 $outputPage->
addSubtitle(
"<span id=\"redirectsub\">" .
907 $context->msg(
'redirectpagesub' )->parse() .
"</span>" );
915 private function getRevisionRedirectTarget(
RevisionRecord $revision ) {
919 $content = $revision->
getContent( SlotRecord::MAIN );
920 return $content ? $content->getRedirectTarget() :
null;
930 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
932 if ( strval( $titleText ) !==
'' ) {
933 $out->setPageTitle( $titleText );
934 $out->setDisplayTitle( $titleText );
946 $request = $context->getRequest();
947 $diff = $request->getVal(
'diff' );
948 $rcid = $request->getInt(
'rcid' );
949 $purge = $request->getRawVal(
'action' ) ===
'purge';
950 $unhide = $request->getInt(
'unhide' ) === 1;
951 $oldid = $this->getOldID();
953 $rev = $this->fetchRevisionRecord();
958 $rev = $this->revisionStore->getRevisionById( $oldid );
965 $msg = $context->msg(
'difference-missing-revision' )
974 $services = MediaWikiServices::getInstance();
976 $contentHandler = $services
977 ->getContentHandlerFactory()
979 $rev->
getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
981 $de = $contentHandler->createDifferenceEngine(
990 $diffType = $request->getVal(
'diff-type' );
992 if ( $diffType ===
null ) {
993 $diffType = $this->userOptionsLookup
994 ->getOption( $context->getUser(),
'diff-type' );
996 $de->setExtraQueryParams( [
'diff-type' => $diffType ] );
999 $de->setSlotDiffOptions( [
1000 'diff-type' => $diffType,
1001 'expand-url' => $this->viewIsRenderAction,
1002 'inline-toggle' =>
true,
1004 $de->showDiffPage( $this->isDiffOnlyView() );
1008 [ , $new ] = $de->mapDiffPrevNext( $oldid, $diff );
1010 $this->mPage->doViewUpdates( $context->getAuthority(), (
int)$new );
1013 $context->getOutput()->addHelpLink(
'Help:Diff' );
1017 return $this->
getContext()->getRequest()->getBool(
1019 $this->userOptionsLookup->getBoolOption( $this->getContext()->getUser(),
'diffonly' )
1032 $mainConfig = $context->getConfig();
1033 $articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies );
1034 $namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies );
1035 $defaultRobotPolicy = $mainConfig->get( MainConfigNames::DefaultRobotPolicy );
1037 $ns = $title->getNamespace();
1039 # Don't index user and user talk pages for blocked users (T13443)
1041 $specificTarget =
null;
1042 $vagueTarget =
null;
1043 $titleText = $title->getText();
1044 if ( IPUtils::isValid( $titleText ) ) {
1045 $vagueTarget = $titleText;
1047 $specificTarget = $title->getRootText();
1049 if ( $this->blockStore->newFromTarget( $specificTarget, $vagueTarget ) instanceof
DatabaseBlock ) {
1051 'index' =>
'noindex',
1052 'follow' =>
'nofollow'
1057 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
1058 # Non-articles (special pages etc), and old revisions
1060 'index' =>
'noindex',
1061 'follow' =>
'nofollow'
1063 } elseif ( $context->getOutput()->isPrintable() ) {
1064 # Discourage indexing of printable versions, but encourage following
1066 'index' =>
'noindex',
1067 'follow' =>
'follow'
1069 } elseif ( $context->getRequest()->getInt(
'curid' ) ) {
1070 # For ?curid=x urls, disallow indexing
1072 'index' =>
'noindex',
1073 'follow' =>
'follow'
1077 # Otherwise, construct the policy based on the various config variables.
1078 $policy = self::formatRobotPolicy( $defaultRobotPolicy );
1080 if ( isset( $namespaceRobotPolicies[$ns] ) ) {
1081 # Honour customised robot policies for this namespace
1082 $policy = array_merge(
1084 self::formatRobotPolicy( $namespaceRobotPolicies[$ns] )
1087 if ( $title->canUseNoindex() && $pOutput && $pOutput->
getIndexPolicy() ) {
1088 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1089 # a final check that we have really got the parser output.
1090 $policy = array_merge(
1096 if ( isset( $articleRobotPolicies[$title->getPrefixedText()] ) ) {
1097 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1098 $policy = array_merge(
1100 self::formatRobotPolicy( $articleRobotPolicies[$title->getPrefixedText()] )
1115 if ( is_array( $policy ) ) {
1117 } elseif ( !$policy ) {
1122 foreach ( explode(
',', $policy ) as $var ) {
1123 $var = trim( $var );
1124 if ( $var ===
'index' || $var ===
'noindex' ) {
1125 $arr[
'index'] = $var;
1126 } elseif ( $var ===
'follow' || $var ===
'nofollow' ) {
1127 $arr[
'follow'] = $var;
1143 $redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources );
1145 $request = $context->getRequest();
1146 $rdfrom = $request->getVal(
'rdfrom' );
1149 $query = $request->getValues();
1150 unset( $query[
'rdfrom'] );
1151 unset( $query[
'title'] );
1152 if ( $this->
getTitle()->isRedirect() ) {
1154 $query[
'redirect'] =
'no';
1156 $redirectTargetUrl = $this->
getTitle()->getLinkURL( $query );
1158 if ( isset( $this->mRedirectedFrom ) ) {
1161 if ( $this->getHookRunner()->onArticleViewRedirect( $this ) ) {
1162 $redir = $this->linkRenderer->makeKnownLink(
1163 $this->mRedirectedFrom,
1166 [
'redirect' =>
'no' ]
1169 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1170 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1176 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1178 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1188 } elseif ( $rdfrom ) {
1191 if ( $redirectSources && preg_match( $redirectSources, $rdfrom ) ) {
1192 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1193 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1194 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1199 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1201 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1215 if ( $this->
getTitle()->isTalkPage() && !$this->
getContext()->msg(
'talkpageheader' )->isDisabled() ) {
1216 $this->
getContext()->getOutput()->wrapWikiMsg(
1217 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1218 [
'talkpageheader' ]
1227 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1229 && IPUtils::isValid( $this->
getTitle()->getText() )
1231 $this->
getContext()->getOutput()->addWikiMsg(
'anontalkpagetext' );
1235 $patrolFooterShown = $this->showPatrolFooter();
1237 $this->getHookRunner()->onArticleViewFooter( $this, $patrolFooterShown );
1252 $mainConfig = $context->getConfig();
1253 $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
1254 $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
1255 $useFilePatrol = $mainConfig->get( MainConfigNames::UseFilePatrol );
1257 if ( !$this->getHookRunner()->onArticleShowPatrolFooter( $this ) ) {
1262 $user = $context->getUser();
1266 if ( !$context->getAuthority()->probablyCan(
'patrol', $title )
1267 || !( $useRCPatrol || $useNPPatrol
1268 || ( $useFilePatrol && $title->inNamespace(
NS_FILE ) ) )
1274 if ( $this->mRevisionRecord
1275 && !RecentChange::isInRCLifespan( $this->mRevisionRecord->getTimestamp(), 21600 )
1283 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1284 $key = $cache->makeKey(
'unpatrollable-page', $title->getArticleID() );
1285 if ( $cache->get( $key ) ) {
1289 $dbr = $this->dbProvider->getReplicaDatabase();
1290 $oldestRevisionRow = $dbr->newSelectQueryBuilder()
1291 ->select( [
'rev_id',
'rev_timestamp' ] )
1292 ->from(
'revision' )
1293 ->where( [
'rev_page' => $title->getArticleID() ] )
1294 ->orderBy( [
'rev_timestamp',
'rev_id' ] )
1295 ->caller( __METHOD__ )->fetchRow();
1296 $oldestRevisionTimestamp = $oldestRevisionRow ? $oldestRevisionRow->rev_timestamp :
false;
1302 $recentPageCreation =
false;
1303 if ( $oldestRevisionTimestamp
1304 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1307 $recentPageCreation =
true;
1308 $rc = RecentChange::newFromConds(
1310 'rc_this_oldid' => intval( $oldestRevisionRow->rev_id ),
1318 $markPatrolledMsg = $context->msg(
'markaspatrolledtext' );
1326 $recentFileUpload =
false;
1327 if ( ( !$rc || $rc->getAttribute(
'rc_patrolled' ) ) && $useFilePatrol
1328 && $title->getNamespace() ===
NS_FILE ) {
1330 $newestUploadTimestamp = $dbr->newSelectQueryBuilder()
1331 ->select(
'img_timestamp' )
1333 ->where( [
'img_name' => $title->getDBkey() ] )
1334 ->caller( __METHOD__ )->fetchField();
1335 if ( $newestUploadTimestamp
1336 && RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 )
1339 $recentFileUpload =
true;
1340 $rc = RecentChange::newFromConds(
1343 'rc_log_type' =>
'upload',
1344 'rc_timestamp' => $newestUploadTimestamp,
1346 'rc_cur_id' => $title->getArticleID()
1352 $markPatrolledMsg = $context->msg(
'markaspatrolledtext-file' );
1357 if ( !$recentPageCreation && !$recentFileUpload ) {
1362 $cache->set( $key,
'1' );
1374 if ( $rc->getAttribute(
'rc_patrolled' ) ) {
1379 $cache->set( $key,
'1' );
1384 if ( $rc->getPerformerIdentity()->equals( $user ) ) {
1391 if ( $context->getAuthority()->isAllowed(
'writeapi' ) ) {
1392 $outputPage->
addModules(
'mediawiki.misc-authed-curate' );
1395 $link = $this->linkRenderer->makeKnownLink(
1398 $markPatrolledMsg->text(),
1401 'action' =>
'markpatrolled',
1402 'rcid' => $rc->getAttribute(
'rc_id' ),
1408 "<div class='patrollink' data-mw='interface'>" .
1409 $context->msg(
'markaspatrolledlink' )->rawParams( $link )->escaped() .
1423 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1424 $cache->delete( $cache->makeKey(
'unpatrollable-page', $articleID ) );
1433 $send404Code = $context->getConfig()->get( MainConfigNames::Send404Code );
1437 $validUserPage =
false;
1441 $services = MediaWikiServices::getInstance();
1443 $contextUser = $context->getUser();
1445 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1446 if ( $title->getNamespace() ===
NS_USER
1449 $rootPart = $title->getRootText();
1450 $user = User::newFromName( $rootPart,
false );
1451 $ip = $this->userNameUtils->isIP( $rootPart );
1452 $block = $this->blockStore->newFromTarget( $user, $user );
1454 if ( $user && $user->isRegistered() && $user->isHidden() &&
1455 !$context->getAuthority()->isAllowed(
'hideuser' )
1462 if ( !( $user && $user->isRegistered() ) && !$ip ) {
1464 $outputPage->
addHTML( Html::warningBox(
1465 $context->msg(
'userpage-userdoesnotexist-view',
wfEscapeWikiText( $rootPart ) )->parse(),
1466 'mw-userpage-userdoesnotexist'
1470 LogEventsList::showLogExtract(
1473 Title::makeTitleSafe(
NS_USER, $rootPart ),
1477 'showIfEmpty' =>
false,
1478 'msgKey' => [
'renameuser-renamed-notice', $title->getBaseText() ]
1483 $block->getType() != DatabaseBlock::TYPE_AUTO &&
1485 $block->isSitewide() ||
1486 $services->getPermissionManager()->isBlockedFrom( $user, $title,
true )
1491 LogEventsList::showLogExtract(
1494 $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
':' .
1495 $block->getTargetName(),
1499 'showIfEmpty' =>
false,
1501 'blocked-notice-logextract',
1502 $user->getName() # Support GENDER in notice
1506 $validUserPage = !$title->isSubpage();
1508 $validUserPage = !$title->isSubpage();
1512 $this->getHookRunner()->onShowMissingArticle( $this );
1514 # Show delete and move logs if there were any such events.
1515 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1516 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1517 $dbCache = MediaWikiServices::getInstance()->getMainObjectStash();
1518 $key = $dbCache->makeKey(
'page-recent-delete', md5( $title->getPrefixedText() ) );
1519 $isRegistered = $contextUser->isRegistered();
1520 $sessionExists = $context->getRequest()->getSession()->isPersistent();
1522 if ( $isRegistered || $dbCache->get( $key ) || $sessionExists ) {
1523 $logTypes = [
'delete',
'move',
'protect' ];
1525 $dbr = $this->dbProvider->getReplicaDatabase();
1527 $conds = [ $dbr->expr(
'log_action',
'!=',
'revision' ) ];
1529 $this->getHookRunner()->onArticle__MissingArticleConditions( $conds, $logTypes );
1530 LogEventsList::showLogExtract(
1538 'showIfEmpty' =>
false,
1539 'msgKey' => [ $isRegistered || $sessionExists
1540 ?
'moveddeleted-notice'
1541 :
'moveddeleted-notice-recent'
1547 if ( !$this->mPage->hasViewableContent() && $send404Code && !$validUserPage ) {
1550 $context->getRequest()->response()->statusHeader( 404 );
1554 $policy = $this->getRobotPolicy(
'view' );
1558 $hookResult = $this->getHookRunner()->onBeforeDisplayNoArticleText( $this );
1560 if ( !$hookResult ) {
1564 # Show error message
1565 $oldid = $this->getOldID();
1566 if ( !$oldid && $title->getNamespace() ===
NS_MEDIAWIKI && $title->hasSourceText() ) {
1567 $text = $this->
getTitle()->getDefaultMessageText() ??
'';
1571 $text = $this->getMissingRevisionMsg( $oldid )->plain();
1572 } elseif ( $context->getAuthority()->probablyCan(
'edit', $title ) ) {
1573 $message = $isRegistered ?
'noarticletext' :
'noarticletextanon';
1574 $text = $context->msg( $message )->plain();
1576 $text = $context->msg(
'noarticletext-nopermission' )->plain();
1579 $dir = $context->getLanguage()->getDir();
1580 $lang = $context->getLanguage()->getHtmlCode();
1582 'class' =>
"noarticletext mw-content-$dir",
1585 ] ) .
"\n$text\n</div>" );
1593 private function showViewError(
string $errortext ) {
1609 if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1615 $titleText = $this->
getTitle()->getPrefixedDBkey();
1617 if ( !$this->mRevisionRecord->userCan(
1618 RevisionRecord::DELETED_TEXT,
1619 $this->getContext()->getAuthority()
1623 $outputPage->
msg(
'rev-deleted-text-permission', $titleText )->parse(),
1631 # Give explanation and add a link to view the revision...
1632 $oldid = intval( $this->getOldID() );
1633 $link = $this->
getTitle()->getFullURL(
"oldid={$oldid}&unhide=1" );
1634 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1635 'rev-suppressed-text-unhide' :
'rev-deleted-text-unhide';
1638 $outputPage->
msg( $msg, $link )->parse(),
1646 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED )
1647 ? [
'rev-suppressed-text-view', $titleText ]
1648 : [
'rev-deleted-text-view', $titleText ];
1651 $outputPage->
msg( $msg[0], $msg[1] )->parse(),
1669 if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
1674 $unhide = $context->getRequest()->getInt(
'unhide' ) === 1;
1676 # Cascade unhide param in links for easy deletion browsing
1679 $extraParams[
'unhide'] = 1;
1682 if ( $this->mRevisionRecord && $this->mRevisionRecord->getId() === $oldid ) {
1683 $revisionRecord = $this->mRevisionRecord;
1685 $revisionRecord = $this->revisionStore->getRevisionById( $oldid );
1687 if ( !$revisionRecord ) {
1688 throw new LogicException(
'There should be a revision record at this point.' );
1691 $timestamp = $revisionRecord->getTimestamp();
1693 $current = ( $oldid == $this->mPage->getLatest() );
1694 $language = $context->getLanguage();
1695 $user = $context->getUser();
1697 $td = $language->userTimeAndDate( $timestamp, $user );
1698 $tddate = $language->userDate( $timestamp, $user );
1699 $tdtime = $language->userTime( $timestamp, $user );
1701 # Show user links if allowed to see them. If hidden, then show them only if requested...
1702 $userlinks = Linker::revUserTools( $revisionRecord, !$unhide );
1704 $infomsg = $current && !$context->msg(
'revision-info-current' )->isDisabled()
1705 ?
'revision-info-current'
1710 'mediawiki.action.styles',
1711 'mediawiki.interface.helpers.styles'
1714 $revisionUser = $revisionRecord->getUser();
1715 $revisionInfo =
"<div id=\"mw-{$infomsg}\">" .
1716 $context->msg( $infomsg, $td )
1717 ->rawParams( $userlinks )
1719 $revisionRecord->getId(),
1722 $revisionUser ? $revisionUser->getName() :
''
1724 ->rawParams( $this->commentFormatter->formatRevision(
1734 ? $context->msg(
'currentrevisionlink' )->escaped()
1735 : $this->linkRenderer->makeKnownLink(
1737 $context->msg(
'currentrevisionlink' )->text(),
1742 ? $context->msg(
'diff' )->escaped()
1743 : $this->linkRenderer->makeKnownLink(
1745 $context->msg(
'diff' )->text(),
1752 $prevExist = (bool)$this->revisionStore->getPreviousRevision( $revisionRecord );
1753 $prevlink = $prevExist
1754 ? $this->linkRenderer->makeKnownLink(
1756 $context->msg(
'previousrevision' )->text(),
1759 'direction' =>
'prev',
1763 : $context->msg(
'previousrevision' )->escaped();
1764 $prevdiff = $prevExist
1765 ? $this->linkRenderer->makeKnownLink(
1767 $context->msg(
'diff' )->text(),
1774 : $context->msg(
'diff' )->escaped();
1775 $nextlink = $current
1776 ? $context->msg(
'nextrevision' )->escaped()
1777 : $this->linkRenderer->makeKnownLink(
1779 $context->msg(
'nextrevision' )->text(),
1782 'direction' =>
'next',
1786 $nextdiff = $current
1787 ? $context->msg(
'diff' )->escaped()
1788 : $this->linkRenderer->makeKnownLink(
1790 $context->msg(
'diff' )->text(),
1798 $cdel = Linker::getRevDeleteLink(
1799 $context->getAuthority(),
1803 if ( $cdel !==
'' ) {
1811 "<div id=\"mw-revision-nav\">" . $cdel .
1812 $context->msg(
'revision-nav' )->rawParams(
1813 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1814 )->escaped() .
"</div>",
1835 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1849 $msg = $out->msg(
'namespace-' . $this->
getTitle()->getNamespace() .
'-helppage' );
1851 if ( !$msg->isDisabled() ) {
1852 $title = Title::newFromText( $msg->plain() );
1853 if ( $title instanceof
Title ) {
1854 $out->addHelpLink( $title->getLocalURL(),
true );
1857 $out->addHelpLink( $to, $overrideBaseUrl );
1865 $this->
getContext()->getRequest()->response()->header(
'X-Robots-Tag: noindex' );
1866 $this->
getContext()->getOutput()->setArticleBodyOnly(
true );
1868 $this->viewIsRenderAction =
true;
1897 static $called =
false;
1900 wfDebug(
"Article::tryFileCache(): called twice!?" );
1905 if ( $this->isFileCacheable() ) {
1907 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1908 wfDebug(
"Article::tryFileCache(): about to load file" );
1909 $cache->loadFromFileCache( $this->
getContext() );
1912 wfDebug(
"Article::tryFileCache(): starting buffer" );
1913 ob_start( [ &$cache,
'saveToFileCache' ] );
1916 wfDebug(
"Article::tryFileCache(): not cacheable" );
1930 if ( HTMLFileCache::useFileCache( $this->
getContext(), $mode ) ) {
1931 $cacheable = $this->mPage->getId()
1932 && !$this->mRedirectedFrom && !$this->
getTitle()->isRedirect();
1935 $cacheable = $this->getHookRunner()->onIsFileCacheable( $this ) ??
false;
1954 if ( $user ===
null ) {
1955 $parserOptions = $this->getParserOptions();
1957 $parserOptions = $this->mPage->makeParserOptions( $user );
1961 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1969 $parserOptions = $this->mPage->makeParserOptions( $this->
getContext() );
1971 return $parserOptions;
1981 $this->mContext = $context;
1992 return $this->mContext;
1994 wfDebug( __METHOD__ .
" called and \$mContext is null. " .
1995 "Return RequestContext::getMain()" );
1996 return RequestContext::getMain();
2006 return $this->mPage->getActionOverrides();
2009 private function getMissingRevisionMsg(
int $oldid ): Message {
2014 $revRecord = $this->archivedRevisionLookup->getArchivedRevisionRecord(
null, $oldid );
2017 $revRecord->userCan(
2018 RevisionRecord::DELETED_TEXT,
2019 $context->getAuthority()
2021 $context->getAuthority()->isAllowedAny(
'deletedtext',
'undelete' )
2023 return $context->msg(
2024 'missing-revision-permission',
2026 $revRecord->getTimestamp(),
2027 Title::newFromPageIdentity( $revRecord->getPage() )->getPrefixedDBkey()
2030 return $context->msg(
'missing-revision', $oldid );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
Legacy class representing an editable page and handling UI for some page actions.
static newFromWikiPage(WikiPage $page, IContextSource $context)
Create an Article object of the appropriate class for the given page.
getContext()
Gets the context this Article is executed in.
getOldIDFromRequest()
Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect.
getRedirectedFrom()
Get the page this view was redirected from.
Title null $mRedirectedFrom
Title from which we were redirected here, if any.
bool $viewIsRenderAction
Whether render() was called.
view()
This is the default action of the index.php entry point: just view the page of the given title.
__construct(Title $title, $oldId=null)
getRobotPolicy( $action, ParserOutput $pOutput=null)
Get the robot policy to be used for the current view.
static purgePatrolFooterCache( $articleID)
Purge the cache used to check if it is worth showing the patrol footer For example,...
ParserOutput null false $mParserOutput
The ParserOutput generated for viewing the page, initialized by view().
LinkRenderer $linkRenderer
getTitle()
Get the title object of the article.
getActionOverrides()
Call to WikiPage function for backwards compatibility.
adjustDisplayTitle(ParserOutput $pOutput)
Adjust title for pages with displaytitle, -{T|}- or language conversion.
DatabaseBlockStore $blockStore
showDeletedRevisionHeader()
If the revision requested for view is deleted, check permissions.
getParserOptions()
Get parser options suitable for rendering the primary article wikitext.
IContextSource null $mContext
The context this Article is executed in.
static getRedirectHeaderHtml(Language $lang, Title $target, $forceKnown=false)
Return the HTML for the top of a redirect page.
getParserOutput( $oldid=null, UserIdentity $user=null)
Lightweight method to get the parser output for a page, checking the parser cache and so on.
protect()
action=protect handler
string false $mRedirectUrl
URL to redirect to or false if none.
isCurrent()
Returns true if the currently-referenced revision is the current edit to this page (and it exists).
showMissingArticle()
Show the error text for a missing article.
IConnectionProvider $dbProvider
unprotect()
action=unprotect handler (alias)
getPage()
Get the WikiPage object of this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static newFromID( $id)
Constructor from a page id.
int null $mOldId
The oldid of the article that was requested to be shown, 0 for the current revision.
static formatRobotPolicy( $policy)
Converts a String robot policy into an associative array, to allow merging of several policies using ...
fetchRevisionRecord()
Fetches the revision to work on.
showPatrolFooter()
If patrol is possible, output a patrol UI box.
setOldSubtitle( $oldid=0)
Generate the navigation links when browsing through an article revisions It shows the information as:...
showViewFooter()
Show the footer section of an ordinary page view.
WikiPage $mPage
The WikiPage object of this instance.
setRedirectedFrom(Title $from)
Tell the page view functions that this view was redirected from another page on the wiki.
isFileCacheable( $mode=HTMLFileCache::MODE_NORMAL)
Check if the page can be cached.
tryFileCache()
checkLastModified returns true if it has taken care of all output to the client that is necessary for...
getRevIdFetched()
Use this to fetch the rev ID used on page views.
showNamespaceHeader()
Show a header specific to the namespace currently being viewed, like [[MediaWiki:Talkpagetext]].
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
showDiffPage()
Show a diff page according to current request variables.
render()
Handle action=render.
showRedirectedFromHeader()
If this request is a redirect view, send "redirected from" subtitle to the output.
setContext( $context)
Sets the context this Article is executed in.
Special handling for category description pages.
Page view caching in the file system.
Rendering of file description pages.
Handle enqueueing of background jobs.
Base class for language-specific code.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Group all the pieces relevant to the context of a request into one instance.
The HTML user interface for page editing.
A class containing constants representing the names of configuration variables.
This is one of the Core classes and should be read at least once by any new developers.
parseAsContent( $text, $linestart=true)
Parse wikitext in the page content language and return the HTML.
disableClientCache()
Force the page to send nocache headers.
addJsConfigVars( $keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
wrapWikiMsg( $wrap,... $msgSpecs)
This function takes a number of message/argument specifications, wraps them in some overall structure...
setIndexPolicy( $policy)
Set the index policy for the page, but leave the follow policy un- touched.
setPreventClickjacking(bool $enable)
Set the prevent-clickjacking flag.
disable()
Disable output completely, i.e.
setRedirectedFrom(PageReference $t)
Set $mRedirectedFrom, the page which redirected us to the current page.
setRevisionTimestamp( $timestamp)
Set the timestamp of the revision which will be displayed.
adaptCdnTTL( $mtime, $minTTL=0, $maxTTL=0)
Get TTL in [$minTTL,$maxTTL] and pass it to lowerCdnMaxage()
addBodyClasses( $classes)
Add a class to the <body> element.
lowerCdnMaxage( $maxage)
Set the value of the "s-maxage" part of the "Cache-control" HTTP header to $maxage if that is lower t...
setContentLangForJS(Bcp47Code $lang)
setLastModified( $timestamp)
Override the last modified timestamp.
setRevisionIsCurrent(bool $isCurrent)
Set whether the revision displayed (as set in ::setRevisionId()) is the latest revision of the page.
setFollowPolicy( $policy)
Set the follow policy for the page, but leave the index policy un- touched.
clearHTML()
Clear the body HTML.
setPageTitle( $name)
"Page title" means the contents of <h1>.
setPageTitleMsg(Message $msg)
"Page title" means the contents of <h1>.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
redirect( $url, $responsecode='302')
Redirect to $url rather than displaying the normal page.
setHTMLTitle( $name)
"HTML title" means the contents of "<title>".
prependHTML( $text)
Prepend $text to the body HTML.
setRobotPolicy( $policy)
Set the robot policy for the page: http://www.robotstxt.org/meta.html
setCanonicalUrl( $url)
Set the URL to be used for the <link rel=canonical>>.
addWikiTextAsContent( $text, $linestart=true, PageReference $title=null)
Convert wikitext in the page content language to HTML and add it to the buffer.
addHTML( $text)
Append $text to the body HTML.
setRevisionId( $revid)
Set the revision ID which will be seen by the wiki text parser for things such as embedded {{REVISION...
addSubtitle( $str)
Add $str to the subtitle.
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.
addParserOutput(ParserOutput $parserOutput, $poOptions=[])
Add everything from a ParserOutput object.
isPrintable()
Return whether the page is "printable".
setArticleFlag( $newVal)
Set whether the displayed content is related to the source of the corresponding article on the wiki S...
addWikiTextAsInterface( $text, $linestart=true, PageReference $title=null)
Convert wikitext in the user interface language to HTML and add it to the buffer.
Service for getting rendered output of a given page.
Handles the page protection UI and backend.
Service for creating WikiPage objects.
Set options of the Parser.
setIsPrintable( $x)
Parsing the printable version of the page?
setRenderReason(string $renderReason)
Sets reason for rendering the content.
static newSpec(int $revisionId, PageRecord $page, array $params=[])
Show an error when a user tries to do something they do not have the necessary permissions for.
hasMessage( $message)
Returns true if the specified message is present as a warning or error.
isOK()
Returns whether the operation completed.
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Base representation for an editable wiki page.
getTitle()
Get the title object of the article.
Interface for objects which can provide a MediaWiki context on request.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)