X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2FEditPage.php;h=bcaab3a3d70e6bc69df5801f93d7bfb731971c68;hb=e74ba29aa6b86995a79200fc8b1bb2932d3a1675;hp=f49157f00de7e757369bd575fb12e3bcab36b363;hpb=911de590d5517d08ee00c33c980d35b9c6f501c0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index f49157f00d..bcaab3a3d7 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,8 @@ 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 ); - $this->showTextbox1(); + $out->addHTML( $editConflictHelper->getEditFormHtmlAfterContent() ); } else { $this->showContentForm(); } @@ -3166,7 +3191,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 +3288,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 ) ); @@ -3361,11 +3386,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 +3718,12 @@ class EditPage { if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$out ] ) ) { $this->incrementConflictStats(); - $out->wrapWikiMsg( '

$1

', "yourdiff" ); - - $content1 = $this->toEditContent( $this->textbox1 ); - $content2 = $this->toEditContent( $this->textbox2 ); - - $handler = ContentHandler::getForModelID( $this->contentModel ); - $de = $handler->createDifferenceEngine( $this->context ); - $de->setContent( $content2, $content1 ); - $de->showDiff( - $this->context->msg( 'yourtext' )->parse(), - $this->context->msg( 'storedversion' )->text() - ); - - $out->wrapWikiMsg( '

$1

', "yourtext" ); - $this->showTextbox2(); + $this->getEditConflictHelper()->showEditFormTextAfterFooters(); } } protected function incrementConflictStats() { - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - $stats->increment( 'edit.failures.conflict' ); - // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics - if ( - $this->mTitle->getNamespace() >= NS_MAIN && - $this->mTitle->getNamespace() <= NS_CATEGORY_TALK - ) { - $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() ); - } + $this->getEditConflictHelper()->incrementConflictStats(); } /** @@ -4003,7 +4012,10 @@ class EditPage { $parserOutput->setEditSectionTokens( false ); // no section edit links return [ 'parserOutput' => $parserOutput, - 'html' => $parserOutput->getText() ]; + 'html' => $parserOutput->getText( [ + 'enableSectionEditLinks' => false + ] ) + ]; } /** @@ -4639,9 +4651,8 @@ class EditPage { * @since 1.29 */ protected function addExplainConflictHeader( OutputPage $out ) { - $out->wrapWikiMsg( - "
\n$1\n
", - [ 'explainconflict', $this->context->msg( $this->getSubmitButtonLabel() )->text() ] + $out->addHTML( + $this->getEditConflictHelper()->getExplainHeader() ); } @@ -4653,38 +4664,9 @@ class EditPage { * @since 1.29 */ protected function buildTextboxAttribs( $name, array $customAttribs, User $user ) { - $attribs = $customAttribs + [ - 'accesskey' => ',', - 'id' => $name, - 'cols' => 80, - 'rows' => 25, - // Avoid PHP notices when appending preferences - // (appending allows customAttribs['style'] to still work). - 'style' => '' - ]; - - // The following classes can be used here: - // * mw-editfont-default - // * mw-editfont-monospace - // * mw-editfont-sans-serif - // * mw-editfont-serif - $class = 'mw-editfont-' . $user->getOption( 'editfont' ); - - if ( isset( $attribs['class'] ) ) { - if ( is_string( $attribs['class'] ) ) { - $attribs['class'] .= ' ' . $class; - } elseif ( is_array( $attribs['class'] ) ) { - $attribs['class'][] = $class; - } - } else { - $attribs['class'] = $class; - } - - $pageLang = $this->mTitle->getPageLanguage(); - $attribs['lang'] = $pageLang->getHtmlCode(); - $attribs['dir'] = $pageLang->getDir(); - - return $attribs; + return ( new TextboxBuilder() )->buildTextboxAttribs( + $name, $customAttribs, $user, $this->mTitle + ); } /** @@ -4693,15 +4675,7 @@ class EditPage { * @since 1.29 */ protected function addNewLineAtEnd( $wikitext ) { - if ( strval( $wikitext ) !== '' ) { - // Ensure there's a newline at the end, otherwise adding lines - // is awkward. - // But don't add a newline if the text is empty, or Firefox in XHTML - // mode will show an extra newline. A bit annoying. - $wikitext .= "\n"; - return $wikitext; - } - return $wikitext; + return ( new TextboxBuilder() )->addNewLineAtEnd( $wikitext ); } /** @@ -4726,4 +4700,42 @@ class EditPage { // Meanwhile, real browsers get real anchors return $wgParser->guessSectionNameFromWikiText( $text ); } + + /** + * Set a factory function to create an EditConflictHelper + * + * @param callable $factory Factory function + * @since 1.31 + */ + public function setEditConflictHelperFactory( callable $factory ) { + $this->editConflictHelperFactory = $factory; + $this->editConflictHelper = null; + } + + /** + * @return TextConflictHelper + */ + private function getEditConflictHelper() { + if ( !$this->editConflictHelper ) { + $this->editConflictHelper = call_user_func( + $this->editConflictHelperFactory, + $this->getSubmitButtonLabel() + ); + } + + return $this->editConflictHelper; + } + + /** + * @param string $submitButtonLabel + * @return TextConflictHelper + */ + private function newTextConflictHelper( $submitButtonLabel ) { + return new TextConflictHelper( + $this->getTitle(), + $this->getContext()->getOutput(), + MediaWikiServices::getInstance()->getStatsdDataFactory(), + $submitButtonLabel + ); + } }