jenkins-bot has submitted this change and it was merged.

Change subject: New variable: new_pst which provides a PSTed version of 
new_wikitext
......................................................................


New variable: new_pst which provides a PSTed version of new_wikitext

It's observed that some vandals use {{subst:void}} to trick the system
and other users and this new variable may help.

It would be nice to be possible to diff this variable against
old_wikitext, but it needs some performance consideration.

Change-Id: I4c4c4e806663363b40936363d659c42016e18cf6
---
M AbuseFilter.class.php
M AbuseFilter.i18n.php
M AbuseFilterVariableHolder.php
3 files changed, 27 insertions(+), 7 deletions(-)

Approvals:
  Anomie: Looks good to me, but someone else must approve
  Siebrand: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php
index c213fb6..4797fcd 100644
--- a/AbuseFilter.class.php
+++ b/AbuseFilter.class.php
@@ -107,6 +107,7 @@
                        'added_links' => 'added-links',
                        'removed_links' => 'removed-links',
                        'all_links' => 'all-links',
+                       'new_pst' => 'new-pst',
                        'new_text' => 'new-text-stripped',
                        'new_html' => 'new-html',
                        'article_restrictions_edit' => 'restrictions-edit',
@@ -1997,6 +1998,14 @@
                                        'title' => $title->getText(),
                                        'text-var' => 'old_wikitext'
                                ) );
+                       $vars->setLazyLoadVar( 'new_pst', 'parse-wikitext',
+                               array(
+                                       'namespace' => $title->getNamespace(),
+                                       'title' => $title->getText(),
+                                       'wikitext-var' => 'new_wikitext',
+                                       'article' => $page,
+                                       'pst' => true,
+                               ) );
                        $vars->setLazyLoadVar( 'new_html', 'parse-wikitext',
                                array(
                                        'namespace' => $title->getNamespace(),
diff --git a/AbuseFilter.i18n.php b/AbuseFilter.i18n.php
index 01d44b6..62681c8 100644
--- a/AbuseFilter.i18n.php
+++ b/AbuseFilter.i18n.php
@@ -335,6 +335,7 @@
        '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-new-text' => 'New page wikitext, after 
the edit',
+       'abusefilter-edit-builder-vars-new-pst' => 'New page wikitext, pre-save 
transformed',
        'abusefilter-edit-builder-vars-new-text-stripped' => 'New page text, 
stripped of any markup',
        'abusefilter-edit-builder-vars-new-html' => 'Parsed HTML source of the 
new revision',
        'abusefilter-edit-builder-vars-recent-contributors' => 'Last ten users 
to contribute to the page',
@@ -875,6 +876,7 @@
        'abusefilter-edit-builder-vars-user-groups' => 'See also:
 * {{msg-mw|Abusefilter-edit-builder-vars-global-user-groups}}',
        'abusefilter-edit-builder-vars-user-blocked' => 'Paraphrased: Boolean 
value on whether the user is blocked. Abuse filter syntax option in a dropdown 
from the group {{msg-mw|abusefilter-edit-builder-group-vars}}.',
+       'abusefilter-edit-builder-vars-new-pst' => 'Paraphrased: The output 
wikitext after pre-save transform is applied to new_wikitext. Abuse filter 
syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.',
        'abusefilter-edit-builder-vars-restrictions-edit' => 'This variable 
contains the level of protection required to edit the page. ("Edit" here is not 
a verb, but an adjective, like "Edit-related protection level"). Abuse filter 
syntax option in a dropdown from the group 
{{msg-mw|abusefilter-edit-builder-group-vars}}.
 
 See also {{msg-mw|Abusefilter-edit-builder-vars-restrictions-create}}, 
{{msg-mw|Abusefilter-edit-builder-vars-restrictions-move}}, 
{{msg-mw|Abusefilter-edit-builder-vars-restrictions-upload}}.',
diff --git a/AbuseFilterVariableHolder.php b/AbuseFilterVariableHolder.php
index 4089b5e..c33da01 100644
--- a/AbuseFilterVariableHolder.php
+++ b/AbuseFilterVariableHolder.php
@@ -437,10 +437,14 @@
                                        // XXX: Use prepareContentForEdit. But 
we need a Content object for that.
                                        $new_text = $vars->getVar( $textVar 
)->toString();
                                        $editInfo = 
$article->prepareTextForEdit( $new_text );
-                                       $newHTML = $editInfo->output->getText();
-                                       // Kill the PP limit comments. Ideally 
we'd just remove these by not setting the
-                                       // parser option, but then we can't 
share a parse operation with the edit, which is bad.
-                                       $result = preg_replace( '/<!--\s*NewPP 
limit report[^>]*-->\s*$/si', '', $newHTML );
+                                       if ( isset( $parameters['pst'] ) && 
$parameters['pst'] ) {
+                                               $result = 
$editInfo->pstContent->serialize( $editInfo->format );
+                                       } else {
+                                               $newHTML = 
$editInfo->output->getText();
+                                               // Kill the PP limit comments. 
Ideally we'd just remove these by not setting the
+                                               // parser option, but then we 
can't share a parse operation with the edit, which is bad.
+                                               $result = preg_replace( 
'/<!--\s*NewPP limit report[^>]*-->\s*$/si', '', $newHTML );
+                                       }
                                        break;
                                }
                                // Otherwise fall back to database
@@ -452,9 +456,14 @@
                                if ( !defined( 'MW_SUPPORTS_CONTENTHANDLER' )
                                        || $article->getContentModel() === 
CONTENT_MODEL_WIKITEXT ) {
 
-                                       $text = $vars->getVar( $textVar 
)->toString();
-                                       $editInfo = 
$this->parseNonEditWikitext( $text, $article );
-                                       $result = $editInfo->output->getText();
+                                       if ( isset( $parameters['pst'] ) && 
$parameters['pst'] ) {
+                                               // $textVar is already PSTed 
when it's not loaded from an ongoing edit.
+                                               $result = $vars->getVar( 
$textVar )->toString();
+                                       } else {
+                                               $text = $vars->getVar( $textVar 
)->toString();
+                                               $editInfo = 
$this->parseNonEditWikitext( $text, $article );
+                                               $result = 
$editInfo->output->getText();
+                                       }
                                } else {
                                        // TODO: Parser Output from Content 
object. But we don't have the content object.
                                        //      And for non-text content, 
$wikitext is usually not going to be a valid

-- 
To view, visit https://gerrit.wikimedia.org/r/47582
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4c4c4e806663363b40936363d659c42016e18cf6
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Liangent <liang...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: CSteipp <cste...@wikimedia.org>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Liangent <liang...@gmail.com>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org>
Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to