Merge "EditPage: Remove unused deprecated method ::submit()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 28 May 2019 19:27:49 +0000 (19:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 28 May 2019 19:27:49 +0000 (19:27 +0000)
RELEASE-NOTES-1.34
includes/MovePage.php
includes/Title.php
includes/preferences/MultiUsernameFilter.php
includes/specials/SpecialMovepage.php
resources/src/mediawiki.action/mediawiki.action.view.dblClickEdit.js
tests/phpunit/includes/MovePageTest.php
tests/phpunit/includes/TitleMethodsTest.php
tests/phpunit/includes/TitleTest.php

index ca9a522..7364d9a 100644 (file)
@@ -236,7 +236,6 @@ because of Phabricator reports.
   MovePage::moveSubpagesIfAllowed.
 * The MWNamespace class is deprecated. Use MediaWikiServices::getNamespaceInfo.
 * (T62260) Hard deprecate Language::getExtraUserToggles() method.
-* …
 
 === Other changes in 1.34 ===
 * …
index d045355..832e24a 100644 (file)
@@ -46,6 +46,14 @@ class MovePage {
                $this->newTitle = $newTitle;
        }
 
+       /**
+        * Check if the user is allowed to perform the move.
+        *
+        * @param User $user
+        * @param string|null $reason To check against summary spam regex. Set to null to skip the check,
+        *   for instance to display errors preemptively before the user has filled in a summary.
+        * @return Status
+        */
        public function checkPermissions( User $user, $reason ) {
                $status = new Status();
 
@@ -63,7 +71,7 @@ class MovePage {
                        }
                }
 
-               if ( EditPage::matchSummarySpamRegex( $reason ) !== false ) {
+               if ( $reason !== null && EditPage::matchSummarySpamRegex( $reason ) !== false ) {
                        // This is kind of lame, won't display nice
                        $status->fatal( 'spamprotectiontext' );
                }
index c4fe858..3d262d5 100644 (file)
@@ -3429,6 +3429,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
         */
        public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
+               wfDeprecated( __METHOD__, '1.25' );
+
                global $wgUser;
 
                if ( !( $nt instanceof Title ) ) {
@@ -3465,6 +3467,8 @@ class Title implements LinkTarget, IDBAccessObject {
        public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true,
                array $changeTags = []
        ) {
+               wfDeprecated( __METHOD__, '1.25' );
+
                global $wgUser;
 
                $mp = new MovePage( $this, $nt );
@@ -3495,26 +3499,10 @@ class Title implements LinkTarget, IDBAccessObject {
        public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true,
                array $changeTags = []
        ) {
-               // Check permissions
-               if ( !$this->userCan( 'move-subpages' ) ) {
-                       return [
-                               [ 'cant-move-subpages' ],
-                       ];
-               }
-               // Do the source and target namespaces support subpages?
-               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
-               if ( !$nsInfo->hasSubpages( $this->mNamespace ) ) {
-                       return [
-                               [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $this->mNamespace ) ],
-                       ];
-               }
-               if ( !$nsInfo->hasSubpages( $nt->getNamespace() ) ) {
-                       return [
-                               [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $nt->getNamespace() ) ],
-                       ];
-               }
+               wfDeprecated( __METHOD__, '1.34' );
 
                global $wgUser;
+
                $mp = new MovePage( $this, $nt );
                $method = $auth ? 'moveSubpagesIfAllowed' : 'moveSubpages';
                $result = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags );
@@ -3592,6 +3580,8 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return bool
         */
        public function isValidMoveTarget( $nt ) {
+               wfDeprecated( __METHOD__, '1.25' );
+
                # Is it an existing file?
                if ( $nt->getNamespace() == NS_FILE ) {
                        $file = wfLocalFile( $nt );
index 2d8ae3c..f1c095e 100644 (file)
@@ -67,7 +67,7 @@ class MultiUsernameFilter implements Filter {
        }
 
        /**
-        * Splits a newline separated list of user ids into a
+        * Splits a newline separated list of user ids into an array.
         *
         * @param string $str
         * @return int[]
index b561e5b..507cd45 100644 (file)
@@ -170,6 +170,8 @@ class MovePageForm extends UnlistedSpecialPage {
                $deleteAndMove = false;
                $moveOverShared = false;
 
+               $user = $this->getUser();
+
                $newTitle = $this->newTitle;
 
                if ( !$newTitle ) {
@@ -180,14 +182,14 @@ class MovePageForm extends UnlistedSpecialPage {
                        # If a title was supplied, probably from the move log revert
                        # link, check for validity. We can then show some diagnostic
                        # information and save a click.
-                       $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
-                       if ( is_array( $newerr ) ) {
-                               $err = $newerr;
+                       $mp = new MovePage( $this->oldTitle, $newTitle );
+                       $status = $mp->isValidMove();
+                       $status->merge( $mp->checkPermissions( $user, null ) );
+                       if ( $status->getErrors() ) {
+                               $err = $status->getErrorsArray();
                        }
                }
 
-               $user = $this->getUser();
-
                if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
                        && $newTitle->quickUserCan( 'delete', $user )
                ) {
@@ -741,14 +743,15 @@ class MovePageForm extends UnlistedSpecialPage {
                                continue;
                        }
 
+                       $mp = new MovePage( $oldSubpage, $newSubpage );
                        # This was copy-pasted from Renameuser, bleh.
-                       if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
+                       if ( $newSubpage->exists() && !$mp->isValidMove()->isOk() ) {
                                $link = $linkRenderer->makeKnownLink( $newSubpage );
                                $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
                        } else {
-                               $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
+                               $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
 
-                               if ( $success === true ) {
+                               if ( $status->isOK() ) {
                                        if ( $this->fixRedirects ) {
                                                DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
                                        }
index dbf029e..7b7c70d 100644 (file)
@@ -7,11 +7,11 @@
                        var $a;
                        // Recheck preference so extensions can do a hack to disable this code.
                        if ( parseInt( mw.user.options.get( 'editondblclick' ), 10 ) ) {
-                               e.preventDefault();
                                // Trigger native HTMLElement click instead of opening URL (T45052)
                                $a = $( '#ca-edit a' );
                                // Not every page has an edit link (T59713)
                                if ( $a.length ) {
+                                       e.preventDefault();
                                        // eslint-disable-next-line no-jquery/no-event-shorthand
                                        $a.get( 0 ).click();
                                }
index db9d2ab..9166666 100644 (file)
@@ -47,29 +47,6 @@ class MovePageTest extends MediaWikiTestCase {
                ];
        }
 
-       /**
-        * Integration test to catch regressions like T74870. Taken and modified
-        * from SemanticMediaWiki
-        *
-        * @covers Title::moveTo
-        */
-       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()
-               );
-       }
-
        /**
         * Test for the move operation being aborted via the TitleMove hook
         * @covers MovePage::move
index abd70b2..77d6f59 100644 (file)
@@ -437,6 +437,31 @@ class TitleMethodsTest extends MediaWikiLangTestCase {
                $this->assertSame( $expected, $title->getLinkURL( $query, $query2, $proto ) );
        }
 
+       /**
+        * Integration test to catch regressions like T74870. Taken and modified
+        * from SemanticMediaWiki
+        *
+        * @covers Title::moveTo
+        */
+       public function testTitleMoveCompleteIntegrationTest() {
+               $this->hideDeprecated( 'Title::moveTo' );
+
+               $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()
+               );
+       }
+
        function tearDown() {
                Title::clearCaches();
                parent::tearDown();
index c46f69b..d6c3401 100644 (file)
@@ -295,6 +295,8 @@ class TitleTest extends MediaWikiTestCase {
         * @covers Title::isValidMoveOperation
         */
        public function testIsValidMoveOperation( $source, $target, $expected ) {
+               $this->hideDeprecated( 'Title::isValidMoveOperation' );
+
                $this->setMwGlobals( 'wgContentHandlerUseDB', false );
                $title = Title::newFromText( $source );
                $nt = Title::newFromText( $target );