Merge "Fix spacing in SpecialRevisiondelete.php"
[lhc/web/wiklou.git] / includes / WikiPage.php
index a191983..b4aa303 100644 (file)
@@ -142,6 +142,11 @@ class WikiPage implements Page, IDBAccessObject {
         * @return WikiPage|null
         */
        public static function newFromID( $id, $from = 'fromdb' ) {
+               // page id's are never 0 or negative, see bug 61166
+               if ( $id < 1 ) {
+                       return null;
+               }
+
                $from = self::convertSelectType( $from );
                $db = wfGetDB( $from === self::READ_LATEST ? DB_MASTER : DB_SLAVE );
                $row = $db->selectRow( 'page', self::selectFields(), array( 'page_id' => $id ), __METHOD__ );
@@ -1168,7 +1173,7 @@ class WikiPage implements Page, IDBAccessObject {
        }
 
        /**
-        * Do standard deferred updates after page view
+        * Do standard deferred updates after page view (existing or missing page)
         * @param User $user The relevant user
         * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
         */
@@ -1563,7 +1568,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param $flags Int
         * @return Int updated $flags
         */
-       function checkFlags( $flags ) {
+       public function checkFlags( $flags ) {
                if ( !( $flags & EDIT_NEW ) && !( $flags & EDIT_UPDATE ) ) {
                        if ( $this->exists() ) {
                                $flags |= EDIT_UPDATE;
@@ -2350,6 +2355,9 @@ class WikiPage implements Page, IDBAccessObject {
                // Truncate for whole multibyte characters
                $reason = $wgContLang->truncate( $reason, 255 );
 
+               $logRelationsValues = array();
+               $logRelationsField = null;
+
                if ( $id ) { // Protection of existing page
                        if ( !wfRunHooks( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
                                return Status::newGood();
@@ -2384,11 +2392,24 @@ class WikiPage implements Page, IDBAccessObject {
                                return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() );
                        }
 
+                       $logRelationsField = 'pr_id';
+
                        // Update restrictions table
                        foreach ( $limit as $action => $restrictions ) {
+                               $dbw->delete(
+                                       'page_restrictions',
+                                       array(
+                                               'pr_page' => $id,
+                                               'pr_type' => $action
+                                       ),
+                                       __METHOD__
+                               );
                                if ( $restrictions != '' ) {
-                                       $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ),
-                                               array( 'pr_page' => $id,
+                                       $dbw->insert(
+                                               'page_restrictions',
+                                               array(
+                                                       'pr_id' => $dbw->nextSequenceValue( 'page_restrictions_pr_id_seq' ),
+                                                       'pr_page' => $id,
                                                        'pr_type' => $action,
                                                        'pr_level' => $restrictions,
                                                        'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0,
@@ -2396,9 +2417,7 @@ class WikiPage implements Page, IDBAccessObject {
                                                ),
                                                __METHOD__
                                        );
-                               } else {
-                                       $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
-                                               'pr_type' => $action ), __METHOD__ );
+                                       $logRelationsValues[] = $dbw->insertId();
                                }
                        }
 
@@ -2451,7 +2470,10 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Update the protection log
                $log = new LogPage( 'protect' );
-               $log->addEntry( $logAction, $this->mTitle, $reason, $params, $user );
+               $logId = $log->addEntry( $logAction, $this->mTitle, $reason, $params, $user );
+               if ( $logRelationsField !== null && count( $logRelationsValues ) ) {
+                       $log->addRelations( $logRelationsField, $logRelationsValues, $logId );
+               }
 
                return Status::newGood();
        }
@@ -2923,6 +2945,29 @@ class WikiPage implements Page, IDBAccessObject {
                        return array( array( 'notvisiblerev' ) );
                }
 
+               // Set patrolling and bot flag on the edits, which gets rollbacked.
+               // This is done before the rollback edit to have patrolling also on failure (bug 62157).
+               $set = array();
+               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
+                       // Mark all reverted edits as bot
+                       $set['rc_bot'] = 1;
+               }
+
+               if ( $wgUseRCPatrol ) {
+                       // Mark all reverted edits as patrolled
+                       $set['rc_patrolled'] = 1;
+               }
+
+               if ( count( $set ) ) {
+                       $dbw->update( 'recentchanges', $set,
+                               array( /* WHERE */
+                                       'rc_cur_id' => $current->getPage(),
+                                       'rc_user_text' => $current->getUserText(),
+                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
+                               ), __METHOD__
+                       );
+               }
+
                // Generate the edit summary if necessary
                $target = Revision::newFromId( $s->rev_id );
                if ( empty( $summary ) ) {
@@ -2969,32 +3014,17 @@ class WikiPage implements Page, IDBAccessObject {
                        return $status->getErrorsArray();
                }
 
-               $set = array();
-               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
-                       // Mark all reverted edits as bot
-                       $set['rc_bot'] = 1;
-               }
-
-               if ( $wgUseRCPatrol ) {
-                       // Mark all reverted edits as patrolled
-                       $set['rc_patrolled'] = 1;
-               }
-
-               if ( count( $set ) ) {
-                       $dbw->update( 'recentchanges', $set,
-                               array( /* WHERE */
-                                       'rc_cur_id' => $current->getPage(),
-                                       'rc_user_text' => $current->getUserText(),
-                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
-                               ), __METHOD__
-                       );
+               // raise error, when the edit is an edit without a new version
+               if ( empty( $status->value['revision'] ) ) {
+                       $resultDetails = array( 'current' => $current );
+                       return array( array( 'alreadyrolled',
+                                       htmlspecialchars( $this->mTitle->getPrefixedText() ),
+                                       htmlspecialchars( $fromP ),
+                                       htmlspecialchars( $current->getUserText() )
+                       ) );
                }
 
-               if ( !empty( $status->value['revision'] ) ) {
-                       $revId = $status->value['revision']->getId();
-               } else {
-                       $revId = false;
-               }
+               $revId = $status->value['revision']->getId();
 
                wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
 
@@ -3480,7 +3510,7 @@ class PoolWorkArticleView extends PoolCounterWork {
         * @param $parserOptions parserOptions to use for the parse operation
         * @param $content Content|String: content to parse or null to load it; may also be given as a wikitext string, for BC
         */
-       function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $content = null ) {
+       public function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $content = null ) {
                if ( is_string( $content ) ) { // BC: old style call
                        $modelId = $page->getRevision()->getContentModel();
                        $format = $page->getRevision()->getContentFormat();
@@ -3526,7 +3556,7 @@ class PoolWorkArticleView extends PoolCounterWork {
        /**
         * @return bool
         */
-       function doWork() {
+       public function doWork() {
                global $wgUseFileCache;
 
                // @todo several of the methods called on $this->page are not declared in Page, but present
@@ -3589,7 +3619,7 @@ class PoolWorkArticleView extends PoolCounterWork {
        /**
         * @return bool
         */
-       function getCachedWork() {
+       public function getCachedWork() {
                $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions );
 
                if ( $this->parserOutput === false ) {
@@ -3604,7 +3634,7 @@ class PoolWorkArticleView extends PoolCounterWork {
        /**
         * @return bool
         */
-       function fallback() {
+       public function fallback() {
                $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
 
                if ( $this->parserOutput === false ) {
@@ -3623,7 +3653,7 @@ class PoolWorkArticleView extends PoolCounterWork {
         * @param $status Status
         * @return bool
         */
-       function error( $status ) {
+       public function error( $status ) {
                $this->error = $status;
                return false;
        }