ParamValidator: Flag as unstable for 1.34
[lhc/web/wiklou.git] / includes / EditPage.php
index 84b81f3..fe00149 100644 (file)
@@ -25,7 +25,7 @@ use MediaWiki\EditPage\TextboxBuilder;
 use MediaWiki\EditPage\TextConflictHelper;
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
-use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Revision\RevisionRecord;
 use Wikimedia\ScopedCallback;
 
 /**
@@ -689,10 +689,6 @@ class EditPage {
                # checking, etc.
                if ( $this->formtype == 'initial' || $this->firsttime ) {
                        if ( $this->initialiseForm() === false ) {
-                               $out = $this->context->getOutput();
-                               if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it
-                                       $this->noSuchSectionPage();
-                               }
                                return;
                        }
 
@@ -1131,7 +1127,7 @@ class EditPage {
         * @return string|null
         */
        protected function importContentFormData( &$request ) {
-               return; // Don't do anything, EditPage already extracted wpTextbox1
+               return null; // Don't do anything, EditPage already extracted wpTextbox1
        }
 
        /**
@@ -1145,8 +1141,26 @@ class EditPage {
 
                $content = $this->getContentObject( false ); # TODO: track content object?!
                if ( $content === false ) {
+                       $out = $this->context->getOutput();
+                       if ( $out->getRedirect() === '' ) { // mcrundo hack redirects, don't override it
+                               $this->noSuchSectionPage();
+                       }
                        return false;
                }
+
+               if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
+                       $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() );
+                       $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel();
+
+                       $out = $this->context->getOutput();
+                       $out->showErrorPage(
+                               'modeleditnotsupported-title',
+                               'modeleditnotsupported-text',
+                               [ $modelName ]
+                       );
+                       return false;
+               }
+
                $this->textbox1 = $this->toEditText( $content );
 
                $user = $this->context->getUser();
@@ -1174,7 +1188,7 @@ class EditPage {
        /**
         * @param Content|null $def_content The default value to return
         *
-        * @return Content|null Content on success, $def_content for invalid sections
+        * @return Content|false|null Content on success, $def_content for invalid sections
         *
         * @since 1.21
         */
@@ -1669,7 +1683,9 @@ class EditPage {
                        case self::AS_CANNOT_USE_CUSTOM_MODEL:
                        case self::AS_PARSE_ERROR:
                        case self::AS_UNICODE_NOT_SUPPORTED:
-                               $out->wrapWikiTextAsInterface( 'error', $status->getWikiText() );
+                               $out->wrapWikiTextAsInterface( 'error',
+                                       $status->getWikiText( false, false, $this->context->getLanguage() )
+                               );
                                return true;
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
@@ -1743,7 +1759,8 @@ class EditPage {
                                // is if an extension hook aborted from inside ArticleSave.
                                // Render the status object into $this->hookError
                                // FIXME this sucks, we should just use the Status object throughout
-                               $this->hookError = '<div class="error">' . "\n" . $status->getWikiText() .
+                               $this->hookError = '<div class="error">' . "\n" .
+                                       $status->getWikiText( false, false, $this->context->getLanguage() ) .
                                        '</div>';
                                return true;
                }
@@ -1790,8 +1807,11 @@ class EditPage {
                } elseif ( !$status->isOK() ) {
                        # ...or the hook could be expecting us to produce an error
                        // FIXME this sucks, we should just use the Status object throughout
+                       if ( !$status->getErrors() ) {
+                               // Provide a fallback error message if none was set
+                               $status->fatal( 'hookaborted' );
+                       }
                        $this->hookError = $this->formatStatusErrors( $status );
-                       $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR_EXPECTED;
                        return false;
                }
@@ -2725,7 +2745,7 @@ ERROR;
         * content.
         *
         * @param Content|null|bool|string $content
-        * @return string The editable text form of the content.
+        * @return string|false|null The editable text form of the content.
         *
         * @throws MWException If $content is not an instance of TextContent and
         *   $this->allowNonTextContent is not true.
@@ -4028,11 +4048,11 @@ ERROR;
 
                if ( $this->isConflict ) {
                        $conflict = Html::rawElement(
-                               'h2', [ 'id' => 'mw-previewconflict' ],
+                               'div', [ 'id' => 'mw-previewconflict', 'class' => 'warningbox' ],
                                $this->context->msg( 'previewconflict' )->escaped()
                        );
                } else {
-                       $conflict = '<hr />';
+                       $conflict = '';
                }
 
                $previewhead = Html::rawElement(
@@ -4041,7 +4061,9 @@ ERROR;
                                'h2', [ 'id' => 'mw-previewheader' ],
                                $this->context->msg( 'preview' )->escaped()
                        ) .
-                       $out->parseAsInterface( $note ) . $conflict
+                       Html::rawElement( 'div', [ 'class' => 'warningbox' ],
+                               $out->parseAsInterface( $note )
+                       ) . $conflict
                );
 
                $pageViewLang = $this->mTitle->getPageViewLanguage();
@@ -4157,7 +4179,7 @@ ERROR;
         *  - 'legacy-name' (optional): short name for backwards-compatibility
         * @param array $checked Array of checkbox name (matching the 'legacy-name') => bool,
         *   where bool indicates the checked status of the checkbox
-        * @return array
+        * @return array[]
         */
        public function getCheckboxesDefinition( $checked ) {
                $checkboxes = [];