From 32ac3913310fe9783458db13929b2caf416cfdc8 Mon Sep 17 00:00:00 2001 From: withoutaname Date: Sat, 21 Jun 2014 18:29:03 -0700 Subject: [PATCH] Move implementations of Page to separate file Moved implementations of the Page interface, including subclasses of WikiPage and Article, to a separate /includes/page file. Separated PoolWorkArticleView to the includes/poolcounter file. Change-Id: I4557eab76e0cb12d9d7f93644c5831bdd5b472b0 --- includes/AutoLoader.php | 22 +- includes/{ => page}/Article.php | 0 includes/{ => page}/CategoryPage.php | 0 includes/{ => page}/ImagePage.php | 0 includes/{ => page}/WikiCategoryPage.php | 0 includes/{ => page}/WikiFilePage.php | 0 includes/{ => page}/WikiPage.php | 190 ----------------- includes/poolcounter/PoolWorkArticleView.php | 208 +++++++++++++++++++ 8 files changed, 220 insertions(+), 200 deletions(-) rename includes/{ => page}/Article.php (100%) rename includes/{ => page}/CategoryPage.php (100%) rename includes/{ => page}/ImagePage.php (100%) rename includes/{ => page}/WikiCategoryPage.php (100%) rename includes/{ => page}/WikiFilePage.php (100%) rename includes/{ => page}/WikiPage.php (95%) create mode 100644 includes/poolcounter/PoolWorkArticleView.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 54425076e2..94264aedde 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -32,7 +32,6 @@ $wgAutoloadLocalClasses = array( 'AjaxDispatcher' => 'includes/AjaxDispatcher.php', 'AjaxResponse' => 'includes/AjaxResponse.php', 'AlphabeticPager' => 'includes/Pager.php', - 'Article' => 'includes/Article.php', 'AtomFeed' => 'includes/Feed.php', 'AuthPlugin' => 'includes/AuthPlugin.php', 'AuthPluginUser' => 'includes/AuthPlugin.php', @@ -42,7 +41,6 @@ $wgAutoloadLocalClasses = array( 'CacheHelper' => 'includes/CacheHelper.php', 'Category' => 'includes/Category.php', 'Categoryfinder' => 'includes/Categoryfinder.php', - 'CategoryPage' => 'includes/CategoryPage.php', 'CategoryViewer' => 'includes/CategoryViewer.php', 'ChangesFeed' => 'includes/ChangesFeed.php', 'ChangeTags' => 'includes/ChangeTags.php', @@ -112,9 +110,6 @@ $wgAutoloadLocalClasses = array( 'ICacheHelper' => 'includes/CacheHelper.php', 'IcuCollation' => 'includes/Collation.php', 'IdentityCollation' => 'includes/Collation.php', - 'ImageHistoryList' => 'includes/ImagePage.php', - 'ImageHistoryPseudoPager' => 'includes/ImagePage.php', - 'ImagePage' => 'includes/ImagePage.php', 'ImageQueryPage' => 'includes/ImageQueryPage.php', 'ImportStreamSource' => 'includes/Import.php', 'ImportStringSource' => 'includes/Import.php', @@ -145,7 +140,6 @@ $wgAutoloadLocalClasses = array( 'MWInit' => 'includes/Init.php', 'MWNamespace' => 'includes/Namespace.php', 'OutputPage' => 'includes/OutputPage.php', - 'Page' => 'includes/WikiPage.php', 'PageQueryPage' => 'includes/PageQueryPage.php', 'Pager' => 'includes/Pager.php', 'PasswordError' => 'includes/User.php', @@ -157,7 +151,7 @@ $wgAutoloadLocalClasses = array( 'PoolCounterRedis' => 'includes/poolcounter/PoolCounterRedis.php', 'PoolCounterWork' => 'includes/poolcounter/PoolCounterWork.php', 'PoolCounterWorkViaCallback' => 'includes/poolcounter/PoolCounterWork.php', - 'PoolWorkArticleView' => 'includes/WikiPage.php', + 'PoolWorkArticleView' => 'includes/poolcounter/PoolWorkArticleView.php', 'Preferences' => 'includes/Preferences.php', 'PreferencesForm' => 'includes/Preferences.php', 'PrefixSearch' => 'includes/PrefixSearch.php', @@ -207,11 +201,8 @@ $wgAutoloadLocalClasses = array( 'WebRequest' => 'includes/WebRequest.php', 'WebRequestUpload' => 'includes/WebRequest.php', 'WebResponse' => 'includes/WebResponse.php', - 'WikiCategoryPage' => 'includes/WikiCategoryPage.php', 'WikiExporter' => 'includes/Export.php', - 'WikiFilePage' => 'includes/WikiFilePage.php', 'WikiImporter' => 'includes/Import.php', - 'WikiPage' => 'includes/WikiPage.php', 'WikiRevision' => 'includes/Import.php', 'WikiMap' => 'includes/WikiMap.php', 'WikiReference' => 'includes/WikiMap.php', @@ -796,6 +787,17 @@ $wgAutoloadLocalClasses = array( 'WinCacheBagOStuff' => 'includes/objectcache/WinCacheBagOStuff.php', 'XCacheBagOStuff' => 'includes/objectcache/XCacheBagOStuff.php', + # includes/page + 'Article' => 'includes/page/Article.php', + 'CategoryPage' => 'includes/page/CategoryPage.php', + 'ImageHistoryList' => 'includes/page/ImagePage.php', + 'ImageHistoryPseudoPager' => 'includes/page/ImagePage.php', + 'ImagePage' => 'includes/page/ImagePage.php', + 'Page' => 'includes/page/WikiPage.php', + 'WikiCategoryPage' => 'includes/page/WikiCategoryPage.php', + 'WikiFilePage' => 'includes/page/WikiFilePage.php', + 'WikiPage' => 'includes/page/WikiPage.php', + # includes/parser 'CacheTime' => 'includes/parser/CacheTime.php', 'CoreParserFunctions' => 'includes/parser/CoreParserFunctions.php', diff --git a/includes/Article.php b/includes/page/Article.php similarity index 100% rename from includes/Article.php rename to includes/page/Article.php diff --git a/includes/CategoryPage.php b/includes/page/CategoryPage.php similarity index 100% rename from includes/CategoryPage.php rename to includes/page/CategoryPage.php diff --git a/includes/ImagePage.php b/includes/page/ImagePage.php similarity index 100% rename from includes/ImagePage.php rename to includes/page/ImagePage.php diff --git a/includes/WikiCategoryPage.php b/includes/page/WikiCategoryPage.php similarity index 100% rename from includes/WikiCategoryPage.php rename to includes/page/WikiCategoryPage.php diff --git a/includes/WikiFilePage.php b/includes/page/WikiFilePage.php similarity index 100% rename from includes/WikiFilePage.php rename to includes/page/WikiFilePage.php diff --git a/includes/WikiPage.php b/includes/page/WikiPage.php similarity index 95% rename from includes/WikiPage.php rename to includes/page/WikiPage.php index c4d1bf3b91..855de8eb58 100644 --- a/includes/WikiPage.php +++ b/includes/page/WikiPage.php @@ -3567,194 +3567,4 @@ class WikiPage implements Page, IDBAccessObject { wfRunHooks( 'WikiPageDeletionUpdates', array( $this, $content, &$updates ) ); return $updates; } - -} - -class PoolWorkArticleView extends PoolCounterWork { - /** @var Page */ - private $page; - - /** @var string */ - private $cacheKey; - - /** @var int */ - private $revid; - - /** @var ParserOptions */ - private $parserOptions; - - /** @var Content|null */ - private $content = null; - - /** @var ParserOutput|bool */ - private $parserOutput = false; - - /** @var bool */ - private $isDirty = false; - - /** @var Status|bool */ - private $error = false; - - /** - * @param Page $page - * @param int $revid ID of the revision being parsed. - * @param bool $useParserCache Whether to use the parser cache. - * @param ParserOptions $parserOptions ParserOptions to use for the parse - * operation. - * @param Content|string $content Content to parse or null to load it; may - * also be given as a wikitext string, for BC. - */ - public function __construct( Page $page, ParserOptions $parserOptions, - $revid, $useParserCache, $content = null - ) { - if ( is_string( $content ) ) { // BC: old style call - $modelId = $page->getRevision()->getContentModel(); - $format = $page->getRevision()->getContentFormat(); - $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelId, $format ); - } - - $this->page = $page; - $this->revid = $revid; - $this->cacheable = $useParserCache; - $this->parserOptions = $parserOptions; - $this->content = $content; - $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions ); - parent::__construct( 'ArticleView', $this->cacheKey . ':revid:' . $revid ); - } - - /** - * Get the ParserOutput from this object, or false in case of failure - * - * @return ParserOutput - */ - public function getParserOutput() { - return $this->parserOutput; - } - - /** - * Get whether the ParserOutput is a dirty one (i.e. expired) - * - * @return bool - */ - public function getIsDirty() { - return $this->isDirty; - } - - /** - * Get a Status object in case of error or false otherwise - * - * @return Status|bool - */ - public function getError() { - return $this->error; - } - - /** - * @return bool - */ - public function doWork() { - global $wgUseFileCache; - - // @todo several of the methods called on $this->page are not declared in Page, but present - // in WikiPage and delegated by Article. - - $isCurrent = $this->revid === $this->page->getLatest(); - - if ( $this->content !== null ) { - $content = $this->content; - } elseif ( $isCurrent ) { - // XXX: why use RAW audience here, and PUBLIC (default) below? - $content = $this->page->getContent( Revision::RAW ); - } else { - $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid ); - - if ( $rev === null ) { - $content = null; - } else { - // XXX: why use PUBLIC audience here (default), and RAW above? - $content = $rev->getContent(); - } - } - - if ( $content === null ) { - return false; - } - - // Reduce effects of race conditions for slow parses (bug 46014) - $cacheTime = wfTimestampNow(); - - $time = - microtime( true ); - $this->parserOutput = $content->getParserOutput( - $this->page->getTitle(), - $this->revid, - $this->parserOptions - ); - $time += microtime( true ); - - // Timing hack - if ( $time > 3 ) { - wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time, - $this->page->getTitle()->getPrefixedDBkey() ) ); - } - - if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) { - ParserCache::singleton()->save( - $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid ); - } - - // Make sure file cache is not used on uncacheable content. - // Output that has magic words in it can still use the parser cache - // (if enabled), though it will generally expire sooner. - if ( !$this->parserOutput->isCacheable() || $this->parserOutput->containsOldMagic() ) { - $wgUseFileCache = false; - } - - if ( $isCurrent ) { - $this->page->doCascadeProtectionUpdates( $this->parserOutput ); - } - - return true; - } - - /** - * @return bool - */ - public function getCachedWork() { - $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions ); - - if ( $this->parserOutput === false ) { - wfDebug( __METHOD__ . ": parser cache miss\n" ); - return false; - } else { - wfDebug( __METHOD__ . ": parser cache hit\n" ); - return true; - } - } - - /** - * @return bool - */ - public function fallback() { - $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions ); - - if ( $this->parserOutput === false ) { - wfDebugLog( 'dirty', 'dirty missing' ); - wfDebug( __METHOD__ . ": no dirty cache\n" ); - return false; - } else { - wfDebug( __METHOD__ . ": sending dirty output\n" ); - wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" ); - $this->isDirty = true; - return true; - } - } - - /** - * @param Status $status - * @return bool - */ - public function error( $status ) { - $this->error = $status; - return false; - } } diff --git a/includes/poolcounter/PoolWorkArticleView.php b/includes/poolcounter/PoolWorkArticleView.php new file mode 100644 index 0000000000..4cdb0fff20 --- /dev/null +++ b/includes/poolcounter/PoolWorkArticleView.php @@ -0,0 +1,208 @@ +getRevision()->getContentModel(); + $format = $page->getRevision()->getContentFormat(); + $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelId, $format ); + } + + $this->page = $page; + $this->revid = $revid; + $this->cacheable = $useParserCache; + $this->parserOptions = $parserOptions; + $this->content = $content; + $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions ); + parent::__construct( 'ArticleView', $this->cacheKey . ':revid:' . $revid ); + } + + /** + * Get the ParserOutput from this object, or false in case of failure + * + * @return ParserOutput + */ + public function getParserOutput() { + return $this->parserOutput; + } + + /** + * Get whether the ParserOutput is a dirty one (i.e. expired) + * + * @return bool + */ + public function getIsDirty() { + return $this->isDirty; + } + + /** + * Get a Status object in case of error or false otherwise + * + * @return Status|bool + */ + public function getError() { + return $this->error; + } + + /** + * @return bool + */ + public function doWork() { + global $wgUseFileCache; + + // @todo several of the methods called on $this->page are not declared in Page, but present + // in WikiPage and delegated by Article. + + $isCurrent = $this->revid === $this->page->getLatest(); + + if ( $this->content !== null ) { + $content = $this->content; + } elseif ( $isCurrent ) { + // XXX: why use RAW audience here, and PUBLIC (default) below? + $content = $this->page->getContent( Revision::RAW ); + } else { + $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid ); + + if ( $rev === null ) { + $content = null; + } else { + // XXX: why use PUBLIC audience here (default), and RAW above? + $content = $rev->getContent(); + } + } + + if ( $content === null ) { + return false; + } + + // Reduce effects of race conditions for slow parses (bug 46014) + $cacheTime = wfTimestampNow(); + + $time = - microtime( true ); + $this->parserOutput = $content->getParserOutput( + $this->page->getTitle(), + $this->revid, + $this->parserOptions + ); + $time += microtime( true ); + + // Timing hack + if ( $time > 3 ) { + wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time, + $this->page->getTitle()->getPrefixedDBkey() ) ); + } + + if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) { + ParserCache::singleton()->save( + $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid ); + } + + // Make sure file cache is not used on uncacheable content. + // Output that has magic words in it can still use the parser cache + // (if enabled), though it will generally expire sooner. + if ( !$this->parserOutput->isCacheable() || $this->parserOutput->containsOldMagic() ) { + $wgUseFileCache = false; + } + + if ( $isCurrent ) { + $this->page->doCascadeProtectionUpdates( $this->parserOutput ); + } + + return true; + } + + /** + * @return bool + */ + public function getCachedWork() { + $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions ); + + if ( $this->parserOutput === false ) { + wfDebug( __METHOD__ . ": parser cache miss\n" ); + return false; + } else { + wfDebug( __METHOD__ . ": parser cache hit\n" ); + return true; + } + } + + /** + * @return bool + */ + public function fallback() { + $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions ); + + if ( $this->parserOutput === false ) { + wfDebugLog( 'dirty', 'dirty missing' ); + wfDebug( __METHOD__ . ": no dirty cache\n" ); + return false; + } else { + wfDebug( __METHOD__ . ": sending dirty output\n" ); + wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" ); + $this->isDirty = true; + return true; + } + } + + /** + * @param Status $status + * @return bool + */ + public function error( $status ) { + $this->error = $status; + return false; + } +} -- 2.20.1