X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=745f8deb6ee3ffcb3a5994f74c8903807ff462a3;hb=68a8243d4910e140b0f1f06e4e93b3504cf9b723;hp=0f27e78987b4683bfc1234ab30f29379a7ad6e70;hpb=dba5cd4c7f0e098b3ad8ce1e39a0a506ccdfb746;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 0f27e78987..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 ] ); - } /** @@ -2237,7 +2236,6 @@ class EditPage { * @return bool */ private function mergeChangesIntoContent( &$editContent ) { - $db = wfGetDB( DB_MASTER ); // This is the revision the editor started from @@ -2328,9 +2326,12 @@ class EditPage { } 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' ) ) { @@ -2600,10 +2601,21 @@ class EditPage { $this->setHeaders(); - if ( $this->showHeader() === false ) { + $this->addTalkPageText(); + $this->addEditNotices(); + + if ( !$this->isConflict && + $this->section != '' && + !$this->isSectionEditSupported() ) { + // We use $this->section to much before this and getVal('wgSection') directly in other places + // at this point we can't reset $this->section to '' to fallback to non-section editing. + // Someone is welcome to try refactoring though + $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' ); return; } + $this->showHeader(); + $wgOut->addHTML( $this->editFormPageTop ); if ( $wgUser->getOption( 'previewontop' ) ) { @@ -2813,7 +2825,6 @@ class EditPage { if ( !$wgUser->getOption( 'previewontop' ) ) { $this->displayPreviewArea( $previewOutput, false ); } - } /** @@ -2839,7 +2850,6 @@ class EditPage { return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ], $templateListFormatter->format( $templates, $type ) ); - } /** @@ -2858,29 +2868,14 @@ class EditPage { } } - /** - * @return bool - */ protected function showHeader() { - global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang; + global $wgOut, $wgUser; global $wgAllowUserCss, $wgAllowUserJs; - $this->addTalkPageText(); - - $this->addEditNotices(); - if ( $this->isConflict ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", 'explainconflict' ); + $this->addExplainConflictHeader( $wgOut ); $this->editRevId = $this->page->getLatest(); } else { - if ( $this->section != '' && !$this->isSectionEditSupported() ) { - // We use $this->section to much before this and getVal('wgSection') directly in other places - // at this point we can't reset $this->section to '' to fallback to non-section editing. - // Someone is welcome to try refactoring though - $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' ); - return false; - } - if ( $this->section != '' && $this->section != 'new' ) { if ( !$this->summary && !$this->preview && !$this->diff ) { $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object @@ -3006,69 +3001,12 @@ class EditPage { } } - if ( $this->mTitle->isProtected( 'edit' ) && - MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ] - ) { - # Is the title semi-protected? - if ( $this->mTitle->isSemiProtected() ) { - $noticeMsg = 'semiprotectedpagewarning'; - } else { - # Then it must be protected based on static groups (regular) - $noticeMsg = 'protectedpagewarning'; - } - LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '', - [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] ); - } - if ( $this->mTitle->isCascadeProtected() ) { - # Is this page under cascading protection from some source pages? - /** @var Title[] $cascadeSources */ - list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources(); - $notice = "
\n$1\n"; - $cascadeSourcesCount = count( $cascadeSources ); - if ( $cascadeSourcesCount > 0 ) { - # Explain, and list the titles responsible - foreach ( $cascadeSources as $page ) { - $notice .= '* [[:' . $page->getPrefixedText() . "]]\n"; - } - } - $notice .= '
'; - $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] ); - } - if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) { - LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '', - [ 'lim' => 1, - 'showIfEmpty' => false, - 'msgKey' => [ 'titleprotectedwarning' ], - 'wrap' => "
\n$1
" ] ); - } + $this->addPageProtectionWarningHeaders(); - if ( $this->contentLength === false ) { - $this->contentLength = strlen( $this->textbox1 ); - } + $this->addLongPageWarningHeader(); - if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", - [ - 'longpageerror', - $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ), - $wgLang->formatNum( $wgMaxArticleSize ) - ] - ); - } else { - if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", - [ - 'longpage-hint', - $wgLang->formatSize( strlen( $this->textbox1 ) ), - strlen( $this->textbox1 ) - ] - ); - } - } # Add header copyright warning $this->showHeaderCopyrightWarning(); - - return true; } /** @@ -3283,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"; - } + $wikitext = $this->addNewLineAtEnd( $wikitext ); - $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; - } - - $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 ) ); } @@ -3507,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 ) { @@ -3554,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() ) . @@ -3640,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 ( @@ -3779,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 @@ -4173,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 * @@ -4207,7 +4105,6 @@ HTML ] + Linker::tooltipAndAccesskeyAttribs( 'preview' ); $buttons['preview'] = Html::submitButton( $this->context->msg( 'showpreview' )->text(), $attribs ); - $buttons['live'] = ''; $attribs = [ 'id' => 'wpDiff', @@ -4401,6 +4298,9 @@ HTML return strtr( $result, [ "�" => "&#x" ] ); } + /** + * @since 1.29 + */ protected function addEditNotices() { global $wgOut; @@ -4419,6 +4319,9 @@ HTML } } + /** + * @since 1.29 + */ protected function addTalkPageText() { global $wgOut; @@ -4426,4 +4329,145 @@ HTML $wgOut->addWikiMsg( 'talkpagetext' ); } } + + /** + * @since 1.29 + */ + protected function addLongPageWarningHeader() { + global $wgMaxArticleSize, $wgOut, $wgLang; + + if ( $this->contentLength === false ) { + $this->contentLength = strlen( $this->textbox1 ); + } + + if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) { + $wgOut->wrapWikiMsg( "
\n$1\n
", + [ + 'longpageerror', + $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ), + $wgLang->formatNum( $wgMaxArticleSize ) + ] + ); + } else { + if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) { + $wgOut->wrapWikiMsg( "
\n$1\n
", + [ + 'longpage-hint', + $wgLang->formatSize( strlen( $this->textbox1 ) ), + strlen( $this->textbox1 ) + ] + ); + } + } + } + + /** + * @since 1.29 + */ + protected function addPageProtectionWarningHeaders() { + global $wgOut; + + if ( $this->mTitle->isProtected( 'edit' ) && + MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ] + ) { + # Is the title semi-protected? + if ( $this->mTitle->isSemiProtected() ) { + $noticeMsg = 'semiprotectedpagewarning'; + } else { + # Then it must be protected based on static groups (regular) + $noticeMsg = 'protectedpagewarning'; + } + LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '', + [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] ); + } + if ( $this->mTitle->isCascadeProtected() ) { + # Is this page under cascading protection from some source pages? + /** @var Title[] $cascadeSources */ + list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources(); + $notice = "
\n$1\n"; + $cascadeSourcesCount = count( $cascadeSources ); + if ( $cascadeSourcesCount > 0 ) { + # Explain, and list the titles responsible + foreach ( $cascadeSources as $page ) { + $notice .= '* [[:' . $page->getPrefixedText() . "]]\n"; + } + } + $notice .= '
'; + $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] ); + } + if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) { + LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '', + [ 'lim' => 1, + 'showIfEmpty' => false, + 'msgKey' => [ 'titleprotectedwarning' ], + '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; + } }