r36998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:< r36997‎ | r36998 | r36999 >
Date:19:05, 3 July 2008
Author:aaron
Status:old
Tags:
Comment:
Refactor some code
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
——@@ -746,12 +746,7 @@
747747 }
748748
749749 # Should the parser cache be used?
750 - $pcache = $wgEnableParserCache
751 - && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0
752 - && $this->exists()
753 - && empty( $oldid )
754 - && !$this->mTitle->isCssOrJsPage()
755 - && !$this->mTitle->isCssJsSubpage();
 750+ $pcache = $this->useParserCache( $oldid );
756751 wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" );
757752 if ( $wgUser->getOption( 'stubthreshold' ) ) {
758753 wfIncrStats( 'pcache_miss_stub' );
——@@ -762,7 +757,6 @@
763758 // This is an internally redirected page view.
764759 // We'll need a backlink to the source page for navigation.
765760 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
766 - $sk = $wgUser->getSkin();
767761 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom, '', 'redirect=no' );
768762 $s = wfMsg( 'redirectedfrom', $redir );
769763 $wgOut->setSubtitle( $s );
——@@ -779,7 +773,6 @@
780774 // If it was reported from a trusted site, supply a backlink.
781775 global $wgRedirectSources;
782776 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
783 - $sk = $wgUser->getSkin();
784777 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
785778 $s = wfMsg( 'redirectedfrom', $redir );
786779 $wgOut->setSubtitle( $s );
——@@ -797,6 +790,7 @@
798791 $outputDone = true;
799792 }
800793 }
 794+ # Fetch content and check for errors
801795 if ( !$outputDone ) {
802796 $text = $this->getContent();
803797 if ( $text === false ) {
——@@ -819,7 +813,6 @@
820814 }
821815
822816 # We're looking at an old revision
823 -
824817 if ( !empty( $oldid ) ) {
825818 $wgOut->setRobotpolicy( 'noindex,nofollow' );
826819 if( is_null( $this->mRevision ) ) {
——@@ -838,16 +831,13 @@
839832 }
840833 }
841834 }
842 -
843835 }
844 - }
845 - if( !$outputDone ) {
 836+
846837 $wgOut->setRevisionId( $this->getRevIdFetched() );
847838
848839 // Pages containing custom CSS or JavaScript get special treatment
849840 if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) {
850841 $wgOut->addHtml( wfMsgExt( 'clearyourcache', 'parse' ) );
851 -
852842 // Give hooks a chance to customise the output
853843 if( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->mTitle, $wgOut ) ) ) {
854844 // Wrap the whole lot in a <pre> and don't parse
——@@ -857,10 +847,7 @@
858848 $wgOut->addHtml( htmlspecialchars( $this->mContent ) );
859849 $wgOut->addHtml( "\n</pre>\n" );
860850 }
861 -
862 - }
863 -
864 - elseif ( $rt = Title::newFromRedirect( $text ) ) {
 851+ } else if ( $rt = Title::newFromRedirect( $text ) ) {
865852 # Don't append the subtitle if this was an old revision
866853 $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() );
867854 $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
——@@ -889,7 +876,6 @@
890877 if( !$this->isCurrent() ) {
891878 $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
892879 }
893 -
894880 }
895881 }
896882 /* title may have been set from the cache */
——@@ -899,8 +885,7 @@
900886 }
901887
902888 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
903 - if( $ns == NS_USER_TALK &&
904 - IP::isValid( $this->mTitle->getText() ) ) {
 889+ if( $ns == NS_USER_TALK && IP::isValid( $this->mTitle->getText() ) ) {
905890 $wgOut->addWikiMsg('anontalkpagetext');
906891 }
907892
——@@ -925,6 +910,20 @@
926911 wfProfileOut( __METHOD__ );
927912 }
928913
 914+ /*
 915+ * Should the parser cache be used?
 916+ */
 917+ protected function useParserCache( $oldid ) {
 918+ global $wgUser, $wgEnableParserCache;
 919+
 920+ return $wgEnableParserCache
 921+ && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0
 922+ && $this->exists()
 923+ && empty( $oldid )
 924+ && !$this->mTitle->isCssOrJsPage()
 925+ && !$this->mTitle->isCssJsSubpage();
 926+ }
 927+
929928 protected function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
930929 global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser;
931930

Status & tagging log