22use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
37use Wikimedia\NonSerializable\NonSerializableTrait;
49 use ProtectedHookAccessorTrait;
50 use NonSerializableTrait;
72 public $mRedirectUrl =
false;
78 private $fetchResult =
null;
92 protected $viewIsRenderAction =
false;
102 private $revisionStore;
107 private $watchlistManager;
112 private $userNameUtils;
117 private $userOptionsLookup;
125 private $mRevisionRecord =
null;
132 $this->mOldId = $oldId;
135 $services = MediaWikiServices::getInstance();
136 $this->linkRenderer = $services->getLinkRenderer();
137 $this->revisionStore = $services->getRevisionStore();
138 $this->watchlistManager = $services->getWatchlistManager();
139 $this->userNameUtils = $services->getUserNameUtils();
140 $this->userOptionsLookup = $services->getUserOptionsLookup();
157 $t = Title::newFromID( $id );
158 return $t ==
null ? null :
new static(
$t );
176 Hooks::runner()->onArticleFromTitle(
$title, $page, $context );
178 switch (
$title->getNamespace() ) {
189 $page->setContext( $context );
202 $article = self::newFromTitle( $page->
getTitle(), $context );
203 $article->mPage = $page;
213 return $this->mRedirectedFrom;
222 $this->mRedirectedFrom = $from;
231 return $this->mPage->getTitle();
245 $this->mRedirectedFrom =
null; #
Title object if set
246 $this->mRedirectUrl =
false;
247 $this->mRevisionRecord =
null;
248 $this->fetchResult =
null;
252 $this->mPage->clear();
263 if ( $this->mOldId ===
null ) {
267 return $this->mOldId;
276 $this->mRedirectUrl =
false;
279 $oldid = $request->getIntOrNull(
'oldid' );
281 if ( $oldid ===
null ) {
285 if ( $oldid !== 0 ) {
286 # Load the given revision and check whether the page is another one.
287 # In that case, update this instance to reflect the change.
288 if ( $oldid === $this->mPage->getLatest() ) {
289 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
291 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
292 if ( $this->mRevisionRecord !==
null ) {
293 $revPageId = $this->mRevisionRecord->getPageId();
295 if ( $this->mPage->getId() != $revPageId ) {
296 $function = get_class( $this->mPage ) .
'::newFromID';
297 $this->mPage = $function( $revPageId );
303 $oldRev = $this->mRevisionRecord;
304 if ( $request->getRawVal(
'direction' ) ===
'next' ) {
307 $nextRev = $this->revisionStore->getNextRevision( $oldRev );
309 $nextid = $nextRev->getId();
314 $this->mRevisionRecord =
null;
316 $this->mRedirectUrl = $this->
getTitle()->getFullURL(
'redirect=no' );
318 } elseif ( $request->getRawVal(
'direction' ) ===
'prev' ) {
321 $prevRev = $this->revisionStore->getPreviousRevision( $oldRev );
323 $previd = $prevRev->getId();
328 $this->mRevisionRecord =
null;
345 if ( $this->fetchResult ) {
346 return $this->mRevisionRecord;
352 if ( !$this->mRevisionRecord ) {
354 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
356 if ( !$this->mRevisionRecord ) {
357 wfDebug( __METHOD__ .
" failed to find page data for title " .
358 $this->
getTitle()->getPrefixedText() );
361 $this->fetchResult = Status::newFatal(
'noarticletext' );
365 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
367 if ( !$this->mRevisionRecord ) {
368 wfDebug( __METHOD__ .
" failed to load revision, rev_id $oldid" );
370 $this->fetchResult = Status::newFatal(
'missing-revision', $oldid );
376 if ( !$this->mRevisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getContext()->getAuthority() ) ) {
377 wfDebug( __METHOD__ .
" failed to retrieve content of revision " . $this->mRevisionRecord->getId() );
381 $this->fetchResult =
new Status;
384 if ( $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
385 $this->fetchResult->
fatal(
'rev-suppressed-text' );
387 $this->fetchResult->fatal(
'rev-deleted-text-permission',
$title );
393 $this->fetchResult = Status::newGood( $this->mRevisionRecord );
394 return $this->mRevisionRecord;
403 # If no oldid, this is the current version.
408 return $this->mPage->exists() &&
409 $this->mRevisionRecord &&
410 $this->mRevisionRecord->isCurrent();
422 if ( $this->fetchResult && $this->fetchResult->isOK() ) {
423 return $this->fetchResult->value->getId();
425 return $this->mPage->getLatest();
435 $useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache );
437 # Get variables from query string
438 # As side effect this will load the revision and update the title
439 # in a revision ID is passed in the request, so this should remain
440 # the first call of this method even if $oldid is used way below.
443 $authority = $context->getAuthority();
444 # Another check in case getOldID() is altering the title
445 $permissionStatus = PermissionStatus::newEmpty();
447 ->authorizeRead(
'read', $this->
getTitle(), $permissionStatus )
449 wfDebug( __METHOD__ .
": denied on secondary read check" );
454 # getOldID() may as well want us to redirect somewhere else
455 if ( $this->mRedirectUrl ) {
456 $outputPage->
redirect( $this->mRedirectUrl );
457 wfDebug( __METHOD__ .
": redirecting due to oldid" );
462 # If we got diff in the query, we want to see a diff page instead of the article.
463 if ( $context->getRequest()->getCheck(
'diff' ) ) {
464 wfDebug( __METHOD__ .
": showing diff page" );
470 # Set page title (may be overridden from ParserOutput if title conversion is enabled or DISPLAYTITLE is used)
472 str_replace(
'_',
' ', $this->
getTitle()->getNsText() ),
478 # Allow frames by default
481 $skin = $context->getSkin();
482 $skinOptions = $skin->getOptions();
487 'injectTOC' => $skinOptions[
'toc'],
489 # Allow extensions to vary parser options used for article rendering
490 Hooks::runner()->onArticleParserOptions( $this, $parserOptions );
491 # Render printable version, use printable version cache
494 $poOptions[
'enableSectionEditLinks'] =
false;
497 $outputPage->
msg(
'printableversion-deprecated-warning' )->escaped()
500 } elseif ( $this->viewIsRenderAction || !$this->
isCurrent() ||
501 !$authority->probablyCan(
'edit', $this->getTitle() )
503 $poOptions[
'enableSectionEditLinks'] =
false;
506 # Try client and file cache
507 if ( $oldid === 0 && $this->mPage->checkTouched() ) {
508 # Try to stream the output from file cache
510 wfDebug( __METHOD__ .
": done file cache" );
511 # tell wgOut that output is taken care of
513 $this->mPage->doViewUpdates( $authority, $oldid );
522 if ( $this->viewIsRenderAction ) {
523 $poOptions += [
'absoluteURLs' =>
true ];
525 $poOptions += [
'includeDebugInfo' =>
true ];
528 $this->generateContentOutput( $authority, $parserOptions, $oldid, $outputPage, $poOptions );
534 # For the main page, overwrite the <title> element with the con-
535 # tents of 'pagetitle-view-mainpage' instead of the default (if
537 # This message always exists because it is in the i18n files
538 if ( $this->
getTitle()->isMainPage() ) {
539 $msg = $context->msg(
'pagetitle-view-mainpage' )->inContentLanguage();
540 if ( !$msg->isDisabled() ) {
545 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
546 # This could use getTouched(), but that could be scary for major template edits.
547 $outputPage->
adaptCdnTTL( $this->mPage->getTimestamp(), IExpiringStore::TTL_DAY );
552 # Load the postEdit module if the user just saved this revision
553 # See also EditPage::setPostEditCookie
554 $request = $context->getRequest();
556 $postEdit = $request->getCookie( $cookieKey );
558 # Clear the cookie. This also prevents caching of the response.
559 $request->response()->clearCookie( $cookieKey );
561 $outputPage->
addModules(
'mediawiki.action.view.postEdit' );
577 private function generateContentOutput(
584 # Should the parser cache be used?
585 $useParserCache =
true;
587 $parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
590 $this->getHookRunner()->onArticleViewHeader( $this, $outputDone, $useParserCache );
593 $pOutput = $outputDone;
597 $this->doOutputMetaData( $pOutput, $outputPage );
603 if ( !$this->mPage->exists() ) {
604 wfDebug( __METHOD__ .
": showing missing article" );
606 $this->mPage->doViewUpdates( $performer );
612 if ( $useParserCache && !$oldid ) {
613 $pOutput = $parserOutputAccess->getCachedParserOutput(
617 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
621 $this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions );
622 $this->doOutputMetaData( $pOutput, $outputPage );
628 if ( !$this->fetchResult->isOK() ) {
629 $this->showViewError( $this->fetchResult->getWikiText(
630 false,
false, $this->getContext()->getLanguage()
635 # Are we looking at an old revision
640 wfDebug( __METHOD__ .
": cannot view deleted revision" );
647 if ( $useParserCache ) {
648 $pOutput = $parserOutputAccess->getCachedParserOutput(
652 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
656 $this->doOutputFromParserCache( $pOutput, $outputPage, $textOptions );
657 $this->doOutputMetaData( $pOutput, $outputPage );
663 # Ensure that UI elements requiring revision ID have
664 # the correct version information.
667 # Preload timestamp to avoid a DB hit
670 # Pages containing custom CSS or JavaScript get special treatment
671 if ( $this->
getTitle()->isSiteConfigPage() || $this->
getTitle()->isUserConfigPage() ) {
672 $dir = $this->
getContext()->getLanguage()->getDir();
676 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
680 } elseif ( !$this->getHookRunner()->onArticleRevisionViewCustom(
688 $this->doOutputMetaData( $pOutput, $outputPage );
692 # Run the parse, protected by a pool counter
693 wfDebug( __METHOD__ .
": doing uncached parse" );
703 $opt |= ParserOutputAccess::OPT_NO_CHECK_CACHE;
706 $opt |= ParserOutputAccess::OPT_NO_AUDIENCE_CHECK;
708 if ( !$rev->
getId() || !$useParserCache ) {
710 $opt |= ParserOutputAccess::OPT_NO_CACHE;
713 $renderStatus = $parserOutputAccess->getParserOutput(
720 $this->doOutputFromRenderStatus(
727 if ( !$renderStatus->
isOK() ) {
731 $pOutput = $renderStatus->
getValue();
732 $this->doOutputMetaData( $pOutput, $outputPage );
741 # Adjust title for main page & pages with displaytitle
743 $this->adjustDisplayTitle( $pOutput );
746 # Check for any __NOINDEX__ tags on the page using $pOutput
747 $policy = $this->getRobotPolicy(
'view', $pOutput ?: null );
751 $this->mParserOutput = $pOutput;
759 private function doOutputFromParserCache(
764 # Ensure that UI elements requiring revision ID have
765 # the correct version information.
769 # Ensure that the skin has the necessary ToC information
770 # (and do this before OutputPage::addParserOutput() calls the
771 # OutputPageParserOutput hook)
774 # Preload timestamp to avoid a DB hit
776 if ( $cachedTimestamp !==
null ) {
778 $this->mPage->setTimestamp( $cachedTimestamp );
788 private function doOutputFromRenderStatus(
795 $cdnMaxageStale = $context->getConfig()->get( MainConfigNames::CdnMaxageStale );
796 $ok = $renderStatus->
isOK();
798 $pOutput = $ok ? $renderStatus->
getValue() :
null;
801 if ( $ok && $renderStatus->
hasMessage(
'view-pool-dirty-output' ) ) {
804 $staleReason = $renderStatus->
hasMessage(
'view-pool-contention' )
805 ? $context->msg(
'view-pool-contention' )
806 : $context->msg(
'view-pool-timeout' );
807 $outputPage->
addHTML(
"<!-- parser cache is expired, " .
808 "sending anyway due to $staleReason-->\n" );
811 if ( !$renderStatus->
isOK() ) {
813 false,
'view-pool-error', $context->getLanguage()
823 if ( $this->getRevisionRedirectTarget( $rev ) ) {
824 $outputPage->
addSubtitle(
"<span id=\"redirectsub\">" .
825 $context->msg(
'redirectpagesub' )->parse() .
"</span>" );
833 private function getRevisionRedirectTarget(
RevisionRecord $revision ) {
848 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
850 if ( strval( $titleText ) !==
'' ) {
851 $out->setPageTitle( $titleText );
852 $out->setDisplayTitle( $titleText );
862 $request = $context->getRequest();
863 $user = $context->getUser();
864 $diff = $request->getVal(
'diff' );
865 $rcid = $request->getInt(
'rcid' );
866 $purge = $request->getRawVal(
'action' ) ===
'purge';
867 $unhide = $request->getInt(
'unhide' ) == 1;
868 $oldid = $this->getOldID();
870 $rev = $this->fetchRevisionRecord();
875 $rev = $this->revisionStore->getRevisionById( $oldid );
881 $context->getOutput()->setPageTitle( $context->msg(
'errorpagetitle' ) );
882 $msg = $context->msg(
'difference-missing-revision' )
886 $context->getOutput()->addHTML( $msg );
891 $contentHandler = MediaWikiServices::getInstance()
892 ->getContentHandlerFactory()
894 $rev->
getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
896 $de = $contentHandler->createDifferenceEngine(
904 $de->setSlotDiffOptions( [
905 'diff-type' => $request->getVal(
'diff-type' ),
906 'expand-url' => $this->viewIsRenderAction
908 $de->showDiffPage( $this->isDiffOnlyView() );
912 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
914 $this->mPage->doViewUpdates( $context->getAuthority(), (
int)$new );
918 return $this->
getContext()->getRequest()->getBool(
920 $this->userOptionsLookup->getBoolOption( $this->getContext()->getUser(),
'diffonly' )
933 $mainConfig = $context->getConfig();
934 $articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies );
935 $namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies );
936 $defaultRobotPolicy = $mainConfig->get( MainConfigNames::DefaultRobotPolicy );
938 $ns =
$title->getNamespace();
940 # Don't index user and user talk pages for blocked users (T13443)
942 $specificTarget =
null;
944 $titleText =
$title->getText();
945 if ( IPUtils::isValid( $titleText ) ) {
946 $vagueTarget = $titleText;
948 $specificTarget = $titleText;
950 if ( DatabaseBlock::newFromTarget( $specificTarget, $vagueTarget ) instanceof
DatabaseBlock ) {
952 'index' =>
'noindex',
953 'follow' =>
'nofollow'
958 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
959 # Non-articles (special pages etc), and old revisions
961 'index' =>
'noindex',
962 'follow' =>
'nofollow'
964 } elseif ( $context->getOutput()->isPrintable() ) {
965 # Discourage indexing of printable versions, but encourage following
967 'index' =>
'noindex',
970 } elseif ( $context->getRequest()->getInt(
'curid' ) ) {
971 # For ?curid=x urls, disallow indexing
973 'index' =>
'noindex',
978 # Otherwise, construct the policy based on the various config variables.
979 $policy = self::formatRobotPolicy( $defaultRobotPolicy );
981 if ( isset( $namespaceRobotPolicies[$ns] ) ) {
982 # Honour customised robot policies for this namespace
983 $policy = array_merge(
985 self::formatRobotPolicy( $namespaceRobotPolicies[$ns] )
989 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
990 # a final check that we have really got the parser output.
991 $policy = array_merge(
997 if ( isset( $articleRobotPolicies[
$title->getPrefixedText()] ) ) {
998 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
999 $policy = array_merge(
1001 self::formatRobotPolicy( $articleRobotPolicies[
$title->getPrefixedText()] )
1016 if ( is_array( $policy ) ) {
1018 } elseif ( !$policy ) {
1023 foreach ( explode(
',', $policy ) as $var ) {
1024 $var = trim( $var );
1025 if ( $var ===
'index' || $var ===
'noindex' ) {
1026 $arr[
'index'] = $var;
1027 } elseif ( $var ===
'follow' || $var ===
'nofollow' ) {
1028 $arr[
'follow'] = $var;
1044 $redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources );
1046 $request = $context->getRequest();
1047 $rdfrom = $request->getVal(
'rdfrom' );
1050 $query = $request->getValues();
1051 unset( $query[
'rdfrom'] );
1052 unset( $query[
'title'] );
1053 if ( $this->
getTitle()->isRedirect() ) {
1055 $query[
'redirect'] =
'no';
1057 $redirectTargetUrl = $this->
getTitle()->getLinkURL( $query );
1059 if ( isset( $this->mRedirectedFrom ) ) {
1062 if ( $this->getHookRunner()->onArticleViewRedirect( $this ) ) {
1063 $redir = $this->linkRenderer->makeKnownLink(
1064 $this->mRedirectedFrom,
1067 [
'redirect' =>
'no' ]
1070 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1071 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1077 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1079 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1089 } elseif ( $rdfrom ) {
1092 if ( $redirectSources && preg_match( $redirectSources, $rdfrom ) ) {
1094 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1095 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1100 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1102 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1116 if ( $this->
getTitle()->isTalkPage() && !$this->
getContext()->msg(
'talkpageheader' )->isDisabled() ) {
1117 $this->
getContext()->getOutput()->wrapWikiMsg(
1118 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1119 [
'talkpageheader' ]
1128 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1130 && IPUtils::isValid( $this->
getTitle()->getText() )
1132 $this->
getContext()->getOutput()->addWikiMsg(
'anontalkpagetext' );
1136 $patrolFooterShown = $this->showPatrolFooter();
1138 $this->getHookRunner()->onArticleViewFooter( $this, $patrolFooterShown );
1153 $mainConfig = $context->getConfig();
1154 $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
1155 $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
1156 $useFilePatrol = $mainConfig->get( MainConfigNames::UseFilePatrol );
1158 if ( !$this->getHookRunner()->onArticleShowPatrolFooter( $this ) ) {
1163 $user = $context->getUser();
1167 if ( !$context->getAuthority()->probablyCan(
'patrol',
$title )
1168 || !( $useRCPatrol || $useNPPatrol
1175 if ( $this->mRevisionRecord
1176 && !RecentChange::isInRCLifespan( $this->mRevisionRecord->getTimestamp(), 21600 )
1184 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1185 $key =
$cache->makeKey(
'unpatrollable-page',
$title->getArticleID() );
1186 if (
$cache->get( $key ) ) {
1191 $oldestRevisionTimestamp =
$dbr->selectField(
1193 'MIN( rev_timestamp )',
1194 [
'rev_page' =>
$title->getArticleID() ],
1203 $recentPageCreation =
false;
1204 if ( $oldestRevisionTimestamp
1205 && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1208 $recentPageCreation =
true;
1209 $rc = RecentChange::newFromConds(
1212 'rc_timestamp' => $oldestRevisionTimestamp,
1213 'rc_namespace' =>
$title->getNamespace(),
1214 'rc_cur_id' =>
$title->getArticleID()
1220 $markPatrolledMsg = $context->msg(
'markaspatrolledtext' );
1228 $recentFileUpload =
false;
1229 if ( ( !$rc || $rc->getAttribute(
'rc_patrolled' ) ) && $useFilePatrol
1232 $newestUploadTimestamp =
$dbr->selectField(
1234 'MAX( img_timestamp )',
1235 [
'img_name' =>
$title->getDBkey() ],
1238 if ( $newestUploadTimestamp
1239 && RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 )
1242 $recentFileUpload =
true;
1243 $rc = RecentChange::newFromConds(
1246 'rc_log_type' =>
'upload',
1247 'rc_timestamp' => $newestUploadTimestamp,
1249 'rc_cur_id' =>
$title->getArticleID()
1255 $markPatrolledMsg = $context->msg(
'markaspatrolledtext-file' );
1260 if ( !$recentPageCreation && !$recentFileUpload ) {
1265 $cache->set( $key,
'1' );
1277 if ( $rc->getAttribute(
'rc_patrolled' ) ) {
1282 $cache->set( $key,
'1' );
1287 if ( $rc->getPerformerIdentity()->equals( $user ) ) {
1294 if ( $context->getAuthority()->isAllowed(
'writeapi' ) ) {
1295 $outputPage->
addModules(
'mediawiki.misc-authed-curate' );
1298 $link = $this->linkRenderer->makeKnownLink(
1301 $markPatrolledMsg->text(),
1304 'action' =>
'markpatrolled',
1305 'rcid' => $rc->getAttribute(
'rc_id' ),
1311 "<div class='patrollink' data-mw='interface'>" .
1312 $context->msg(
'markaspatrolledlink' )->rawParams( $link )->escaped() .
1326 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1327 $cache->delete(
$cache->makeKey(
'unpatrollable-page', $articleID ) );
1336 $send404Code = $context->getConfig()->get( MainConfigNames::Send404Code );
1340 $validUserPage =
false;
1344 $services = MediaWikiServices::getInstance();
1346 $contextUser = $context->getUser();
1348 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1352 $rootPart = explode(
'/',
$title->getText() )[0];
1354 $ip = $this->userNameUtils->isIP( $rootPart );
1355 $block = DatabaseBlock::newFromTarget( $user, $user );
1357 if ( $user && $user->isRegistered() && $user->isHidden() &&
1358 !$context->getAuthority()->isAllowed(
'hideuser' )
1365 if ( !( $user && $user->isRegistered() ) && !$ip ) { #
User does not exist
1366 $outputPage->addHtml( Html::warningBox(
1367 $context->msg(
'userpage-userdoesnotexist-view',
wfEscapeWikiText( $rootPart ) )->parse(),
1368 'mw-userpage-userdoesnotexist'
1372 $block->getType() != DatabaseBlock::TYPE_AUTO &&
1374 $block->isSitewide() ||
1375 $user->isBlockedFrom(
$title,
true )
1380 LogEventsList::showLogExtract(
1383 $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
':' .
1384 $block->getTargetName(),
1388 'showIfEmpty' =>
false,
1390 'blocked-notice-logextract',
1391 $user->getName() # Support GENDER in notice
1395 $validUserPage = !
$title->isSubpage();
1397 $validUserPage = !
$title->isSubpage();
1401 $this->getHookRunner()->onShowMissingArticle( $this );
1403 # Show delete and move logs if there were any such events.
1404 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1405 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1406 $dbCache = MediaWikiServices::getInstance()->getMainObjectStash();
1407 $key = $dbCache->makeKey(
'page-recent-delete', md5(
$title->getPrefixedText() ) );
1408 $isRegistered = $contextUser->isRegistered();
1409 $sessionExists = $context->getRequest()->getSession()->isPersistent();
1411 if ( $isRegistered || $dbCache->get( $key ) || $sessionExists ) {
1412 $logTypes = [
'delete',
'move',
'protect' ];
1416 $conds = [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ];
1418 $this->getHookRunner()->onArticle__MissingArticleConditions( $conds, $logTypes );
1419 LogEventsList::showLogExtract(
1427 'showIfEmpty' =>
false,
1428 'msgKey' => [ $isRegistered || $sessionExists
1429 ?
'moveddeleted-notice'
1430 :
'moveddeleted-notice-recent'
1436 if ( !$this->mPage->hasViewableContent() && $send404Code && !$validUserPage ) {
1439 $context->getRequest()->response()->statusHeader( 404 );
1443 $policy = $this->getRobotPolicy(
'view' );
1447 $hookResult = $this->getHookRunner()->onBeforeDisplayNoArticleText( $this );
1449 if ( !$hookResult ) {
1453 # Show error message
1454 $oldid = $this->getOldID();
1456 $text = $this->
getTitle()->getDefaultMessageText() ??
'';
1463 $revRecord = $pa->getArchivedRevisionRecord( $oldid );
1464 if ( $revRecord && $revRecord->userCan(
1465 RevisionRecord::DELETED_TEXT,
1466 $context->getAuthority()
1467 ) && $context->getAuthority()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
1468 $text = $context->msg(
1469 'missing-revision-permission', $oldid,
1470 $revRecord->getTimestamp(),
1471 $title->getPrefixedDBkey()
1474 $text = $context->msg(
'missing-revision', $oldid )->plain();
1477 } elseif ( $context->getAuthority()->probablyCan(
'edit',
$title ) ) {
1478 $message = $isRegistered ?
'noarticletext' :
'noarticletextanon';
1479 $text = $context->msg( $message )->plain();
1481 $text = $context->msg(
'noarticletext-nopermission' )->plain();
1484 $dir = $context->getLanguage()->getDir();
1485 $lang = $context->getLanguage()->getHtmlCode();
1487 'class' =>
"noarticletext mw-content-$dir",
1490 ] ) .
"\n$text\n</div>" );
1498 private function showViewError(
string $errortext ) {
1514 if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1520 $titleText = $this->
getTitle()->getPrefixedDBkey();
1522 if ( !$this->mRevisionRecord->userCan(
1523 RevisionRecord::DELETED_TEXT,
1524 $this->getContext()->getAuthority()
1526 $outputPage->addHtml(
1528 $outputPage->
msg(
'rev-deleted-text-permission', $titleText )->parse(),
1535 } elseif ( $this->
getContext()->getRequest()->getInt(
'unhide' ) != 1 ) {
1536 # Give explanation and add a link to view the revision...
1537 $oldid = intval( $this->getOldID() );
1538 $link = $this->
getTitle()->getFullURL(
"oldid={$oldid}&unhide=1" );
1539 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1540 'rev-suppressed-text-unhide' :
'rev-deleted-text-unhide';
1541 $outputPage->addHtml(
1543 $outputPage->
msg( $msg, $link )->parse(),
1551 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED )
1552 ? [
'rev-suppressed-text-view', $titleText ]
1553 : [
'rev-deleted-text-view', $titleText ];
1554 $outputPage->addHtml(
1556 $outputPage->
msg( $msg[0], $msg[1] )->parse(),
1574 if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
1579 $unhide = $context->getRequest()->getInt(
'unhide' ) == 1;
1581 # Cascade unhide param in links for easy deletion browsing
1584 $extraParams[
'unhide'] = 1;
1587 if ( $this->mRevisionRecord && $this->mRevisionRecord->getId() === $oldid ) {
1588 $revisionRecord = $this->mRevisionRecord;
1590 $revisionRecord = $this->revisionStore->getRevisionById( $oldid );
1593 $timestamp = $revisionRecord->getTimestamp();
1595 $current = ( $oldid == $this->mPage->getLatest() );
1596 $language = $context->getLanguage();
1597 $user = $context->getUser();
1599 $td = $language->userTimeAndDate( $timestamp, $user );
1600 $tddate = $language->userDate( $timestamp, $user );
1601 $tdtime = $language->userTime( $timestamp, $user );
1603 # Show user links if allowed to see them. If hidden, then show them only if requested...
1607 $infomsg = $current && !$context->msg(
'revision-info-current' )->isDisabled()
1608 ?
'revision-info-current'
1613 'mediawiki.action.styles',
1614 'mediawiki.interface.helpers.styles'
1617 $revisionUser = $revisionRecord->getUser();
1618 $revisionInfo =
"<div id=\"mw-{$infomsg}\">" .
1619 $context->msg( $infomsg, $td )
1620 ->rawParams( $userlinks )
1622 $revisionRecord->getId(),
1625 $revisionUser ? $revisionUser->getName() :
''
1637 ? $context->msg(
'currentrevisionlink' )->escaped()
1638 : $this->linkRenderer->makeKnownLink(
1640 $context->msg(
'currentrevisionlink' )->text(),
1645 ? $context->msg(
'diff' )->escaped()
1646 : $this->linkRenderer->makeKnownLink(
1648 $context->msg(
'diff' )->text(),
1656 $prevExist = (bool)$this->revisionStore->getPreviousRevision( $revisionRecord );
1657 $prevlink = $prevExist
1658 ? $this->linkRenderer->makeKnownLink(
1660 $context->msg(
'previousrevision' )->text(),
1663 'direction' =>
'prev',
1667 : $context->msg(
'previousrevision' )->escaped();
1668 $prevdiff = $prevExist
1669 ? $this->linkRenderer->makeKnownLink(
1671 $context->msg(
'diff' )->text(),
1678 : $context->msg(
'diff' )->escaped();
1679 $nextlink = $current
1680 ? $context->msg(
'nextrevision' )->escaped()
1681 : $this->linkRenderer->makeKnownLink(
1683 $context->msg(
'nextrevision' )->text(),
1686 'direction' =>
'next',
1690 $nextdiff = $current
1691 ? $context->msg(
'diff' )->escaped()
1692 : $this->linkRenderer->makeKnownLink(
1694 $context->msg(
'diff' )->text(),
1703 $context->getAuthority(),
1708 if ( $cdel !==
'' ) {
1716 "<div id=\"mw-revision-nav\">" . $cdel .
1717 $context->msg(
'revision-nav' )->rawParams(
1718 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1719 )->escaped() .
"</div>",
1738 public function viewRedirect( $target, $appendSubtitle =
true, $forceKnown =
false ) {
1742 if ( $appendSubtitle ) {
1743 $out->addSubtitle( $this->
getContext()->msg(
'redirectpagesub' ) );
1745 $out->addModuleStyles(
'mediawiki.action.view.redirectPage' );
1746 return static::getRedirectHeaderHtml(
$lang, $target, $forceKnown );
1762 if ( is_array( $target ) ) {
1764 wfDeprecatedMsg(
'The $target parameter can no longer be an array',
'1.39' );
1765 $target = reset( $target );
1768 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1770 $html =
'<ul class="redirectText">';
1771 if ( $forceKnown ) {
1774 $target->getFullText(),
1777 $target->isRedirect() ? [
'redirect' =>
'no' ] : []
1782 $target->getFullText(),
1785 $target->isRedirect() ? [
'redirect' =>
'no' ] : []
1788 $html .=
'<li>' . $link .
'</li>';
1791 $redirectToText =
wfMessage(
'redirectto' )->inLanguage(
$lang )->escaped();
1793 return '<div class="redirectMsg">' .
1794 '<p>' . $redirectToText .
'</p>' .
1809 $msg = $out->msg(
'namespace-' . $this->
getTitle()->getNamespace() .
'-helppage' );
1811 if ( !$msg->isDisabled() ) {
1812 $title = Title::newFromText( $msg->plain() );
1814 $out->addHelpLink(
$title->getLocalURL(),
true );
1817 $out->addHelpLink( $to, $overrideBaseUrl );
1825 $this->
getContext()->getRequest()->response()->header(
'X-Robots-Tag: noindex' );
1826 $this->
getContext()->getOutput()->setArticleBodyOnly(
true );
1828 $this->viewIsRenderAction =
true;
1860 public function doDelete( $reason, $suppress =
false, $immediate =
false ) {
1865 $user = $context->getUser();
1866 $status = $this->mPage->doDeleteArticleReal(
1867 $reason, $user, $suppress,
null, $error,
1868 null, [],
'delete', $immediate
1871 if ( $status->isOK() ) {
1872 $deleted = $this->
getTitle()->getPrefixedText();
1874 $outputPage->
setPageTitle( $context->msg(
'actioncomplete' ) );
1877 if ( $status->isGood() ) {
1878 $loglink =
'[[Special:Log/delete|' . $context->msg(
'deletionlog' )->text() .
']]';
1880 $this->getHookRunner()->onArticleDeleteAfterSuccess( $this->
getTitle(), $outputPage );
1888 $context->msg(
'cannotdelete-title',
1889 $this->getTitle()->getPrefixedText() )
1892 if ( $error ==
'' ) {
1894 'error mw-error-cannotdelete',
1895 $status->getWikiText(
false,
false, $context->getLanguage() )
1897 $deleteLogPage =
new LogPage(
'delete' );
1898 $outputPage->
addHTML( Xml::element(
'h2',
null, $deleteLogPage->getName()->text() ) );
1900 LogEventsList::showLogExtract(
1906 $outputPage->
addHTML( $error );
1921 static $called =
false;
1924 wfDebug(
"Article::tryFileCache(): called twice!?" );
1929 if ( $this->isFileCacheable() ) {
1931 if (
$cache->isCacheGood( $this->mPage->getTouched() ) ) {
1932 wfDebug(
"Article::tryFileCache(): about to load file" );
1936 wfDebug(
"Article::tryFileCache(): starting buffer" );
1937 ob_start( [ &
$cache,
'saveToFileCache' ] );
1940 wfDebug(
"Article::tryFileCache(): not cacheable" );
1955 $cacheable = $this->mPage->getId()
1956 && !$this->mRedirectedFrom && !$this->
getTitle()->isRedirect();
1959 $cacheable = $this->getHookRunner()->onIsFileCacheable( $this ) ??
false;
1980 if ( $user ===
null ) {
1981 $parserOptions = $this->getParserOptions();
1983 $parserOptions = $this->mPage->makeParserOptions( $user );
1986 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1994 return $this->mPage->makeParserOptions( $this->
getContext() );
2004 $this->mContext = $context;
2015 return $this->mContext;
2017 wfDebug( __METHOD__ .
" called and \$mContext is null. " .
2018 "Return RequestContext::getMain()" );
2019 return RequestContext::getMain();
2033 wfDeprecatedMsg(
"Accessing Article::\$$fname is deprecated since MediaWiki 1.35",
2036 if ( property_exists( $this->mPage, $fname ) ) {
2037 return $this->mPage->$fname;
2039 trigger_error(
'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2051 public function __set( $fname, $fvalue ) {
2052 wfDeprecatedMsg(
"Setting Article::\$$fname is deprecated since MediaWiki 1.35",
2055 if ( property_exists( $this->mPage, $fname ) ) {
2056 $this->mPage->$fname = $fvalue;
2058 } elseif ( !in_array( $fname, [
'mContext',
'mPage' ] ) ) {
2059 $this->mPage->$fname = $fvalue;
2061 trigger_error(
'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2071 return $this->mPage->getActionOverrides();
2081 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
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.
string bool $mRedirectUrl
URL to redirect to or false if none.
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.
viewRedirect( $target, $appendSubtitle=true, $forceKnown=false)
Return the HTML for the top of a redirect page.
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.
Rendering of file description pages.
Base class for language-specific code.
static revComment(RevisionRecord $revRecord, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision's comment block, if the current user is allowed to view it.
static getRevDeleteLink(Authority $performer, RevisionRecord $revRecord, LinkTarget $title)
Get a revision-deletion link, or disabled link, or nothing, depending on user permissions & the setti...
static revUserTools(RevisionRecord $revRecord, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
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.
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.
setSections(array $sections)
Adds sections to OutputPage from ParserOutput.
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?
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.
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.
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 newFromName( $name, $validate='valid')
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)
if(!isset( $args[0])) $lang