X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=34062c062170b73a65da26b21bf7d1e92df8d3cd;hb=63c1c841d88f4dc572ceded8b48bd44937713ec6;hp=05fa366ebafb5286b2385bd0e2b446995eb2431c;hpb=93222688610be9735eb53aef30683e1c231b2833;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 05fa366eba..34062c0621 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -498,7 +498,10 @@ class EditPage { $this->enableApiEditOverride = $enableOverride; } - function submit() { + /** + * @deprecated since 1.29, call edit directly + */ + public function submit() { $this->edit(); } @@ -513,7 +516,7 @@ class EditPage { * is made and all is well do we actually save and redirect to * the newly-edited page. */ - function edit() { + public function edit() { global $wgOut, $wgRequest, $wgUser; // Allow extensions to modify/prevent this form or submission if ( !Hooks::run( 'AlternateEdit', [ $this ] ) ) { @@ -837,7 +840,7 @@ class EditPage { * @param WebRequest $request * @throws ErrorPageError */ - function importFormData( &$request ) { + public function importFormData( &$request ) { global $wgContLang, $wgUser; # Section edit can come from either the form or a link @@ -1068,7 +1071,7 @@ class EditPage { * Called on the first invocation, e.g. when a user clicks an edit link * @return bool If the requested section is valid */ - function initialiseForm() { + public function initialiseForm() { global $wgUser; $this->edittime = $this->page->getTimestamp(); $this->editRevId = $this->page->getLatest(); @@ -1420,7 +1423,7 @@ class EditPage { * @return bool * @private */ - function tokenOk( &$request ) { + public function tokenOk( &$request ) { global $wgUser; $token = $request->getVal( 'wpEditToken' ); $this->mTokenOk = $wgUser->matchEditToken( $token ); @@ -1621,15 +1624,7 @@ class EditPage { */ protected function runPostMergeFilters( Content $content, Status $status, User $user ) { // Run old style post-section-merge edit filter - if ( !ContentHandler::runLegacyHooks( 'EditFilterMerged', - [ $this, $content, &$this->hookError, $this->summary ], - '1.21' - ) ) { - # Error messages etc. could be handled within the hook... - $status->fatal( 'hookaborted' ); - $status->value = self::AS_HOOK_ERROR; - return false; - } elseif ( $this->hookError != '' ) { + if ( $this->hookError != '' ) { # ...or the hook could be expecting us to produce an error $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR_EXPECTED; @@ -1722,7 +1717,7 @@ class EditPage { * AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some * time. */ - function internalAttemptSave( &$result, $bot = false ) { + public function internalAttemptSave( &$result, $bot = false ) { global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize; global $wgContentHandlerUseDB; @@ -2278,7 +2273,7 @@ class EditPage { * one might think of X as the "base revision", which is NOT what this returns. * @return Revision Current version when the edit was started */ - function getBaseRevision() { + public function getBaseRevision() { if ( !$this->mBaseRevision ) { $db = wfGetDB( DB_MASTER ); $this->mBaseRevision = $this->editRevId @@ -2330,7 +2325,7 @@ class EditPage { return false; } - function setHeaders() { + public function setHeaders() { global $wgOut, $wgUser, $wgAjaxEditStash, $wgCookieSetOnAutoblock; $wgOut->addModules( 'mediawiki.action.edit' ); @@ -2590,7 +2585,7 @@ class EditPage { * The $formCallback parameter is deprecated since MediaWiki 1.25. Please * use the EditPage::showEditForm:fields hook instead. */ - function showEditForm( $formCallback = null ) { + public function showEditForm( $formCallback = null ) { global $wgOut, $wgUser; # need to parse the preview early so that we know which templates are used, @@ -3032,7 +3027,7 @@ class EditPage { * * @return array An array in the format [ $label, $input ] */ - function getSummaryInput( $summary = "", $labelText = null, + public function getSummaryInput( $summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null ) { // Note: the maxlength is overridden in JS to 255 and to make it use UTF-8 bytes, not characters. @@ -3287,14 +3282,14 @@ HTML */ protected function showPreview( $text ) { global $wgOut; - if ( $this->mTitle->getNamespace() == NS_CATEGORY ) { + if ( $this->mArticle instanceof CategoryPage ) { $this->mArticle->openShowCategory(); } # This hook seems slightly odd here, but makes things more # consistent for extensions. Hooks::run( 'OutputPageBeforeHTML', [ &$wgOut, &$text ] ); $wgOut->addHTML( $text ); - if ( $this->mTitle->getNamespace() == NS_CATEGORY ) { + if ( $this->mArticle instanceof CategoryPage ) { $this->mArticle->closeShowCategory(); } } @@ -3306,7 +3301,7 @@ HTML * If this is a section edit, we'll replace the section as for final * save and then make a comparison. */ - function showDiff() { + public function showDiff() { global $wgUser, $wgContLang, $wgOut; $oldtitlemsg = 'currentrev'; @@ -3548,15 +3543,7 @@ HTML // Avoid PHP 7.1 warning of passing $this by reference $editPage = $this; if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$wgOut ] ) ) { - $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->incrementConflictStats(); $wgOut->wrapWikiMsg( '

$1

', "yourdiff" ); @@ -3576,11 +3563,24 @@ HTML } } + private 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() ); + } + } + /** * @return string */ public function getCancelLink() { $cancelParams = []; + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); if ( !$this->isConflict && $this->oldid > 0 ) { $cancelParams['oldid'] = $this->oldid; } elseif ( $this->getContextTitle()->isRedirect() ) { @@ -3588,9 +3588,9 @@ HTML } $attrs = [ 'id' => 'mw-editform-cancel' ]; - return Linker::linkKnown( + return $linkRenderer->makeKnownLink( $this->getContextTitle(), - $this->context->msg( 'cancel' )->parse(), + new HtmlArmor( $this->context->msg( 'cancel' )->parse() ), Html::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ), $cancelParams ); @@ -3683,12 +3683,10 @@ HTML * @throws MWException * @return string */ - function getPreviewText() { + public function getPreviewText() { global $wgOut, $wgRawHtml, $wgLang; global $wgAllowUserCss, $wgAllowUserJs; - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - if ( $wgRawHtml && !$this->mTokenOk ) { // Could be an offsite preview attempt. This is very unsafe if // HTML is enabled, as it could be an attack. @@ -3701,7 +3699,7 @@ HTML $this->context->msg( 'session_fail_preview_html' )->text() . "", true, /* interface */true ); } - $stats->increment( 'edit.failures.session_loss' ); + $this->incrementEditFailureStats( 'session_loss' ); return $parsedNote; } @@ -3725,15 +3723,15 @@ HTML if ( $this->mTriedSave && !$this->mTokenOk ) { if ( $this->mTokenOkExceptSuffix ) { $note = $this->context->msg( 'token_suffix_mismatch' )->plain(); - $stats->increment( 'edit.failures.bad_token' ); + $this->incrementEditFailureStats( 'bad_token' ); } else { $note = $this->context->msg( 'session_fail_preview' )->plain(); - $stats->increment( 'edit.failures.session_loss' ); + $this->incrementEditFailureStats( 'session_loss' ); } } elseif ( $this->incompleteForm ) { $note = $this->context->msg( 'edit_form_incomplete' )->plain(); if ( $this->mTriedSave ) { - $stats->increment( 'edit.failures.incomplete_form' ); + $this->incrementEditFailureStats( 'incomplete_form' ); } } else { $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing; @@ -3779,7 +3777,6 @@ HTML } $hook_args = [ $this, &$content ]; - ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args, '1.25' ); Hooks::run( 'EditPageGetPreviewContent', $hook_args ); $parserResult = $this->doPreviewParse( $content ); @@ -3822,6 +3819,11 @@ HTML return $previewhead . $previewHTML . $this->previewTextAfterContent; } + private function incrementEditFailureStats( $failureType ) { + $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); + $stats->increment( 'edit.failures.' . $failureType ); + } + /** * Get parser options for a preview * @return ParserOptions @@ -3860,7 +3862,7 @@ HTML /** * @return array */ - function getTemplates() { + public function getTemplates() { if ( $this->preview || $this->section != '' ) { $templates = []; if ( !isset( $this->mParserOutput ) ) { @@ -3884,7 +3886,7 @@ HTML * @param Title $title Title object for the page being edited (optional) * @return string */ - static function getEditToolbar( $title = null ) { + public static function getEditToolbar( $title = null ) { global $wgContLang, $wgOut; global $wgEnableUploads, $wgForeignFileRepos; @@ -4137,7 +4139,7 @@ HTML * Creates a basic error page which informs the user that * they have attempted to edit a nonexistent section. */ - function noSuchSectionPage() { + public function noSuchSectionPage() { global $wgOut; $wgOut->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );