23 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
40 use Wikimedia\IPUtils;
41 use Wikimedia\NonSerializable\NonSerializableTrait;
53 use ProtectedHookAccessorTrait;
54 use NonSerializableTrait;
82 private $fetchResult =
null;
106 private $revisionStore;
111 private $watchlistManager;
116 private $userNameUtils;
121 private $userOptionsLookup;
124 private $commentFormatter;
127 private $wikiPageFactory;
130 private $jobQueueGroup;
138 private $mRevisionRecord =
null;
145 $this->mOldId = $oldId;
146 $this->mPage = $this->
newPage( $title );
148 $services = MediaWikiServices::getInstance();
149 $this->linkRenderer = $services->getLinkRenderer();
150 $this->revisionStore = $services->getRevisionStore();
151 $this->watchlistManager = $services->getWatchlistManager();
152 $this->userNameUtils = $services->getUserNameUtils();
153 $this->userOptionsLookup = $services->getUserOptionsLookup();
154 $this->commentFormatter = $services->getCommentFormatter();
155 $this->wikiPageFactory = $services->getWikiPageFactory();
156 $this->jobQueueGroup = $services->getJobQueueGroup();
174 return $t ==
null ? null :
new static(
$t );
194 switch (
$title->getNamespace() ) {
205 $page->setContext( $context );
219 $article->mPage = $page;
238 $this->mRedirectedFrom = $from;
247 return $this->mPage->getTitle();
261 $this->mRedirectedFrom =
null; #
Title object if set
262 $this->mRedirectUrl =
false;
263 $this->mRevisionRecord =
null;
264 $this->fetchResult =
null;
268 $this->mPage->clear();
279 if ( $this->mOldId ===
null ) {
292 $this->mRedirectUrl =
false;
295 $oldid = $request->getIntOrNull(
'oldid' );
297 if ( $oldid ===
null ) {
301 if ( $oldid !== 0 ) {
302 # Load the given revision and check whether the page is another one.
303 # In that case, update this instance to reflect the change.
304 if ( $oldid === $this->mPage->getLatest() ) {
305 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
307 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
308 if ( $this->mRevisionRecord !==
null ) {
309 $revPageId = $this->mRevisionRecord->getPageId();
311 if ( $this->mPage->getId() != $revPageId ) {
312 $this->mPage = $this->wikiPageFactory->newFromID( $revPageId );
318 $oldRev = $this->mRevisionRecord;
319 if ( $request->getRawVal(
'direction' ) ===
'next' ) {
322 $nextRev = $this->revisionStore->getNextRevision( $oldRev );
324 $nextid = $nextRev->getId();
329 $this->mRevisionRecord =
null;
331 $this->mRedirectUrl = $this->
getTitle()->getFullURL(
'redirect=no' );
333 } elseif ( $request->getRawVal(
'direction' ) ===
'prev' ) {
336 $prevRev = $this->revisionStore->getPreviousRevision( $oldRev );
338 $previd = $prevRev->getId();
343 $this->mRevisionRecord =
null;
360 if ( $this->fetchResult ) {
361 return $this->mRevisionRecord;
367 if ( !$this->mRevisionRecord ) {
369 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
371 if ( !$this->mRevisionRecord ) {
372 wfDebug( __METHOD__ .
" failed to find page data for title " .
373 $this->
getTitle()->getPrefixedText() );
380 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
382 if ( !$this->mRevisionRecord ) {
383 wfDebug( __METHOD__ .
" failed to load revision, rev_id $oldid" );
391 if ( !$this->mRevisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getContext()->getAuthority() ) ) {
392 wfDebug( __METHOD__ .
" failed to retrieve content of revision " . $this->mRevisionRecord->getId() );
396 $this->fetchResult =
new Status;
399 if ( $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
400 $this->fetchResult->fatal(
'rev-suppressed-text' );
402 $this->fetchResult->fatal(
'rev-deleted-text-permission',
$title );
409 return $this->mRevisionRecord;
418 # If no oldid, this is the current version.
423 return $this->mPage->exists() &&
424 $this->mRevisionRecord &&
425 $this->mRevisionRecord->isCurrent();
437 if ( $this->fetchResult && $this->fetchResult->isOK() ) {
439 $rev = $this->fetchResult->getValue();
440 return $rev->
getId();
442 return $this->mPage->getLatest();
452 $useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache );
454 # Get variables from query string
455 # As side effect this will load the revision and update the title
456 # in a revision ID is passed in the request, so this should remain
457 # the first call of this method even if $oldid is used way below.
460 $authority = $context->getAuthority();
461 # Another check in case getOldID() is altering the title
462 $permissionStatus = PermissionStatus::newEmpty();
464 ->authorizeRead(
'read', $this->
getTitle(), $permissionStatus )
466 wfDebug( __METHOD__ .
": denied on secondary read check" );
471 # getOldID() may as well want us to redirect somewhere else
472 if ( $this->mRedirectUrl ) {
473 $outputPage->
redirect( $this->mRedirectUrl );
474 wfDebug( __METHOD__ .
": redirecting due to oldid" );
479 # If we got diff in the query, we want to see a diff page instead of the article.
480 if ( $context->getRequest()->getCheck(
'diff' ) ) {
481 wfDebug( __METHOD__ .
": showing diff page" );
487 # Set page title (may be overridden from ParserOutput if title conversion is enabled or DISPLAYTITLE is used)
489 str_replace(
'_',
' ', $this->
getTitle()->getNsText() ),
495 # Allow frames by default
501 # Allow extensions to vary parser options used for article rendering
502 Hooks::runner()->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
522 wfDebug( __METHOD__ .
": done file cache" );
523 # tell wgOut that output is taken care of
525 $this->mPage->doViewUpdates( $authority, $oldid );
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 );
569 # Load the postEdit module if the user just saved this revision
570 # See also EditPage::setPostEditCookie
571 $request = $context->getRequest();
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" );
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 );
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
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" );
720 $opt |= ParserOutputAccess::OPT_NO_CHECK_CACHE;
723 $opt |= ParserOutputAccess::OPT_NO_AUDIENCE_CHECK;
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;
1254 [
'rc_this_oldid' => intval( $oldestRevisionRow->rev_id ) ],
1259 $markPatrolledMsg = $context->msg(
'markaspatrolledtext' );
1267 $recentFileUpload =
false;
1268 if ( ( !$rc || $rc->getAttribute(
'rc_patrolled' ) ) && $useFilePatrol
1271 $newestUploadTimestamp =
$dbr->selectField(
1274 [
'img_name' =>
$title->getDBkey() ],
1277 if ( $newestUploadTimestamp
1281 $recentFileUpload =
true;
1285 'rc_log_type' =>
'upload',
1286 'rc_timestamp' => $newestUploadTimestamp,
1288 'rc_cur_id' =>
$title->getArticleID()
1294 $markPatrolledMsg = $context->msg(
'markaspatrolledtext-file' );
1299 if ( !$recentPageCreation && !$recentFileUpload ) {
1304 $cache->set( $key,
'1' );
1316 if ( $rc->getAttribute(
'rc_patrolled' ) ) {
1321 $cache->set( $key,
'1' );
1326 if ( $rc->getPerformerIdentity()->equals( $user ) ) {
1333 if ( $context->getAuthority()->isAllowed(
'writeapi' ) ) {
1334 $outputPage->
addModules(
'mediawiki.misc-authed-curate' );
1337 $link = $this->linkRenderer->makeKnownLink(
1340 $markPatrolledMsg->text(),
1343 'action' =>
'markpatrolled',
1344 'rcid' => $rc->getAttribute(
'rc_id' ),
1350 "<div class='patrollink' data-mw='interface'>" .
1351 $context->msg(
'markaspatrolledlink' )->rawParams( $link )->escaped() .
1365 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1366 $cache->delete( $cache->makeKey(
'unpatrollable-page', $articleID ) );
1375 $send404Code = $context->getConfig()->get( MainConfigNames::Send404Code );
1379 $validUserPage =
false;
1383 $services = MediaWikiServices::getInstance();
1385 $contextUser = $context->getUser();
1387 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1391 $rootPart = explode(
'/',
$title->getText() )[0];
1393 $ip = $this->userNameUtils->isIP( $rootPart );
1394 $block = DatabaseBlock::newFromTarget( $user, $user );
1396 if ( $user && $user->isRegistered() && $user->isHidden() &&
1397 !$context->getAuthority()->isAllowed(
'hideuser' )
1404 if ( !( $user && $user->isRegistered() ) && !$ip ) { #
User does not exist
1406 $context->msg(
'userpage-userdoesnotexist-view',
wfEscapeWikiText( $rootPart ) )->parse(),
1407 'mw-userpage-userdoesnotexist'
1411 $block->getType() != DatabaseBlock::TYPE_AUTO &&
1413 $block->isSitewide() ||
1414 $services->getPermissionManager()->isBlockedFrom( $user,
$title,
true )
1422 $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
':' .
1423 $block->getTargetName(),
1427 'showIfEmpty' =>
false,
1429 'blocked-notice-logextract',
1430 $user->getName() # Support GENDER in notice
1434 $validUserPage = !
$title->isSubpage();
1436 $validUserPage = !
$title->isSubpage();
1440 $this->getHookRunner()->onShowMissingArticle( $this );
1442 # Show delete and move logs if there were any such events.
1443 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1444 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1445 $dbCache = MediaWikiServices::getInstance()->getMainObjectStash();
1446 $key = $dbCache->makeKey(
'page-recent-delete', md5(
$title->getPrefixedText() ) );
1447 $isRegistered = $contextUser->isRegistered();
1448 $sessionExists = $context->getRequest()->getSession()->isPersistent();
1450 if ( $isRegistered || $dbCache->get( $key ) || $sessionExists ) {
1451 $logTypes = [
'delete',
'move',
'protect' ];
1455 $conds = [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ];
1457 $this->getHookRunner()->onArticle__MissingArticleConditions( $conds, $logTypes );
1466 'showIfEmpty' =>
false,
1467 'msgKey' => [ $isRegistered || $sessionExists
1468 ?
'moveddeleted-notice'
1469 :
'moveddeleted-notice-recent'
1475 if ( !$this->mPage->hasViewableContent() && $send404Code && !$validUserPage ) {
1478 $context->getRequest()->response()->statusHeader( 404 );
1482 $policy = $this->getRobotPolicy(
'view' );
1486 $hookResult = $this->getHookRunner()->onBeforeDisplayNoArticleText( $this );
1488 if ( !$hookResult ) {
1492 # Show error message
1493 $oldid = $this->getOldID();
1495 $text = $this->
getTitle()->getDefaultMessageText() ??
'';
1502 $revRecord = $pa->getArchivedRevisionRecord( $oldid );
1503 if ( $revRecord && $revRecord->userCan(
1504 RevisionRecord::DELETED_TEXT,
1505 $context->getAuthority()
1507 $text = $context->msg(
1508 'missing-revision-permission', $oldid,
1509 $revRecord->getTimestamp(),
1510 $title->getPrefixedDBkey()
1513 $text = $context->msg(
'missing-revision', $oldid )->plain();
1516 } elseif ( $context->getAuthority()->probablyCan(
'edit',
$title ) ) {
1517 $message = $isRegistered ?
'noarticletext' :
'noarticletextanon';
1518 $text = $context->msg( $message )->plain();
1520 $text = $context->msg(
'noarticletext-nopermission' )->plain();
1523 $dir = $context->getLanguage()->getDir();
1524 $lang = $context->getLanguage()->getHtmlCode();
1526 'class' =>
"noarticletext mw-content-$dir",
1529 ] ) .
"\n$text\n</div>" );
1537 private function showViewError(
string $errortext ) {
1538 $outputPage = $this->
getContext()->getOutput();
1553 if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1557 $outputPage = $this->
getContext()->getOutput();
1559 $titleText = $this->
getTitle()->getPrefixedDBkey();
1561 if ( !$this->mRevisionRecord->userCan(
1562 RevisionRecord::DELETED_TEXT,
1563 $this->getContext()->getAuthority()
1567 $outputPage->
msg(
'rev-deleted-text-permission', $titleText )->parse(),
1575 # Give explanation and add a link to view the revision...
1576 $oldid = intval( $this->getOldID() );
1577 $link = $this->
getTitle()->getFullURL(
"oldid={$oldid}&unhide=1" );
1578 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1579 'rev-suppressed-text-unhide' :
'rev-deleted-text-unhide';
1582 $outputPage->
msg( $msg, $link )->parse(),
1590 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED )
1591 ? [
'rev-suppressed-text-view', $titleText ]
1592 : [
'rev-deleted-text-view', $titleText ];
1595 $outputPage->
msg( $msg[0], $msg[1] )->parse(),
1613 if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
1618 $unhide = $context->getRequest()->getInt(
'unhide' ) == 1;
1620 # Cascade unhide param in links for easy deletion browsing
1623 $extraParams[
'unhide'] = 1;
1626 if ( $this->mRevisionRecord && $this->mRevisionRecord->getId() === $oldid ) {
1627 $revisionRecord = $this->mRevisionRecord;
1629 $revisionRecord = $this->revisionStore->getRevisionById( $oldid );
1632 $timestamp = $revisionRecord->getTimestamp();
1634 $current = ( $oldid == $this->mPage->getLatest() );
1635 $language = $context->getLanguage();
1636 $user = $context->getUser();
1638 $td = $language->userTimeAndDate( $timestamp, $user );
1639 $tddate = $language->userDate( $timestamp, $user );
1640 $tdtime = $language->userTime( $timestamp, $user );
1642 # Show user links if allowed to see them. If hidden, then show them only if requested...
1644 $userlinks = Linker::revUserTools( $revisionRecord, !$unhide );
1646 $infomsg = $current && !$context->msg(
'revision-info-current' )->isDisabled()
1647 ?
'revision-info-current'
1652 'mediawiki.action.styles',
1653 'mediawiki.interface.helpers.styles'
1656 $revisionUser = $revisionRecord->getUser();
1657 $revisionInfo =
"<div id=\"mw-{$infomsg}\">" .
1658 $context->msg( $infomsg, $td )
1659 ->rawParams( $userlinks )
1661 $revisionRecord->getId(),
1664 $revisionUser ? $revisionUser->getName() :
''
1666 ->rawParams( $this->commentFormatter->formatRevision(
1677 ? $context->msg(
'currentrevisionlink' )->escaped()
1678 : $this->linkRenderer->makeKnownLink(
1680 $context->msg(
'currentrevisionlink' )->text(),
1685 ? $context->msg(
'diff' )->escaped()
1686 : $this->linkRenderer->makeKnownLink(
1688 $context->msg(
'diff' )->text(),
1696 $prevExist = (bool)$this->revisionStore->getPreviousRevision( $revisionRecord );
1697 $prevlink = $prevExist
1698 ? $this->linkRenderer->makeKnownLink(
1700 $context->msg(
'previousrevision' )->text(),
1703 'direction' =>
'prev',
1707 : $context->msg(
'previousrevision' )->escaped();
1708 $prevdiff = $prevExist
1709 ? $this->linkRenderer->makeKnownLink(
1711 $context->msg(
'diff' )->text(),
1718 : $context->msg(
'diff' )->escaped();
1719 $nextlink = $current
1720 ? $context->msg(
'nextrevision' )->escaped()
1721 : $this->linkRenderer->makeKnownLink(
1723 $context->msg(
'nextrevision' )->text(),
1726 'direction' =>
'next',
1730 $nextdiff = $current
1731 ? $context->msg(
'diff' )->escaped()
1732 : $this->linkRenderer->makeKnownLink(
1734 $context->msg(
'diff' )->text(),
1742 $cdel = Linker::getRevDeleteLink(
1743 $context->getAuthority(),
1748 if ( $cdel !==
'' ) {
1756 "<div id=\"mw-revision-nav\">" . $cdel .
1757 $context->msg(
'revision-nav' )->rawParams(
1758 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1759 )->escaped() .
"</div>",
1778 if ( is_array( $target ) ) {
1780 wfDeprecatedMsg(
'The $target parameter can no longer be an array',
'1.39' );
1781 $target = reset( $target );
1784 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1786 $html =
'<ul class="redirectText">';
1787 if ( $forceKnown ) {
1790 $target->getFullText(),
1793 $target->isRedirect() ? [
'redirect' =>
'no' ] : []
1798 $target->getFullText(),
1801 $target->isRedirect() ? [
'redirect' =>
'no' ] : []
1804 $html .=
'<li>' . $link .
'</li>';
1807 $redirectToText =
wfMessage(
'redirectto' )->inLanguage(
$lang )->escaped();
1809 return '<div class="redirectMsg">' .
1810 '<p>' . $redirectToText .
'</p>' .
1825 $msg = $out->msg(
'namespace-' . $this->
getTitle()->getNamespace() .
'-helppage' );
1827 if ( !$msg->isDisabled() ) {
1830 $out->addHelpLink(
$title->getLocalURL(),
true );
1833 $out->addHelpLink( $to, $overrideBaseUrl );
1841 $this->
getContext()->getRequest()->response()->header(
'X-Robots-Tag: noindex' );
1842 $this->
getContext()->getOutput()->setArticleBodyOnly(
true );
1844 $this->viewIsRenderAction =
true;
1876 public function doDelete( $reason, $suppress =
false, $immediate =
false ) {
1881 $user = $context->getUser();
1882 $status = $this->mPage->doDeleteArticleReal(
1883 $reason, $user, $suppress,
null, $error,
1884 null, [],
'delete', $immediate
1887 if ( $status->isOK() ) {
1888 $deleted = $this->
getTitle()->getPrefixedText();
1890 $outputPage->
setPageTitle( $context->msg(
'actioncomplete' ) );
1893 if ( $status->isGood() ) {
1894 $loglink =
'[[Special:Log/delete|' . $context->msg(
'deletionlog' )->text() .
']]';
1896 $this->getHookRunner()->onArticleDeleteAfterSuccess( $this->
getTitle(), $outputPage );
1904 $context->msg(
'cannotdelete-title',
1905 $this->getTitle()->getPrefixedText() )
1908 if ( $error ==
'' ) {
1910 'error mw-error-cannotdelete',
1911 $status->getWikiText(
false,
false, $context->getLanguage() )
1913 $deleteLogPage =
new LogPage(
'delete' );
1922 $outputPage->
addHTML( $error );
1937 static $called =
false;
1940 wfDebug(
"Article::tryFileCache(): called twice!?" );
1945 if ( $this->isFileCacheable() ) {
1947 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1948 wfDebug(
"Article::tryFileCache(): about to load file" );
1949 $cache->loadFromFileCache( $this->
getContext() );
1952 wfDebug(
"Article::tryFileCache(): starting buffer" );
1953 ob_start( [ &$cache,
'saveToFileCache' ] );
1956 wfDebug(
"Article::tryFileCache(): not cacheable" );
1971 $cacheable = $this->mPage->getId()
1972 && !$this->mRedirectedFrom && !$this->
getTitle()->isRedirect();
1975 $cacheable = $this->getHookRunner()->onIsFileCacheable( $this ) ??
false;
1996 if ( $user ===
null ) {
1997 $parserOptions = $this->getParserOptions();
1999 $parserOptions = $this->mPage->makeParserOptions( $user );
2003 return $this->mPage->getParserOutput( $parserOptions, $oldid );
2011 $parserOptions = $this->mPage->makeParserOptions( $this->
getContext() );
2013 return $parserOptions;
2023 $this->mContext = $context;
2034 return $this->mContext;
2036 wfDebug( __METHOD__ .
" called and \$mContext is null. " .
2037 "Return RequestContext::getMain()" );
2052 wfDeprecatedMsg(
"Accessing Article::\$$fname is deprecated since MediaWiki 1.35",
2055 if ( property_exists( $this->mPage, $fname ) ) {
2056 return $this->mPage->$fname;
2058 trigger_error(
'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2070 public function __set( $fname, $fvalue ) {
2071 wfDeprecatedMsg(
"Setting Article::\$$fname is deprecated since MediaWiki 1.35",
2074 if ( property_exists( $this->mPage, $fname ) ) {
2075 $this->mPage->$fname = $fvalue;
2077 } elseif ( !in_array( $fname, [
'mContext',
'mPage' ] ) ) {
2078 $this->mPage->$fname = $fvalue;
2080 trigger_error(
'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2090 return $this->mPage->getActionOverrides();
2100 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.
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,...
doDelete( $reason, $suppress=false, $immediate=false)
Perform a deletion and output success or failure messages.
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.
getParserOutput( $oldid=null, UserIdentity $user=null)
#-
static getRedirectHeaderHtml(Language $lang, $target, $forceKnown=false)
Return the HTML for the top of a redirect page.
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()
const POST_EDIT_COOKIE_KEY_PREFIX
Prefix of key for cookie used to pass post-edit state.
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.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
static warningBox( $html, $className='')
Return a warning box.
static errorBox( $html, $heading='', $className='')
Return an error box.
Rendering of file description pages.
Base class for language-specific code.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Class to simplify the use of log pages.
A class containing constants representing the names of configuration variables.
Service for getting rendered output of a given page.
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.
addWikiMsg(... $args)
Add a wikitext-formatted message to the output.
wrapWikiTextAsInterface( $wrapperClass, $text)
Convert wikitext in the user interface language to HTML and add it to the buffer with a <div class="$...
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>".
returnToMain( $unused=null, $returnto=null, $returntoquery=null)
Add a "return to" link pointing to a specified title, or the title indicated in the request,...
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.
Represents a title within MediaWiki.
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
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.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
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