X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=745f8deb6ee3ffcb3a5994f74c8903807ff462a3;hb=68a8243d4910e140b0f1f06e4e93b3504cf9b723;hp=cd6fb562bb4af24a6ded9ce064a0f5975d4dd78b;hpb=bcc28e8b772066c56a339448b86cb549c772d259;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index cd6fb562bb..745f8deb6e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1044,7 +1044,6 @@ class EditPage { // Allow extensions to modify form data Hooks::run( 'EditPage::importFormData', [ $this, $request ] ); - } /** @@ -1646,7 +1645,7 @@ class EditPage { // being set. This is used by ConfirmEdit to display a captcha // without any error message cruft. } else { - $this->hookError = $this->formatStatusErrors( $status ); + $this->hookError = $status->getWikiText(); } // Use the existing $status->value if the hook set it if ( !$status->value ) { @@ -1656,7 +1655,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 = $this->formatStatusErrors( $status ); + $this->hookError = $status->getWikiText(); $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR_EXPECTED; return false; @@ -1665,26 +1664,6 @@ class EditPage { return true; } - /** - * Wrap status errors in an errorbox for increased visiblity - * - * @param Status $status - * @return string - */ - private function formatStatusErrors( Status $status ) { - $errmsg = $status->getHTML( - 'edit-error-short', - 'edit-error-long', - $this->context->getLanguage() - ); - return << -{$errmsg} - -
-ERROR; - } - /** * Return the summary to be used for a new section. * @@ -2257,7 +2236,6 @@ ERROR; * @return bool */ private function mergeChangesIntoContent( &$editContent ) { - $db = wfGetDB( DB_MASTER ); // This is the revision the editor started from @@ -2348,9 +2326,12 @@ ERROR; } function setHeaders() { - global $wgOut, $wgUser, $wgAjaxEditStash; + global $wgOut, $wgUser, $wgAjaxEditStash, $wgCookieSetOnAutoblock; $wgOut->addModules( 'mediawiki.action.edit' ); + if ( $wgCookieSetOnAutoblock === true ) { + $wgOut->addModules( 'mediawiki.user.blockcookie' ); + } $wgOut->addModuleStyles( 'mediawiki.action.edit.styles' ); if ( $wgUser->getOption( 'showtoolbar' ) ) { @@ -2844,7 +2825,6 @@ ERROR; if ( !$wgUser->getOption( 'previewontop' ) ) { $this->displayPreviewArea( $previewOutput, false ); } - } /** @@ -2870,7 +2850,6 @@ ERROR; return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ], $templateListFormatter->format( $templates, $type ) ); - } /** @@ -2890,10 +2869,11 @@ ERROR; } protected function showHeader() { + global $wgOut, $wgUser; global $wgAllowUserCss, $wgAllowUserJs; if ( $this->isConflict ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", 'explainconflict' ); + $this->addExplainConflictHeader( $wgOut ); $this->editRevId = $this->page->getLatest(); } else { if ( $this->section != '' && $this->section != 'new' ) { @@ -3241,44 +3221,9 @@ HTML global $wgOut, $wgUser; $wikitext = $this->safeUnicodeOutput( $text ); - if ( strval( $wikitext ) !== '' ) { - // Ensure there's a newline at the end, otherwise adding lines - // is awkward. - // But don't add a newline if the ext is empty, or Firefox in XHTML - // mode will show an extra newline. A bit annoying. - $wikitext .= "\n"; - } - - $attribs = $customAttribs + [ - 'accesskey' => ',', - 'id' => $name, - 'cols' => $wgUser->getIntOption( 'cols' ), - 'rows' => $wgUser->getIntOption( 'rows' ), - // 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-' . $wgUser->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; - } + $wikitext = $this->addNewLineAtEnd( $wikitext ); - $pageLang = $this->mTitle->getPageLanguage(); - $attribs['lang'] = $pageLang->getHtmlCode(); - $attribs['dir'] = $pageLang->getDir(); + $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $wgUser ); $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); } @@ -3465,6 +3410,7 @@ HTML * * @param Title $title * @param string $format Output format, valid values are any function of a Message object + * @param Language|string|null $langcode Language code or Language object. * @return string */ public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) { @@ -3512,22 +3458,16 @@ HTML ] ) . Html::openElement( 'tbody' ); - foreach ( $output->getLimitReportData()['limitreport'] as $key => $value ) { + foreach ( $output->getLimitReportData() as $key => $value ) { if ( Hooks::run( 'ParserLimitReportFormat', [ $key, &$value, &$limitReport, true, true ] ) ) { - $keyMsg = wfMessage( "limitreport-$key" ); - $valueMsg = wfMessage( - [ "limitreport-$key-value-html", "limitreport-$key-value" ] - ); + $keyMsg = wfMessage( $key ); + $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] ); if ( !$valueMsg->exists() ) { $valueMsg = new RawMessage( '$1' ); } if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) { - // If it's a value/limit array, convert it for $1/$2 - if ( is_array( $value ) && isset( $value['value'] ) ) { - $value = [ $value['value'], $value['limit'] ]; - } $limitReport .= Html::openElement( 'tr' ) . Html::rawElement( 'th', null, $keyMsg->parse() ) . Html::rawElement( 'td', null, $valueMsg->params( $value )->parse() ) . @@ -3598,7 +3538,7 @@ HTML global $wgOut; if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$this, &$wgOut ] ) ) { - $stats = $wgOut->getContext()->getStats(); + $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); $stats->increment( 'edit.failures.conflict' ); // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics if ( @@ -3737,7 +3677,7 @@ HTML global $wgOut, $wgRawHtml, $wgLang; global $wgAllowUserCss, $wgAllowUserJs; - $stats = $wgOut->getContext()->getStats(); + $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); if ( $wgRawHtml && !$this->mTokenOk ) { // Could be an offsite preview attempt. This is very unsafe if @@ -4131,7 +4071,7 @@ HTML /** * Returns an array of html code of the following buttons: - * save, diff, preview and live + * save, diff and preview * * @param int $tabindex Current tabindex * @@ -4165,7 +4105,6 @@ HTML ] + Linker::tooltipAndAccesskeyAttribs( 'preview' ); $buttons['preview'] = Html::submitButton( $this->context->msg( 'showpreview' )->text(), $attribs ); - $buttons['live'] = ''; $attribs = [ 'id' => 'wpDiff', @@ -4359,6 +4298,9 @@ HTML return strtr( $result, [ "�" => "&#x" ] ); } + /** + * @since 1.29 + */ protected function addEditNotices() { global $wgOut; @@ -4377,6 +4319,9 @@ HTML } } + /** + * @since 1.29 + */ protected function addTalkPageText() { global $wgOut; @@ -4458,4 +4403,71 @@ HTML 'wrap' => "
\n$1
" ] ); } } + + /** + * @param OutputPage $out + * @since 1.29 + */ + protected function addExplainConflictHeader( OutputPage $out ) { + $out->wrapWikiMsg( "
\n$1\n
", 'explainconflict' ); + } + + /** + * @param string $name + * @param mixed[] $customAttribs + * @param User $user + * @return mixed[] + * @since 1.29 + */ + protected function buildTextboxAttribs( $name, array $customAttribs, User $user ) { + $attribs = $customAttribs + [ + 'accesskey' => ',', + 'id' => $name, + 'cols' => $user->getIntOption( 'cols' ), + 'rows' => $user->getIntOption( 'rows' ), + // 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; + } + + /** + * @param string $wikitext + * @return string + * @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; + } }