Merge "API: Deprecate diff and parse parameters in ApiQueryRevisionsBase"
[lhc/web/wiklou.git] / includes / EditPage.php
index 0d3c74f..6be8771 100644 (file)
@@ -1452,10 +1452,8 @@ class EditPage {
         * This uses a temporary cookie for each revision ID so separate saves will never
         * interfere with each other.
         *
-        * The cookie is deleted in the mediawiki.action.view.postEdit JS module after
-        * the redirect.  It must be clearable by JavaScript code, so it must not be
-        * marked HttpOnly. The JavaScript code converts the cookie to a wgPostEdit config
-        * variable.
+        * Article::view deletes the cookie on server-side after the redirect and
+        * converts the value to the global JavaScript variable wgPostEdit.
         *
         * If the variable were set on the server, it would be cached, which is unwanted
         * since the post-edit state should only apply to the load right after the save.
@@ -1474,9 +1472,7 @@ class EditPage {
                }
 
                $response = RequestContext::getMain()->getRequest()->response();
-               $response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION, [
-                       'httpOnly' => false,
-               ] );
+               $response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION );
        }
 
        /**
@@ -2757,6 +2753,9 @@ class EditPage {
                $wgOut->addHTML( Html::hidden( 'format', $this->contentFormat ) );
                $wgOut->addHTML( Html::hidden( 'model', $this->contentModel ) );
 
+               // Preserve &ooui=1 / &ooui=0 from URL parameters after submitting the page for preview
+               $wgOut->addHTML( Html::hidden( 'ooui', $this->oouiEnabled ? '1' : '0' ) );
+
                // following functions will need OOUI, enable it only once; here.
                if ( $this->oouiEnabled ) {
                        $wgOut->enableOOUI();
@@ -2909,7 +2908,7 @@ class EditPage {
                                }
                        }
 
-                       $buttonLabelKey = $this->getSaveButtonLabel();
+                       $buttonLabel = $this->context->msg( $this->getSaveButtonLabel() )->text();
 
                        if ( $this->missingComment ) {
                                $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
@@ -2918,28 +2917,28 @@ class EditPage {
                        if ( $this->missingSummary && $this->section != 'new' ) {
                                $wgOut->wrapWikiMsg(
                                        "<div id='mw-missingsummary'>\n$1\n</div>",
-                                       [ 'missingsummary', $buttonLabelKey ]
+                                       [ 'missingsummary', $buttonLabel ]
                                );
                        }
 
                        if ( $this->missingSummary && $this->section == 'new' ) {
                                $wgOut->wrapWikiMsg(
                                        "<div id='mw-missingcommentheader'>\n$1\n</div>",
-                                       [ 'missingcommentheader', $buttonLabelKey ]
+                                       [ 'missingcommentheader', $buttonLabel ]
                                );
                        }
 
                        if ( $this->blankArticle ) {
                                $wgOut->wrapWikiMsg(
                                        "<div id='mw-blankarticle'>\n$1\n</div>",
-                                       [ 'blankarticle', $buttonLabelKey ]
+                                       [ 'blankarticle', $buttonLabel ]
                                );
                        }
 
                        if ( $this->selfRedirect ) {
                                $wgOut->wrapWikiMsg(
                                        "<div id='mw-selfredirect'>\n$1\n</div>",
-                                       [ 'selfredirect', $buttonLabelKey ]
+                                       [ 'selfredirect', $buttonLabel ]
                                );
                        }
 
@@ -3060,7 +3059,7 @@ class EditPage {
                        'id' => 'wpSummary',
                        'name' => 'wpSummary',
                        'maxlength' => '200',
-                       'tabindex' => '1',
+                       'tabindex' => 1,
                        'size' => 60,
                        'spellcheck' => 'true',
                ] + Linker::tooltipAndAccesskeyAttribs( 'summary' );
@@ -3120,6 +3119,10 @@ class EditPage {
                        $this->getSummaryInputAttributes( $inputAttrs )
                );
 
+               // For compatibility with old scripts and extensions, we want the legacy 'id' on the `<input>`
+               $inputAttrs['inputId'] = $inputAttrs['id'];
+               $inputAttrs['id'] = 'wpSummaryWidget';
+
                return new OOUI\FieldLayout(
                        new OOUI\TextInputWidget( [
                                'value' => $summary,
@@ -4269,7 +4272,8 @@ HTML
                                new OOUI\CheckboxInputWidget( [
                                        'tabIndex' => ++$tabindex,
                                        'accessKey' => $accesskey,
-                                       'id' => $options['id'],
+                                       'id' => $options['id'] . 'Widget',
+                                       'inputId' => $options['id'],
                                        'name' => $name,
                                        'selected' => $options['default'],
                                        'infusable' => true,
@@ -4328,10 +4332,9 @@ HTML
        public function getEditButtons( &$tabindex ) {
                $buttons = [];
 
-               $buttonLabelKey = $this->getSaveButtonLabel();
+               $buttonLabel = $this->context->msg( $this->getSaveButtonLabel() )->text();
 
                $attribs = [
-                       'id' => 'wpSave',
                        'name' => 'wpSave',
                        'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'save' );
@@ -4339,29 +4342,32 @@ HTML
                if ( $this->oouiEnabled ) {
                        $saveConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                        $buttons['save'] = new OOUI\ButtonInputWidget( [
+                               'id' => 'wpSaveWidget',
+                               'inputId' => 'wpSave',
                                // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
                                'useInputTag' => true,
                                'flags' => [ 'constructive', 'primary' ],
-                               'label' => $this->context->msg( $buttonLabelKey )->text(),
+                               'label' => $buttonLabel,
                                'infusable' => true,
                                'type' => 'submit',
                        ] + $saveConfig );
                } else {
                        $buttons['save'] = Html::submitButton(
-                               $this->context->msg( $buttonLabelKey )->text(),
-                               $attribs,
+                               $buttonLabel,
+                               $attribs + [ 'id' => 'wpSave' ],
                                [ 'mw-ui-progressive' ]
                        );
                }
 
                $attribs = [
-                       'id' => 'wpPreview',
                        'name' => 'wpPreview',
                        'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'preview' );
                if ( $this->oouiEnabled ) {
                        $previewConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                        $buttons['preview'] = new OOUI\ButtonInputWidget( [
+                               'id' => 'wpPreviewWidget',
+                               'inputId' => 'wpPreview',
                                // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
                                'useInputTag' => true,
                                'label' => $this->context->msg( 'showpreview' )->text(),
@@ -4371,17 +4377,18 @@ HTML
                } else {
                        $buttons['preview'] = Html::submitButton(
                                $this->context->msg( 'showpreview' )->text(),
-                               $attribs
+                               $attribs + [ 'id' => 'wpPreview' ]
                        );
                }
                $attribs = [
-                       'id' => 'wpDiff',
                        'name' => 'wpDiff',
                        'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'diff' );
                if ( $this->oouiEnabled ) {
                        $diffConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                        $buttons['diff'] = new OOUI\ButtonInputWidget( [
+                               'id' => 'wpDiffWidget',
+                               'inputId' => 'wpDiff',
                                // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
                                'useInputTag' => true,
                                'label' => $this->context->msg( 'showdiff' )->text(),
@@ -4391,7 +4398,7 @@ HTML
                } else {
                        $buttons['diff'] = Html::submitButton(
                                $this->context->msg( 'showdiff' )->text(),
-                               $attribs
+                               $attribs + [ 'id' => 'wpDiff' ]
                        );
                }
 
@@ -4698,7 +4705,7 @@ HTML
        protected function addExplainConflictHeader( OutputPage $out ) {
                $out->wrapWikiMsg(
                        "<div class='mw-explainconflict'>\n$1\n</div>",
-                       [ 'explainconflict', $this->getSaveButtonLabel() ]
+                       [ 'explainconflict', $this->context->msg( $this->getSaveButtonLabel() )->text() ]
                );
        }