25 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
44 use Wikimedia\IPUtils;
45 use Wikimedia\NonSerializable\NonSerializableTrait;
57 use ProtectedHookAccessorTrait;
58 use NonSerializableTrait;
86 private $fetchResult =
null;
110 private $revisionStore;
115 private $userNameUtils;
120 private $userOptionsLookup;
123 private $commentFormatter;
126 private $wikiPageFactory;
129 private $jobQueueGroup;
137 private $mRevisionRecord =
null;
144 $this->mOldId = $oldId;
145 $this->mPage = $this->
newPage( $title );
147 $services = MediaWikiServices::getInstance();
148 $this->linkRenderer = $services->getLinkRenderer();
149 $this->revisionStore = $services->getRevisionStore();
150 $this->userNameUtils = $services->getUserNameUtils();
151 $this->userOptionsLookup = $services->getUserOptionsLookup();
152 $this->commentFormatter = $services->getCommentFormatter();
153 $this->wikiPageFactory = $services->getWikiPageFactory();
154 $this->jobQueueGroup = $services->getJobQueueGroup();
171 $t = Title::newFromID( $id );
172 return $t ===
null ? null :
new static(
$t );
189 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
191 ->onArticleFromTitle(
$title, $page, $context );
193 switch (
$title->getNamespace() ) {
204 $page->setContext( $context );
217 $article = self::newFromTitle( $page->
getTitle(), $context );
218 $article->mPage = $page;
228 return $this->mRedirectedFrom;
237 $this->mRedirectedFrom = $from;
246 return $this->mPage->getTitle();
260 $this->mRedirectedFrom =
null; #
Title object if set
261 $this->mRedirectUrl =
false;
262 $this->mRevisionRecord =
null;
263 $this->fetchResult =
null;
267 $this->mPage->clear();
278 if ( $this->mOldId ===
null ) {
279 $this->mOldId = $this->getOldIDFromRequest();
282 return $this->mOldId;
291 $this->mRedirectUrl =
false;
294 $oldid = $request->getIntOrNull(
'oldid' );
296 if ( $oldid ===
null ) {
300 if ( $oldid !== 0 ) {
301 # Load the given revision and check whether the page is another one.
302 # In that case, update this instance to reflect the change.
303 if ( $oldid === $this->mPage->getLatest() ) {
304 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
306 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
307 if ( $this->mRevisionRecord !==
null ) {
308 $revPageId = $this->mRevisionRecord->getPageId();
310 if ( $this->mPage->getId() !== $revPageId ) {
311 $this->mPage = $this->wikiPageFactory->newFromID( $revPageId );
317 $oldRev = $this->mRevisionRecord;
318 if ( $request->getRawVal(
'direction' ) ===
'next' ) {
321 $nextRev = $this->revisionStore->getNextRevision( $oldRev );
323 $nextid = $nextRev->getId();
328 $this->mRevisionRecord =
null;
330 $this->mRedirectUrl = $this->
getTitle()->getFullURL(
'redirect=no' );
332 } elseif ( $request->getRawVal(
'direction' ) ===
'prev' ) {
335 $prevRev = $this->revisionStore->getPreviousRevision( $oldRev );
337 $previd = $prevRev->getId();
342 $this->mRevisionRecord =
null;
359 if ( $this->fetchResult ) {
360 return $this->mRevisionRecord;
363 $oldid = $this->getOldID();
366 if ( !$this->mRevisionRecord ) {
368 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
370 if ( !$this->mRevisionRecord ) {
371 wfDebug( __METHOD__ .
" failed to find page data for title " .
372 $this->
getTitle()->getPrefixedText() );
379 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
381 if ( !$this->mRevisionRecord ) {
382 wfDebug( __METHOD__ .
" failed to load revision, rev_id $oldid" );
390 if ( !$this->mRevisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getContext()->getAuthority() ) ) {
391 wfDebug( __METHOD__ .
" failed to retrieve content of revision " . $this->mRevisionRecord->getId() );
395 $this->fetchResult =
new Status;
398 if ( $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
399 $this->fetchResult->fatal(
'rev-suppressed-text' );
401 $this->fetchResult->fatal(
'rev-deleted-text-permission',
$title );
408 return $this->mRevisionRecord;
417 # If no oldid, this is the current version.
418 if ( $this->getOldID() == 0 ) {
422 return $this->mPage->exists() &&
423 $this->mRevisionRecord &&
424 $this->mRevisionRecord->isCurrent();
436 if ( $this->fetchResult && $this->fetchResult->isOK() ) {
438 $rev = $this->fetchResult->getValue();
439 return $rev->
getId();
441 return $this->mPage->getLatest();
451 $useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache );
453 # Get variables from query string
454 # As side effect this will load the revision and update the title
455 # in a revision ID is passed in the request, so this should remain
456 # the first call of this method even if $oldid is used way below.
457 $oldid = $this->getOldID();
459 $authority = $context->getAuthority();
460 # Another check in case getOldID() is altering the title
461 $permissionStatus = PermissionStatus::newEmpty();
463 ->authorizeRead(
'read', $this->
getTitle(), $permissionStatus )
465 wfDebug( __METHOD__ .
": denied on secondary read check" );
470 # getOldID() may as well want us to redirect somewhere else
471 if ( $this->mRedirectUrl ) {
472 $outputPage->
redirect( $this->mRedirectUrl );
473 wfDebug( __METHOD__ .
": redirecting due to oldid" );
478 # If we got diff in the query, we want to see a diff page instead of the article.
479 if ( $context->getRequest()->getCheck(
'diff' ) ) {
480 wfDebug( __METHOD__ .
": showing diff page" );
481 $this->showDiffPage();
486 # Set page title (may be overridden from ParserOutput if title conversion is enabled or DISPLAYTITLE is used)
488 str_replace(
'_',
' ', $this->
getTitle()->getNsText() ),
494 # Allow frames by default
497 $parserOptions = $this->getParserOptions();
500 # Allow extensions to vary parser options used for article rendering
501 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
502 ->onArticleParserOptions( $this, $parserOptions );
503 # Render printable version, use printable version cache
506 $poOptions[
'enableSectionEditLinks'] =
false;
509 $outputPage->
msg(
'printableversion-deprecated-warning' )->escaped()
512 } elseif ( $this->viewIsRenderAction || !$this->isCurrent() ||
513 !$authority->probablyCan(
'edit', $this->getTitle() )
515 $poOptions[
'enableSectionEditLinks'] =
false;
518 # Try client and file cache
519 if ( $oldid === 0 && $this->mPage->checkTouched() ) {
520 # Try to stream the output from file cache
521 if ( $useFileCache && $this->tryFileCache() ) {
522 wfDebug( __METHOD__ .
": done file cache" );
523 # tell wgOut that output is taken care of
525 $this->mPage->doViewUpdates( $authority, $oldid );
531 $this->showRedirectedFromHeader();
532 $this->showNamespaceHeader();
534 if ( $this->viewIsRenderAction ) {
535 $poOptions += [
'absoluteURLs' =>
true ];
537 $poOptions += [
'includeDebugInfo' =>
true ];
541 $this->generateContentOutput( $authority, $parserOptions, $oldid, $outputPage, $poOptions );
544 $this->showViewError(
wfMessage(
'badrevision' )->text() );
551 # For the main page, overwrite the <title> element with the con-
552 # tents of 'pagetitle-view-mainpage' instead of the default (if
554 # This message always exists because it is in the i18n files
555 if ( $this->
getTitle()->isMainPage() ) {
556 $msg = $context->msg(
'pagetitle-view-mainpage' )->inContentLanguage();
557 if ( !$msg->isDisabled() ) {
562 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
563 # This could use getTouched(), but that could be scary for major template edits.
564 $outputPage->
adaptCdnTTL( $this->mPage->getTimestamp(), IExpiringStore::TTL_DAY );
566 $this->showViewFooter();
567 $this->mPage->doViewUpdates( $authority, $oldid, $this->fetchRevisionRecord() );
569 # Load the postEdit module if the user just saved this revision
570 # See also EditPage::setPostEditCookie
571 $request = $context->getRequest();
572 $cookieKey = EditPage::POST_EDIT_COOKIE_KEY_PREFIX . $this->getRevIdFetched();
573 $postEdit = $request->getCookie( $cookieKey );
575 # Clear the cookie. This also prevents caching of the response.
576 $request->response()->clearCookie( $cookieKey );
578 $outputPage->
addModules(
'mediawiki.action.view.postEdit' );
594 private function generateContentOutput(
601 # Should the parser cache be used?
602 $useParserCache =
true;
604 $parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
607 $this->getHookRunner()->onArticleViewHeader( $this, $outputDone, $useParserCache );
610 $pOutput = $outputDone;
614 $this->doOutputMetaData( $pOutput, $outputPage );
620 if ( !$this->mPage->exists() ) {
621 wfDebug( __METHOD__ .
": showing missing article" );
622 $this->showMissingArticle();
623 $this->mPage->doViewUpdates( $performer );
629 if ( $useParserCache && !$oldid ) {
630 $pOutput = $parserOutputAccess->getCachedParserOutput(
634 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
638 $this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions );
639 $this->doOutputMetaData( $pOutput, $outputPage );
644 $rev = $this->fetchRevisionRecord();
645 if ( !$this->fetchResult->isOK() ) {
646 $this->showViewError( $this->fetchResult->getWikiText(
647 false,
false, $this->getContext()->getLanguage()
652 # Are we looking at an old revision
654 $this->setOldSubtitle( $oldid );
656 if ( !$this->showDeletedRevisionHeader() ) {
657 wfDebug( __METHOD__ .
": cannot view deleted revision" );
664 if ( $useParserCache ) {
665 $pOutput = $parserOutputAccess->getCachedParserOutput(
669 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
673 $this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions );
674 $this->doOutputMetaData( $pOutput, $outputPage );
680 # Ensure that UI elements requiring revision ID have
681 # the correct version information.
684 # Preload timestamp to avoid a DB hit
687 # Pages containing custom CSS or JavaScript get special treatment
688 if ( $this->
getTitle()->isSiteConfigPage() || $this->
getTitle()->isUserConfigPage() ) {
689 $dir = $this->
getContext()->getLanguage()->getDir();
693 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
697 } elseif ( !$this->getHookRunner()->onArticleRevisionViewCustom(
705 $this->doOutputMetaData( $pOutput, $outputPage );
709 # Run the parse, protected by a pool counter
710 wfDebug( __METHOD__ .
": doing uncached parse" );
715 $opt |= ParserOutputAccess::OPT_NO_CHECK_CACHE;
718 $opt |= ParserOutputAccess::OPT_NO_AUDIENCE_CHECK;
723 $opt |= ParserOutputAccess::OPT_LINKS_UPDATE;
725 if ( !$rev->
getId() || !$useParserCache ) {
727 $opt |= ParserOutputAccess::OPT_NO_CACHE;
730 $renderStatus = $parserOutputAccess->getParserOutput(
752 if ( $oldid === 0 || $oldid === $this->getPage()->getLatest() ) {
753 $parsoidCacheWarmingEnabled = $this->
getContext()->getConfig()
754 ->get( MainConfigNames::ParsoidCacheConfig )[
'WarmParsoidParserCache'];
756 if ( $parsoidCacheWarmingEnabled ) {
760 [
'causeAction' =>
'view' ]
762 $this->jobQueueGroup->lazyPush( $parsoidJobSpec );
766 $this->doOutputFromRenderStatus(
773 if ( !$renderStatus->
isOK() ) {
777 $pOutput = $renderStatus->
getValue();
778 $this->doOutputMetaData( $pOutput, $outputPage );
787 # Adjust title for main page & pages with displaytitle
789 $this->adjustDisplayTitle( $pOutput );
792 # Check for any __NOINDEX__ tags on the page using $pOutput
793 $policy = $this->getRobotPolicy(
'view', $pOutput ?:
null );
797 $this->mParserOutput = $pOutput;
805 private function doOutputFromParserCache(
810 # Ensure that UI elements requiring revision ID have
811 # the correct version information.
816 # Preload timestamp to avoid a DB hit
818 if ( $cachedTimestamp !==
null ) {
820 $this->mPage->setTimestamp( $cachedTimestamp );
830 private function doOutputFromRenderStatus(
837 $cdnMaxageStale = $context->getConfig()->get( MainConfigNames::CdnMaxageStale );
838 $ok = $renderStatus->
isOK();
840 $pOutput = $ok ? $renderStatus->
getValue() :
null;
843 if ( $ok && $renderStatus->
hasMessage(
'view-pool-dirty-output' ) ) {
846 $staleReason = $renderStatus->
hasMessage(
'view-pool-contention' )
847 ? $context->msg(
'view-pool-contention' )
848 : $context->msg(
'view-pool-timeout' );
849 $outputPage->
addHTML(
"<!-- parser cache is expired, " .
850 "sending anyway due to $staleReason-->\n" );
853 if ( !$renderStatus->
isOK() ) {
855 false,
'view-pool-error', $context->getLanguage()
864 if ( $this->getRevisionRedirectTarget( $rev ) ) {
865 $outputPage->
addSubtitle(
"<span id=\"redirectsub\">" .
866 $context->msg(
'redirectpagesub' )->parse() .
"</span>" );
874 private function getRevisionRedirectTarget(
RevisionRecord $revision ) {
889 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
891 if ( strval( $titleText ) !==
'' ) {
892 $out->setPageTitle( $titleText );
893 $out->setDisplayTitle( $titleText );
903 $request = $context->getRequest();
904 $diff = $request->getVal(
'diff' );
905 $rcid = $request->getInt(
'rcid' );
906 $purge = $request->getRawVal(
'action' ) ===
'purge';
907 $unhide = $request->getInt(
'unhide' ) === 1;
908 $oldid = $this->getOldID();
910 $rev = $this->fetchRevisionRecord();
915 $rev = $this->revisionStore->getRevisionById( $oldid );
921 $context->getOutput()->setPageTitle( $context->msg(
'errorpagetitle' ) );
922 $msg = $context->msg(
'difference-missing-revision' )
926 $context->getOutput()->addHTML( $msg );
931 $contentHandler = MediaWikiServices::getInstance()
932 ->getContentHandlerFactory()
934 $rev->
getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
936 $de = $contentHandler->createDifferenceEngine(
944 $de->setSlotDiffOptions( [
945 'diff-type' => $request->getVal(
'diff-type' ),
946 'expand-url' => $this->viewIsRenderAction
948 $de->showDiffPage( $this->isDiffOnlyView() );
952 [ , $new ] = $de->mapDiffPrevNext( $oldid, $diff );
954 $this->mPage->doViewUpdates( $context->getAuthority(), (
int)$new );
957 $context->getOutput()->addHelpLink(
'Help:Diff' );
961 return $this->
getContext()->getRequest()->getBool(
963 $this->userOptionsLookup->getBoolOption( $this->getContext()->getUser(),
'diffonly' )
976 $mainConfig = $context->getConfig();
977 $articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies );
978 $namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies );
979 $defaultRobotPolicy = $mainConfig->get( MainConfigNames::DefaultRobotPolicy );
981 $ns =
$title->getNamespace();
983 # Don't index user and user talk pages for blocked users (T13443)
985 $specificTarget =
null;
987 $titleText =
$title->getText();
988 if ( IPUtils::isValid( $titleText ) ) {
989 $vagueTarget = $titleText;
991 $specificTarget = $titleText;
993 if ( DatabaseBlock::newFromTarget( $specificTarget, $vagueTarget ) instanceof
DatabaseBlock ) {
995 'index' =>
'noindex',
996 'follow' =>
'nofollow'
1001 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
1002 # Non-articles (special pages etc), and old revisions
1004 'index' =>
'noindex',
1005 'follow' =>
'nofollow'
1007 } elseif ( $context->getOutput()->isPrintable() ) {
1008 # Discourage indexing of printable versions, but encourage following
1010 'index' =>
'noindex',
1011 'follow' =>
'follow'
1013 } elseif ( $context->getRequest()->getInt(
'curid' ) ) {
1014 # For ?curid=x urls, disallow indexing
1016 'index' =>
'noindex',
1017 'follow' =>
'follow'
1021 # Otherwise, construct the policy based on the various config variables.
1022 $policy = self::formatRobotPolicy( $defaultRobotPolicy );
1024 if ( isset( $namespaceRobotPolicies[$ns] ) ) {
1025 # Honour customised robot policies for this namespace
1026 $policy = array_merge(
1028 self::formatRobotPolicy( $namespaceRobotPolicies[$ns] )
1032 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
1033 # a final check that we have really got the parser output.
1034 $policy = array_merge(
1040 if ( isset( $articleRobotPolicies[
$title->getPrefixedText()] ) ) {
1041 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
1042 $policy = array_merge(
1044 self::formatRobotPolicy( $articleRobotPolicies[
$title->getPrefixedText()] )
1059 if ( is_array( $policy ) ) {
1061 } elseif ( !$policy ) {
1066 foreach ( explode(
',', $policy ) as $var ) {
1067 $var = trim( $var );
1068 if ( $var ===
'index' || $var ===
'noindex' ) {
1069 $arr[
'index'] = $var;
1070 } elseif ( $var ===
'follow' || $var ===
'nofollow' ) {
1071 $arr[
'follow'] = $var;
1087 $redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources );
1089 $request = $context->getRequest();
1090 $rdfrom = $request->getVal(
'rdfrom' );
1093 $query = $request->getValues();
1094 unset( $query[
'rdfrom'] );
1095 unset( $query[
'title'] );
1096 if ( $this->
getTitle()->isRedirect() ) {
1098 $query[
'redirect'] =
'no';
1100 $redirectTargetUrl = $this->
getTitle()->getLinkURL( $query );
1102 if ( isset( $this->mRedirectedFrom ) ) {
1105 if ( $this->getHookRunner()->onArticleViewRedirect( $this ) ) {
1106 $redir = $this->linkRenderer->makeKnownLink(
1107 $this->mRedirectedFrom,
1110 [
'redirect' =>
'no' ]
1113 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1114 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1120 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1122 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1132 } elseif ( $rdfrom ) {
1135 if ( $redirectSources && preg_match( $redirectSources, $rdfrom ) ) {
1136 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1137 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1138 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1143 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1145 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1159 if ( $this->
getTitle()->isTalkPage() && !$this->
getContext()->msg(
'talkpageheader' )->isDisabled() ) {
1160 $this->
getContext()->getOutput()->wrapWikiMsg(
1161 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1162 [
'talkpageheader' ]
1171 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1173 && IPUtils::isValid( $this->
getTitle()->getText() )
1175 $this->
getContext()->getOutput()->addWikiMsg(
'anontalkpagetext' );
1179 $patrolFooterShown = $this->showPatrolFooter();
1181 $this->getHookRunner()->onArticleViewFooter( $this, $patrolFooterShown );
1196 $mainConfig = $context->getConfig();
1197 $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
1198 $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
1199 $useFilePatrol = $mainConfig->get( MainConfigNames::UseFilePatrol );
1201 if ( !$this->getHookRunner()->onArticleShowPatrolFooter( $this ) ) {
1206 $user = $context->getUser();
1210 if ( !$context->getAuthority()->probablyCan(
'patrol',
$title )
1211 || !( $useRCPatrol || $useNPPatrol
1218 if ( $this->mRevisionRecord
1227 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1228 $key = $cache->makeKey(
'unpatrollable-page',
$title->getArticleID() );
1229 if ( $cache->get( $key ) ) {
1234 $oldestRevisionRow =
$dbr->selectRow(
1236 [
'rev_id',
'rev_timestamp' ],
1237 [
'rev_page' =>
$title->getArticleID() ],
1239 [
'ORDER BY' => [
'rev_timestamp',
'rev_id' ] ]
1241 $oldestRevisionTimestamp = $oldestRevisionRow ? $oldestRevisionRow->rev_timestamp :
false;
1247 $recentPageCreation =
false;
1248 if ( $oldestRevisionTimestamp
1252 $recentPageCreation =
true;
1255 'rc_this_oldid' => intval( $oldestRevisionRow->rev_id ),
1263 $markPatrolledMsg = $context->msg(
'markaspatrolledtext' );
1271 $recentFileUpload =
false;
1272 if ( ( !$rc || $rc->getAttribute(
'rc_patrolled' ) ) && $useFilePatrol
1275 $newestUploadTimestamp =
$dbr->selectField(
1278 [
'img_name' =>
$title->getDBkey() ],
1281 if ( $newestUploadTimestamp
1285 $recentFileUpload =
true;
1289 'rc_log_type' =>
'upload',
1290 'rc_timestamp' => $newestUploadTimestamp,
1292 'rc_cur_id' =>
$title->getArticleID()
1298 $markPatrolledMsg = $context->msg(
'markaspatrolledtext-file' );
1303 if ( !$recentPageCreation && !$recentFileUpload ) {
1308 $cache->set( $key,
'1' );
1320 if ( $rc->getAttribute(
'rc_patrolled' ) ) {
1325 $cache->set( $key,
'1' );
1330 if ( $rc->getPerformerIdentity()->equals( $user ) ) {
1337 if ( $context->getAuthority()->isAllowed(
'writeapi' ) ) {
1338 $outputPage->
addModules(
'mediawiki.misc-authed-curate' );
1341 $link = $this->linkRenderer->makeKnownLink(
1344 $markPatrolledMsg->text(),
1347 'action' =>
'markpatrolled',
1348 'rcid' => $rc->getAttribute(
'rc_id' ),
1354 "<div class='patrollink' data-mw='interface'>" .
1355 $context->msg(
'markaspatrolledlink' )->rawParams( $link )->escaped() .
1369 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1370 $cache->delete( $cache->makeKey(
'unpatrollable-page', $articleID ) );
1379 $send404Code = $context->getConfig()->get( MainConfigNames::Send404Code );
1383 $validUserPage =
false;
1387 $services = MediaWikiServices::getInstance();
1389 $contextUser = $context->getUser();
1391 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1395 $rootPart =
$title->getRootText();
1397 $ip = $this->userNameUtils->isIP( $rootPart );
1398 $block = DatabaseBlock::newFromTarget( $user, $user );
1400 if ( $user && $user->isRegistered() && $user->isHidden() &&
1401 !$context->getAuthority()->isAllowed(
'hideuser' )
1408 if ( !( $user && $user->isRegistered() ) && !$ip ) {
1410 $outputPage->
addHTML( Html::warningBox(
1411 $context->msg(
'userpage-userdoesnotexist-view',
wfEscapeWikiText( $rootPart ) )->parse(),
1412 'mw-userpage-userdoesnotexist'
1419 Title::makeTitleSafe(
NS_USER, $rootPart ),
1423 'showIfEmpty' =>
false,
1424 'msgKey' => [
'renameuser-renamed-notice',
$title->getBaseText() ]
1429 $block->getType() != DatabaseBlock::TYPE_AUTO &&
1431 $block->isSitewide() ||
1432 $services->getPermissionManager()->isBlockedFrom( $user,
$title,
true )
1440 $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
':' .
1441 $block->getTargetName(),
1445 'showIfEmpty' =>
false,
1447 'blocked-notice-logextract',
1448 $user->getName() # Support GENDER in notice
1452 $validUserPage = !
$title->isSubpage();
1454 $validUserPage = !
$title->isSubpage();
1458 $this->getHookRunner()->onShowMissingArticle( $this );
1460 # Show delete and move logs if there were any such events.
1461 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1462 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1463 $dbCache = MediaWikiServices::getInstance()->getMainObjectStash();
1464 $key = $dbCache->makeKey(
'page-recent-delete', md5(
$title->getPrefixedText() ) );
1465 $isRegistered = $contextUser->isRegistered();
1466 $sessionExists = $context->getRequest()->getSession()->isPersistent();
1468 if ( $isRegistered || $dbCache->get( $key ) || $sessionExists ) {
1469 $logTypes = [
'delete',
'move',
'protect' ];
1473 $conds = [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ];
1475 $this->getHookRunner()->onArticle__MissingArticleConditions( $conds, $logTypes );
1484 'showIfEmpty' =>
false,
1485 'msgKey' => [ $isRegistered || $sessionExists
1486 ?
'moveddeleted-notice'
1487 :
'moveddeleted-notice-recent'
1493 if ( !$this->mPage->hasViewableContent() && $send404Code && !$validUserPage ) {
1496 $context->getRequest()->response()->statusHeader( 404 );
1500 $policy = $this->getRobotPolicy(
'view' );
1504 $hookResult = $this->getHookRunner()->onBeforeDisplayNoArticleText( $this );
1506 if ( !$hookResult ) {
1510 # Show error message
1511 $oldid = $this->getOldID();
1513 $text = $this->
getTitle()->getDefaultMessageText() ??
'';
1520 $revRecord = $pa->getArchivedRevisionRecord( $oldid );
1521 if ( $revRecord && $revRecord->userCan(
1522 RevisionRecord::DELETED_TEXT,
1523 $context->getAuthority()
1525 $text = $context->msg(
1526 'missing-revision-permission', $oldid,
1527 $revRecord->getTimestamp(),
1528 $title->getPrefixedDBkey()
1531 $text = $context->msg(
'missing-revision', $oldid )->plain();
1534 } elseif ( $context->getAuthority()->probablyCan(
'edit',
$title ) ) {
1535 $message = $isRegistered ?
'noarticletext' :
'noarticletextanon';
1536 $text = $context->msg( $message )->plain();
1538 $text = $context->msg(
'noarticletext-nopermission' )->plain();
1541 $dir = $context->getLanguage()->getDir();
1542 $lang = $context->getLanguage()->getHtmlCode();
1544 'class' =>
"noarticletext mw-content-$dir",
1547 ] ) .
"\n$text\n</div>" );
1555 private function showViewError(
string $errortext ) {
1556 $outputPage = $this->
getContext()->getOutput();
1571 if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1575 $outputPage = $this->
getContext()->getOutput();
1577 $titleText = $this->
getTitle()->getPrefixedDBkey();
1579 if ( !$this->mRevisionRecord->userCan(
1580 RevisionRecord::DELETED_TEXT,
1581 $this->getContext()->getAuthority()
1585 $outputPage->
msg(
'rev-deleted-text-permission', $titleText )->parse(),
1593 # Give explanation and add a link to view the revision...
1594 $oldid = intval( $this->getOldID() );
1595 $link = $this->
getTitle()->getFullURL(
"oldid={$oldid}&unhide=1" );
1596 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1597 'rev-suppressed-text-unhide' :
'rev-deleted-text-unhide';
1600 $outputPage->
msg( $msg, $link )->parse(),
1608 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED )
1609 ? [
'rev-suppressed-text-view', $titleText ]
1610 : [
'rev-deleted-text-view', $titleText ];
1613 $outputPage->
msg( $msg[0], $msg[1] )->parse(),
1631 if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
1636 $unhide = $context->getRequest()->getInt(
'unhide' ) === 1;
1638 # Cascade unhide param in links for easy deletion browsing
1641 $extraParams[
'unhide'] = 1;
1644 if ( $this->mRevisionRecord && $this->mRevisionRecord->getId() === $oldid ) {
1645 $revisionRecord = $this->mRevisionRecord;
1647 $revisionRecord = $this->revisionStore->getRevisionById( $oldid );
1649 if ( !$revisionRecord ) {
1650 throw new LogicException(
'There should be a revision record at this point.' );
1653 $timestamp = $revisionRecord->getTimestamp();
1655 $current = ( $oldid == $this->mPage->getLatest() );
1656 $language = $context->getLanguage();
1657 $user = $context->getUser();
1659 $td = $language->userTimeAndDate( $timestamp, $user );
1660 $tddate = $language->userDate( $timestamp, $user );
1661 $tdtime = $language->userTime( $timestamp, $user );
1663 # Show user links if allowed to see them. If hidden, then show them only if requested...
1664 $userlinks = Linker::revUserTools( $revisionRecord, !$unhide );
1666 $infomsg = $current && !$context->msg(
'revision-info-current' )->isDisabled()
1667 ?
'revision-info-current'
1672 'mediawiki.action.styles',
1673 'mediawiki.interface.helpers.styles'
1676 $revisionUser = $revisionRecord->getUser();
1677 $revisionInfo =
"<div id=\"mw-{$infomsg}\">" .
1678 $context->msg( $infomsg, $td )
1679 ->rawParams( $userlinks )
1681 $revisionRecord->getId(),
1684 $revisionUser ? $revisionUser->getName() :
''
1686 ->rawParams( $this->commentFormatter->formatRevision(
1696 ? $context->msg(
'currentrevisionlink' )->escaped()
1697 : $this->linkRenderer->makeKnownLink(
1699 $context->msg(
'currentrevisionlink' )->text(),
1704 ? $context->msg(
'diff' )->escaped()
1705 : $this->linkRenderer->makeKnownLink(
1707 $context->msg(
'diff' )->text(),
1714 $prevExist = (bool)$this->revisionStore->getPreviousRevision( $revisionRecord );
1715 $prevlink = $prevExist
1716 ? $this->linkRenderer->makeKnownLink(
1718 $context->msg(
'previousrevision' )->text(),
1721 'direction' =>
'prev',
1725 : $context->msg(
'previousrevision' )->escaped();
1726 $prevdiff = $prevExist
1727 ? $this->linkRenderer->makeKnownLink(
1729 $context->msg(
'diff' )->text(),
1736 : $context->msg(
'diff' )->escaped();
1737 $nextlink = $current
1738 ? $context->msg(
'nextrevision' )->escaped()
1739 : $this->linkRenderer->makeKnownLink(
1741 $context->msg(
'nextrevision' )->text(),
1744 'direction' =>
'next',
1748 $nextdiff = $current
1749 ? $context->msg(
'diff' )->escaped()
1750 : $this->linkRenderer->makeKnownLink(
1752 $context->msg(
'diff' )->text(),
1760 $cdel = Linker::getRevDeleteLink(
1761 $context->getAuthority(),
1765 if ( $cdel !==
'' ) {
1773 "<div id=\"mw-revision-nav\">" . $cdel .
1774 $context->msg(
'revision-nav' )->rawParams(
1775 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1776 )->escaped() .
"</div>",
1795 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1797 $html =
'<ul class="redirectText">';
1798 if ( $forceKnown ) {
1804 $target->
isRedirect() ? [
'redirect' =>
'no' ] : []
1812 $target->
isRedirect() ? [
'redirect' =>
'no' ] : []
1815 $html .=
'<li>' . $link .
'</li>';
1818 $redirectToText =
wfMessage(
'redirectto' )->inLanguage(
$lang )->escaped();
1820 return '<div class="redirectMsg">' .
1821 '<p>' . $redirectToText .
'</p>' .
1836 $msg = $out->msg(
'namespace-' . $this->
getTitle()->getNamespace() .
'-helppage' );
1838 if ( !$msg->isDisabled() ) {
1839 $title = Title::newFromText( $msg->plain() );
1841 $out->addHelpLink(
$title->getLocalURL(),
true );
1844 $out->addHelpLink( $to, $overrideBaseUrl );
1852 $this->
getContext()->getRequest()->response()->header(
'X-Robots-Tag: noindex' );
1853 $this->
getContext()->getOutput()->setArticleBodyOnly(
true );
1855 $this->viewIsRenderAction =
true;
1884 static $called =
false;
1887 wfDebug(
"Article::tryFileCache(): called twice!?" );
1892 if ( $this->isFileCacheable() ) {
1894 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1895 wfDebug(
"Article::tryFileCache(): about to load file" );
1896 $cache->loadFromFileCache( $this->
getContext() );
1899 wfDebug(
"Article::tryFileCache(): starting buffer" );
1900 ob_start( [ &$cache,
'saveToFileCache' ] );
1903 wfDebug(
"Article::tryFileCache(): not cacheable" );
1918 $cacheable = $this->mPage->getId()
1919 && !$this->mRedirectedFrom && !$this->
getTitle()->isRedirect();
1922 $cacheable = $this->getHookRunner()->onIsFileCacheable( $this ) ??
false;
1943 if ( $user ===
null ) {
1944 $parserOptions = $this->getParserOptions();
1946 $parserOptions = $this->mPage->makeParserOptions( $user );
1950 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1958 $parserOptions = $this->mPage->makeParserOptions( $this->
getContext() );
1960 return $parserOptions;
1970 $this->mContext = $context;
1981 return $this->mContext;
1983 wfDebug( __METHOD__ .
" called and \$mContext is null. " .
1984 "Return RequestContext::getMain()" );
1999 wfDeprecatedMsg(
"Accessing Article::\$$fname is deprecated since MediaWiki 1.35",
2002 if ( property_exists( $this->mPage, $fname ) ) {
2003 return $this->mPage->$fname;
2005 trigger_error(
'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2017 public function __set( $fname, $fvalue ) {
2018 wfDeprecatedMsg(
"Setting Article::\$$fname is deprecated since MediaWiki 1.35",
2021 if ( property_exists( $this->mPage, $fname ) ) {
2022 $this->mPage->$fname = $fvalue;
2024 } elseif ( !in_array( $fname, [
'mContext',
'mPage' ] ) ) {
2025 $this->mPage->$fname = $fvalue;
2027 trigger_error(
'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2037 return $this->mPage->getActionOverrides();
2047 return $this->mPage->getTimestamp();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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.
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)
#-
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.
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.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Page view caching in the file system.
static useFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Check if pages can be cached for this request/user.
Rendering of file description pages.
Base class for language-specific code.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
The HTML user interface for page editing.
A class containing constants representing the names of configuration variables.
Service for getting rendered output of a given page.
Handles the page protection UI and backend.
Service for creating WikiPage objects.
This is one of the Core classes and should be read at least once by any new developers.
disable()
Disable output completely, i.e.
setArticleFlag( $newVal)
Set whether the displayed content is related to the source of the corresponding article on the wiki S...
setRobotPolicy( $policy)
Set the robot policy for the page: http://www.robotstxt.org/meta.html
setIndexPolicy( $policy)
Set the index policy for the page, but leave the follow policy un- touched.
setPageTitle( $name)
"Page title" means the contents of <h1>.
redirect( $url, $responsecode='302')
Redirect to $url rather than displaying the normal page.
setLastModified( $timestamp)
Override the last modified timestamp.
adaptCdnTTL( $mtime, $minTTL=0, $maxTTL=0)
Get TTL in [$minTTL,$maxTTL] and pass it to lowerCdnMaxage()
setRevisionIsCurrent(bool $isCurrent)
Set whether the revision displayed (as set in ::setRevisionId()) is the latest revision of the page.
wrapWikiMsg( $wrap,... $msgSpecs)
This function takes a number of message/argument specifications, wraps them in some overall structure...
setCdnMaxage( $maxage)
Set the value of the "s-maxage" part of the "Cache-control" HTTP header.
parseAsContent( $text, $linestart=true)
Parse wikitext in the page content language and return the HTML.
addParserOutput(ParserOutput $parserOutput, $poOptions=[])
Add everything from a ParserOutput object.
addWikiTextAsInterface( $text, $linestart=true, PageReference $title=null)
Convert wikitext in the user interface language to HTML and add it to the buffer.
setFollowPolicy( $policy)
Set the follow policy for the page, but leave the index policy un- touched.
isPrintable()
Return whether the page is "printable".
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.
setHTMLTitle( $name)
"HTML title" means the contents of "<title>".
disableClientCache()
Force the page to send nocache headers.
addSubtitle( $str)
Add $str to the subtitle.
setRevisionId( $revid)
Set the revision ID which will be seen by the wiki text parser for things such as embedded {{REVISION...
clearHTML()
Clear the body HTML.
setPreventClickjacking(bool $enable)
Set the prevent-clickjacking flag.
addHTML( $text)
Append $text to the body HTML.
addJsConfigVars( $keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
setCanonicalUrl( $url)
Set the URL to be used for the <link rel=canonical>>.
setRevisionTimestamp( $timestamp)
Set the timestamp of the revision which will be displayed.
setRedirectedFrom(PageReference $t)
Set $mRedirectedFrom, the page which redirected us to the current page.
prependHTML( $text)
Prepend $text to the body HTML.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
addWikiTextAsContent( $text, $linestart=true, PageReference $title=null)
Convert wikitext in the page content language to HTML and add it to the buffer.
Used to show archived pages and eventually restore them.
Set options of the Parser.
setIsPrintable( $x)
Parsing the printable version of the page?
setRenderReason(string $renderReason)
Sets reason for rendering the content.
static formatPageTitle( $nsText, $nsSeparator, $mainText)
Add HTML tags marking the parts of a page title, to be displayed in the first heading of the page.
static newSpec(int $revisionId, int $pageId, array $params=[])
Show an error when a user tries to do something they do not have the necessary permissions for.
static isInRCLifespan( $timestamp, $tolerance=0)
Check whether the given timestamp is new enough to have a RC row with a given tolerance as the recent...
static newFromConds( $conds, $fname=__METHOD__, $dbType=DB_REPLICA)
Find the first recent change matching some specific conditions.
static getMain()
Get the RequestContext object associated with the main request.
hasMessage( $message)
Returns true if the specified message is present as a warning or error.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
isOK()
Returns whether the operation completed.
static newGood( $value=null)
Factory function for good results.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getWikiText( $shortContext=false, $longContext=false, $lang=null)
Get the error list as a wikitext formatted list.
static newFromName( $name, $validate='valid')
Base representation for an editable wiki page.
getTitle()
Get the title object of the article.
static openElement( $element, $attribs=null)
This opens an XML element.
Interface for objects which can provide a MediaWiki context on request.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
if(!isset( $args[0])) $lang