2009-02-27 00:03:30 +00:00
|
|
|
<?php
|
|
|
|
class AbuseFilterVariableHolder {
|
|
|
|
var $mVars = array();
|
2009-03-19 02:05:58 +00:00
|
|
|
static $varBlacklist = array( 'context' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $variable
|
|
|
|
* @param $datum
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function setVar( $variable, $datum ) {
|
|
|
|
$variable = strtolower( $variable );
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !( $datum instanceof AFPData || $datum instanceof AFComputedVariable ) ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
$datum = AFPData::newFromPHPVar( $datum );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$this->mVars[$variable] = $datum;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $variable
|
|
|
|
* @param $method
|
|
|
|
* @param $parameters
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function setLazyLoadVar( $variable, $method, $parameters ) {
|
|
|
|
$placeholder = new AFComputedVariable( $method, $parameters );
|
|
|
|
$this->setVar( $variable, $placeholder );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $variable
|
|
|
|
* @return AFPData
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function getVar( $variable ) {
|
|
|
|
$variable = strtolower( $variable );
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( isset( $this->mVars[$variable] ) ) {
|
|
|
|
if ( $this->mVars[$variable] instanceof AFComputedVariable ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
$value = $this->mVars[$variable]->compute( $this );
|
|
|
|
$this->setVar( $variable, $value );
|
|
|
|
return $value;
|
2009-05-22 06:42:10 +00:00
|
|
|
} elseif ( $this->mVars[$variable] instanceof AFPData ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
return $this->mVars[$variable];
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2012-06-21 13:31:09 +00:00
|
|
|
return new AFPData();
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @return AbuseFilterVariableHolder
|
|
|
|
*/
|
2009-10-07 13:57:06 +00:00
|
|
|
static function merge() {
|
2009-02-27 00:03:30 +00:00
|
|
|
$newHolder = new AbuseFilterVariableHolder;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( func_get_args() as $addHolder ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
$newHolder->addHolder( $addHolder );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
return $newHolder;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $addHolder
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function addHolder( $addHolder ) {
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !is_object( $addHolder ) ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new MWException( 'Invalid argument to AbuseFilterVariableHolder::addHolder' );
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
$this->mVars = array_merge( $this->mVars, $addHolder->mVars );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-19 02:05:58 +00:00
|
|
|
function __wakeup() {
|
|
|
|
// Reset the context.
|
|
|
|
$this->setVar( 'context', 'stored' );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function exportAllVars() {
|
|
|
|
$allVarNames = array_keys( $this->mVars );
|
|
|
|
$exported = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $allVarNames as $varName ) {
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !in_array( $varName, self::$varBlacklist ) ) {
|
2009-03-19 02:05:58 +00:00
|
|
|
$exported[$varName] = $this->getVar( $varName )->toString();
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
return $exported;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $var
|
|
|
|
* @return bool
|
|
|
|
*/
|
2009-04-01 06:53:18 +00:00
|
|
|
function varIsSet( $var ) {
|
|
|
|
return array_key_exists( $var, $this->mVars );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute all vars which need DB access. Useful for vars which are going to be saved
|
|
|
|
* cross-wiki or used for offline analysis.
|
|
|
|
*/
|
2009-03-30 06:12:12 +00:00
|
|
|
function computeDBVars() {
|
2009-10-07 13:57:06 +00:00
|
|
|
static $dbTypes = array(
|
|
|
|
'links-from-wikitext-or-database',
|
|
|
|
'load-recent-authors',
|
|
|
|
'get-page-restrictions',
|
|
|
|
'simple-user-accessor',
|
|
|
|
'user-age',
|
|
|
|
'user-groups',
|
|
|
|
'revision-text-by-id',
|
|
|
|
'revision-text-by-timestamp'
|
|
|
|
);
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $this->mVars as $name => $value ) {
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( $value instanceof AFComputedVariable &&
|
2009-03-30 06:12:12 +00:00
|
|
|
in_array( $value->mMethod, $dbTypes ) ) {
|
2012-06-21 13:31:09 +00:00
|
|
|
$value = $value->compute( $this );
|
|
|
|
$this->setVar( $name, $value );
|
2009-03-30 06:12:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class AFComputedVariable {
|
|
|
|
var $mMethod, $mParameters;
|
|
|
|
static $userCache = array();
|
|
|
|
static $articleCache = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $method
|
|
|
|
* @param $parameters
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function __construct( $method, $parameters ) {
|
|
|
|
$this->mMethod = $method;
|
|
|
|
$this->mParameters = $parameters;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-08-24 22:11:52 +00:00
|
|
|
/**
|
|
|
|
* It's like Article::prepareTextForEdit, but not for editing (old wikitext usually)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param $wikitext String
|
|
|
|
* @param $article Article
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function parseNonEditWikitext( $wikitext, $article ) {
|
|
|
|
static $cache = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
$cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( isset( $cache[$cacheKey] ) ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
return $cache[$cacheKey];
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
global $wgParser;
|
|
|
|
$edit = (object)array();
|
|
|
|
$options = new ParserOptions;
|
|
|
|
$options->setTidy( true );
|
2011-08-24 22:11:52 +00:00
|
|
|
$edit->output = $wgParser->parse( $wikitext, $article->getTitle(), $options );
|
2009-02-27 00:03:30 +00:00
|
|
|
$cache[$cacheKey] = $edit;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
return $edit;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $username string
|
|
|
|
* @return User
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
static function userObjectFromName( $username ) {
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( isset( self::$userCache[$username] ) ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
return self::$userCache[$username];
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
wfDebug( "Couldn't find user $username in cache\n" );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
if ( count( self::$userCache ) > 1000 ) {
|
|
|
|
self::$userCache = array();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( IP::isIPAddress( $username ) ) {
|
2009-02-28 01:10:45 +00:00
|
|
|
$u = new User;
|
|
|
|
$u->setName( $username );
|
2009-05-22 06:42:10 +00:00
|
|
|
self::$userCache[$username] = $u;
|
|
|
|
return $u;
|
2009-02-28 01:10:45 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-10 23:28:18 +00:00
|
|
|
$user = User::newFromName( $username );
|
|
|
|
$user->load();
|
|
|
|
self::$userCache[$username] = $user;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-10 23:28:18 +00:00
|
|
|
return $user;
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $namespace
|
|
|
|
* @param $title Title
|
|
|
|
* @return Article
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
static function articleFromTitle( $namespace, $title ) {
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( isset( self::$articleCache["$namespace:$title"] ) ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
return self::$articleCache["$namespace:$title"];
|
2009-05-22 06:42:10 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
if ( count( self::$articleCache ) > 1000 ) {
|
|
|
|
self::$articleCache = array();
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-28 01:10:45 +00:00
|
|
|
wfDebug( "Creating article object for $namespace:$title in cache\n" );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$t = Title::makeTitle( $namespace, $title );
|
|
|
|
self::$articleCache["$namespace:$title"] = new Article( $t );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
return self::$articleCache["$namespace:$title"];
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $article Article
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-03-19 02:05:58 +00:00
|
|
|
static function getLinksFromDB( $article ) {
|
|
|
|
// Stolen from ConfirmEdit
|
|
|
|
$id = $article->getId();
|
2009-05-22 06:42:10 +00:00
|
|
|
if ( !$id ) {
|
|
|
|
return array();
|
|
|
|
}
|
2010-02-13 14:10:36 +00:00
|
|
|
|
2009-03-19 02:05:58 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-08-19 21:12:09 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'externallinks',
|
|
|
|
array( 'el_to' ),
|
|
|
|
array( 'el_from' => $id ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2009-03-19 02:05:58 +00:00
|
|
|
$links = array();
|
2010-08-19 21:12:09 +00:00
|
|
|
foreach( $res as $row ) {
|
2009-03-19 02:05:58 +00:00
|
|
|
$links[] = $row->el_to;
|
|
|
|
}
|
|
|
|
return $links;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-03-11 20:40:04 +00:00
|
|
|
/**
|
|
|
|
* @param $vars AbuseFilterVariableHolder
|
|
|
|
* @return AFPData|array|int|mixed|null|string
|
|
|
|
* @throws MWException
|
|
|
|
* @throws AFPException
|
|
|
|
*/
|
2009-02-27 00:03:30 +00:00
|
|
|
function compute( $vars ) {
|
|
|
|
$parameters = $this->mParameters;
|
|
|
|
$result = null;
|
|
|
|
switch( $this->mMethod ) {
|
|
|
|
case 'diff':
|
|
|
|
$text1Var = $parameters['oldtext-var'];
|
|
|
|
$text2Var = $parameters['newtext-var'];
|
|
|
|
$text1 = $vars->getVar( $text1Var )->toString();
|
|
|
|
$text2 = $vars->getVar( $text2Var )->toString();
|
|
|
|
$result = wfDiff( $text1, $text2 );
|
2009-06-05 10:32:31 +00:00
|
|
|
$result = trim( preg_replace( "/^\\\\ No newline at end of file\n/m", '', $result ) );
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'diff-split':
|
|
|
|
$diff = $vars->getVar( $parameters['diff-var'] )->toString();
|
|
|
|
$line_prefix = $parameters['line-prefix'];
|
|
|
|
$diff_lines = explode( "\n", $diff );
|
|
|
|
$interest_lines = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $diff_lines as $line ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( substr( $line, 0, 1 ) === $line_prefix ) {
|
|
|
|
$interest_lines[] = substr( $line, strlen( $line_prefix ) );
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 19:07:47 +00:00
|
|
|
$result = $interest_lines;
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'links-from-wikitext':
|
2009-05-26 13:08:15 +00:00
|
|
|
// This should ONLY be used when sharing a parse operation with the edit.
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-11-09 08:36:26 +00:00
|
|
|
$article = $parameters['article'];
|
|
|
|
if ( $article ) {
|
2009-05-26 13:08:15 +00:00
|
|
|
$textVar = $parameters['text-var'];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
$new_text = $vars->getVar( $textVar )->toString();
|
|
|
|
$editInfo = $article->prepareTextForEdit( $new_text );
|
|
|
|
$links = array_keys( $editInfo->output->getExternalLinks() );
|
|
|
|
$result = $links;
|
2011-11-09 08:36:26 +00:00
|
|
|
break;
|
2009-05-26 13:08:15 +00:00
|
|
|
}
|
2011-11-09 08:36:26 +00:00
|
|
|
// Otherwise fall back to database
|
2009-03-19 03:10:18 +00:00
|
|
|
case 'links-from-wikitext-nonedit':
|
2009-03-19 02:05:58 +00:00
|
|
|
case 'links-from-wikitext-or-database':
|
2010-08-19 21:12:09 +00:00
|
|
|
$article = self::articleFromTitle(
|
|
|
|
$parameters['namespace'],
|
|
|
|
$parameters['title']
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
if ( $vars->getVar( 'context' )->toString() == 'filter' ) {
|
2009-03-19 02:05:58 +00:00
|
|
|
$links = $this->getLinksFromDB( $article );
|
|
|
|
wfDebug( "AbuseFilter: loading old links from DB\n" );
|
2010-02-13 14:10:36 +00:00
|
|
|
} else {
|
2009-03-19 02:05:58 +00:00
|
|
|
wfDebug( "AbuseFilter: loading old links from Parser\n" );
|
|
|
|
$textVar = $parameters['text-var'];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-19 02:05:58 +00:00
|
|
|
$wikitext = $vars->getVar( $textVar )->toString();
|
|
|
|
$editInfo = $this->parseNonEditWikitext( $wikitext, $article );
|
|
|
|
$links = array_keys( $editInfo->output->getExternalLinks() );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-04-05 19:07:47 +00:00
|
|
|
$result = $links;
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'link-diff-added':
|
|
|
|
case 'link-diff-removed':
|
|
|
|
$oldLinkVar = $parameters['oldlink-var'];
|
|
|
|
$newLinkVar = $parameters['newlink-var'];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$oldLinks = $vars->getVar( $oldLinkVar )->toString();
|
|
|
|
$newLinks = $vars->getVar( $newLinkVar )->toString();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$oldLinks = explode( "\n", $oldLinks );
|
|
|
|
$newLinks = explode( "\n", $newLinks );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $this->mMethod == 'link-diff-added' ) {
|
2009-05-26 13:08:15 +00:00
|
|
|
$result = array_diff( $newLinks, $oldLinks );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mMethod == 'link-diff-removed' ) {
|
2009-05-26 13:08:15 +00:00
|
|
|
$result = array_diff( $oldLinks, $newLinks );
|
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'parse-wikitext':
|
2009-05-26 13:08:15 +00:00
|
|
|
// Should ONLY be used when sharing a parse operation with the edit.
|
2011-11-09 08:36:26 +00:00
|
|
|
|
|
|
|
$article = $parameters['article'];
|
|
|
|
if ( $article ) {
|
2009-05-26 13:08:15 +00:00
|
|
|
$textVar = $parameters['wikitext-var'];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
$new_text = $vars->getVar( $textVar )->toString();
|
|
|
|
$editInfo = $article->prepareTextForEdit( $new_text );
|
|
|
|
$newHTML = $editInfo->output->getText();
|
2010-02-13 14:10:36 +00:00
|
|
|
// Kill the PP limit comments. Ideally we'd just remove these by not setting the
|
2009-05-26 13:08:15 +00:00
|
|
|
// 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 );
|
2011-11-09 08:36:26 +00:00
|
|
|
break;
|
2009-05-26 13:08:15 +00:00
|
|
|
}
|
2011-11-09 08:36:26 +00:00
|
|
|
// Otherwise fall back to database
|
2009-02-27 00:03:30 +00:00
|
|
|
case 'parse-wikitext-nonedit':
|
|
|
|
$article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] );
|
|
|
|
$textVar = $parameters['wikitext-var'];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$text = $vars->getVar( $textVar )->toString();
|
2009-05-22 06:42:10 +00:00
|
|
|
$editInfo = $this->parseNonEditWikitext( $text, $article );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$result = $editInfo->output->getText();
|
|
|
|
break;
|
|
|
|
case 'strip-html':
|
|
|
|
$htmlVar = $parameters['html-var'];
|
|
|
|
$html = $vars->getVar( $htmlVar )->toString();
|
2009-05-26 13:08:15 +00:00
|
|
|
$result = StringUtils::delimiterReplace( '<', '>', '', $html );
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'load-recent-authors':
|
|
|
|
$cutOff = $parameters['cutoff'];
|
|
|
|
$title = Title::makeTitle( $parameters['namespace'], $parameters['title'] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( !$title->exists() ) {
|
2009-03-16 08:21:24 +00:00
|
|
|
$result = '';
|
|
|
|
break;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-08-19 21:12:09 +00:00
|
|
|
$res = $dbr->select( 'revision',
|
|
|
|
'DISTINCT rev_user_text',
|
2009-02-27 00:03:30 +00:00
|
|
|
array(
|
2012-03-11 19:04:37 +00:00
|
|
|
'rev_page' => $title->getArticleID(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'rev_timestamp<' . $dbr->addQuotes( $dbr->timestamp( $cutOff ) )
|
|
|
|
),
|
|
|
|
__METHOD__,
|
|
|
|
array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 10 )
|
|
|
|
);
|
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$users = array();
|
2011-02-11 11:42:19 +00:00
|
|
|
foreach( $res as $row ) {
|
|
|
|
$users[] = $row->rev_user_text;
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2009-04-05 19:07:47 +00:00
|
|
|
$result = $users;
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'get-page-restrictions':
|
|
|
|
$action = $parameters['action'];
|
|
|
|
$title = Title::makeTitle( $parameters['namespace'], $parameters['title'] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$rights = $title->getRestrictions( $action );
|
2009-10-07 13:57:06 +00:00
|
|
|
$rights = count( $rights ) ? $rights : array();
|
2009-04-05 19:07:47 +00:00
|
|
|
$result = $rights;
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'simple-user-accessor':
|
|
|
|
$user = $parameters['user'];
|
|
|
|
$method = $parameters['method'];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( !$user ) {
|
|
|
|
throw new MWException( 'No user parameter given.' );
|
2009-02-27 13:16:34 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$obj = self::userObjectFromName( $user );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( !$obj ) {
|
2009-02-27 13:16:34 +00:00
|
|
|
throw new MWException( "Invalid username $user" );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$result = call_user_func( array( $obj, $method ) );
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'user-age':
|
|
|
|
$user = $parameters['user'];
|
|
|
|
$asOf = $parameters['asof'];
|
|
|
|
$obj = self::userObjectFromName( $user );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
if ( $obj->getId() == 0 ) {
|
2009-03-18 00:26:28 +00:00
|
|
|
$result = 0;
|
|
|
|
break;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$registration = $obj->getRegistration();
|
|
|
|
$result =
|
2009-10-07 13:57:06 +00:00
|
|
|
wfTimestamp( TS_UNIX, $asOf ) -
|
2009-03-18 00:26:28 +00:00
|
|
|
wfTimestampOrNull( TS_UNIX, $registration );
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'user-groups':
|
|
|
|
$user = $parameters['user'];
|
|
|
|
$obj = self::userObjectFromName( $user );
|
2009-04-05 19:07:47 +00:00
|
|
|
$result = $obj->getEffectiveGroups();
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
case 'length':
|
|
|
|
$s = $vars->getVar( $parameters['length-var'] )->toString();
|
|
|
|
$result = strlen( $s );
|
|
|
|
break;
|
|
|
|
case 'subtract':
|
|
|
|
$v1 = $vars->getVar( $parameters['val1-var'] )->toFloat();
|
|
|
|
$v2 = $vars->getVar( $parameters['val2-var'] )->toFloat();
|
|
|
|
$result = $v1 - $v2;
|
|
|
|
break;
|
|
|
|
case 'revision-text-by-id':
|
|
|
|
$rev = Revision::newFromId( $parameters['revid'] );
|
|
|
|
$result = $rev->getText();
|
|
|
|
break;
|
|
|
|
case 'revision-text-by-timestamp':
|
|
|
|
$timestamp = $parameters['timestamp'];
|
|
|
|
$title = Title::makeTitle( $parameters['namespace'], $parameters['title'] );
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-27 00:03:30 +00:00
|
|
|
$rev = Revision::loadFromTimestamp( $dbr, $title, $timestamp );
|
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $rev ) {
|
2009-02-27 00:03:30 +00:00
|
|
|
$result = $rev->getText();
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-02-27 00:03:30 +00:00
|
|
|
$result = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( wfRunHooks( 'AbuseFilter-computeVariable',
|
2009-03-25 05:18:27 +00:00
|
|
|
array( $this->mMethod, $vars ) ) ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
throw new AFPException( 'Unknown variable compute type ' . $this->mMethod );
|
2009-03-25 05:18:27 +00:00
|
|
|
}
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-05-26 13:08:15 +00:00
|
|
|
return $result instanceof AFPData
|
|
|
|
? $result : AFPData::newFromPHPVar( $result );
|
2009-02-27 00:03:30 +00:00
|
|
|
}
|
2009-03-25 05:18:27 +00:00
|
|
|
}
|