Merge branch 'master' into Wikidata
[lhc/web/wiklou.git] / includes / Article.php
index 5c6d7be..d516ce9 100644 (file)
@@ -275,12 +275,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() );
+                                       }
                                }
                        }
                }
@@ -508,7 +512,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 );
                }
 
@@ -1048,6 +1052,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 +1086,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 +1149,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 +1663,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 +1851,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 ) ) ) {