X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FEditPage.php;h=3c109f63c19599dba4a83b4c64788ecc7189c65e;hb=bdf062a8e9f351d3b94f99f2cbe9f7176f0b8801;hp=3fc12ced8c64981dca2a62f1ebd6819ac6a7f400;hpb=f23ff352ac8b883e958d3a7f506f991571d18d88;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 3fc12ced8c..3c109f63c1 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\EditPage\TextboxBuilder; +use MediaWiki\EditPage\TextConflictHelper; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use Wikimedia\ScopedCallback; @@ -446,6 +448,18 @@ class EditPage { */ private $unicodeCheck; + /** + * Factory function to create an edit conflict helper + * + * @var callable + */ + private $editConflictHelperFactory; + + /** + * @var TextConflictHelper|null + */ + private $editConflictHelper; + /** * @param Article $article */ @@ -459,6 +473,7 @@ class EditPage { $handler = ContentHandler::getForModelID( $this->contentModel ); $this->contentFormat = $handler->getDefaultFormat(); + $this->editConflictHelperFactory = [ $this, 'newTextConflictHelper' ]; } /** @@ -1534,8 +1549,7 @@ class EditPage { return; } - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - $stats->increment( 'edit.failures.conflict.resolved' ); + $this->getEditConflictHelper()->incrementResolvedStats(); } /** @@ -2394,6 +2408,7 @@ class EditPage { $out->addModules( 'mediawiki.action.edit' ); $out->addModuleStyles( 'mediawiki.action.edit.styles' ); + $out->addModuleStyles( 'mediawiki.editfont.styles' ); $user = $this->context->getUser(); if ( $user->getOption( 'showtoolbar' ) ) { @@ -2818,6 +2833,20 @@ class EditPage { } $out->addHTML( $this->editFormTextBeforeContent ); + if ( $this->isConflict ) { + // In an edit conflict, we turn textbox2 into the user's text, + // and textbox1 into the stored version + $this->textbox2 = $this->textbox1; + + $content = $this->getCurrentContent(); + $this->textbox1 = $this->toEditText( $content ); + + $editConflictHelper = $this->getEditConflictHelper(); + $editConflictHelper->setTextboxes( $this->textbox2, $this->textbox1 ); + $editConflictHelper->setContentModel( $this->contentModel ); + $editConflictHelper->setContentFormat( $this->contentFormat ); + $out->addHTML( $editConflictHelper->getEditFormHtmlBeforeContent() ); + } if ( !$this->mTitle->isCssJsSubpage() && $showToolbar && $user->getOption( 'showtoolbar' ) ) { $out->addHTML( self::getEditToolbar( $this->mTitle ) ); @@ -2832,12 +2861,15 @@ 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->textbox2 = $this->textbox1; - - $content = $this->getCurrentContent(); - $this->textbox1 = $this->toEditText( $content ); + $conflictTextBoxAttribs = []; + if ( $this->wasDeletedSinceLastEdit() ) { + $conflictTextBoxAttribs['style'] = 'display:none;'; + } elseif ( $this->isOldRev ) { + $conflictTextBoxAttribs['class'] = 'mw-textarea-oldrev'; + } - $this->showTextbox1(); + $out->addHTML( $editConflictHelper->getEditConflictMainTextBox( $conflictTextBoxAttribs ) ); + $out->addHTML( $editConflictHelper->getEditFormHtmlAfterContent() ); } else { $this->showContentForm(); } @@ -3166,7 +3198,7 @@ class EditPage { */ function getSummaryInputOOUI( $summary = "", $labelText = null, $inputAttrs = null ) { wfDeprecated( __METHOD__, '1.30' ); - $this->getSummaryInputWidget( $summary, $labelText, $inputAttrs ); + return $this->getSummaryInputWidget( $summary, $labelText, $inputAttrs ); } /** @@ -3263,7 +3295,7 @@ class EditPage { protected function showFormBeforeText() { $out = $this->context->getOutput(); - $out->addHTML( Html::hidden( 'wpSection', htmlspecialchars( $this->section ) ) ); + $out->addHTML( Html::hidden( 'wpSection', $this->section ) ); $out->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) ); $out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) ); $out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) ); @@ -3314,22 +3346,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'; @@ -3341,12 +3360,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( @@ -3361,11 +3375,17 @@ class EditPage { } protected function showTextbox( $text, $name, $customAttribs = [] ) { - $wikitext = $this->addNewLineAtEnd( $text ); - - $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $this->context->getUser() ); + $builder = new TextboxBuilder(); + $attribs = $builder->buildTextboxAttribs( + $name, + $customAttribs, + $this->context->getUser(), + $this->mTitle + ); - $this->context->getOutput()->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); + $this->context->getOutput()->addHTML( + Html::textarea( $name, $builder->addNewLineAtEnd( $text ), $attribs ) + ); } protected function displayPreviewArea( $previewOutput, $isOnTop = false ) { @@ -3687,34 +3707,12 @@ class EditPage { if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$out ] ) ) { $this->incrementConflictStats(); - $out->wrapWikiMsg( '