Merge "Remove parameter 'options' from hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
index 5cbad8a..b561e5b 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * A special page that allows users to change page titles
  *
@@ -75,7 +77,7 @@ class MovePageForm extends UnlistedSpecialPage {
                $this->outputHeader();
 
                $request = $this->getRequest();
-               $target = !is_null( $par ) ? $par : $request->getVal( 'target' );
+               $target = $par ?? $request->getVal( 'target' );
 
                // Yes, the use of getVal() and getText() is wanted, see T22365
 
@@ -122,7 +124,7 @@ class MovePageForm extends UnlistedSpecialPage {
                $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile' );
                $this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
 
-               if ( 'submit' == $request->getVal( 'action' ) && $request->wasPosted()
+               if ( $request->getVal( 'action' ) == 'submit' && $request->wasPosted()
                        && $user->matchEditToken( $request->getVal( 'wpEditToken' ) )
                ) {
                        $this->doSubmit();
@@ -137,8 +139,9 @@ class MovePageForm extends UnlistedSpecialPage {
         * @param array $err Error messages. Each item is an error message.
         *    It may either be a string message name or array message name and
         *    parameters, like the second argument to OutputPage::wrapWikiMsg().
+        * @param bool $isPermError Whether the error message is about user permissions.
         */
-       function showForm( $err ) {
+       function showForm( $err, $isPermError = false ) {
                $this->getSkin()->setRelevantTitle( $this->oldTitle );
 
                $out = $this->getOutput();
@@ -235,9 +238,13 @@ class MovePageForm extends UnlistedSpecialPage {
                }
 
                if ( count( $err ) ) {
-                       $action_desc = $this->msg( 'action-move' )->plain();
-                       $errMsgHtml = $this->msg( 'permissionserrorstext-withaction',
-                               count( $err ), $action_desc )->parseAsBlock();
+                       if ( $isPermError ) {
+                               $action_desc = $this->msg( 'action-move' )->plain();
+                               $errMsgHtml = $this->msg( 'permissionserrorstext-withaction',
+                                       count( $err ), $action_desc )->parseAsBlock();
+                       } else {
+                               $errMsgHtml = $this->msg( 'cannotmove', count( $err ) )->parseAsBlock();
+                       }
 
                        if ( count( $err ) == 1 ) {
                                $errMsg = $err[0];
@@ -292,7 +299,7 @@ class MovePageForm extends UnlistedSpecialPage {
 
                $immovableNamespaces = [];
                foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
-                       if ( !MWNamespace::isMovable( $nsId ) ) {
+                       if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->isMovable( $nsId ) ) {
                                $immovableNamespaces[] = $nsId;
                        }
                }
@@ -328,14 +335,12 @@ class MovePageForm extends UnlistedSpecialPage {
 
                // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
                // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
-               // Unicode codepoints (or 255 UTF-8 bytes for old schema).
-               $conf = $this->getConfig();
-               $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
+               // Unicode codepoints.
                $fields[] = new OOUI\FieldLayout(
                        new OOUI\TextInputWidget( [
                                'name' => 'wpReason',
                                'id' => 'wpReason',
-                               'maxLength' => $oldCommentSchema ? 200 : CommentStore::COMMENT_CHARACTER_LIMIT,
+                               'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
                                'infusable' => true,
                                'value' => $this->reason,
                        ] ),
@@ -542,7 +547,7 @@ class MovePageForm extends UnlistedSpecialPage {
                        $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
                        if ( count( $permErrors ) ) {
                                # Only show the first error
-                               $this->showForm( $permErrors );
+                               $this->showForm( $permErrors, true );
 
                                return;
                        }
@@ -588,21 +593,12 @@ class MovePageForm extends UnlistedSpecialPage {
 
                # Do the actual move.
                $mp = new MovePage( $ot, $nt );
-               $valid = $mp->isValidMove();
-               if ( !$valid->isOK() ) {
-                       $this->showForm( $valid->getErrorsArray() );
-                       return;
-               }
 
-               $permStatus = $mp->checkPermissions( $user, $this->reason );
-               if ( !$permStatus->isOK() ) {
-                       $this->showForm( $permStatus->getErrorsArray() );
-                       return;
-               }
+               $userPermitted = $mp->checkPermissions( $user, $this->reason )->isOK();
 
-               $status = $mp->move( $user, $this->reason, $createRedirect );
+               $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
                if ( !$status->isOK() ) {
-                       $this->showForm( $status->getErrorsArray() );
+                       $this->showForm( $status->getErrorsArray(), !$userPermitted );
                        return;
                }
 
@@ -670,11 +666,12 @@ class MovePageForm extends UnlistedSpecialPage {
                 */
 
                // @todo FIXME: Use Title::moveSubpages() here
+               $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
                $dbr = wfGetDB( DB_MASTER );
                if ( $this->moveSubpages && (
-                       MWNamespace::hasSubpages( $nt->getNamespace() ) || (
+                       $nsInfo->hasSubpages( $nt->getNamespace() ) || (
                                $this->moveTalk
-                                       && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
+                                       && $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
                        )
                ) ) {
                        $conds = [
@@ -682,11 +679,11 @@ class MovePageForm extends UnlistedSpecialPage {
                                        . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
                        ];
                        $conds['page_namespace'] = [];
-                       if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
+                       if ( $nsInfo->hasSubpages( $nt->getNamespace() ) ) {
                                $conds['page_namespace'][] = $ot->getNamespace();
                        }
                        if ( $this->moveTalk &&
-                               MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
+                               $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
                        ) {
                                $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
                        }
@@ -805,7 +802,8 @@ class MovePageForm extends UnlistedSpecialPage {
         * @param Title $title Page being moved.
         */
        function showSubpages( $title ) {
-               $nsHasSubpages = MWNamespace::hasSubpages( $title->getNamespace() );
+               $nsHasSubpages = MediaWikiServices::getInstance()->getNamespaceInfo()->
+                       hasSubpages( $title->getNamespace() );
                $subpages = $title->getSubpages();
                $count = $subpages instanceof TitleArray ? $subpages->count() : 0;