MediaWiki
REL1_24
|
00001 <?php 00021 class PoolWorkArticleView extends PoolCounterWork { 00023 private $page; 00024 00026 private $cacheKey; 00027 00029 private $revid; 00030 00032 private $parserOptions; 00033 00035 private $content = null; 00036 00038 private $parserOutput = false; 00039 00041 private $isDirty = false; 00042 00044 private $error = false; 00045 00055 public function __construct( Page $page, ParserOptions $parserOptions, 00056 $revid, $useParserCache, $content = null 00057 ) { 00058 if ( is_string( $content ) ) { // BC: old style call 00059 $modelId = $page->getRevision()->getContentModel(); 00060 $format = $page->getRevision()->getContentFormat(); 00061 $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelId, $format ); 00062 } 00063 00064 $this->page = $page; 00065 $this->revid = $revid; 00066 $this->cacheable = $useParserCache; 00067 $this->parserOptions = $parserOptions; 00068 $this->content = $content; 00069 $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions ); 00070 parent::__construct( 'ArticleView', $this->cacheKey . ':revid:' . $revid ); 00071 } 00072 00078 public function getParserOutput() { 00079 return $this->parserOutput; 00080 } 00081 00087 public function getIsDirty() { 00088 return $this->isDirty; 00089 } 00090 00096 public function getError() { 00097 return $this->error; 00098 } 00099 00103 public function doWork() { 00104 global $wgUseFileCache; 00105 00106 // @todo several of the methods called on $this->page are not declared in Page, but present 00107 // in WikiPage and delegated by Article. 00108 00109 $isCurrent = $this->revid === $this->page->getLatest(); 00110 00111 if ( $this->content !== null ) { 00112 $content = $this->content; 00113 } elseif ( $isCurrent ) { 00114 // XXX: why use RAW audience here, and PUBLIC (default) below? 00115 $content = $this->page->getContent( Revision::RAW ); 00116 } else { 00117 $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid ); 00118 00119 if ( $rev === null ) { 00120 $content = null; 00121 } else { 00122 // XXX: why use PUBLIC audience here (default), and RAW above? 00123 $content = $rev->getContent(); 00124 } 00125 } 00126 00127 if ( $content === null ) { 00128 return false; 00129 } 00130 00131 // Reduce effects of race conditions for slow parses (bug 46014) 00132 $cacheTime = wfTimestampNow(); 00133 00134 $time = - microtime( true ); 00135 $this->parserOutput = $content->getParserOutput( 00136 $this->page->getTitle(), 00137 $this->revid, 00138 $this->parserOptions 00139 ); 00140 $time += microtime( true ); 00141 00142 // Timing hack 00143 if ( $time > 3 ) { 00144 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time, 00145 $this->page->getTitle()->getPrefixedDBkey() ) ); 00146 } 00147 00148 if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) { 00149 ParserCache::singleton()->save( 00150 $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid ); 00151 } 00152 00153 // Make sure file cache is not used on uncacheable content. 00154 // Output that has magic words in it can still use the parser cache 00155 // (if enabled), though it will generally expire sooner. 00156 if ( !$this->parserOutput->isCacheable() || $this->parserOutput->containsOldMagic() ) { 00157 $wgUseFileCache = false; 00158 } 00159 00160 if ( $isCurrent ) { 00161 $this->page->doCascadeProtectionUpdates( $this->parserOutput ); 00162 } 00163 00164 return true; 00165 } 00166 00170 public function getCachedWork() { 00171 $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions ); 00172 00173 if ( $this->parserOutput === false ) { 00174 wfDebug( __METHOD__ . ": parser cache miss\n" ); 00175 return false; 00176 } else { 00177 wfDebug( __METHOD__ . ": parser cache hit\n" ); 00178 return true; 00179 } 00180 } 00181 00185 public function fallback() { 00186 $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions ); 00187 00188 if ( $this->parserOutput === false ) { 00189 wfDebugLog( 'dirty', 'dirty missing' ); 00190 wfDebug( __METHOD__ . ": no dirty cache\n" ); 00191 return false; 00192 } else { 00193 wfDebug( __METHOD__ . ": sending dirty output\n" ); 00194 wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" ); 00195 $this->isDirty = true; 00196 return true; 00197 } 00198 } 00199 00204 public function error( $status ) { 00205 $this->error = $status; 00206 return false; 00207 } 00208 }