Convert article delete to use OOUI
[lhc/web/wiklou.git] / includes / EditPage.php
index c19ed5e..b1f50f0 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 );
        }
 
        /**
@@ -2909,24 +2905,38 @@ class EditPage {
                                }
                        }
 
+                       $buttonLabelKey = $this->getSaveButtonLabel();
+
                        if ( $this->missingComment ) {
                                $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
                        }
 
                        if ( $this->missingSummary && $this->section != 'new' ) {
-                               $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>", 'missingsummary' );
+                               $wgOut->wrapWikiMsg(
+                                       "<div id='mw-missingsummary'>\n$1\n</div>",
+                                       [ 'missingsummary', $buttonLabelKey ]
+                               );
                        }
 
                        if ( $this->missingSummary && $this->section == 'new' ) {
-                               $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
+                               $wgOut->wrapWikiMsg(
+                                       "<div id='mw-missingcommentheader'>\n$1\n</div>",
+                                       [ 'missingcommentheader', $buttonLabelKey ]
+                               );
                        }
 
                        if ( $this->blankArticle ) {
-                               $wgOut->wrapWikiMsg( "<div id='mw-blankarticle'>\n$1\n</div>", 'blankarticle' );
+                               $wgOut->wrapWikiMsg(
+                                       "<div id='mw-blankarticle'>\n$1\n</div>",
+                                       [ 'blankarticle', $buttonLabelKey ]
+                               );
                        }
 
                        if ( $this->selfRedirect ) {
-                               $wgOut->wrapWikiMsg( "<div id='mw-selfredirect'>\n$1\n</div>", 'selfredirect' );
+                               $wgOut->wrapWikiMsg(
+                                       "<div id='mw-selfredirect'>\n$1\n</div>",
+                                       [ 'selfredirect', $buttonLabelKey ]
+                               );
                        }
 
                        if ( $this->hookError !== '' ) {
@@ -3044,6 +3054,7 @@ class EditPage {
                // Note: the maxlength is overridden in JS to 255 and to make it use UTF-8 bytes, not characters.
                return ( is_array( $inputAttrs ) ? $inputAttrs : [] ) + [
                        'id' => 'wpSummary',
+                       'name' => 'wpSummary',
                        'maxlength' => '200',
                        'tabindex' => '1',
                        'size' => 60,
@@ -3108,6 +3119,7 @@ class EditPage {
                return new OOUI\FieldLayout(
                        new OOUI\TextInputWidget( [
                                'value' => $summary,
+                               'infusable' => true,
                        ] + $inputAttrs ),
                        [
                                'label' => new OOUI\HtmlSnippet( $labelText ),
@@ -3154,7 +3166,6 @@ class EditPage {
                        );
                        $wgOut->addHTML( "{$label} {$input}" );
                }
-
        }
 
        /**
@@ -3672,6 +3683,7 @@ HTML
                                'href' => $this->getContextTitle()->getLinkUrl( $cancelParams ),
                                'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
                                'framed' => false,
+                               'infusable' => true,
                                'flags' => 'destructive',
                        ] );
                } else {
@@ -4094,11 +4106,14 @@ HTML
                }
 
                $script .= '});';
-               $wgOut->addScript( ResourceLoader::makeInlineScript( $script ) );
 
                $toolbar = '<div id="toolbar"></div>';
 
-               Hooks::run( 'EditPageBeforeEditToolbar', [ &$toolbar ] );
+               if ( Hooks::run( 'EditPageBeforeEditToolbar', [ &$toolbar ] ) ) {
+                       // Only add the old toolbar cruft to the page payload if the toolbar has not
+                       // been over-written by a hook caller
+                       $wgOut->addScript( ResourceLoader::makeInlineScript( $script ) );
+               };
 
                return $toolbar;
        }
@@ -4253,6 +4268,7 @@ HTML
                                        'id' => $options['id'],
                                        'name' => $name,
                                        'selected' => $options['default'],
+                                       'infusable' => true,
                                ] ),
                                [
                                        'align' => 'inline',
@@ -4276,6 +4292,27 @@ HTML
                return $checkboxes;
        }
 
+       /**
+        * Get the message key of the label for the button to save the page
+        *
+        * @return string
+        */
+       private function getSaveButtonLabel() {
+               $labelAsPublish =
+                       $this->mArticle->getContext()->getConfig()->get( 'EditSubmitButtonLabelPublish' );
+
+               // Can't use $this->isNew as that's also true if we're adding a new section to an extant page
+               $newPage = !$this->mTitle->exists();
+
+               if ( $labelAsPublish ) {
+                       $buttonLabelKey =  $newPage ? 'publishpage' : 'publishchanges';
+               } else {
+                       $buttonLabelKey = $newPage ? 'savearticle' : 'savechanges';
+               }
+
+               return $buttonLabelKey;
+       }
+
        /**
         * Returns an array of html code of the following buttons:
         * save, diff and preview
@@ -4287,15 +4324,8 @@ HTML
        public function getEditButtons( &$tabindex ) {
                $buttons = [];
 
-               $labelAsPublish =
-                       $this->mArticle->getContext()->getConfig()->get( 'EditSubmitButtonLabelPublish' );
+               $buttonLabelKey = $this->getSaveButtonLabel();
 
-               // Can't use $this->isNew as that's also true if we're adding a new section to an extant page
-               if ( $labelAsPublish ) {
-                       $buttonLabelKey = !$this->mTitle->exists() ? 'publishpage' : 'publishchanges';
-               } else {
-                       $buttonLabelKey = !$this->mTitle->exists() ? 'savearticle' : 'savechanges';
-               }
                $attribs = [
                        'id' => 'wpSave',
                        'name' => 'wpSave',
@@ -4305,8 +4335,11 @@ HTML
                if ( $this->oouiEnabled ) {
                        $saveConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                        $buttons['save'] = new OOUI\ButtonInputWidget( [
+                               // 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(),
+                               'infusable' => true,
                                'type' => 'submit',
                        ] + $saveConfig );
                } else {
@@ -4325,7 +4358,10 @@ HTML
                if ( $this->oouiEnabled ) {
                        $previewConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                        $buttons['preview'] = new OOUI\ButtonInputWidget( [
+                               // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
+                               'useInputTag' => true,
                                'label' => $this->context->msg( 'showpreview' )->text(),
+                               'infusable' => true,
                                'type' => 'submit'
                        ] + $previewConfig );
                } else {
@@ -4342,7 +4378,10 @@ HTML
                if ( $this->oouiEnabled ) {
                        $diffConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                        $buttons['diff'] = new OOUI\ButtonInputWidget( [
+                               // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
+                               'useInputTag' => true,
                                'label' => $this->context->msg( 'showdiff' )->text(),
+                               'infusable' => true,
                                'type' => 'submit',
                        ] + $diffConfig );
                } else {
@@ -4653,7 +4692,10 @@ HTML
         * @since 1.29
         */
        protected function addExplainConflictHeader( OutputPage $out ) {
-               $out->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
+               $out->wrapWikiMsg(
+                       "<div class='mw-explainconflict'>\n$1\n</div>",
+                       [ 'explainconflict', $this->getSaveButtonLabel() ]
+               );
        }
 
        /**