+ # Should the parser cache be used?
+ $useParserCache = $this->useParserCache( $oldid );
+ wfDebug( 'Article::view using parser cache: ' . ($useParserCache ? 'yes' : 'no' ) . "\n" );
+ if( $wgUser->getOption( 'stubthreshold' ) ) {
+ wfIncrStats( 'pcache_miss_stub' );
+ }
+
+ # For the main page, overwrite the <title> element with the con-
+ # tents of 'pagetitle-view-mainpage' instead of the default (if
+ # that's not empty).
+ if( $this->mTitle->equals( Title::newMainPage() )
+ && wfMsgForContent( 'pagetitle-view-mainpage' ) !== '' )
+ {
+ $wgOut->setHTMLTitle( wfMsgForContent( 'pagetitle-view-mainpage' ) );
+ }
+
+ $wasRedirected = $this->showRedirectedFromHeader();
+ $this->showNamespaceHeader();
+
+ $outputDone = false;
+ wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
+
+ # Try the parser cache
+ if( !$outputDone && $useParserCache ) {
+ $parserOutput = $parserCache->get( $this, $parserOptions );
+ if ( $parserOutput !== false ) {
+ wfDebug( __METHOD__.": showing parser cache contents\n" );
+ $wgOut->addParserOutput( $parserOutput );
+ // Ensure that UI elements requiring revision ID have
+ // the correct version information.
+ $wgOut->setRevisionId( $this->mLatest );
+ $outputDone = true;
+ }
+ }
+
+ if ( $outputDone ) {
+ $this->showViewFooter();
+ $this->viewUpdates();
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ $text = $this->getContent();
+ if( $text === false || $this->getID() == 0 ) {
+ wfDebug( __METHOD__.": showing missing article\n" );
+ $this->showMissingArticle();
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ # Another whitelist check in case oldid is altering the title
+ if( !$this->mTitle->userCanRead() ) {
+ wfDebug( __METHOD__.": denied on secondary read check\n" );
+ $wgOut->loginToUse();
+ $wgOut->output();
+ $wgOut->disable();
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ # We're looking at an old revision
+ if( $oldid && !is_null( $this->mRevision ) ) {
+ $this->setOldSubtitle( $oldid );
+ if ( !$this->showDeletedRevisionHeader() ) {
+ wfDebug( __METHOD__.": cannot view deleted revision\n" );
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ if ( $oldid === $this->getLatest() && $this->useParserCache( false ) ) {
+ $parserOutput = $parserCache->get( $this, $parserOptions );
+ if ( $parserOutput ) {
+ wfDebug( __METHOD__.": showing parser cache for current rev permalink\n" );
+ $wgOut->addParserOutput( $parserOutput );
+ $this->showViewFooter();
+ $this->viewUpdates();
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+ }
+ }
+
+ // Ensure that UI elements requiring revision ID have
+ // the correct version information.
+ $wgOut->setRevisionId( $this->getRevIdFetched() );
+
+ // Pages containing custom CSS or JavaScript get special treatment
+ if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) {
+ wfDebug( __METHOD__.": showing CSS/JS source\n" );
+ $this->showCssOrJsPage();
+ $outputDone = true;
+ } else if( $rt = Title::newFromRedirectArray( $text ) ) {
+ wfDebug( __METHOD__.": showing redirect=no page\n" );
+ # Viewing a redirect page (e.g. with parameter redirect=no)
+ # Don't append the subtitle if this was an old revision
+ $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
+ # Parse just to get categories, displaytitle, etc.
+ $parserOutput = $wgParser->parse( $text, $this->mTitle, $parserOptions );
+ $wgOut->addParserOutputNoText( $parserOutput );
+ $outputDone = true;
+ }
+ if ( $outputDone ) {
+ $this->showViewFooter();
+ $this->viewUpdates();
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ # Run the parse, protected by a pool counter
+ wfDebug( __METHOD__.": doing uncached parse\n" );
+ $key = $parserCache->getKey( $this, $parserOptions );
+ $poolCounter = PoolCounter::factory( 'Article::view', $key );
+ $dirtyCallback = $useParserCache ? array( $this, 'tryDirtyCache' ) : false;
+ $status = $poolCounter->executeProtected( array( $this, 'doViewParse' ), $dirtyCallback );
+
+ if ( !$status->isOK() ) {
+ # Connection or timeout error
+ $this->showPoolError( $status );
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ $this->showViewFooter();
+ $this->viewUpdates();
+ wfProfileOut( __METHOD__ );
+ }
+
+ /**
+ * Show a diff page according to current request variables. For use within
+ * Article::view() only, other callers should use the DifferenceEngine class.
+ */
+ public function showDiffPage() {
+ global $wgOut, $wgRequest, $wgUser;
+