docu cleanup; marked contenthandler stuff as @since 1.WD
[lhc/web/wiklou.git] / includes / Article.php
index 5c6d7be..76f063e 100644 (file)
@@ -41,6 +41,7 @@ class Article extends Page {
 
        /**
         * @var Content
+        * @since 1.WD
         */
        var $mContentObject;
 
@@ -195,18 +196,21 @@ class Article extends Page {
         * This function has side effects! Do not use this function if you
         * only want the real revision text if any.
         *
-        * @deprecated in 1.20; use getContentObject() instead
+        * @deprecated in 1.WD; use getContentObject() instead
         *
         * @return string The text of this revision
         */
        public function getContent() {
-               wfDeprecated( __METHOD__, '1.20' );
+               wfDeprecated( __METHOD__, '1.WD' );
                $content = $this->getContentObject();
                return ContentHandler::getContentText( $content );
        }
 
        /**
-        * Note that getContent/loadContent do not follow redirects anymore.
+        * Returns a Content object representing the pages effective display content,
+     * not necessarily the revision's content!
+     *
+     * Note that getContent/loadContent do not follow redirects anymore.
         * If you need to fetch redirectable content easily, try
         * the shortcut in WikiPage::getRedirectTarget()
         *
@@ -214,8 +218,10 @@ class Article extends Page {
         * only want the real revision text if any.
         *
         * @return Content
+        *
+        * @since 1.WD
         */
-   public function getContentObject() {
+   protected function getContentObject() {
                global $wgUser;
 
                wfProfileIn( __METHOD__ );
@@ -275,12 +281,16 @@ class Article extends Page {
                if ( $oldid !== 0 ) {
                        # Load the given revision and check whether the page is another one.
                        # In that case, update this instance to reflect the change.
-                       $this->mRevision = Revision::newFromId( $oldid );
-                       if ( $this->mRevision !== null ) {
-                               // Revision title doesn't match the page title given?
-                               if ( $this->mPage->getID() != $this->mRevision->getPage() ) {
-                                       $function = array( get_class( $this->mPage ), 'newFromID' );
-                                       $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
+                       if ( $oldid === $this->mPage->getLatest() ) {
+                               $this->mRevision = $this->mPage->getRevision();
+                       } else {
+                               $this->mRevision = Revision::newFromId( $oldid );
+                               if ( $this->mRevision !== null ) {
+                                       // Revision title doesn't match the page title given?
+                                       if ( $this->mPage->getID() != $this->mRevision->getPage() ) {
+                                               $function = array( get_class( $this->mPage ), 'newFromID' );
+                                               $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
+                                       }
                                }
                        }
                }
@@ -319,10 +329,10 @@ class Article extends Page {
         * Does *NOT* follow redirects.
         *
         * @return mixed string containing article contents, or false if null
-        * @deprecated in 1.20, use getContentObject() instead
+        * @deprecated in 1.WD, use getContentObject() instead
         */
        protected function fetchContent() { #BC cruft!
-               wfDeprecated( __METHOD__, '1.20' );
+               wfDeprecated( __METHOD__, '1.WD' );
 
                if ( $this->mContentLoaded && $this->mContent ) {
                        return $this->mContent;
@@ -347,6 +357,8 @@ class Article extends Page {
         * TODO: when is this null?
         *
         * @return Content|null
+        *
+        * @since 1.WD
         */
        protected function fetchContentObject() {
                if ( $this->mContentLoaded ) {
@@ -364,7 +376,7 @@ class Article extends Page {
                # fails we'll have something telling us what we intended.
                $t = $this->getTitle()->getPrefixedText();
                $d = $oldid ? wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
-               $this->mContentObject = new MessageContent( 'missing-article', array($t, $d), array() ) ;
+               $this->mContentObject = new MessageContent( 'missing-article', array($t, $d), array() ) ; // @todo: this isn't page content but a UI message. horrible.
 
                if ( $oldid ) {
                        # $this->mRevision might already be fetched by getOldIDFromRequest()
@@ -508,7 +520,7 @@ class Article extends Page {
                if ( $wgOut->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
                        $parserOptions->setEditSection( false );
-               } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
+               } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit' ) ) {
                        $parserOptions->setEditSection( false );
                }
 
@@ -631,7 +643,7 @@ class Article extends Page {
                                                        # Viewing a redirect page (e.g. with parameter redirect=no)
                                                        $wgOut->addHTML( $this->viewRedirect( $rt ) );
                                                        # Parse just to get categories, displaytitle, etc.
-                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions );
+                                                       $this->mParserOutput = $content->getParserOutput( $this->getContext(), $oldid, $parserOptions, false );
                                                        $wgOut->addParserOutputNoText( $this->mParserOutput );
                                                        $outputDone = true;
                                                }
@@ -641,8 +653,9 @@ class Article extends Page {
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
+                                       // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
                                        $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
-                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
+                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
 
                                        if ( !$poolArticleView->execute() ) {
                                                $error = $poolArticleView->getError();
@@ -737,7 +750,7 @@ class Article extends Page {
                $oldid = $this->getOldID();
 
                $contentHandler = ContentHandler::getForTitle( $this->getTitle() );
-               $de = $contentHandler->getDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
+               $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
 
                // DifferenceEngine directly fetched the revision:
                $this->mRevIdFetched = $de->mNewid;
@@ -769,7 +782,7 @@ class Article extends Page {
 
                // Give hooks a chance to customise the output
                if ( !Hooks::isRegistered('ShowRawCssJs') || wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated
-                       $po = $this->mContentObject->getParserOutput();
+                       $po = $this->mContentObject->getParserOutput( $this->getContext() );
                        $wgOut->addHTML( $po->getText() );
                }
        }
@@ -1048,6 +1061,18 @@ class Article extends Page {
                                'msgKey' => array( 'moveddeleted-notice' ) )
                );
 
+               if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
+                       // If there's no backing content, send a 404 Not Found
+                       // for better machine handling of broken links.
+                       $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
+               }
+
+               $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
+
+               if ( ! $hookResult ) {
+                       return;
+               }
+
                # Show error message
                $oldid = $this->getOldID();
                if ( $oldid ) {
@@ -1070,12 +1095,6 @@ class Article extends Page {
                }
                $text = "<div class='noarticletext'>\n$text\n</div>";
 
-               if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
-                       // If there's no backing content, send a 404 Not Found
-                       // for better machine handling of broken links.
-                       $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
-               }
-
                $wgOut->addWikiText( $text );
        }
 
@@ -1139,11 +1158,16 @@ class Article extends Page {
 
                # Cascade unhide param in links for easy deletion browsing
                $extraParams = array();
-               if ( $wgRequest->getVal( 'unhide' ) ) {
+               if ( $unhide ) {
                        $extraParams['unhide'] = 1;
                }
 
-               $revision = Revision::newFromId( $oldid );
+               if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
+                       $revision = $this->mRevision;
+               } else {
+                       $revision = Revision::newFromId( $oldid );
+               }
+
                $timestamp = $revision->getTimestamp();
 
                $current = ( $oldid == $this->mPage->getLatest() );
@@ -1648,7 +1672,7 @@ class Article extends Page {
 
        /**
         * Get parser options suitable for rendering the primary article wikitext
-        * @return ParserOptions|false
+        * @return ParserOptions
         */
        public function getParserOptions() {
                global $wgUser;
@@ -1836,6 +1860,7 @@ class Article extends Page {
         *
         * @param $fname String Name of called method
         * @param $args Array Arguments to the method
+        * @return mixed
         */
        public function __call( $fname, $args ) {
                if ( is_callable( array( $this->mPage, $fname ) ) ) {
@@ -1956,7 +1981,7 @@ class Article extends Page {
         * @param $newtext
         * @param $flags
         * @return string
-        * @deprecated since 1.20, use ContentHandler::getAutosummary() instead
+        * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
         */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
                return WikiPage::getAutosummary( $oldtext, $newtext, $flags );