Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / EditPage.php
index 6d64388..6bf3c89 100644 (file)
@@ -1717,7 +1717,7 @@ class EditPage {
                                // being set. This is used by ConfirmEdit to display a captcha
                                // without any error message cruft.
                        } else {
-                               $this->hookError = $status->getWikiText();
+                               $this->hookError = $this->formatStatusErrors( $status );
                        }
                        // Use the existing $status->value if the hook set it
                        if ( !$status->value ) {
@@ -1727,7 +1727,7 @@ 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
-                       $this->hookError = $status->getWikiText();
+                       $this->hookError = $this->formatStatusErrors( $status );
                        $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR_EXPECTED;
                        return false;
@@ -1736,6 +1736,26 @@ class EditPage {
                return true;
        }
 
+       /**
+        * Wrap status errors in an errorbox for increased visiblity
+        *
+        * @param Status $status
+        * @return string Wikitext
+        */
+       private function formatStatusErrors( Status $status ) {
+               $errmsg = $status->getWikiText(
+                       'edit-error-short',
+                       'edit-error-long',
+                       $this->context->getLanguage()
+               );
+               return <<<ERROR
+<div class="errorbox">
+{$errmsg}
+</div>
+<br clear="all" />
+ERROR;
+       }
+
        /**
         * Return the summary to be used for a new section.
         *
@@ -2452,12 +2472,22 @@ class EditPage {
                        $displayTitle = $contextTitle->getPrefixedText();
                }
                $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
+
+               $config = $this->context->getConfig();
+
                # Transmit the name of the message to JavaScript for live preview
                # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
                $out->addJsConfigVars( [
                        'wgEditMessage' => $msg,
-                       'wgAjaxEditStash' => $this->context->getConfig()->get( 'AjaxEditStash' ),
+                       'wgAjaxEditStash' => $config->get( 'AjaxEditStash' ),
                ] );
+
+               // Add whether to use 'save' or 'publish' messages to JavaScript for post-edit, other
+               // editors, etc.
+               $out->addJsConfigVars(
+                       'wgEditSubmitButtonLabelPublish',
+                       $config->get( 'EditSubmitButtonLabelPublish' )
+               );
        }
 
        /**
@@ -2861,7 +2891,14 @@ class EditPage {
                        // and fallback to the raw wpTextbox1 since editconflicts can't be
                        // resolved between page source edits and custom ui edits using the
                        // custom edit ui.
-                       $this->showTextbox1();
+                       $conflictTextBoxAttribs = [];
+                       if ( $this->wasDeletedSinceLastEdit() ) {
+                               $conflictTextBoxAttribs['style'] = 'display:none;';
+                       } elseif ( $this->isOldRev ) {
+                               $conflictTextBoxAttribs['class'] = 'mw-textarea-oldrev';
+                       }
+
+                       $out->addHTML( $editConflictHelper->getEditConflictMainTextBox( $conflictTextBoxAttribs ) );
                        $out->addHTML( $editConflictHelper->getEditFormHtmlAfterContent() );
                } else {
                        $this->showContentForm();
@@ -3339,22 +3376,9 @@ class EditPage {
                if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
                        $attribs = [ 'style' => 'display:none;' ];
                } else {
-                       $classes = []; // Textarea CSS
-                       if ( $this->mTitle->isProtected( 'edit' ) &&
-                               MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
-                       ) {
-                               # Is the title semi-protected?
-                               if ( $this->mTitle->isSemiProtected() ) {
-                                       $classes[] = 'mw-textarea-sprotected';
-                               } else {
-                                       # Then it must be protected based on static groups (regular)
-                                       $classes[] = 'mw-textarea-protected';
-                               }
-                               # Is the title cascade-protected?
-                               if ( $this->mTitle->isCascadeProtected() ) {
-                                       $classes[] = 'mw-textarea-cprotected';
-                               }
-                       }
+                       $builder = new TextboxBuilder();
+                       $classes = $builder->getTextboxProtectionCSSClasses( $this->getTitle() );
+
                        # Is an old revision being edited?
                        if ( $this->isOldRev ) {
                                $classes[] = 'mw-textarea-oldrev';
@@ -3366,12 +3390,7 @@ class EditPage {
                                $attribs += $customAttribs;
                        }
 
-                       if ( count( $classes ) ) {
-                               if ( isset( $attribs['class'] ) ) {
-                                       $classes[] = $attribs['class'];
-                               }
-                               $attribs['class'] = implode( ' ', $classes );
-                       }
+                       $attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs );
                }
 
                $this->showTextbox(
@@ -3615,6 +3634,8 @@ class EditPage {
         * @return string HTML
         */
        public static function getPreviewLimitReport( $output ) {
+               global $wgLang;
+
                if ( !$output || !$output->getLimitReportData() ) {
                        return '';
                }
@@ -3643,7 +3664,9 @@ class EditPage {
                                if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
                                        $limitReport .= Html::openElement( 'tr' ) .
                                                Html::rawElement( 'th', null, $keyMsg->parse() ) .
-                                               Html::rawElement( 'td', null, $valueMsg->params( $value )->parse() ) .
+                                               Html::rawElement( 'td', null,
+                                                       $wgLang->formatNum( $valueMsg->params( $value )->parse() )
+                                               ) .
                                                Html::closeElement( 'tr' );
                                }
                        }
@@ -3681,11 +3704,6 @@ class EditPage {
                $out->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
 
                $cancel = $this->getCancelLink();
-               if ( $cancel !== '' ) {
-                       $cancel .= Html::element( 'span',
-                               [ 'class' => 'mw-editButtons-pipe-separator' ],
-                               $this->context->msg( 'pipe-separator' )->text() );
-               }
 
                $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
                $edithelpurl = Skin::makeInternalOrExternalUrl( $message );
@@ -3739,7 +3757,7 @@ class EditPage {
 
                return new OOUI\ButtonWidget( [
                        'id' => 'mw-editform-cancel',
-                       'href' => $this->getContextTitle()->getLinkUrl( $cancelParams ),
+                       'href' => $this->getContextTitle()->getLinkURL( $cancelParams ),
                        'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
                        'framed' => false,
                        'infusable' => true,
@@ -4404,34 +4422,32 @@ class EditPage {
        public function getEditButtons( &$tabindex ) {
                $buttons = [];
 
-               $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
+               $labelAsPublish =
+                       $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
 
-               $attribs = [
-                       'name' => 'wpSave',
-                       'tabindex' => ++$tabindex,
-               ];
+               $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
+               $buttonTooltip = $labelAsPublish ? 'publish' : 'save';
 
-               $saveConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                $buttons['save'] = new OOUI\ButtonInputWidget( [
+                       'name' => 'wpSave',
+                       'tabIndex' => ++$tabindex,
                        'id' => 'wpSaveWidget',
                        'inputId' => 'wpSave',
                        // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
                        'useInputTag' => true,
-                       'flags' => [ 'constructive', 'primary' ],
+                       'flags' => [ 'progressive', 'primary' ],
                        'label' => $buttonLabel,
                        'infusable' => true,
                        'type' => 'submit',
-                       'title' => Linker::titleAttrib( 'save' ),
-                       'accessKey' => Linker::accesskey( 'save' ),
-               ] + $saveConfig );
-
-               $attribs = [
-                       'name' => 'wpPreview',
-                       'tabindex' => ++$tabindex,
-               ];
+                       // Messages used: tooltip-save, tooltip-publish
+                       'title' => Linker::titleAttrib( $buttonTooltip ),
+                       // Messages used: accesskey-save, accesskey-publish
+                       'accessKey' => Linker::accesskey( $buttonTooltip ),
+               ] );
 
-               $previewConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                $buttons['preview'] = new OOUI\ButtonInputWidget( [
+                       'name' => 'wpPreview',
+                       'tabIndex' => ++$tabindex,
                        'id' => 'wpPreviewWidget',
                        'inputId' => 'wpPreview',
                        // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
@@ -4439,17 +4455,15 @@ class EditPage {
                        'label' => $this->context->msg( 'showpreview' )->text(),
                        'infusable' => true,
                        'type' => 'submit',
+                       // Message used: tooltip-preview
                        'title' => Linker::titleAttrib( 'preview' ),
+                       // Message used: accesskey-preview
                        'accessKey' => Linker::accesskey( 'preview' ),
-               ] + $previewConfig );
-
-               $attribs = [
-                       'name' => 'wpDiff',
-                       'tabindex' => ++$tabindex,
-               ];
+               ] );
 
-               $diffConfig = OOUI\Element::configFromHtmlAttributes( $attribs );
                $buttons['diff'] = new OOUI\ButtonInputWidget( [
+                       'name' => 'wpDiff',
+                       'tabIndex' => ++$tabindex,
                        'id' => 'wpDiffWidget',
                        'inputId' => 'wpDiff',
                        // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
@@ -4457,9 +4471,11 @@ class EditPage {
                        'label' => $this->context->msg( 'showdiff' )->text(),
                        'infusable' => true,
                        'type' => 'submit',
+                       // Message used: tooltip-diff
                        'title' => Linker::titleAttrib( 'diff' ),
+                       // Message used: accesskey-diff
                        'accessKey' => Linker::accesskey( 'diff' ),
-               ] + $diffConfig );
+               ] );
 
                // Avoid PHP 7.1 warning of passing $this by reference
                $editPage = $this;