mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Merge "(Bug 42064) Change getText to getContent in AbuseFilter"
This commit is contained in:
commit
5f8e9c9ff8
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue