Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71945
Change subject: Make use of the APIEditBeforeSave hook for nicer errors
......................................................................
Make use of the APIEditBeforeSave hook for nicer errors
Bug: 32216
Change-Id: I654eb21faffa1371f637d98d0fcd38c005048507
---
M AbuseFilter.hooks.php
M AbuseFilter.php
2 files changed, 50 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter
refs/changes/45/71945/1
diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php
index 96b421c..de19c00 100644
--- a/AbuseFilter.hooks.php
+++ b/AbuseFilter.hooks.php
@@ -8,6 +8,47 @@
// Hooray!
/**
+ * Entry point for the APIEditBeforeSave hook.
+ * This is needed to give a useful error for API edits (Bug 32216)
+ *
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/APIEditBeforeSave
+ *
+ * @param EditPage $editPage
+ * @param string $text New text of the article (has yet to be saved)
+ * @param array &$resultArr Data in this array will be added to the API
result
+ *
+ * @return bool
+ */
+ public function onAPIEditBeforeSave( $editPage, $text, &$result ) {
+ global $wgUser;
+
+ $context = $editPage->mArticle->getContext();
+
+ $status = Status::newGood();
+ $minoredit = $editPage->minoredit;
+ $summary = $editPage->getSummaryInput();
+
+ // poor man's PST, see bug 20310
+ $text = str_replace( "\r\n", "\n", $text );
+
+ $continue = self::filterEdit( $context, null, $text, $status,
$summary, $wgUser, $minoredit );
+
+ if ( !$status->isOK() ) {
+ $msg = $status->getErrorsArray();
+
+ $result = array(
+ 'error' => $msg[0][0],
+ 'info' => $status->getHTML()
+ );
+ }
+
+ // Let the onEditFilterMerged(Content) handler know that we
already filtered the edit... this sucks
+ $title = $context->getTitle();
+ $title->editAlreadyAPIFiltered = true;
+ return $status->isOK();
+ }
+
+ /**
* Entry points for MediaWiki hook 'EditFilterMerged' (MW 1.20 and
earlier)
*
* @param $editor EditPage instance (object)
@@ -58,7 +99,8 @@
}
/**
- * Common implementation for EditFilterMerged and
EditFilterMergedContent hooks.
+ * Common implementation for the APIEditBeforeSave, EditFilterMerged
+ * and EditFilterMergedContent hooks.
*
* @param IContextSource $context the context of the edit
* @param Content|null $content the new Content generated by the edit
@@ -83,6 +125,12 @@
$oldcontent = null;
$title = $context->getTitle();
+
+ if ( isset( $title->editAlreadyAPIFiltered ) ) {
+ // Don't filter changes twice
+ return true;
+ }
+
if ( ( $title instanceof Title ) && $title->canExist() &&
$title->exists() ) {
// Make sure we load the latest text saved in database
(bug 31656)
$page = $context->getWikiPage();
diff --git a/AbuseFilter.php b/AbuseFilter.php
index 67ceddc..ba38823 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -87,6 +87,7 @@
$wgHooks['UploadVerifyFile'][] = 'AbuseFilterHooks::onUploadVerifyFile';
$wgHooks['MakeGlobalVariablesScript'][] =
'AbuseFilterHooks::onMakeGlobalVariablesScript';
$wgHooks['ArticleSaveComplete'][] = 'AbuseFilterHooks::onArticleSaveComplete';
+$wgHooks['APIEditBeforeSave'][] = 'AbuseFilterHooks::onAPIEditBeforeSave';
$wgAvailableRights[] = 'abusefilter-modify';
$wgAvailableRights[] = 'abusefilter-log-detail';
--
To view, visit https://gerrit.wikimedia.org/r/71945
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I654eb21faffa1371f637d98d0fcd38c005048507
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits