2018-11-29 17:10:39 +00:00
|
|
|
mw.libs.ve.targetLoader.addPlugin( function () {
|
|
|
|
|
|
|
|
ve.init.mw.SpamBlacklistSaveErrorHandler = function () {};
|
|
|
|
|
|
|
|
OO.inheritClass( ve.init.mw.SpamBlacklistSaveErrorHandler, ve.init.mw.SaveErrorHandler );
|
|
|
|
|
|
|
|
ve.init.mw.SpamBlacklistSaveErrorHandler.static.name = 'spamBlacklist';
|
|
|
|
|
2018-12-07 19:17:55 +00:00
|
|
|
ve.init.mw.SpamBlacklistSaveErrorHandler.static.matchFunction = function ( data ) {
|
Actually return errors for action=edit API
Setting 'apiHookResult' results in a "successful" response; if we want
to report an error, we need to use ApiMessage. We already were doing
this for action=upload. Now our action=edit API responses will be
consistent with MediaWiki and other extensions, and will be able to
take advantage of errorformat=html.
Additionally, remove incorrect 'message' value from action=upload
output. It was anyway redundant to the normal error information.
To avoid user interface regressions in VisualEditor, the changes
I3b9c4fef (in VE) and I106dbd3c (in MediaWiki) should be merged first.
Before:
{
"edit": {
"spamblacklist": "example.com/test|example.net/test",
"result": "Failure"
}
}
After:
{
"errors": [
{
"code": "spamblacklist",
"data": {
"spamblacklist": {
"matches": [
"example.com/test",
"example.net/test"
]
}
},
"module": "edit",
"*": "The text you wanted to save was blocked ..."
}
],
"*": "See http://localhost:3080/w/api.php for API usage. ..."
}
For comparison, a 'readonly' error:
{
"errors": [
{
"code": "readonly",
"data": {
"readonlyreason": "foo bar"
},
"module": "main",
"*": "The wiki is currently in read-only mode."
}
],
"*": "See http://localhost:3080/w/api.php for API usage. ..."
}
Bug: T229539
Depends-On: I106dbd3cbdbf7082b1d1f1c1106ece6b19c22a86
Depends-On: I3b9c4fefc0869ef7999c21cef754434febd852ec
Change-Id: Id36aa6bdb8f873fe7deb8123a7fc774103721c01
2019-08-20 18:47:21 +00:00
|
|
|
return data.errors && data.errors.some( function ( err ) {
|
|
|
|
return err.code === 'spamblacklist';
|
|
|
|
} );
|
2018-11-29 17:10:39 +00:00
|
|
|
};
|
|
|
|
|
2018-12-07 19:17:55 +00:00
|
|
|
ve.init.mw.SpamBlacklistSaveErrorHandler.static.process = function ( data, target ) {
|
2018-11-29 17:10:39 +00:00
|
|
|
// Handle spam blacklist error from Extension:SpamBlacklist
|
|
|
|
target.showSaveError(
|
Actually return errors for action=edit API
Setting 'apiHookResult' results in a "successful" response; if we want
to report an error, we need to use ApiMessage. We already were doing
this for action=upload. Now our action=edit API responses will be
consistent with MediaWiki and other extensions, and will be able to
take advantage of errorformat=html.
Additionally, remove incorrect 'message' value from action=upload
output. It was anyway redundant to the normal error information.
To avoid user interface regressions in VisualEditor, the changes
I3b9c4fef (in VE) and I106dbd3c (in MediaWiki) should be merged first.
Before:
{
"edit": {
"spamblacklist": "example.com/test|example.net/test",
"result": "Failure"
}
}
After:
{
"errors": [
{
"code": "spamblacklist",
"data": {
"spamblacklist": {
"matches": [
"example.com/test",
"example.net/test"
]
}
},
"module": "edit",
"*": "The text you wanted to save was blocked ..."
}
],
"*": "See http://localhost:3080/w/api.php for API usage. ..."
}
For comparison, a 'readonly' error:
{
"errors": [
{
"code": "readonly",
"data": {
"readonlyreason": "foo bar"
},
"module": "main",
"*": "The wiki is currently in read-only mode."
}
],
"*": "See http://localhost:3080/w/api.php for API usage. ..."
}
Bug: T229539
Depends-On: I106dbd3cbdbf7082b1d1f1c1106ece6b19c22a86
Depends-On: I3b9c4fefc0869ef7999c21cef754434febd852ec
Change-Id: Id36aa6bdb8f873fe7deb8123a7fc774103721c01
2019-08-20 18:47:21 +00:00
|
|
|
target.extractErrorMessages( data ),
|
2018-11-29 17:10:39 +00:00
|
|
|
false // prevents reapply
|
|
|
|
);
|
|
|
|
// Emit event for tracking. TODO: This is a bad design
|
|
|
|
target.emit( 'saveErrorSpamBlacklist' );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.init.mw.saveErrorHandlerFactory.register( ve.init.mw.SpamBlacklistSaveErrorHandler );
|
|
|
|
|
|
|
|
} );
|