Check $auth parameter in Title::isValidMoveOperation()
authorKunal Mehta <legoktm@gmail.com>
Thu, 5 Feb 2015 18:52:10 +0000 (10:52 -0800)
committerKunal Mehta <legoktm@gmail.com>
Thu, 5 Feb 2015 18:52:10 +0000 (10:52 -0800)
This also includes the integration test from SemanticMediaWiki that
caught this issue.

Bug: T74870
Change-Id: I699e14958ee36ec5e86278e5dc0caed2a015d9af

includes/Title.php
tests/phpunit/includes/MovePageTest.php

index 463f75e..9a7cd04 100644 (file)
@@ -3607,7 +3607,7 @@ class Title {
         *
         * @deprecated since 1.25, use MovePage's methods instead
         * @param Title $nt The new title
-        * @param bool $auth Ignored
+        * @param bool $auth Whether to check user permissions (uses $wgUser)
         * @param string $reason Is the log summary of the move, used for spam checking
         * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
         */
@@ -3621,10 +3621,13 @@ class Title {
                }
 
                $mp = new MovePage( $this, $nt );
-               $errors = wfMergeErrorArrays(
-                       $mp->isValidMove()->getErrorsArray(),
-                       $mp->checkPermissions( $wgUser, $reason )->getErrorsArray()
-               );
+               $errors = $mp->isValidMove()->getErrorsArray();
+               if ( $auth ) {
+                       $errors = wfMergeErrorArrays(
+                               $errors,
+                               $mp->checkPermissions( $wgUser, $reason )->getErrorsArray()
+                       );
+               }
 
                return $errors ? : true;
        }
index 027b877..9501e45 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+/**
+ * @group Database
+ */
 class MovePageTest extends MediaWikiTestCase {
 
        /**
@@ -36,4 +39,25 @@ class MovePageTest extends MediaWikiTestCase {
                        array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ),
                );
        }
+
+       /**
+        * Integration test to catch regressions like T74870. Taken and modified
+        * from SemanticMediaWiki
+        */
+       public function testTitleMoveCompleteIntegrationTest() {
+               $oldTitle = Title::newFromText( 'Help:Some title' );
+               WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
+               $newTitle = Title::newFromText( 'Help:Some other title' );
+               $this->assertNull(
+                       WikiPage::factory( $newTitle )->getRevision()
+               );
+
+               $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
+               $this->assertNotNull(
+                       WikiPage::factory( $oldTitle )->getRevision()
+               );
+               $this->assertNotNull(
+                       WikiPage::factory( $newTitle)->getRevision()
+               );
+       }
 }