bug 36087: PostgresUpdater fails on 8.3.14
[lhc/web/wiklou.git] / includes / Article.php
index a5084f1..393f770 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
         */
@@ -172,12 +183,12 @@ class Article extends Page {
        /**
         * Note that getContent/loadContent do not follow redirects anymore.
         * If you need to fetch redirectable content easily, try
-        * the shortcut in Article::followRedirect()
+        * the shortcut in WikiPage::getRedirectTarget()
         *
         * This function has side effects! Do not use this function if you
         * only want the real revision text if any.
         *
-        * @return Return the text of this revision
+        * @return string Return the text of this revision
         */
        public function getContent() {
                global $wgUser;
@@ -237,12 +248,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() );
+                                       }
                                }
                        }
                }
@@ -251,6 +266,7 @@ class Article extends Page {
                        $nextid = $this->getTitle()->getNextRevisionID( $oldid );
                        if ( $nextid ) {
                                $oldid = $nextid;
+                               $this->mRevision = null;
                        } else {
                                $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
                        }
@@ -258,6 +274,7 @@ class Article extends Page {
                        $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
                        if ( $previd ) {
                                $oldid = $previd;
+                               $this->mRevision = null;
                        }
                }
 
@@ -356,6 +373,19 @@ class Article extends Page {
                return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
        }
 
+       /**
+        * Get the fetched Revision object depending on request parameters or null
+        * on failure.
+        *
+        * @since 1.19
+        * @return Revision|null
+        */
+       public function getRevisionFetched() {
+               $this->fetchContent();
+
+               return $this->mRevision;
+       }
+
        /**
         * Use this to fetch the rev ID used on page views
         *
@@ -425,7 +455,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 );
                }
 
@@ -446,7 +476,7 @@ class Article extends Page {
                                wfDebug( __METHOD__ . ": done file cache\n" );
                                # tell wgOut that output is taken care of
                                $wgOut->disable();
-                               $this->mPage->doViewUpdates( $this->getContext()->getUser() );
+                               $this->mPage->doViewUpdates( $wgUser );
                                wfProfileOut( __METHOD__ );
 
                                return;
@@ -618,7 +648,7 @@ class Article extends Page {
                $wgOut->setFollowPolicy( $policy['follow'] );
 
                $this->showViewFooter();
-               $this->mPage->doViewUpdates( $this->getContext()->getUser() );
+               $this->mPage->doViewUpdates( $wgUser );
 
                wfProfileOut( __METHOD__ );
        }
@@ -657,7 +687,7 @@ class Article extends Page {
 
                if ( $diff == 0 || $diff == $this->mPage->getLatest() ) {
                        # Run view updates for current revision only
-                       $this->mPage->doViewUpdates( $this->getContext()->getUser() );
+                       $this->mPage->doViewUpdates( $wgUser );
                }
        }
 
@@ -962,6 +992,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 ) {
@@ -984,12 +1026,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 );
        }
 
@@ -1053,11 +1089,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() );
@@ -1147,21 +1188,8 @@ class Article extends Page {
                                array( 'known', 'noclasses' )
                        );
 
-               $cdel = '';
-
-               // User can delete revisions or view deleted revisions...
-               $canHide = $wgUser->isAllowed( 'deleterevision' );
-               if ( $canHide || ( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
-                       if ( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
-                               $cdel = Linker::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
-                       } else {
-                               $query = array(
-                                       'type'   => 'revision',
-                                       'target' => $this->getTitle()->getPrefixedDbkey(),
-                                       'ids'    => $oldid
-                               );
-                               $cdel = Linker::revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
-                       }
+               $cdel = Linker::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
+               if ( $cdel !== '' ) {
                        $cdel .= ' ';
                }
 
@@ -1289,18 +1317,6 @@ class Article extends Page {
                        return;
                }
 
-               # Hack for big sites
-               $bigHistory = $this->mPage->isBigDeletion();
-               if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
-                       global $wgDeleteRevisionsLimit;
-
-                       $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
-                       $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
-                               array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
-
-                       return;
-               }
-
                $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
                $deleteReason = $wgRequest->getText( 'wpReason' );
 
@@ -1338,7 +1354,7 @@ class Article extends Page {
 
                // If the page has a history, insert a warning
                if ( $hasHistory ) {
-                       $revisions = $this->mPage->estimateRevisionCount();
+                       $revisions = $this->mTitle->estimateRevisionCount();
                        // @todo FIXME: i18n issue/patchwork message
                        $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
                                wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
@@ -1349,7 +1365,7 @@ class Article extends Page {
                                '</strong>'
                        );
 
-                       if ( $bigHistory ) {
+                       if ( $this->mTitle->isBigDeletion() ) {
                                global $wgDeleteRevisionsLimit;
                                $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
                                        array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
@@ -1473,10 +1489,8 @@ class Article extends Page {
        public function doDelete( $reason, $suppress = false ) {
                global $wgOut;
 
-               $id = $this->getTitle()->getArticleID( Title::GAID_FOR_UPDATE );
-
                $error = '';
-               if ( $this->mPage->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
+               if ( $this->mPage->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
                        $deleted = $this->getTitle()->getPrefixedText();
 
                        $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
@@ -1583,7 +1597,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;
@@ -1771,6 +1785,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 ) ) ) {
@@ -1782,6 +1797,18 @@ class Article extends Page {
 
        // ****** B/C functions to work-around PHP silliness with __call and references ****** //
 
+       /**
+        * @param $limit array
+        * @param $expiry array
+        * @param $cascade bool
+        * @param $reason string
+        * @param $user User
+        * @return Status
+        */
+       public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User $user ) {
+               return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
+       }
+
        /**
         * @param $limit array
         * @param $reason string