22 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
35 use Wikimedia\IPUtils;
36 use Wikimedia\NonSerializable\NonSerializableTrait;
48 use ProtectedHookAccessorTrait;
49 use NonSerializableTrait;
126 $this->mOldId = $oldId;
127 $this->mPage = $this->
newPage( $title );
129 $services = MediaWikiServices::getInstance();
130 $this->linkRenderer = $services->getLinkRenderer();
131 $this->revisionStore = $services->getRevisionStore();
132 $this->watchlistManager = $services->getWatchlistManager();
133 $this->userNameUtils = $services->getUserNameUtils();
151 return $t ==
null ? null :
new static(
$t );
171 switch (
$title->getNamespace() ) {
182 $page->setContext( $context );
196 $article->mPage = $page;
215 $this->mRedirectedFrom = $from;
224 return $this->mPage->getTitle();
238 $this->mRedirectedFrom =
null; #
Title object if set
239 $this->mRedirectUrl =
false;
240 $this->mRevisionRecord =
null;
241 $this->fetchResult =
null;
245 $this->mPage->clear();
256 if ( $this->mOldId ===
null ) {
269 $this->mRedirectUrl =
false;
272 $oldid = $request->getIntOrNull(
'oldid' );
274 if ( $oldid ===
null ) {
278 if ( $oldid !== 0 ) {
279 # Load the given revision and check whether the page is another one.
280 # In that case, update this instance to reflect the change.
281 if ( $oldid === $this->mPage->getLatest() ) {
282 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
284 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
285 if ( $this->mRevisionRecord !==
null ) {
286 $revPageId = $this->mRevisionRecord->getPageId();
288 if ( $this->mPage->getId() != $revPageId ) {
289 $function = get_class( $this->mPage ) .
'::newFromID';
290 $this->mPage = $function( $revPageId );
297 if ( $request->getRawVal(
'direction' ) ===
'next' ) {
300 $nextRev = $this->revisionStore->getNextRevision( $oldRev );
302 $nextid = $nextRev->
getId();
307 $this->mRevisionRecord =
null;
309 $this->mRedirectUrl = $this->
getTitle()->getFullURL(
'redirect=no' );
311 } elseif ( $request->getRawVal(
'direction' ) ===
'prev' ) {
314 $prevRev = $this->revisionStore->getPreviousRevision( $oldRev );
316 $previd = $prevRev->getId();
321 $this->mRevisionRecord =
null;
338 if ( $this->fetchResult ) {
345 if ( !$this->mRevisionRecord ) {
347 $this->mRevisionRecord = $this->mPage->getRevisionRecord();
349 if ( !$this->mRevisionRecord ) {
350 wfDebug( __METHOD__ .
" failed to find page data for title " .
351 $this->
getTitle()->getPrefixedText() );
358 $this->mRevisionRecord = $this->revisionStore->getRevisionById( $oldid );
360 if ( !$this->mRevisionRecord ) {
361 wfDebug( __METHOD__ .
" failed to load revision, rev_id $oldid" );
369 if ( !$this->mRevisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getContext()->getAuthority() ) ) {
370 wfDebug( __METHOD__ .
" failed to retrieve content of revision " . $this->mRevisionRecord->getId() );
374 $this->fetchResult =
new Status;
377 if ( $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
378 $this->fetchResult->fatal(
'rev-suppressed-text' );
380 $this->fetchResult->fatal(
'rev-deleted-text-permission',
$title );
396 # If no oldid, this is the current version.
401 return $this->mPage->exists() &&
402 $this->mRevisionRecord &&
403 $this->mRevisionRecord->isCurrent();
415 if ( $this->fetchResult && $this->fetchResult->isOK() ) {
416 return $this->fetchResult->value->getId();
418 return $this->mPage->getLatest();
427 $useFileCache = MediaWikiServices::getInstance()
428 ->getMainConfig()->get( MainConfigNames::UseFileCache );
430 # Get variables from query string
431 # As side effect this will load the revision and update the title
432 # in a revision ID is passed in the request, so this should remain
433 # the first call of this method even if $oldid is used way below.
437 # Another check in case getOldID() is altering the title
438 $permissionStatus = PermissionStatus::newEmpty();
440 ->authorizeRead(
'read', $this->
getTitle(), $permissionStatus )
442 wfDebug( __METHOD__ .
": denied on secondary read check" );
446 $outputPage = $this->
getContext()->getOutput();
447 # getOldID() may as well want us to redirect somewhere else
448 if ( $this->mRedirectUrl ) {
449 $outputPage->
redirect( $this->mRedirectUrl );
450 wfDebug( __METHOD__ .
": redirecting due to oldid" );
455 # If we got diff in the query, we want to see a diff page instead of the article.
456 if ( $this->
getContext()->getRequest()->getCheck(
'diff' ) ) {
457 wfDebug( __METHOD__ .
": showing diff page" );
463 # Set page title (may be overridden by DISPLAYTITLE)
467 # Allow frames by default
470 $skin = $outputPage->
getSkin();
471 $skinOptions = $skin->getOptions();
476 'injectTOC' => $skinOptions[
'toc'],
478 # Allow extensions to vary parser options used for article rendering
479 Hooks::runner()->onArticleParserOptions( $this, $parserOptions );
480 # Render printable version, use printable version cache
483 $poOptions[
'enableSectionEditLinks'] =
false;
486 $outputPage->
msg(
'printableversion-deprecated-warning' )->escaped()
489 } elseif ( $this->viewIsRenderAction || !$this->
isCurrent() ||
492 $poOptions[
'enableSectionEditLinks'] =
false;
495 # Try client and file cache
496 if ( $oldid === 0 && $this->mPage->checkTouched() ) {
497 # Try to stream the output from file cache
499 wfDebug( __METHOD__ .
": done file cache" );
500 # tell wgOut that output is taken care of
502 $this->mPage->doViewUpdates( $user, $oldid );
511 if ( $this->viewIsRenderAction ) {
512 $poOptions += [
'absoluteURLs' =>
true ];
514 $poOptions += [
'includeDebugInfo' =>
true ];
523 # For the main page, overwrite the <title> element with the con-
524 # tents of 'pagetitle-view-mainpage' instead of the default (if
526 # This message always exists because it is in the i18n files
527 if ( $this->
getTitle()->isMainPage() ) {
528 $msg =
wfMessage(
'pagetitle-view-mainpage' )->inContentLanguage();
529 if ( !$msg->isDisabled() ) {
530 $outputPage->
setHTMLTitle( $msg->page( $this->getTitle() )->text() );
534 # Use adaptive TTLs for CDN so delayed/failed purges are noticed less often.
535 # This could use getTouched(), but that could be scary for major template edits.
536 $outputPage->
adaptCdnTTL( $this->mPage->getTimestamp(), IExpiringStore::TTL_DAY );
541 # Load the postEdit module if the user just saved this revision
542 # See also EditPage::setPostEditCookie
545 $postEdit = $request->getCookie( $cookieKey );
547 # Clear the cookie. This also prevents caching of the response.
548 $request->response()->clearCookie( $cookieKey );
550 $outputPage->
addModules(
'mediawiki.action.view.postEdit' );
573 # Should the parser cache be used?
574 $useParserCache =
true;
576 $parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
579 $this->getHookRunner()->onArticleViewHeader( $this, $outputDone, $useParserCache );
582 $pOutput = $outputDone;
592 if ( !$this->mPage->exists() ) {
593 wfDebug( __METHOD__ .
": showing missing article" );
595 $this->mPage->doViewUpdates( $performer );
601 if ( $useParserCache && !$oldid ) {
602 $pOutput = $parserOutputAccess->getCachedParserOutput(
606 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
617 if ( !$this->fetchResult->isOK() ) {
619 false,
false, $this->getContext()->getLanguage()
624 # Are we looking at an old revision
629 wfDebug( __METHOD__ .
": cannot view deleted revision" );
636 if ( $useParserCache ) {
637 $pOutput = $parserOutputAccess->getCachedParserOutput(
641 ParserOutputAccess::OPT_NO_AUDIENCE_CHECK
652 # Ensure that UI elements requiring revision ID have
653 # the correct version information.
655 # Preload timestamp to avoid a DB hit
658 # Pages containing custom CSS or JavaScript get special treatment
659 if ( $this->
getTitle()->isSiteConfigPage() || $this->
getTitle()->isUserConfigPage() ) {
660 $dir = $this->
getContext()->getLanguage()->getDir();
664 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
668 } elseif ( !$this->getHookRunner()->onArticleRevisionViewCustom(
680 # Run the parse, protected by a pool counter
681 wfDebug( __METHOD__ .
": doing uncached parse" );
691 $opt |= ParserOutputAccess::OPT_NO_CHECK_CACHE;
694 $opt |= ParserOutputAccess::OPT_NO_AUDIENCE_CHECK;
696 if ( !$rev->getId() || !$useParserCache ) {
698 $opt |= ParserOutputAccess::OPT_NO_CACHE;
701 $renderStatus = $parserOutputAccess->getParserOutput(
715 if ( !$renderStatus->isOK() ) {
719 $pOutput = $renderStatus->getValue();
729 # Adjust title for main page & pages with displaytitle
731 $this->adjustDisplayTitle( $pOutput );
734 # Check for any __NOINDEX__ tags on the page using $pOutput
735 $policy = $this->getRobotPolicy(
'view', $pOutput ?:
null );
739 $this->mParserOutput = $pOutput;
752 # Ensure that UI elements requiring revision ID have
753 # the correct version information.
755 # Ensure that the skin has the necessary ToC information
756 # (and do this before OutputPage::addParserOutput() calls the
757 # OutputPageParserOutput hook)
760 # Preload timestamp to avoid a DB hit
762 if ( $cachedTimestamp !==
null ) {
764 $this->mPage->setTimestamp( $cachedTimestamp );
780 $cdnMaxageStale = MediaWikiServices::getInstance()
781 ->getMainConfig()->get( MainConfigNames::CdnMaxageStale );
782 $ok = $renderStatus->
isOK();
784 $pOutput = $ok ? $renderStatus->
getValue() :
null;
787 if ( $ok && $renderStatus->
hasMessage(
'view-pool-dirty-output' ) ) {
790 $staleReason = $renderStatus->
hasMessage(
'view-pool-contention' )
791 ? $this->
getContext()->msg(
'view-pool-contention' )
792 : $this->
getContext()->msg(
'view-pool-timeout' );
793 $outputPage->
addHTML(
"<!-- parser cache is expired, " .
794 "sending anyway due to $staleReason-->\n" );
797 if ( !$renderStatus->
isOK() ) {
799 false,
'view-pool-error', $this->getContext()->getLanguage()
806 $outputPage->
setSections( $pOutput->getSections() );
809 if ( $this->getRevisionRedirectTarget( $rev ) ) {
810 $outputPage->
addSubtitle(
"<span id=\"redirectsub\">" .
811 $this->
getContext()->msg(
'redirectpagesub' )->parse() .
"</span>" );
834 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
836 if ( strval( $titleText ) !==
'' ) {
837 $out->setPageTitle( $titleText );
838 $out->setDisplayTitle( $titleText );
849 $diff = $request->getVal(
'diff' );
850 $rcid = $request->getInt(
'rcid' );
851 $diffOnly = $request->getBool(
'diffonly', $user->getOption(
'diffonly' ) );
852 $purge = $request->getRawVal(
'action' ) ===
'purge';
853 $unhide = $request->getInt(
'unhide' ) == 1;
854 $oldid = $this->getOldID();
856 $rev = $this->fetchRevisionRecord();
861 $rev = $this->revisionStore->getRevisionById( $oldid );
868 $msg = $this->
getContext()->msg(
'difference-missing-revision' )
872 $this->
getContext()->getOutput()->addHTML( $msg );
877 $contentHandler = MediaWikiServices::getInstance()
878 ->getContentHandlerFactory()
880 $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
882 $de = $contentHandler->createDifferenceEngine(
890 $de->setSlotDiffOptions( [
891 'diff-type' => $request->getVal(
'diff-type' ),
892 'expand-url' => $this->viewIsRenderAction
894 $de->showDiffPage( $diffOnly );
898 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
900 $this->mPage->doViewUpdates( $user, (
int)$new );
911 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
912 $articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies );
913 $namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies );
914 $defaultRobotPolicy = $mainConfig->get( MainConfigNames::DefaultRobotPolicy );
915 $ns = $this->
getTitle()->getNamespace();
917 # Don't index user and user talk pages for blocked users (T13443)
919 $specificTarget =
null;
921 $titleText = $this->
getTitle()->getText();
922 if ( IPUtils::isValid( $titleText ) ) {
923 $vagueTarget = $titleText;
925 $specificTarget = $titleText;
927 if ( DatabaseBlock::newFromTarget( $specificTarget, $vagueTarget ) instanceof
DatabaseBlock ) {
929 'index' =>
'noindex',
930 'follow' =>
'nofollow'
935 if ( $this->mPage->getId() === 0 || $this->getOldID() ) {
936 # Non-articles (special pages etc), and old revisions
938 'index' =>
'noindex',
939 'follow' =>
'nofollow'
941 } elseif ( $this->
getContext()->getOutput()->isPrintable() ) {
942 # Discourage indexing of printable versions, but encourage following
944 'index' =>
'noindex',
947 } elseif ( $this->
getContext()->getRequest()->getInt(
'curid' ) ) {
948 # For ?curid=x urls, disallow indexing
950 'index' =>
'noindex',
955 # Otherwise, construct the policy based on the various config variables.
956 $policy = self::formatRobotPolicy( $defaultRobotPolicy );
958 if ( isset( $namespaceRobotPolicies[$ns] ) ) {
959 # Honour customised robot policies for this namespace
960 $policy = array_merge(
962 self::formatRobotPolicy( $namespaceRobotPolicies[$ns] )
965 if ( $this->
getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
966 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
967 # a final check that we have really got the parser output.
968 $policy = array_merge(
970 [
'index' => $pOutput->getIndexPolicy() ]
974 if ( isset( $articleRobotPolicies[$this->
getTitle()->getPrefixedText()] ) ) {
975 # (T16900) site config can override user-defined __INDEX__ or __NOINDEX__
976 $policy = array_merge(
978 self::formatRobotPolicy( $articleRobotPolicies[$this->
getTitle()->getPrefixedText()] )
993 if ( is_array( $policy ) ) {
995 } elseif ( !$policy ) {
1000 foreach ( explode(
',', $policy ) as $var ) {
1001 $var = trim( $var );
1002 if ( $var ===
'index' || $var ===
'noindex' ) {
1003 $arr[
'index'] = $var;
1004 } elseif ( $var ===
'follow' || $var ===
'nofollow' ) {
1005 $arr[
'follow'] = $var;
1020 $redirectSources = MediaWikiServices::getInstance()
1021 ->getMainConfig()->get( MainConfigNames::RedirectSources );
1025 $request = $context->getRequest();
1026 $rdfrom = $request->getVal(
'rdfrom' );
1029 $query = $request->getValues();
1030 unset( $query[
'rdfrom'] );
1031 unset( $query[
'title'] );
1032 if ( $this->
getTitle()->isRedirect() ) {
1034 $query[
'redirect'] =
'no';
1036 $redirectTargetUrl = $this->
getTitle()->getLinkURL( $query );
1038 if ( isset( $this->mRedirectedFrom ) ) {
1041 if ( $this->getHookRunner()->onArticleViewRedirect( $this ) ) {
1042 $redir = $this->linkRenderer->makeKnownLink(
1043 $this->mRedirectedFrom,
1046 [
'redirect' =>
'no' ]
1049 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1050 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1056 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1058 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1068 } elseif ( $rdfrom ) {
1071 if ( $redirectSources && preg_match( $redirectSources, $rdfrom ) ) {
1073 $outputPage->
addSubtitle(
"<span class=\"mw-redirectedfrom\">" .
1074 $context->msg(
'redirectedfrom' )->rawParams( $redir )->parse()
1079 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1081 $outputPage->
addModules(
'mediawiki.action.view.redirect' );
1095 if ( $this->
getTitle()->isTalkPage() && !
wfMessage(
'talkpageheader' )->isDisabled() ) {
1096 $this->
getContext()->getOutput()->wrapWikiMsg(
1097 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1098 [
'talkpageheader' ]
1107 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1109 && IPUtils::isValid( $this->
getTitle()->getText() )
1111 $this->
getContext()->getOutput()->addWikiMsg(
'anontalkpagetext' );
1115 $patrolFooterShown = $this->showPatrolFooter();
1117 $this->getHookRunner()->onArticleViewFooter( $this, $patrolFooterShown );
1131 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
1132 $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
1133 $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
1134 $useFilePatrol = $mainConfig->get( MainConfigNames::UseFilePatrol );
1136 if ( !$this->getHookRunner()->onArticleShowPatrolFooter( $this ) ) {
1140 $outputPage = $this->
getContext()->getOutput();
1146 || !( $useRCPatrol || $useNPPatrol
1153 if ( $this->mRevisionRecord
1162 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1163 $key =
$cache->makeKey(
'unpatrollable-page',
$title->getArticleID() );
1164 if (
$cache->get( $key ) ) {
1169 $oldestRevisionTimestamp =
$dbr->selectField(
1171 'MIN( rev_timestamp )',
1172 [
'rev_page' =>
$title->getArticleID() ],
1181 $recentPageCreation =
false;
1182 if ( $oldestRevisionTimestamp
1186 $recentPageCreation =
true;
1190 'rc_timestamp' => $oldestRevisionTimestamp,
1191 'rc_namespace' =>
$title->getNamespace(),
1192 'rc_cur_id' =>
$title->getArticleID()
1198 $markPatrolledMsg =
wfMessage(
'markaspatrolledtext' );
1206 $recentFileUpload =
false;
1207 if ( ( !$rc || $rc->getAttribute(
'rc_patrolled' ) ) && $useFilePatrol
1210 $newestUploadTimestamp =
$dbr->selectField(
1212 'MAX( img_timestamp )',
1213 [
'img_name' =>
$title->getDBkey() ],
1216 if ( $newestUploadTimestamp
1220 $recentFileUpload =
true;
1224 'rc_log_type' =>
'upload',
1225 'rc_timestamp' => $newestUploadTimestamp,
1227 'rc_cur_id' =>
$title->getArticleID()
1233 $markPatrolledMsg =
wfMessage(
'markaspatrolledtext-file' );
1238 if ( !$recentPageCreation && !$recentFileUpload ) {
1243 $cache->set( $key,
'1' );
1255 if ( $rc->getAttribute(
'rc_patrolled' ) ) {
1260 $cache->set( $key,
'1' );
1265 if ( $rc->getPerformerIdentity()->equals( $user ) ) {
1273 $outputPage->
addModules(
'mediawiki.misc-authed-curate' );
1276 $link = $this->linkRenderer->makeKnownLink(
1279 $markPatrolledMsg->text(),
1282 'action' =>
'markpatrolled',
1283 'rcid' => $rc->getAttribute(
'rc_id' ),
1289 "<div class='patrollink' data-mw='interface'>" .
1290 wfMessage(
'markaspatrolledlink' )->rawParams( $link )->escaped() .
1304 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1305 $cache->delete(
$cache->makeKey(
'unpatrollable-page', $articleID ) );
1313 $send404Code = MediaWikiServices::getInstance()
1314 ->getMainConfig()->get( MainConfigNames::Send404Code );
1316 $outputPage = $this->
getContext()->getOutput();
1318 $validUserPage =
false;
1322 $services = MediaWikiServices::getInstance();
1324 $contextUser = $this->
getContext()->getUser();
1326 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1330 $rootPart = explode(
'/',
$title->getText() )[0];
1332 $ip = $this->userNameUtils->isIP( $rootPart );
1333 $block = DatabaseBlock::newFromTarget( $user, $user );
1335 if ( $user && $user->isRegistered() && $user->isHidden() &&
1336 !$this->getContext()->getAuthority()->isAllowed(
'hideuser' )
1343 if ( !( $user && $user->isRegistered() ) && !$ip ) { #
User does not exist
1345 $outputPage->
msg(
'userpage-userdoesnotexist-view',
wfEscapeWikiText( $rootPart ) )->parse(),
1346 'mw-userpage-userdoesnotexist'
1350 $block->getType() != DatabaseBlock::TYPE_AUTO &&
1352 $block->isSitewide() ||
1353 $user->isBlockedFrom(
$title,
true )
1361 $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
':' .
1362 $block->getTargetName(),
1366 'showIfEmpty' =>
false,
1368 'blocked-notice-logextract',
1369 $user->getName() # Support GENDER in notice
1373 $validUserPage = !
$title->isSubpage();
1375 $validUserPage = !
$title->isSubpage();
1379 $this->getHookRunner()->onShowMissingArticle( $this );
1381 # Show delete and move logs if there were any such events.
1382 # The logging query can DOS the site when bots/crawlers cause 404 floods,
1383 # so be careful showing this. 404 pages must be cheap as they are hard to cache.
1384 $dbCache = MediaWikiServices::getInstance()->getMainObjectStash();
1385 $key = $dbCache->makeKey(
'page-recent-delete', md5(
$title->getPrefixedText() ) );
1386 $isRegistered = $contextUser->isRegistered();
1387 $sessionExists = $this->
getContext()->getRequest()->getSession()->isPersistent();
1389 if ( $isRegistered || $dbCache->get( $key ) || $sessionExists ) {
1390 $logTypes = [
'delete',
'move',
'protect' ];
1394 $conds = [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ];
1396 $this->getHookRunner()->onArticle__MissingArticleConditions( $conds, $logTypes );
1405 'showIfEmpty' =>
false,
1406 'msgKey' => [ $isRegistered || $sessionExists
1407 ?
'moveddeleted-notice'
1408 :
'moveddeleted-notice-recent'
1414 if ( !$this->mPage->hasViewableContent() && $send404Code && !$validUserPage ) {
1417 $this->
getContext()->getRequest()->response()->statusHeader( 404 );
1421 $policy = $this->getRobotPolicy(
'view' );
1425 $hookResult = $this->getHookRunner()->onBeforeDisplayNoArticleText( $this );
1427 if ( !$hookResult ) {
1431 # Show error message
1432 $oldid = $this->getOldID();
1434 $text = $this->
getTitle()->getDefaultMessageText() ??
'';
1441 $revRecord = $pa->getArchivedRevisionRecord( $oldid );
1442 if ( $revRecord && $revRecord->userCan(
1443 RevisionRecord::DELETED_TEXT,
1444 $this->getContext()->getAuthority()
1447 'missing-revision-permission', $oldid,
1448 $revRecord->getTimestamp(),
1449 $title->getPrefixedDBkey()
1452 $text =
wfMessage(
'missing-revision', $oldid )->plain();
1457 $message = $isRegistered ?
'noarticletext' :
'noarticletextanon';
1460 $text =
wfMessage(
'noarticletext-nopermission' )->plain();
1463 $dir = $this->
getContext()->getLanguage()->getDir();
1466 'class' =>
"noarticletext mw-content-$dir",
1469 ] ) .
"\n$text\n</div>" );
1478 $outputPage = $this->
getContext()->getOutput();
1493 if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
1497 $outputPage = $this->
getContext()->getOutput();
1500 $titleText = $this->
getTitle()->getPrefixedDBkey();
1502 if ( !$this->mRevisionRecord->userCan(
1503 RevisionRecord::DELETED_TEXT,
1504 $this->getContext()->getAuthority()
1506 $outputPage->addHtml(
1508 $outputPage->
msg(
'rev-deleted-text-permission', $titleText )->parse(),
1515 } elseif ( $this->
getContext()->getRequest()->getInt(
'unhide' ) != 1 ) {
1516 # Give explanation and add a link to view the revision...
1517 $oldid = intval( $this->getOldID() );
1518 $link = $this->
getTitle()->getFullURL(
"oldid={$oldid}&unhide=1" );
1519 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ?
1520 'rev-suppressed-text-unhide' :
'rev-deleted-text-unhide';
1521 $outputPage->addHtml(
1523 $outputPage->
msg( $msg, $link )->parse(),
1531 $msg = $this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED )
1532 ? [
'rev-suppressed-text-view', $titleText ]
1533 : [
'rev-deleted-text-view', $titleText ];
1534 $outputPage->addHtml(
1536 $outputPage->
msg( $msg[0], $msg[1] )->parse(),
1554 if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
1559 $unhide = $context->getRequest()->getInt(
'unhide' ) == 1;
1561 # Cascade unhide param in links for easy deletion browsing
1564 $extraParams[
'unhide'] = 1;
1567 if ( $this->mRevisionRecord && $this->mRevisionRecord->getId() === $oldid ) {
1568 $revisionRecord = $this->mRevisionRecord;
1570 $revisionRecord = $this->revisionStore->getRevisionById( $oldid );
1573 $timestamp = $revisionRecord->getTimestamp();
1575 $current = ( $oldid == $this->mPage->getLatest() );
1576 $language = $context->getLanguage();
1577 $user = $context->getUser();
1579 $td = $language->userTimeAndDate( $timestamp, $user );
1580 $tddate = $language->userDate( $timestamp, $user );
1581 $tdtime = $language->userTime( $timestamp, $user );
1583 # Show user links if allowed to see them. If hidden, then show them only if requested...
1587 $infomsg = $current && !$context->msg(
'revision-info-current' )->isDisabled()
1588 ?
'revision-info-current'
1593 'mediawiki.action.styles',
1594 'mediawiki.interface.helpers.styles'
1597 $revisionUser = $revisionRecord->getUser();
1598 $revisionInfo =
"<div id=\"mw-{$infomsg}\">" .
1599 $context->msg( $infomsg, $td )
1600 ->rawParams( $userlinks )
1602 $revisionRecord->getId(),
1605 $revisionUser ? $revisionUser->getName() :
''
1617 ? $context->msg(
'currentrevisionlink' )->escaped()
1618 : $this->linkRenderer->makeKnownLink(
1620 $context->msg(
'currentrevisionlink' )->text(),
1625 ? $context->msg(
'diff' )->escaped()
1626 : $this->linkRenderer->makeKnownLink(
1628 $context->msg(
'diff' )->text(),
1636 $prevExist = (bool)$this->revisionStore->getPreviousRevision( $revisionRecord );
1637 $prevlink = $prevExist
1638 ? $this->linkRenderer->makeKnownLink(
1640 $context->msg(
'previousrevision' )->text(),
1643 'direction' =>
'prev',
1647 : $context->msg(
'previousrevision' )->escaped();
1648 $prevdiff = $prevExist
1649 ? $this->linkRenderer->makeKnownLink(
1651 $context->msg(
'diff' )->text(),
1658 : $context->msg(
'diff' )->escaped();
1659 $nextlink = $current
1660 ? $context->msg(
'nextrevision' )->escaped()
1661 : $this->linkRenderer->makeKnownLink(
1663 $context->msg(
'nextrevision' )->text(),
1666 'direction' =>
'next',
1670 $nextdiff = $current
1671 ? $context->msg(
'diff' )->escaped()
1672 : $this->linkRenderer->makeKnownLink(
1674 $context->msg(
'diff' )->text(),
1688 if ( $cdel !==
'' ) {
1696 "<div id=\"mw-revision-nav\">" . $cdel .
1697 $context->msg(
'revision-nav' )->rawParams(
1698 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1699 )->escaped() .
"</div>",
1718 public function viewRedirect( $target, $appendSubtitle =
true, $forceKnown =
false ) {
1721 if ( $appendSubtitle ) {
1722 $out->addSubtitle(
wfMessage(
'redirectpagesub' ) );
1724 $out->addModuleStyles(
'mediawiki.action.view.redirectPage' );
1725 return static::getRedirectHeaderHtml(
$lang, $target, $forceKnown );
1741 if ( is_array( $target ) ) {
1743 wfDeprecatedMsg(
'The $target parameter can no longer be an array',
'1.39' );
1744 $target = reset( $target );
1747 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1749 $html =
'<ul class="redirectText">';
1750 if ( $forceKnown ) {
1753 $target->getFullText(),
1756 $target->isRedirect() ? [
'redirect' =>
'no' ] : []
1761 $target->getFullText(),
1764 $target->isRedirect() ? [
'redirect' =>
'no' ] : []
1767 $html .=
'<li>' . $link .
'</li>';
1770 $redirectToText =
wfMessage(
'redirectto' )->inLanguage(
$lang )->escaped();
1772 return '<div class="redirectMsg">' .
1773 '<p>' . $redirectToText .
'</p>' .
1788 $msg = $out->msg(
'namespace-' . $this->
getTitle()->getNamespace() .
'-helppage' );
1790 if ( !$msg->isDisabled() ) {
1793 $out->addHelpLink(
$title->getLocalURL(),
true );
1796 $out->addHelpLink( $to, $overrideBaseUrl );
1804 $this->
getContext()->getRequest()->response()->header(
'X-Robots-Tag: noindex' );
1805 $this->
getContext()->getOutput()->setArticleBodyOnly(
true );
1807 $this->viewIsRenderAction =
true;
1839 public function doDelete( $reason, $suppress =
false, $immediate =
false ) {
1844 $user = $context->getUser();
1845 $status = $this->mPage->doDeleteArticleReal(
1846 $reason, $user, $suppress,
null, $error,
1847 null, [],
'delete', $immediate
1850 if ( $status->isOK() ) {
1851 $deleted = $this->
getTitle()->getPrefixedText();
1856 if ( $status->isGood() ) {
1857 $loglink =
'[[Special:Log/delete|' .
wfMessage(
'deletionlog' )->text() .
']]';
1859 $this->getHookRunner()->onArticleDeleteAfterSuccess( $this->
getTitle(), $outputPage );
1868 $this->
getTitle()->getPrefixedText() )
1871 if ( $error ==
'' ) {
1873 'error mw-error-cannotdelete',
1874 $status->getWikiText(
false,
false, $context->getLanguage() )
1876 $deleteLogPage =
new LogPage(
'delete' );
1885 $outputPage->
addHTML( $error );
1900 static $called =
false;
1903 wfDebug(
"Article::tryFileCache(): called twice!?" );
1908 if ( $this->isFileCacheable() ) {
1910 if (
$cache->isCacheGood( $this->mPage->getTouched() ) ) {
1911 wfDebug(
"Article::tryFileCache(): about to load file" );
1915 wfDebug(
"Article::tryFileCache(): starting buffer" );
1916 ob_start( [ &
$cache,
'saveToFileCache' ] );
1919 wfDebug(
"Article::tryFileCache(): not cacheable" );
1934 $cacheable = $this->mPage->getId()
1935 && !$this->mRedirectedFrom && !$this->
getTitle()->isRedirect();
1938 $cacheable = $this->getHookRunner()->onIsFileCacheable( $this ) ??
false;
1959 if ( $user ===
null ) {
1960 $parserOptions = $this->getParserOptions();
1962 $parserOptions = $this->mPage->makeParserOptions( $user );
1965 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1973 return $this->mPage->makeParserOptions( $this->
getContext() );
1983 $this->mContext = $context;
1994 return $this->mContext;
1996 wfDebug( __METHOD__ .
" called and \$mContext is null. " .
1997 "Return RequestContext::getMain()" );
2012 wfDeprecatedMsg(
"Accessing Article::\$$fname is deprecated since MediaWiki 1.35",
2015 if ( property_exists( $this->mPage, $fname ) ) {
2016 return $this->mPage->$fname;
2018 trigger_error(
'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
2030 public function __set( $fname, $fvalue ) {
2031 wfDeprecatedMsg(
"Setting Article::\$$fname is deprecated since MediaWiki 1.35",
2034 if ( property_exists( $this->mPage, $fname ) ) {
2035 $this->mPage->$fname = $fvalue;
2037 } elseif ( !in_array( $fname, [
'mContext',
'mPage' ] ) ) {
2038 $this->mPage->$fname = $fvalue;
2040 trigger_error(
'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
2050 return $this->mPage->getActionOverrides();
2060 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.
UserNameUtils $userNameUtils
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.
RevisionRecord null $mRevisionRecord
Revision to be shown.
RevisionStore $revisionStore
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)
#-
showViewError(string $errortext)
Show error text for errors generated in Article::view().
static getRedirectHeaderHtml(Language $lang, $target, $forceKnown=false)
Return the HTML for the top of a redirect page.
protect()
action=protect handler
generateContentOutput(Authority $performer, ParserOptions $parserOptions, int $oldid, OutputPage $outputPage, array $textOptions)
Determines the desired ParserOutput and passes it to $outputPage.
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.
Status null $fetchResult
represents the outcome of fetchRevisionRecord().
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.
doOutputMetaData(?ParserOutput $pOutput, OutputPage $outputPage)
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]].
WatchlistManager $watchlistManager
getRevisionRedirectTarget(RevisionRecord $revision)
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
doOutputFromRenderStatus(?RevisionRecord $rev, Status $renderStatus, OutputPage $outputPage, array $textOptions)
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.
doOutputFromParserCache(ParserOutput $pOutput, OutputPage $outputPage, array $textOptions)
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.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
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.
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.
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()
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?
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