WMDE-Fisch has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395743 )
Change subject: Moved textbox1 building into TextConflictHelper on edit conflicts ...................................................................... Moved textbox1 building into TextConflictHelper on edit conflicts Factored out some minor parts about building editor CSS classes. getEditConflictMainTextBox() mainly mirrors showTextbox1 parts not included were moved to the EditPage. Change-Id: I671e095acc08382dd0a1c3d167fdaaa623ec5499 --- M includes/EditPage.php M includes/editpage/TextConflictHelper.php M includes/editpage/TextboxBuilder.php 3 files changed, 86 insertions(+), 23 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/43/395743/1 diff --git a/includes/EditPage.php b/includes/EditPage.php index bcaab3a..3c109f6 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2861,7 +2861,14 @@ // 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 +3346,9 @@ 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 +3360,7 @@ $attribs += $customAttribs; } - if ( count( $classes ) ) { - if ( isset( $attribs['class'] ) ) { - $classes[] = $attribs['class']; - } - $attribs['class'] = implode( ' ', $classes ); - } + $attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs ); } $this->showTextbox( diff --git a/includes/editpage/TextConflictHelper.php b/includes/editpage/TextConflictHelper.php index b1eaa4b..1892e27 100644 --- a/includes/editpage/TextConflictHelper.php +++ b/includes/editpage/TextConflictHelper.php @@ -154,6 +154,36 @@ } /** + * HTML to build the textbox1 on edit conflicts + * + * @param mixed[]|null $customAttribs + * @return string HTML + */ + public function getEditConflictMainTextBox( $customAttribs = null ) { + $builder = new TextboxBuilder(); + $classes = $builder->getTextboxProtectionCSSClasses( $this->title ); + + $attribs = [ 'tabindex' => 1 ]; + + if ( is_array( $customAttribs ) ) { + $attribs += $customAttribs; + } + + $attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs ); + + $attribs = $builder->buildTextboxAttribs( + 'wpTextbox1', + $attribs, + $this->out->getUser(), + $this->title + ); + + $this->out->addHTML( + Html::textarea( 'wpTextbox1', $builder->addNewLineAtEnd( $this->storedversion ), $attribs ) + ); + } + + /** * Content to go in the edit form before textbox1 * * @see EditPage::$editFormTextBeforeContent diff --git a/includes/editpage/TextboxBuilder.php b/includes/editpage/TextboxBuilder.php index a6ae9bc..f46e707 100644 --- a/includes/editpage/TextboxBuilder.php +++ b/includes/editpage/TextboxBuilder.php @@ -24,6 +24,7 @@ namespace MediaWiki\EditPage; +use MWNamespace; use Title; use User; @@ -51,6 +52,49 @@ } /** + * @param string[] $classes + * @param mixed[] $attribs + * @return mixed[] + */ + public function mergeClassesIntoAttributes( array $classes, array $attribs ) { + if ( !count( $classes ) ) { + return $attribs; + } + + if ( isset( $attribs['class'] ) ) { + $classes[] = $attribs['class']; + } + $attribs['class'] = implode( ' ', $classes ); + + return $attribs; + } + + /** + * @param Title $title + * @return string[] + */ + public function getTextboxProtectionCSSClasses( Title $title ) { + $classes = []; // Textarea CSS + if ( $title->isProtected( 'edit' ) && + MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ] + ) { + # Is the title semi-protected? + if ( $$title->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 ( $title->isCascadeProtected() ) { + $classes[] = 'mw-textarea-cprotected'; + } + } + + return $classes; + } + + /** * @param string $name * @param mixed[] $customAttribs * @param User $user -- To view, visit https://gerrit.wikimedia.org/r/395743 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I671e095acc08382dd0a1c3d167fdaaa623ec5499 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: WMDE-Fisch <christoph.jau...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits