diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php index 7497a6805..8999d82e1 100644 --- a/AbuseFilter.class.php +++ b/AbuseFilter.class.php @@ -2063,4 +2063,37 @@ class AbuseFilter { $msg = "abusefilter-group-$group"; return wfMessage($msg)->exists() ? wfMessage($msg)->escaped() : $group; } + + /** + * Look up some text of a revision from its revision id + * + * Note that this is really *some* text, we do not make *any* guarantee + * that this text will be even close to what the user actually sees, or + * that the form is fit for any intended purpose. + * + * Note also that if the revision for any reason is not an Revision + * the function returns with an empty string. + * + * @param Revision $revision a valid revision + * @param $audience Integer: one of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to the given user + * Revision::RAW get the text regardless of permissions + * @return string|null the content of the revision as some kind of string, + * or an empty string if it can not be found + */ + static function revisionToString( $revision, $audience = Revision::FOR_PUBLIC ) { + if ( !$revision instanceof Revision ) { + return ''; + } + if ( defined( 'MW_SUPPORTS_CONTENTHANDLER' ) ) { + $content = $revision->getContent( $audience ); + $result = $content instanceof TextContent ? $content->getNativeData() : $content->getTextForSearchIndex(); + } else { + // For MediaWiki without contenthandler support (< 1.21) + $result = $revision->getText(); + } + return $result; + } + } diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php index da3034b9c..cd531a286 100644 --- a/AbuseFilter.hooks.php +++ b/AbuseFilter.hooks.php @@ -37,7 +37,7 @@ class AbuseFilterHooks { if ( !$revision ) { return true; } - $oldtext = $revision->getRawText(); + $oldtext = AbuseFilter::revisionToString( $revision, Revision::RAW ); } // Cache article object so we can share a parse operation diff --git a/AbuseFilterVariableHolder.php b/AbuseFilterVariableHolder.php index 3d5799710..72473dc0f 100644 --- a/AbuseFilterVariableHolder.php +++ b/AbuseFilterVariableHolder.php @@ -326,7 +326,7 @@ class AFComputedVariable { break; case 'parse-wikitext': // Should ONLY be used when sharing a parse operation with the edit. - + $article = $parameters['article']; if ( $article ) { $textVar = $parameters['wikitext-var']; @@ -436,20 +436,14 @@ class AFComputedVariable { break; case 'revision-text-by-id': $rev = Revision::newFromId( $parameters['revid'] ); - $result = $rev->getText(); + $result = AbuseFilter::revisionToString( $rev ); break; case 'revision-text-by-timestamp': $timestamp = $parameters['timestamp']; $title = Title::makeTitle( $parameters['namespace'], $parameters['title'] ); $dbr = wfGetDB( DB_SLAVE ); - $rev = Revision::loadFromTimestamp( $dbr, $title, $timestamp ); - - if ( $rev ) { - $result = $rev->getText(); - } else { - $result = ''; - } + $result = AbuseFilter::revisionToString( $rev ); break; default: if ( wfRunHooks( 'AbuseFilter-computeVariable',