From 418b3503b15f859b02a2a4885db30810965b39ae Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 6 Jan 2012 20:00:04 +0000 Subject: [PATCH] * Added WikiPage to RequestContext and related so that it can be shared to avoid creating a new object each time and thus avoiding database queries to load the state of the object * Added Article::getPage() as accessor to the WikiPage object so that it can be set in the context from MediaWiki::initializeArticle() * Use it WikiPage::main() to call doViewUpdates() I'm doing to this now so that I can revert r105790 and use the WikiPage object before the 1.19 release --- includes/Article.php | 11 +++++++++ includes/Wiki.php | 13 +++++++---- includes/context/ContextSource.php | 10 ++++++++ includes/context/DerivativeContext.php | 31 +++++++++++++++++++++++++ includes/context/IContextSource.php | 8 +++++++ includes/context/RequestContext.php | 32 ++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 5 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index d33358a464..53b87f46ee 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -150,12 +150,23 @@ class Article extends Page { /** * Get the title object of the article + * * @return Title object of this page */ public function getTitle() { return $this->mPage->getTitle(); } + /** + * Get the WikiPage object of this instance + * + * @since 1.19 + * @return WikiPage + */ + public function getPage() { + return $this->mPage; + } + /** * Clear the object */ diff --git a/includes/Wiki.php b/includes/Wiki.php index 6882bc2a90..0bbcee40f2 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -337,19 +337,21 @@ class MediaWiki { wfProfileIn( __METHOD__ ); - $request = $this->context->getRequest(); $title = $this->context->getTitle(); - - $action = $request->getVal( 'action', 'view' ); $article = Article::newFromTitle( $title, $this->context ); + $this->context->setWikiPage( $article->getPage() ); // NS_MEDIAWIKI has no redirects. // It is also used for CSS/JS, so performance matters here... if ( $title->getNamespace() == NS_MEDIAWIKI ) { wfProfileOut( __METHOD__ ); return $article; } + + $request = $this->context->getRequest(); + // Namespace might change when using redirects // Check for redirects ... + $action = $request->getVal( 'action', 'view' ); $file = ( $title->getNamespace() == NS_FILE ) ? $article->getFile() : null; if ( ( $action == 'view' || $action == 'render' ) // ... for actions that show content && !$request->getVal( 'oldid' ) && // ... and are not old revisions @@ -384,10 +386,12 @@ class MediaWiki { $rarticle->setRedirectedFrom( $title ); $article = $rarticle; $this->context->setTitle( $target ); + $this->context->setWikiPage( $article->getPage() ); } } } else { $this->context->setTitle( $article->getTitle() ); + $this->context->setWikiPage( $article->getPage() ); } } @@ -604,8 +608,7 @@ class MediaWiki { $cache->loadFromFileCache( $this->context ); } # Do any stats increment/watchlist stuff - $page = WikiPage::factory( $this->getTitle() ); - $page->doViewUpdates( $this->context->getUser() ); + $this->context->getWikiPage()->doViewUpdates( $this->context->getUser() ); # Tell OutputPage that output is taken care of $this->context->getOutput()->disable(); wfProfileOut( 'main-try-filecache' ); diff --git a/includes/context/ContextSource.php b/includes/context/ContextSource.php index ed387db72c..2fbc776712 100644 --- a/includes/context/ContextSource.php +++ b/includes/context/ContextSource.php @@ -78,6 +78,16 @@ abstract class ContextSource implements IContextSource { return $this->getContext()->getTitle(); } + /** + * Get the WikiPage object + * + * @since 1.19 + * @return WikiPage + */ + public function getWikiPage() { + return $this->getContext()->getWikiPage(); + } + /** * Get the OutputPage object * diff --git a/includes/context/DerivativeContext.php b/includes/context/DerivativeContext.php index 1cd649f28b..ee817dbd26 100644 --- a/includes/context/DerivativeContext.php +++ b/includes/context/DerivativeContext.php @@ -41,6 +41,11 @@ class DerivativeContext extends ContextSource { */ private $title; + /** + * @var WikiPage + */ + private $wikipage; + /** * @var OutputPage */ @@ -114,6 +119,32 @@ class DerivativeContext extends ContextSource { } /** + * Set the WikiPage object + * + * @since 1.19 + * @param $p WikiPage object + */ + public function setWikiPage( WikiPage $p ) { + $this->wikipage = $p; + } + + /** + * Get the WikiPage object + * + * @since 1.19 + * @return WikiPage + */ + public function getWikiPage() { + if ( !is_null( $this->wikipage ) ) { + return $this->wikipage; + } else { + return $this->getContext()->getWikiPage(); + } + } + + /** + * Set the OutputPage object + * * @param $o OutputPage */ public function setOutput( OutputPage $o ) { diff --git a/includes/context/IContextSource.php b/includes/context/IContextSource.php index 446cb3f436..edc0c17c63 100644 --- a/includes/context/IContextSource.php +++ b/includes/context/IContextSource.php @@ -42,6 +42,14 @@ interface IContextSource { */ public function getTitle(); + /** + * Get the WikiPage object + * + * @since 1.19 + * @return WikiPage + */ + public function getWikiPage(); + /** * Get the OutputPage object * diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 5aac68b532..7f000410e0 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -39,6 +39,11 @@ class RequestContext implements IContextSource { */ private $title; + /** + * @var WikiPage + */ + private $wikipage; + /** * @var OutputPage */ @@ -103,6 +108,33 @@ class RequestContext implements IContextSource { return $this->title; } + /** + * Set the WikiPage object + * + * @since 1.19 + * @param $p WikiPage object + */ + public function setWikiPage( WikiPage $p ) { + $this->wikipage = $p; + } + + /** + * Get the WikiPage object + * + * @since 1.19 + * @return WikiPage + */ + public function getWikiPage() { + if ( $this->wikipage === null ) { + $title = $this->getTitle(); + if ( $title === null ) { + throw new MWException( __METHOD__ . ' called without Title object set' ); + } + $this->wikipage = WikiPage::factory( $title ); + } + return $this->wikipage; + } + /** * @param $o OutputPage */ -- 2.20.1