* Added WikiPage to RequestContext and related so that it can be shared to avoid...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Fri, 6 Jan 2012 20:00:04 +0000 (20:00 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Fri, 6 Jan 2012 20:00:04 +0000 (20:00 +0000)
* 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
includes/Wiki.php
includes/context/ContextSource.php
includes/context/DerivativeContext.php
includes/context/IContextSource.php
includes/context/RequestContext.php

index d33358a..53b87f4 100644 (file)
@@ -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
         */
index 6882bc2..0bbcee4 100644 (file)
@@ -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' );
index ed387db..2fbc776 100644 (file)
@@ -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
         *
index 1cd649f..ee817db 100644 (file)
@@ -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 ) {
index 446cb3f..edc0c17 100644 (file)
@@ -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
         *
index 5aac68b..7f00041 100644 (file)
@@ -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
         */