Merge "Stop computing removed variables and show custom error message"

This commit is contained in:
jenkins-bot 2018-06-27 00:20:38 +00:00 committed by Gerrit Code Review
commit 8b0f289e10
5 changed files with 19 additions and 14 deletions

View file

@ -327,7 +327,7 @@
"abusefilter-edit-builder-vars-all-links": "All external links in the new text",
"abusefilter-edit-builder-vars-added-links": "All external links added in the edit",
"abusefilter-edit-builder-vars-removed-links": "All external links removed in the edit",
"abusefilter-edit-builder-vars-old-text": "Old page wikitext, before the edit",
"abusefilter-edit-builder-vars-old-text": "Old page wikitext, before the edit (no more in use)",
"abusefilter-edit-builder-vars-new-text": "New page wikitext, after the edit",
"abusefilter-edit-builder-vars-new-pst": "New page wikitext, pre-save transformed",
"abusefilter-edit-builder-vars-diff-pst": "Unified diff of changes made by edit, pre-save transformed",
@ -348,7 +348,7 @@
"abusefilter-edit-builder-vars-movedto-restrictions-upload": "Upload protection of move destination file",
"abusefilter-edit-builder-vars-old-text-stripped": "Old page text, stripped of any markup",
"abusefilter-edit-builder-vars-old-links": "Links in the page, before the edit",
"abusefilter-edit-builder-vars-old-html": "Old page wikitext, parsed into HTML",
"abusefilter-edit-builder-vars-old-html": "Old page wikitext, parsed into HTML (no more in use)",
"abusefilter-edit-builder-vars-minor-edit": "Whether or not the edit is marked as minor",
"abusefilter-edit-builder-vars-file-sha1": "SHA1 hash of file contents",
"abusefilter-edit-builder-vars-file-size": "Size of the file in bytes",
@ -397,6 +397,7 @@
"abusefilter-exception-notarray": "Requesting array item of non-array at character $1.",
"abusefilter-exception-unclosedcomment": "Unclosed comment at character $1.",
"abusefilter-exception-invalidiprange": "Invalid IP range \"$2\" provided at character $1.",
"abusefilter-exception-disabledvar": "Variable $2 at character $1 is no more in use.",
"abusefilter-action-tag": "Tag",
"abusefilter-action-throttle": "Throttle",
"abusefilter-action-warn": "Warn",

View file

@ -430,6 +430,7 @@
"abusefilter-exception-notarray": "Error message from the abuse filter parser. Parameters:\n* $1 - Position in the string",
"abusefilter-exception-unclosedcomment": "Error message from the abuse filter parser. Parameters:\n* $1 - Position in the string",
"abusefilter-exception-invalidiprange": "Error message from the abuse filter parser. Parameters:\n* $1 - Position in the string\n* $2 - String provided as an argument to a function",
"abusefilter-exception-disabledvar": "Error message from the abuse filter parser. Parameters:\n* $1 - Position in the string\n* $2 - Name of the disabled variable",
"abusefilter-action-tag": "{{doc-abusefilter-action}}\n\nThe edit or change can be 'tagged' with a particular tag, which will be shown on Recent Changes, contributions, logs, new pages, history, and everywhere else. \n\nThis is a verb in the imperative form.\n\n{{Identical|Tag}}",
"abusefilter-action-throttle": "{{doc-abusefilter-action}}",
"abusefilter-action-warn": "{{doc-abusefilter-action}}",

View file

@ -157,8 +157,6 @@ class AbuseFilter {
'moved_to_restrictions_upload' => 'movedto-restrictions-upload',
'moved_to_recent_contributors' => 'movedto-recent-contributors',
'moved_to_first_contributor' => 'movedto-first-contributor',
// 'old_text' => 'old-text-stripped', // Disabled, performance
// 'old_html' => 'old-html', // Disabled, performance
'old_links' => 'old-links',
'minor_edit' => 'minor-edit',
'file_sha1' => 'file-sha1',
@ -171,6 +169,12 @@ class AbuseFilter {
],
];
/** @var array Old vars which aren't in use anymore */
public static $disabledVars = [
'old_text' => 'old-text-stripped',
'old_html' => 'old-html'
];
public static $editboxName = null;
/**
@ -2382,8 +2386,6 @@ class AbuseFilter {
[ 'oldlink-var' => 'old_links', 'newlink-var' => 'all_links' ] );
$vars->setLazyLoadVar( 'new_text', 'strip-html',
[ 'html-var' => 'new_html' ] );
$vars->setLazyLoadVar( 'old_text', 'strip-html',
[ 'html-var' => 'old_html' ] );
if ( $title instanceof Title ) {
$vars->setLazyLoadVar( 'all_links', 'links-from-wikitext',
@ -2414,12 +2416,6 @@ class AbuseFilter {
'wikitext-var' => 'new_wikitext',
'article' => $page
] );
$vars->setLazyLoadVar( 'old_html', 'parse-wikitext-nonedit',
[
'namespace' => $title->getNamespace(),
'title' => $title->getText(),
'wikitext-var' => 'old_wikitext'
] );
}
return $vars;
@ -2468,6 +2464,10 @@ class AbuseFilter {
$mapping = $variableMessageMappings[$key];
$keyDisplay = $context->msg( "abusefilter-edit-builder-vars-$mapping" )->parse() .
' ' . Xml::element( 'code', null, $context->msg( 'parentheses' )->rawParams( $key )->text() );
} elseif ( !empty( self::$disabledVars[$key] ) ) {
$mapping = self::$disabledVars[$key];
$keyDisplay = $context->msg( "abusefilter-edit-builder-vars-$mapping" )->parse() .
' ' . Xml::element( 'code', null, $context->msg( 'parentheses' )->rawParams( $key )->text() );
} else {
$keyDisplay = Xml::element( 'code', null, $key );
}

View file

@ -38,7 +38,7 @@ class AFPUserVisibleException extends AFPException {
// abusefilter-exception-notenoughargs, abusefilter-exception-regexfailure
// abusefilter-exception-overridebuiltin, abusefilter-exception-outofbounds
// abusefilter-exception-notarray, abusefilter-exception-unclosedcomment
// abusefilter-exception-invalidiprange
// abusefilter-exception-invalidiprange, abusefilter-exception-disabledvar
return wfMessage(
'abusefilter-exception-' . $this->mExceptionID,
$this->mPosition, ...$this->mParams

View file

@ -833,9 +833,12 @@ class AbuseFilterParser {
if ( !( array_key_exists( $var, $builderValues['vars'] )
|| $this->mVars->varIsSet( $var ) )
) {
$msg = array_key_exists( $var, AbuseFilter::$disabledVars ) ?
'disabledvar' :
'unrecognisedvar';
// If the variable is invalid, throw an exception
throw new AFPUserVisibleException(
'unrecognisedvar',
$msg,
$this->mCur->pos,
[ $var ]
);