Merge "media: Fix $ext property name in BmpHandler::getThumbType()"
[lhc/web/wiklou.git] / includes / EditPage.php
index 1d9ff05..ab7d6bb 100644 (file)
@@ -565,14 +565,6 @@ class EditPage {
                $this->enableApiEditOverride = $enableOverride;
        }
 
-       /**
-        * @deprecated since 1.29, call edit directly
-        */
-       public function submit() {
-               wfDeprecated( __METHOD__, '1.29' );
-               $this->edit();
-       }
-
        /**
         * This is the function that gets called for "action=edit". It
         * sets up various member variables, then passes execution to
@@ -1483,8 +1475,9 @@ class EditPage {
 
                $user = $this->context->getUser();
                $title = Title::newFromText( $preload );
+
                # Check for existence to avoid getting MediaWiki:Noarticletext
-               if ( $title === null || !$title->exists() || !$title->userCan( 'read', $user ) ) {
+               if ( !$this->isPageExistingAndViewable( $title, $user ) ) {
                        // TODO: somehow show a warning to the user!
                        return $handler->makeEmptyContent();
                }
@@ -1493,7 +1486,7 @@ class EditPage {
                if ( $page->isRedirect() ) {
                        $title = $page->getRedirectTarget();
                        # Same as before
-                       if ( $title === null || !$title->exists() || !$title->userCan( 'read', $user ) ) {
+                       if ( !$this->isPageExistingAndViewable( $title, $user ) ) {
                                // TODO: somehow show a warning to the user!
                                return $handler->makeEmptyContent();
                        }
@@ -1526,6 +1519,21 @@ class EditPage {
                return $content->preloadTransform( $title, $parserOptions, $params );
        }
 
+       /**
+        * Verify if a given title exists and the given user is allowed to view it
+        *
+        * @see EditPage::getPreloadedContent()
+        * @param Title|null $title
+        * @param User $user
+        * @return bool
+        * @throws Exception
+        */
+       private function isPageExistingAndViewable( $title, User $user ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
+               return $title && $title->exists() && $permissionManager->userCan( 'read', $user, $title );
+       }
+
        /**
         * Make sure the form isn't faking a user's credentials.
         *
@@ -1988,6 +1996,8 @@ ERROR;
                        }
                }
 
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
                $changingContentModel = false;
                if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
                        if ( !$config->get( 'ContentHandlerUseDB' ) ) {
@@ -2001,10 +2011,19 @@ ERROR;
                        // Make sure the user can edit the page under the new content model too
                        $titleWithNewContentModel = clone $this->mTitle;
                        $titleWithNewContentModel->setContentModel( $this->contentModel );
-                       if ( !$titleWithNewContentModel->userCan( 'editcontentmodel', $user )
-                               || !$titleWithNewContentModel->userCan( 'edit', $user )
+
+                       $canEditModel = $permissionManager->userCan(
+                               'editcontentmodel',
+                               $user,
+                               $titleWithNewContentModel
+                       );
+
+                       if (
+                               !$canEditModel
+                               || !$permissionManager->userCan( 'edit', $user, $titleWithNewContentModel )
                        ) {
                                $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
+
                                return $status;
                        }
 
@@ -2048,7 +2067,7 @@ ERROR;
 
                if ( $new ) {
                        // Late check for create permission, just in case *PARANOIA*
-                       if ( !$this->mTitle->userCan( 'create', $user ) ) {
+                       if ( !$permissionManager->userCan( 'create', $user, $this->mTitle ) ) {
                                $status->fatal( 'nocreatetext' );
                                $status->value = self::AS_NO_CREATE_PERMISSION;
                                wfDebug( __METHOD__ . ": no create permission\n" );
@@ -2609,7 +2628,8 @@ ERROR;
                                LogEventsList::showLogExtract(
                                        $out,
                                        'block',
-                                       MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
+                                       MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                               getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
                                        '',
                                        [
                                                'lim' => 1,
@@ -2671,7 +2691,7 @@ ERROR;
        protected function showCustomIntro() {
                if ( $this->editintro ) {
                        $title = Title::newFromText( $this->editintro );
-                       if ( $title instanceof Title && $title->exists() && $title->userCan( 'read' ) ) {
+                       if ( $this->isPageExistingAndViewable( $title, $this->context->getUser() ) ) {
                                // Added using template syntax, to take <noinclude>'s into account.
                                $this->context->getOutput()->addWikiTextAsContent(
                                        '<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',
@@ -2933,7 +2953,7 @@ ERROR;
                }
 
                if ( !$this->mTitle->isUserConfigPage() ) {
-                       $out->addHTML( self::getEditToolbar( $this->mTitle ) );
+                       $out->addHTML( self::getEditToolbar() );
                }
 
                if ( $this->blankArticle ) {
@@ -4100,10 +4120,9 @@ ERROR;
        /**
         * Allow extensions to provide a toolbar.
         *
-        * @param Title|null $title Title object for the page being edited (optional)
         * @return string|null
         */
-       public static function getEditToolbar( $title = null ) {
+       public static function getEditToolbar() {
                $startingToolbar = '<div id="toolbar"></div>';
                $toolbar = $startingToolbar;
 
@@ -4359,33 +4378,6 @@ ERROR;
                $out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] );
        }
 
-       /**
-        * Filter an input field through a Unicode de-armoring process if it
-        * came from an old browser with known broken Unicode editing issues.
-        *
-        * @deprecated since 1.30, does nothing
-        *
-        * @param WebRequest $request
-        * @param string $field
-        * @return string
-        */
-       protected function safeUnicodeInput( $request, $field ) {
-               return rtrim( $request->getText( $field ) );
-       }
-
-       /**
-        * Filter an output field through a Unicode armoring process if it is
-        * going to an old browser with known broken Unicode editing issues.
-        *
-        * @deprecated since 1.30, does nothing
-        *
-        * @param string $text
-        * @return string
-        */
-       protected function safeUnicodeOutput( $text ) {
-               return $text;
-       }
-
        /**
         * @since 1.29
         */
@@ -4451,7 +4443,9 @@ ERROR;
        protected function addPageProtectionWarningHeaders() {
                $out = $this->context->getOutput();
                if ( $this->mTitle->isProtected( 'edit' ) &&
-                       MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
+                       MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+                               $this->mTitle->getNamespace()
+                       ) !== [ '' ]
                ) {
                        # Is the title semi-protected?
                        if ( $this->mTitle->isSemiProtected() ) {