Revert r111217 (unreviewed rev in AbuseFilter) and its dependencies r113585, r113587, r113588, r113589.

All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
This commit is contained in:
Roan Kattouw 2012-03-21 19:41:11 +00:00
parent 946571c063
commit 6c4bd57043
Notes: Roan Kattouw 2012-03-21 19:41:11 +00:00
14 changed files with 76 additions and 977 deletions

View file

@ -120,10 +120,6 @@ class AbuseFilter {
);
public static $editboxName = null;
/**
* @param $context IContextSource
* @param $pageType
*/
public static function addNavigationLinks( IContextSource $context, $pageType ) {
$linkDefs = array(
'home' => 'Special:AbuseFilter',
@ -163,7 +159,7 @@ class AbuseFilter {
if ( $name == $pageType ) {
$links[] = Xml::tags( 'strong', null, $msg );
} else {
$links[] = Linker::link( $title, $msg );
$links[] = $context->getSkin()->link( $title, $msg );
}
}
@ -196,9 +192,6 @@ class AbuseFilter {
return $vars;
}
/**
* @return array
*/
public static function getBuilderValues() {
static $realValues = null;
@ -212,10 +205,6 @@ class AbuseFilter {
return $realValues;
}
/**
* @param $filter
* @return bool
*/
public static function filterHidden( $filter ) {
$globalIndex = self::decodeGlobalName( $filter );
if ( $globalIndex ) {
@ -237,10 +226,6 @@ class AbuseFilter {
return $hidden ? true : false;
}
/**
* @param $val int
* @throws MWException
*/
public static function triggerLimiter( $val = 1 ) {
self::$condCount += $val;
@ -257,8 +242,9 @@ class AbuseFilter {
}
/**
* @param $title Title
* @param $prefix
* @static
* @param $title Title
* @param $prefix
* @return AbuseFilterVariableHolder
*/
public static function generateTitleVars( $title, $prefix ) {
@ -294,10 +280,6 @@ class AbuseFilter {
return $vars;
}
/**
* @param $filter
* @return mixed
*/
public static function checkSyntax( $filter ) {
global $wgAbuseFilterParserClass;
@ -306,11 +288,6 @@ class AbuseFilter {
return $parser->checkSyntax( $filter );
}
/**
* @param $expr
* @param array $vars
* @return string
*/
public static function evaluateExpression( $expr, $vars = array() ) {
global $wgAbuseFilterParserClass;
@ -325,20 +302,8 @@ class AbuseFilter {
return $parser->evaluateExpression( $expr );
}
/**
* @param $conds
* @param $vars
* @param $ignoreError bool
* @param $keepVars string
* @return bool
* @throws Exception
*/
public static function checkConditions(
$conds,
$vars,
$ignoreError = true,
$keepVars = 'resetvars'
) {
public static function checkConditions( $conds, $vars, $ignoreError = true,
$keepVars = 'resetvars' ) {
global $wgAbuseFilterParserClass;
static $parser;
@ -423,14 +388,6 @@ class AbuseFilter {
return $filter_matched;
}
/**
* @static
* @param $row
* @param $vars
* @param $profile bool
* @param $prefix string
* @return bool
*/
public static function checkFilter( $row, $vars, $profile = false, $prefix = '' ) {
$filterID = $prefix . $row->af_id;
@ -444,12 +401,8 @@ class AbuseFilter {
// Check conditions...
$pattern = trim( $row->af_pattern );
if ( self::checkConditions(
$pattern,
$vars,
true /* ignore errors */,
'keepvars'
) ) {
if ( self::checkConditions( $pattern, $vars, true /* ignore errors */,
'keepvars' ) ) {
// Record match.
$result = true;
} else {
@ -470,9 +423,6 @@ class AbuseFilter {
return $result;
}
/**
* @param $filter
*/
public static function resetFilterProfile( $filter ) {
global $wgMemc;
$countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
@ -482,11 +432,6 @@ class AbuseFilter {
$wgMemc->delete( $totalKey );
}
/**
* @param $filter
* @param $time
* @param $conds
*/
public static function recordProfilingResult( $filter, $time, $conds ) {
global $wgMemc;
@ -509,10 +454,6 @@ class AbuseFilter {
}
}
/**
* @param $filter
* @return array
*/
public static function getFilterProfile( $filter ) {
global $wgMemc;
@ -542,7 +483,7 @@ class AbuseFilter {
*
* @param $filter string
*
* @return string|bool
* @return string|false
*/
public static function decodeGlobalName( $filter ) {
if ( strpos( $filter, 'global-' ) == 0 ) {
@ -552,10 +493,6 @@ class AbuseFilter {
return false;
}
/**
* @param $filters array
* @return array
*/
public static function getConsequencesForFilters( $filters ) {
$globalFilters = array();
$localFilters = array();
@ -591,12 +528,6 @@ class AbuseFilter {
return $consequences;
}
/**
* @param $dbr DatabaseBase
* @param $filters array
* @param $prefix string
* @return array
*/
public static function loadConsequencesFromDB( $dbr, $filters, $prefix = '' ) {
$actionsByFilter = array();
foreach ( $filters as $filter ) {
@ -731,11 +662,6 @@ class AbuseFilter {
return array( $actionsTaken, implode( "\n", $messages ) );
}
/**
* @param $vars AbuseFilterVariableHolder
* @param $title
* @return bool
*/
public static function filterAction( $vars, $title ) {
global $wgUser, $wgTitle;
@ -756,10 +682,8 @@ class AbuseFilter {
$filter_matched = self::checkAllFilters( $vars );
$matched_filters = array_keys( array_filter( $filter_matched ) );
// Short-cut any remaining code if no filters were hit.
if ( count( $matched_filters ) == 0 ) {
if ( count( array_filter( $filter_matched ) ) == 0 ) {
wfProfileOut( __METHOD__ );
return true;
}
@ -767,7 +691,7 @@ class AbuseFilter {
wfProfileIn( __METHOD__ . '-block' );
list( $actions_taken, $error_msg ) = self::executeFilterActions(
$matched_filters, $title, $vars );
array_keys( array_filter( $filter_matched ) ), $title, $vars );
$action = $vars->getVar( 'ACTION' )->toString();
@ -797,13 +721,6 @@ class AbuseFilter {
return $error_msg;
}
/**
* @param $actions_taken
* @param $log_template
* @param $action
* @param $vars AbuseFilterVariableHolder
* @return mixed
*/
public static function addLogEntries( $actions_taken, $log_template, $action, $vars ) {
wfProfileIn( __METHOD__ );
$dbw = wfGetDB( DB_MASTER );
@ -866,11 +783,7 @@ class AbuseFilter {
// Increment trigger counter
$wgMemc->incr( self::filterMatchesKey() );
$local_log_ids = array();
foreach( $log_rows as $row ) {
$dbw->insert( 'abuse_filter_log', $row, __METHOD__ );
$local_log_ids[] = $dbw->insertId();
}
$dbw->insert( 'abuse_filter_log', $log_rows, __METHOD__ );
if ( count( $logged_local_filters ) ) {
// Update hit-counter.
@ -881,8 +794,6 @@ class AbuseFilter {
);
}
$global_log_ids = array();
// Global stuff
if ( count( $logged_global_filters ) ) {
$vars->computeDBVars();
@ -895,9 +806,7 @@ class AbuseFilter {
global $wgAbuseFilterCentralDB;
$fdb = wfGetDB( DB_MASTER, array(), $wgAbuseFilterCentralDB );
foreach( $central_log_rows as $row ) {
$fdb->insert( 'abuse_filter_log', $row, __METHOD__ );
}
$fdb->insert( 'abuse_filter_log', $central_log_rows, __METHOD__ );
$fdb->update( 'abuse_filter',
array( 'af_hit_count=af_hit_count+1' ),
@ -906,9 +815,6 @@ class AbuseFilter {
);
}
$vars->setVar( 'global_log_ids', $global_log_ids );
$vars->setVar( 'local_log_ids', $local_log_ids );
// Check for emergency disabling.
$total = $wgMemc->get( AbuseFilter::filterUsedKey() );
self::checkEmergencyDisable( $logged_local_filters, $total );
@ -990,7 +896,7 @@ class AbuseFilter {
*
* @param $stored_dump
*
* @return object|AbuseFilterVariableHolder
* @return object
*/
public static function loadVarDump( $stored_dump ) {
wfProfileIn( __METHOD__ );
@ -1034,14 +940,6 @@ class AbuseFilter {
return $obj;
}
/**
* @param $action string
* @param $parameters array
* @param $title Title
* @param $vars AbuseFilterVariableHolder
* @param $rule_desc
* @return string
*/
public static function takeConsequenceAction( $action, $parameters, $title,
$vars, $rule_desc )
{
@ -1201,14 +1099,6 @@ class AbuseFilter {
return $display;
}
/**
* @param $throttleId
* @param $types
* @param $title
* @param $rateCount
* @param $ratePeriod
* @return bool
*/
public static function isThrottled( $throttleId, $types, $title, $rateCount, $ratePeriod ) {
global $wgMemc;
@ -1237,11 +1127,6 @@ class AbuseFilter {
return false; // NOT THROTTLED
}
/**
* @param $type
* @param $title Title
* @return Int|string
*/
public static function throttleIdentifier( $type, $title ) {
global $wgUser;
@ -1272,12 +1157,6 @@ class AbuseFilter {
return $identifier;
}
/**
* @param $throttleId
* @param $type
* @param $title Title
* @return String
*/
public static function throttleKey( $throttleId, $type, $title ) {
$types = explode( ',', $type );
@ -1292,17 +1171,10 @@ class AbuseFilter {
return wfMemcKey( 'abusefilter', 'throttle', $throttleId, $type, $identifier );
}
/**
* @param $user User
* @return String
*/
public static function autoPromoteBlockKey( $user ) {
return wfMemcKey( 'abusefilter', 'block-autopromote', $user->getId() );
}
/**
* @param $filters
*/
public static function recordStats( $filters ) {
global $wgAbuseFilterConditionLimit, $wgMemc;
@ -1341,10 +1213,6 @@ class AbuseFilter {
wfProfileOut( __METHOD__ );
}
/**
* @param $filters
* @param $total
*/
public static function checkEmergencyDisable( $filters, $total ) {
global $wgAbuseFilterEmergencyDisableThreshold, $wgAbuseFilterEmergencyDisableCount,
$wgAbuseFilterEmergencyDisableAge, $wgMemc;
@ -1383,31 +1251,18 @@ class AbuseFilter {
}
}
/**
* @return String
*/
public static function filterLimitReachedKey() {
return wfMemcKey( 'abusefilter', 'stats', 'overflow' );
}
/**
* @return String
*/
public static function filterUsedKey() {
return wfMemcKey( 'abusefilter', 'stats', 'total' );
}
/**
* @param $filter
* @return String
*/
public static function filterMatchesKey( $filter = null ) {
return wfMemcKey( 'abusefilter', 'stats', 'matches', $filter );
}
/**
* @return User
*/
public static function getFilterUser() {
$user = User::newFromName( wfMsgForContent( 'abusefilter-blocker' ) );
$user->load();
@ -1442,7 +1297,6 @@ class AbuseFilter {
* @param $textName String
* @param $addResultDiv Boolean
* @param $canEdit Boolean
* @return string
*/
static function buildEditBox( $rules, $textName = 'wpFilterRules', $addResultDiv = true,
$canEdit = true ) {
@ -1567,10 +1421,6 @@ class AbuseFilter {
return array_unique( $differences );
}
/**
* @param $row
* @return array
*/
static function translateFromHistory( $row ) {
# Translate into an abuse_filter row with some black magic.
# This is ever so slightly evil!
@ -1606,20 +1456,12 @@ class AbuseFilter {
return array( $af_row, $actions_output );
}
/**
* @param $action string
* @return String
*/
static function getActionDisplay( $action ) {
$display = wfMsg( "abusefilter-action-$action" );
$display = wfEmptyMsg( "abusefilter-action-$action", $display ) ? $action : $display;
return $display;
}
/**
* @param $row
* @return AbuseFilterVariableHolder|null
*/
public static function getVarsFromRCRow( $row ) {
if ( $row->rc_this_oldid ) {
// It's an edit.
@ -1639,10 +1481,6 @@ class AbuseFilter {
return $vars;
}
/**
* @param $row
* @return AbuseFilterVariableHolder
*/
public static function getCreateVarsFromRCRow( $row ) {
$vars = new AbuseFilterVariableHolder;
@ -1659,10 +1497,6 @@ class AbuseFilter {
return $vars;
}
/**
* @param $row
* @return AbuseFilterVariableHolder
*/
public static function getEditVarsFromRCRow( $row ) {
$vars = new AbuseFilterVariableHolder;
$title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
@ -1696,10 +1530,6 @@ class AbuseFilter {
return $vars;
}
/**
* @param $row
* @return AbuseFilterVariableHolder
*/
public static function getMoveVarsFromRCRow( $row ) {
$vars = new AbuseFilterVariableHolder;
@ -1729,8 +1559,8 @@ class AbuseFilter {
}
/**
* @param $title Title
* @param $article Array
* @static
* @param $title Title
* @return AbuseFilterVariableHolder
*/
public static function getEditVars( $title, $article = null ) {
@ -1789,10 +1619,6 @@ class AbuseFilter {
return $vars;
}
/**
* @param $vars AbuseFilterVariableHolder
* @return string
*/
public static function buildVarDumpTable( $vars ) {
// Export all values
if ( $vars instanceof AbuseFilterVariableHolder ) {
@ -1846,32 +1672,20 @@ class AbuseFilter {
return $output;
}
/**
* @param $page
* @param $type
* @param $title Title
* @param $sk Skin
* @param $args array
* @return String
*/
static function modifyActionText( $page, $type, $title, $sk, $args ) {
list( $history_id, $filter_id ) = $args;
$filter_link = Linker::link( $title );
$filter_link = $sk ? $sk->link( $title ) : $title->getCanonicalURL();
$details_title = SpecialPage::getTitleFor( 'AbuseFilter', "history/$filter_id/diff/prev/$history_id" );
$details_text = wfMsgExt( 'abusefilter-log-detailslink', 'parseinline' );
$details_link = Linker::link( $details_title, $details_text );
$details_link =
$sk ? $sk->link( $details_title, $details_text ) : $details_title->getCanonicalURL();
return wfMsgExt( 'abusefilter-log-entry-modify',
array( 'parseinline', 'replaceafter' ), array( $filter_link, $details_link ) );
}
/**
* @param $action
* @param $parameters
* @return String
*/
static function formatAction( $action, $parameters ) {
global $wgLang;
if ( count( $parameters ) == 0 ) {
@ -1884,10 +1698,6 @@ class AbuseFilter {
return $displayAction;
}
/**
* @param $value array
* @return string
*/
static function formatFlags( $value ) {
global $wgLang;
$flags = array_filter( explode( ',', $value ) );
@ -1898,9 +1708,6 @@ class AbuseFilter {
return $wgLang->commaList( $flags_display );
}
/**
* @param $data string
*/
static function sendToUDP( $data ) {
global $wgAbuseFilterUDPPrefix, $wgAbuseFilterUDPAddress, $wgAbuseFilterUDPPort;
@ -1912,15 +1719,11 @@ class AbuseFilter {
);
}
/**
* @param $filterID
* @return bool|mixed|string
*/
static function getGlobalFilterDescription( $filterID ) {
global $wgAbuseFilterCentralDB;
if ( !$wgAbuseFilterCentralDB ) {
return '';
return;
}
$fdb = wfGetDB( DB_SLAVE, array(), $wgAbuseFilterCentralDB );

View file

@ -4,11 +4,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
}
class AbuseFilterHooks {
/**
* @var AbuseFilterVariableHolder
*/
static $successful_action_vars = false;
// So far, all of the error message out-params for these hooks accept HTML.
// Hooray!
@ -16,8 +11,8 @@ class AbuseFilterHooks {
* Entry points for MediaWiki hook 'EditFilterMerged'
*
* @param $editor EditPage instance (object)
* @param $text string Content of the edit box
* @param &$error string Error message to return
* @param $text Content of the edit box
* @param &$error Error message to return
* @param $summary Edit summary for page
* @return bool
*/
@ -25,8 +20,6 @@ class AbuseFilterHooks {
// Load vars
$vars = new AbuseFilterVariableHolder;
self::$successful_action_vars = false;
// Check for null edits.
$oldtext = '';
@ -48,9 +41,9 @@ class AbuseFilterHooks {
global $wgUser;
$vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) );
$vars->addHolder( AbuseFilter::generateTitleVars( $title , 'article' ) );
$vars->setVar( 'action', 'edit' );
$vars->setVar( 'summary', $summary );
$vars->addHolder( AbuseFilter::generateTitleVars( $title , 'ARTICLE' ) );
$vars->setVar( 'ACTION', 'edit' );
$vars->setVar( 'SUMMARY', $summary );
$vars->setVar( 'minor_edit', $editor->minoredit );
$vars->setVar( 'old_wikitext', $oldtext );
@ -66,77 +59,9 @@ class AbuseFilterHooks {
$editor->showEditForm();
return false;
}
self::$successful_action_vars = $vars;
return true;
}
/**
* @param $article Article
* @param $user User
* @param $text string
* @param $summary string
* @param $minoredit bool
* @param $watchthis bool
* @param $sectionanchor
* @param $flags
* @param $revision Revision
* @return bool
*/
public static function onArticleSaveComplete(
&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor,
&$flags, $revision
) {
if ( ! self::$successful_action_vars ) {
return true;
}
$vars = self::$successful_action_vars;
if ( $vars->getVar('article_prefixedtext')->toString() !==
$article->getTitle()->getPrefixedText()
) {
return true;
}
if ( $vars->getVar('local_log_ids') ) {
// Now actually do our storage
$log_ids = $vars->getVar('local_log_ids')->toNative();
$dbw = wfGetDB( DB_MASTER );
if ( count($log_ids) ) {
$dbw->update( 'abuse_filter_log',
array( 'afl_rev_id' => $revision->getId() ),
array( 'afl_id' => $log_ids ),
__METHOD__
);
}
}
if ( $vars->getVar('global_log_ids') ) {
$log_ids = $vars->getVar('global_log_ids')->toNative();
global $wgAbuseFilterCentralDB;
$dbw = wfGetDB( DB_MASTER, array(), $wgAbuseFilterCentralDB );
if ( count($log_ids) ) {
$dbw->update( 'abuse_filter_log',
array( 'afl_rev_id' => $revision->getId() ),
array( 'afl_id' => $log_ids, 'afl_wiki' => wfWikiId() ),
__METHOD__
);
}
}
return true;
}
/**
* @param $user
* @param $promote
* @return bool
*/
public static function onGetAutoPromoteGroups( $user, &$promote ) {
global $wgMemc;
@ -149,14 +74,6 @@ class AbuseFilterHooks {
return true;
}
/**
* @param $oldTitle Title
* @param $newTitle Title
* @param $user User
* @param $error
* @param $reason
* @return bool
*/
public static function onAbortMove( $oldTitle, $newTitle, $user, &$error, $reason ) {
$vars = new AbuseFilterVariableHolder;
@ -178,34 +95,22 @@ class AbuseFilterHooks {
return $filter_result == '' || $filter_result === true;
}
/**
* @param $article Article
* @param $user User
* @param $reason string
* @param $error
* @return bool
*/
public static function onArticleDelete( &$article, &$user, &$reason, &$error ) {
$vars = new AbuseFilterVariableHolder;
global $wgUser;
$vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) );
$vars->addHolder( AbuseFilter::generateTitleVars( $article->getTitle(), 'ARTICLE' ) );
$vars->addHolder( AbuseFilter::generateTitleVars( $article->mTitle, 'ARTICLE' ) );
$vars->setVar( 'SUMMARY', $reason );
$vars->setVar( 'ACTION', 'delete' );
$filter_result = AbuseFilter::filterAction( $vars, $article->getTitle() );
$filter_result = AbuseFilter::filterAction( $vars, $article->mTitle );
$error = $filter_result;
return $filter_result == '' || $filter_result === true;
}
/**
* @param $user User
* @param $message
* @return bool
*/
public static function onAbortNewAccount( $user, &$message ) {
if ( $user->getName() == wfMsgForContent( 'abusefilter-blocker' ) ) {
$message = wfMsg( 'abusefilter-accountreserved' );
@ -230,14 +135,10 @@ class AbuseFilterHooks {
return $filter_result == '' || $filter_result === true;
}
/**
* @param $recentChange RecentChange
* @return bool
*/
public static function onRecentChangeSave( $recentChange ) {
$title = Title::makeTitle(
$recentChange->getAttribute( 'rc_namespace' ),
$recentChange->getAttribute( 'rc_title' )
$recentChange->mAttribs['rc_namespace'],
$recentChange->mAttribs['rc_title']
);
$action = $recentChange->mAttribs['rc_log_type'] ?
$recentChange->mAttribs['rc_log_type'] : 'edit';
@ -259,10 +160,6 @@ class AbuseFilterHooks {
return true;
}
/**
* @param $emptyTags array
* @return bool
*/
public static function onListDefinedTags( &$emptyTags ) {
# This is a pretty awful hack.
$dbr = wfGetDB( DB_SLAVE );
@ -287,7 +184,6 @@ class AbuseFilterHooks {
/**
* @param $updater DatabaseUpdater
* @throws MWException
* @return bool
*/
public static function onLoadExtensionSchemaUpdates( $updater = null ) {
@ -305,7 +201,6 @@ class AbuseFilterHooks {
$updater->addExtensionUpdate( array( 'addField', 'abuse_filter', 'af_deleted', "$dir/db_patches/patch-af_deleted.sql", true ) );
$updater->addExtensionUpdate( array( 'addField', 'abuse_filter', 'af_actions', "$dir/db_patches/patch-af_actions.sql", true ) );
$updater->addExtensionUpdate( array( 'addField', 'abuse_filter', 'af_global', "$dir/db_patches/patch-global_filters.sql", true ) );
$updater->addExtensionUpdate( array( 'addField', 'abuse_filter_log', 'afl_rev_id', "$dir/db_patches/patch-afl_action_id.sql", true ) );
if ( $updater->getDB()->getType() == 'mysql' ) {
$updater->addExtensionUpdate( array( 'addIndex', 'abuse_filter_log', 'filter_timestamp', "$dir/db_patches/patch-fix-indexes.sql", true ) );
} else {
@ -353,16 +248,11 @@ class AbuseFilterHooks {
}
}
/**
* @param $id
* @param $nt Title
* @param $tools
* @return bool
*/
public static function onContributionsToolLinks( $id, $nt, &$tools ) {
global $wgUser;
if ( $wgUser->isAllowed( 'abusefilter-log' ) ) {
$tools[] = Linker::link(
$sk = $wgUser->getSkin();
$tools[] = $sk->link(
SpecialPage::getTitleFor( 'AbuseLog' ),
wfMsg( 'abusefilter-log-linkoncontribs' ),
array( 'title' =>
@ -373,12 +263,6 @@ class AbuseFilterHooks {
return true;
}
/**
* @param $saveName
* @param $tempName
* @param $error
* @return bool
*/
public static function onUploadVerification( $saveName, $tempName, &$error ) {
$vars = new AbuseFilterVariableHolder;

View file

@ -91,7 +91,6 @@ Filter description: $7 ($8)',
'abusefilter-log-detailedentry-global' => 'global filter $1',
'abusefilter-log-detailedentry-local' => 'filter $1',
'abusefilter-log-detailslink' => 'details',
'abusefilter-log-diff' => 'diff',
'abusefilter-log-hidelink' => 'adjust visibility',
'abusefilter-log-details-legend' => 'Details for log entry $1',
'abusefilter-log-details-var' => 'Variable',
@ -104,7 +103,7 @@ Filter description: $7 ($8)',
'abusefilter-log-linkoncontribs' => 'abuse log',
'abusefilter-log-linkoncontribs-text' => 'Abuse log for this user',
'abusefilter-log-hidden' => '(entry hidden)',
'abusefilter-log-hidden-implicit' => '(hidden because revision has been deleted)',
'abusefilter-log-hide' => 'hide or unhide', // @todo FIXME: Message unused?
'abusefilter-log-cannot-see-details' => 'You do not have permission to see details of this entry.',
'abusefilter-log-details-hidden' => 'You cannot view the details for this entry because it is hidden from public view.',

View file

@ -74,20 +74,11 @@ class AFPData {
var $type;
var $data;
/**
* @param string $type
* @param null $val
*/
public function __construct( $type = self::DNull, $val = null ) {
$this->type = $type;
$this->data = $val;
}
/**
* @param $var
* @return AFPData
* @throws AFPException
*/
public static function newFromPHPVar( $var ) {
if ( is_string( $var ) ) {
return new AFPData( self::DString, $var );
@ -112,18 +103,10 @@ class AFPData {
}
}
/**
* @return AFPData
*/
public function dup() {
return new AFPData( $this->type, $this->data );
}
/**
* @param $orig AFPData
* @param $target
* @return AFPData
*/
public static function castTypes( $orig, $target ) {
if ( $orig->type == $target ) {
return $orig->dup();
@ -137,7 +120,7 @@ class AFPData {
return new AFPData( self::DBool, (bool)count( $orig->data ) );
}
if ( $target == self::DFloat ) {
return new AFPData( self::DFloat, floatval( count( $orig->data ) ) );
return new AFPData( self::DFloat, doubleval( count( $orig->data ) ) );
}
if ( $target == self::DInt ) {
return new AFPData( self::DInt, intval( count( $orig->data ) ) );
@ -155,7 +138,7 @@ class AFPData {
return new AFPData( self::DBool, (bool)$orig->data );
}
if ( $target == self::DFloat ) {
return new AFPData( self::DFloat, floatval( $orig->data ) );
return new AFPData( self::DFloat, doubleval( $orig->data ) );
}
if ( $target == self::DInt ) {
return new AFPData( self::DInt, intval( $orig->data ) );
@ -168,28 +151,14 @@ class AFPData {
}
}
/**
* @param $value AFPData
* @return AFPData
*/
public static function boolInvert( $value ) {
return new AFPData( self::DBool, !$value->toBool() );
}
/**
* @param $base AFPData
* @param $exponent AFPData
* @return AFPData
*/
public static function pow( $base, $exponent ) {
return new AFPData( self::DFloat, pow( $base->toFloat(), $exponent->toFloat() ) );
}
/**
* @param $a AFPData
* @param $b AFPData
* @return AFPData
*/
public static function keywordIn( $a, $b ) {
$a = $a->toString();
$b = $b->toString();
@ -201,11 +170,6 @@ class AFPData {
return new AFPData( self::DBool, in_string( $a, $b ) );
}
/**
* @param $a AFPData
* @param $b AFPData
* @return AFPData
*/
public static function keywordContains( $a, $b ) {
$a = $a->toString();
$b = $b->toString();
@ -217,11 +181,6 @@ class AFPData {
return new AFPData( self::DBool, in_string( $b, $a ) );
}
/**
* @param $value
* @param $list
* @return bool
*/
public static function listContains( $value, $list ) {
// Should use built-in PHP function somehow
foreach ( $list->data as $item ) {
@ -232,21 +191,11 @@ class AFPData {
return false;
}
/**
* @param $d1 AFPData
* @param $d2 AFPData
* @return bool
*/
public static function equals( $d1, $d2 ) {
return $d1->type != self::DList && $d2->type != self::DList &&
$d1->toString() === $d2->toString();
}
/**
* @param $str AFPData
* @param $pattern AFPData
* @return AFPData
*/
public static function keywordLike( $str, $pattern ) {
$str = $str->toString();
$pattern = $pattern->toString();
@ -256,14 +205,6 @@ class AFPData {
return new AFPData( self::DBool, (bool)$result );
}
/**
* @param $str AFPData
* @param $regex AFPData
* @param $pos
* @param $insensitive bool
* @return AFPData
* @throws Exception
*/
public static function keywordRegex( $str, $regex, $pos, $insensitive = false ) {
$str = $str->toString();
$pattern = $regex->toString();
@ -287,20 +228,10 @@ class AFPData {
return new AFPData( self::DBool, (bool)$result );
}
/**
* @param $str
* @param $regex
* @param $pos
* @return AFPData
*/
public static function keywordRegexInsensitive( $str, $regex, $pos ) {
return self::keywordRegex( $str, $regex, $pos, true );
}
/**
* @param $data AFPData
* @return AFPData
*/
public static function unaryMinus( $data ) {
if ( $data->type == self::DInt ) {
return new AFPData( $data->type, - $data->toInt() );
@ -309,13 +240,6 @@ class AFPData {
}
}
/**
* @param $a AFPData
* @param $b AFPData
* @param $op string
* @return AFPData
* @throws AFPException
*/
public static function boolOp( $a, $b, $op ) {
$a = $a->toBool();
$b = $b->toBool();
@ -331,13 +255,6 @@ class AFPData {
throw new AFPException( "Invalid boolean operation: {$op}" ); // Should never happen.
}
/**
* @param $a AFPData
* @param $b AFPData
* @param $op string
* @return AFPData
* @throws AFPException
*/
public static function compareOp( $a, $b, $op ) {
if ( $op == '==' || $op == '=' ) {
return new AFPData( self::DBool, self::equals( $a, $b ) );
@ -368,15 +285,6 @@ class AFPData {
throw new AFPException( "Invalid comparison operation: {$op}" ); // Should never happen
}
/**
* @param $a AFPData
* @param $b AFPData
* @param $op string
* @param $pos
* @return AFPData
* @throws AFPUserVisibleException
* @throws AFPException
*/
public static function mulRel( $a, $b, $op, $pos ) {
// Figure out the type.
if ( $a->type == self::DFloat || $b->type == self::DFloat ||
@ -407,17 +315,12 @@ class AFPData {
if ( $type == self::DInt ) {
$data = intval( $data );
} else {
$data = floatval( $data );
$data = doubleval( $data );
}
return new AFPData( $type, $data );
}
/**
* @param $a AFPData
* @param $b AFPData
* @return AFPData
*/
public static function sum( $a, $b ) {
if ( $a->type == self::DString || $b->type == self::DString ) {
return new AFPData( self::DString, $a->toString() . $b->toString() );
@ -428,51 +331,12 @@ class AFPData {
}
}
/**
* @param $a AFPData
* @param $b AFPData
* @return AFPData
*/
public static function sub( $a, $b ) {
return new AFPData( self::DFloat, $a->toFloat() - $b->toFloat() );
}
/** Convert shorteners */
/**
* @throws MWException
* @return mixed
*/
public function toNative() {
switch( $this->type ) {
case self::DBool:
return $this->toBool();
break;
case self::DString:
return $this->toString();
break;
case self::DFloat:
return $this->toFloat();
break;
case self::DInt:
return $this->toInt();
break;
case self::DList:
$input = $this->toList();
$output = array();
foreach( $input as $item ) {
$output[] = $item->toNative();
}
return $output;
break;
case self::DNull:
return null;
break;
default:
throw new MWException( "Unknown type" );
}
}
/**
* @return bool
*/
@ -537,15 +401,6 @@ class AFPRegexErrorHandler {
$this->pos = $pos;
}
/**
* @param $errno
* @param $errstr
* @param $errfile
* @param $errline
* @param $context
* @return bool
* @throws AFPUserVisibleException
*/
function handleError( $errno, $errstr, $errfile, $errline, $context ) {
if ( error_reporting() == 0 ) {
return true;
@ -567,12 +422,7 @@ class AFPRegexErrorHandler {
}
class AbuseFilterParser {
var $mParams, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort, $mLen;
/**
* @var AbuseFilterVariableHolder
*/
var $mVars;
var $mParams, $mVars, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort;
// length,lcase,ccnorm,rmdoubles,specialratio,rmspecials,norm,count
static $mFunctions = array(
@ -646,10 +496,6 @@ class AbuseFilterParser {
$this->mAllowShort = true;
}
/**
* @param $filter
* @return array|bool
*/
public function checkSyntax( $filter ) {
try {
$origAS = $this->mAllowShort;
@ -663,18 +509,11 @@ class AbuseFilterParser {
return true;
}
/**
* @param $name
* @param $value
*/
public function setVar( $name, $value ) {
$name = strtolower( $name );
$this->mVars->setVar( $name, $value );
}
/**
* @param $vars
*/
public function setVars( $vars ) {
if ( is_array( $vars ) ) {
foreach ( $vars as $name => $var ) {
@ -685,9 +524,6 @@ class AbuseFilterParser {
}
}
/**
* @return AFPToken
*/
protected function move( ) {
wfProfileIn( __METHOD__ );
list( $val, $type, $code, $offset ) =
@ -699,28 +535,17 @@ class AbuseFilterParser {
return $this->mCur = $token;
}
/**
* getState() function allows parser state to be rollbacked to several tokens back
* @return AFPParserState
*/
// getState() and setState() function allows parser state to be rollbacked to several tokens back
protected function getState() {
return new AFPParserState( $this->mCur, $this->mPos );
}
/**
* setState() function allows parser state to be rollbacked to several tokens back
* @param AFPParserState $state
*/
protected function setState( AFPParserState $state ) {
$this->mCur = $state->token;
$this->mPos = $state->pos;
self::$lastHandledToken = $state->lastInput;
}
/**
* @return mixed
* @throws AFPUserVisibleException
*/
protected function skipOverBraces() {
if ( !( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == '(' ) || !$this->mShortCircuit ) {
return;
@ -743,26 +568,14 @@ class AbuseFilterParser {
throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, array( ')' ) );
}
/**
* @param $code
* @return bool
*/
public function parse( $code ) {
return $this->intEval( $code )->toBool();
}
/**
* @param $filter
* @return string
*/
public function evaluateExpression( $filter ) {
return $this->intEval( $filter )->toString();
}
/**
* @param $code
* @return AFPData
*/
function intEval( $code ) {
// Setup, resetting
$this->mCode = $code;
@ -775,11 +588,6 @@ class AbuseFilterParser {
return $result;
}
/**
* @param $a
* @param $b
* @return int
*/
static function lengthCompare( $a, $b ) {
if ( strlen( $a ) == strlen( $b ) ) {
return 0;
@ -794,7 +602,6 @@ class AbuseFilterParser {
* Handles unexpected characters after the expression
*
* @param $result
* @throws AFPUserVisibleException
*/
protected function doLevelEntry( &$result ) {
$this->doLevelSemicolon( $result );
@ -821,8 +628,6 @@ class AbuseFilterParser {
* Handles multiple expressions
*
* @param $result
* @throws AFPUserVisibleException
* @return
*/
protected function doLevelSet( &$result ) {
if ( $this->mCur->type == AFPToken::TID ) {
@ -886,10 +691,6 @@ class AbuseFilterParser {
$this->doLevelConditions( $result );
}
/**
* @param $result
* @throws AFPUserVisibleException
*/
protected function doLevelConditions( &$result ) {
if ( $this->mCur->type == AFPToken::TKeyword && $this->mCur->value == 'if' ) {
$this->move();
@ -1004,9 +805,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result AFPData
*/
protected function doLevelBoolOps( &$result ) {
$this->doLevelCompares( $result );
$ops = array( '&', '|', '^' );
@ -1045,9 +843,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
*/
protected function doLevelCompares( &$result ) {
AbuseFilter::triggerLimiter();
$this->doLevelSumRels( $result );
@ -1063,9 +858,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
*/
protected function doLevelSumRels( &$result ) {
$this->doLevelMulRels( $result );
wfProfileIn( __METHOD__ );
@ -1085,9 +877,6 @@ class AbuseFilterParser {
wfProfileOut( __METHOD__ );
}
/**
* @param $result
*/
protected function doLevelMulRels( &$result ) {
$this->doLevelPow( $result );
wfProfileIn( __METHOD__ );
@ -1102,9 +891,6 @@ class AbuseFilterParser {
wfProfileOut( __METHOD__ );
}
/**
* @param $result
*/
protected function doLevelPow( &$result ) {
$this->doLevelBoolInvert( $result );
wfProfileIn( __METHOD__ );
@ -1117,9 +903,6 @@ class AbuseFilterParser {
wfProfileOut( __METHOD__ );
}
/**
* @param $result
*/
protected function doLevelBoolInvert( &$result ) {
if ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == '!' ) {
$this->move();
@ -1132,9 +915,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
*/
protected function doLevelSpecialWords( &$result ) {
$this->doLevelUnarys( $result );
$keyword = strtolower( $this->mCur->value );
@ -1166,9 +946,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
*/
protected function doLevelUnarys( &$result ) {
$op = $this->mCur->value;
if ( $this->mCur->type == AFPToken::TOp && ( $op == "+" || $op == "-" ) ) {
@ -1184,10 +961,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
* @throws AFPUserVisibleException
*/
protected function doLevelListElements( &$result ) {
$this->doLevelBraces( $result );
while ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == '[' ) {
@ -1211,10 +984,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
* @throws AFPUserVisibleException
*/
protected function doLevelBraces( &$result ) {
if ( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == '(' ) {
if ( $this->mShortCircuit ) {
@ -1234,10 +1003,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
* @throws AFPUserVisibleException
*/
protected function doLevelFunction( &$result ) {
if ( $this->mCur->type == AFPToken::TID && isset( self::$mFunctions[$this->mCur->value] ) ) {
wfProfileIn( __METHOD__ );
@ -1306,11 +1071,6 @@ class AbuseFilterParser {
}
}
/**
* @param $result
* @throws AFPUserVisibleException
* @return AFPData
*/
protected function doLevelAtom( &$result ) {
wfProfileIn( __METHOD__ );
$tok = $this->mCur->value;
@ -1393,11 +1153,6 @@ class AbuseFilterParser {
/* End of levels */
/**
* @param $var
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function getVarValue( $var ) {
wfProfileIn( __METHOD__ );
$var = strtolower( $var );
@ -1418,11 +1173,6 @@ class AbuseFilterParser {
}
}
/**
* @param $name
* @param $value
* @throws AFPUserVisibleException
*/
protected function setUserVariable( $name, $value ) {
$builderValues = AbuseFilter::getBuilderValues();
if ( array_key_exists( $name, $builderValues['vars'] ) ) {
@ -1431,13 +1181,6 @@ class AbuseFilterParser {
$this->mVars->setVar( $name, $value );
}
/**
* @param $code
* @param $offset
* @return array
* @throws AFPException
* @throws AFPUserVisibleException
*/
static function nextToken( $code, $offset ) {
$tok = '';
@ -1618,7 +1361,7 @@ class AbuseFilterParser {
return array(
$float
? floatval( $num )
? doubleval( $num )
: intval( $num ),
$float
? AFPToken::TFloat
@ -1650,12 +1393,6 @@ class AbuseFilterParser {
}
// Built-in functions
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcLc( $args ) {
global $wgContLang;
if ( count( $args ) < 1 ) {
@ -1669,11 +1406,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $wgContLang->lc( $s ) );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcLen( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1686,11 +1418,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DInt, mb_strlen( $s, 'utf-8' ) );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcSimpleNorm( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1706,11 +1433,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $s );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcSpecialRatio( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1732,11 +1454,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DFloat, $val );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcCount( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1767,12 +1484,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DInt, $count );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
* @throws Exception
*/
protected function funcRCount( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1808,11 +1519,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DInt, $count );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcIPInRange( $args ) {
if ( count( $args ) < 2 ) {
throw new AFPUserVisibleException(
@ -1830,11 +1536,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DBool, $result );
}
/**
* @param $args
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcCCNorm( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1851,11 +1552,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $s );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcContainsAny( $args ) {
if ( count( $args ) < 2 ) {
throw new AFPUserVisibleException(
@ -1892,10 +1588,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DBool, $ok );
}
/**
* @param $s
* @return mixed
*/
protected function ccnorm( $s ) {
static $equivset = null;
static $replacementArray = null;
@ -1909,35 +1601,20 @@ class AbuseFilterParser {
return $replacementArray->replace( $s );
}
/**
* @param $s string
* @return array|string
*/
protected function rmspecials( $s ) {
return preg_replace( '/[^\p{L}\p{N}]/u', '', $s );
$s = preg_replace( '/[^\p{L}\p{N}]/u', '', $s );
return $s;
}
/**
* @param $s string
* @return array|string
*/
protected function rmdoubles( $s ) {
return preg_replace( '/(.)\1+/us', '\1', $s );
}
/**
* @param $s string
* @return array|string
*/
protected function rmwhitespace( $s ) {
return preg_replace( '/\s+/u', '', $s );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcRMSpecials( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1953,11 +1630,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $s );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcRMWhitespace( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1973,11 +1645,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $s );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcRMDoubles( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -1993,11 +1660,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $s );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcNorm( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException(
@ -2016,11 +1678,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $s );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcSubstr( $args ) {
if ( count( $args ) < 2 ) {
throw new AFPUserVisibleException(
@ -2044,11 +1701,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, $result );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcStrPos( $args ) {
if ( count( $args ) < 2 ) {
throw new AFPUserVisibleException(
@ -2075,11 +1727,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DInt, $result );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcStrReplace( $args ) {
if ( count( $args ) < 3 ) {
throw new AFPUserVisibleException(
@ -2096,11 +1743,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, str_replace( $search, $replace, $subject ) );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function funcStrRegexEscape( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException( 'notenoughargs', $this->mCur->pos,
@ -2113,11 +1755,6 @@ class AbuseFilterParser {
return new AFPData( AFPData::DString, preg_quote( $string ) );
}
/**
* @param $args array
* @return mixed
* @throws AFPUserVisibleException
*/
protected function funcSetVar( $args ) {
if ( count( $args ) < 2 ) {
throw new AFPUserVisibleException(
@ -2135,11 +1772,6 @@ class AbuseFilterParser {
return $value;
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function castString( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
@ -2149,11 +1781,6 @@ class AbuseFilterParser {
return AFPData::castTypes( $val, AFPData::DString );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function castInt( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
@ -2163,11 +1790,6 @@ class AbuseFilterParser {
return AFPData::castTypes( $val, AFPData::DInt );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function castFloat( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );
@ -2177,11 +1799,6 @@ class AbuseFilterParser {
return AFPData::castTypes( $val, AFPData::DFloat );
}
/**
* @param $args array
* @return AFPData
* @throws AFPUserVisibleException
*/
protected function castBool( $args ) {
if ( count( $args ) < 1 ) {
throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) );

View file

@ -78,7 +78,6 @@ $wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onLoadExtensionSch
$wgHooks['ContributionsToolLinks'][] = 'AbuseFilterHooks::onContributionsToolLinks';
$wgHooks['UploadVerification'][] = 'AbuseFilterHooks::onUploadVerification';
$wgHooks['MakeGlobalVariablesScript'][] = 'AbuseFilterHooks::onMakeGlobalVariablesScript';
$wgHooks['ArticleSaveComplete'][] = 'AbuseFilterHooks::onArticleSaveComplete';
$wgAvailableRights[] = 'abusefilter-modify';
$wgAvailableRights[] = 'abusefilter-log-detail';

View file

@ -3,10 +3,6 @@ class AbuseFilterVariableHolder {
var $mVars = array();
static $varBlacklist = array( 'context' );
/**
* @param $variable
* @param $datum
*/
function setVar( $variable, $datum ) {
$variable = strtolower( $variable );
if ( !( $datum instanceof AFPData || $datum instanceof AFComputedVariable ) ) {
@ -16,20 +12,11 @@ class AbuseFilterVariableHolder {
$this->mVars[$variable] = $datum;
}
/**
* @param $variable
* @param $method
* @param $parameters
*/
function setLazyLoadVar( $variable, $method, $parameters ) {
$placeholder = new AFComputedVariable( $method, $parameters );
$this->setVar( $variable, $placeholder );
}
/**
* @param $variable
* @return AFPData
*/
function getVar( $variable ) {
$variable = strtolower( $variable );
if ( isset( $this->mVars[$variable] ) ) {
@ -45,9 +32,6 @@ class AbuseFilterVariableHolder {
}
}
/**
* @return AbuseFilterVariableHolder
*/
static function merge() {
$newHolder = new AbuseFilterVariableHolder;
@ -58,10 +42,6 @@ class AbuseFilterVariableHolder {
return $newHolder;
}
/**
* @param $addHolder
* @throws MWException
*/
function addHolder( $addHolder ) {
if ( !is_object( $addHolder ) ) {
throw new MWException( 'Invalid argument to AbuseFilterVariableHolder::addHolder' );
@ -74,9 +54,6 @@ class AbuseFilterVariableHolder {
$this->setVar( 'context', 'stored' );
}
/**
* @return array
*/
function exportAllVars() {
$allVarNames = array_keys( $this->mVars );
$exported = array();
@ -90,10 +67,6 @@ class AbuseFilterVariableHolder {
return $exported;
}
/**
* @param $var
* @return bool
*/
function varIsSet( $var ) {
return array_key_exists( $var, $this->mVars );
}
@ -129,10 +102,6 @@ class AFComputedVariable {
static $userCache = array();
static $articleCache = array();
/**
* @param $method
* @param $parameters
*/
function __construct( $method, $parameters ) {
$this->mMethod = $method;
$this->mParameters = $parameters;
@ -150,7 +119,7 @@ class AFComputedVariable {
function parseNonEditWikitext( $wikitext, $article ) {
static $cache = array();
$cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText();
$cacheKey = md5( $wikitext ) . ':' . $article->mTitle->getPrefixedText();
if ( isset( $cache[$cacheKey] ) ) {
return $cache[$cacheKey];
@ -166,10 +135,6 @@ class AFComputedVariable {
return $edit;
}
/**
* @param $username string
* @return User
*/
static function userObjectFromName( $username ) {
if ( isset( self::$userCache[$username] ) ) {
return self::$userCache[$username];
@ -195,11 +160,6 @@ class AFComputedVariable {
return $user;
}
/**
* @param $namespace
* @param $title Title
* @return Article
*/
static function articleFromTitle( $namespace, $title ) {
if ( isset( self::$articleCache["$namespace:$title"] ) ) {
return self::$articleCache["$namespace:$title"];
@ -217,10 +177,6 @@ class AFComputedVariable {
return self::$articleCache["$namespace:$title"];
}
/**
* @param $article Article
* @return array
*/
static function getLinksFromDB( $article ) {
// Stolen from ConfirmEdit
$id = $article->getId();
@ -242,12 +198,6 @@ class AFComputedVariable {
return $links;
}
/**
* @param $vars AbuseFilterVariableHolder
* @return AFPData|array|int|mixed|null|string
* @throws MWException
* @throws AFPException
*/
function compute( $vars ) {
$parameters = $this->mParameters;
$result = null;

View file

@ -53,12 +53,6 @@ abstract class AbuseFilterView extends ContextSource {
}
class AbuseFilterChangesList extends OldChangesList {
/**
* @param $s
* @param $rc
* @param $classes array
*/
public function insertExtra( &$s, &$rc, &$classes ) {
$examineParams = empty( $rc->examineParams ) ? array() : $rc->examineParams;

View file

@ -94,7 +94,7 @@ class AbuseFilterViewDiff extends AbuseFilterView {
'history/' . $this->mFilter . '/item/' . $other['meta']['history_id'] );
global $wgOut;
$wgOut->redirect( $t->getFullURL() );
return null;
return;
}
} elseif ( $spec == 'next' && !in_array( $otherSpec, $dependentSpecs ) ) {
@ -117,7 +117,7 @@ class AbuseFilterViewDiff extends AbuseFilterView {
'history/' . $this->mFilter . '/item/' . $other['meta']['history_id'] );
global $wgOut;
$wgOut->redirect( $t->getFullURL() );
return null;
return;
}
}
@ -148,11 +148,6 @@ class AbuseFilterViewDiff extends AbuseFilterView {
);
}
/**
* @param $timestamp
* @param $history_id
* @return string
*/
function formatVersionLink( $timestamp, $history_id ) {
$filter = $this->mFilter;
$text = $this->getLanguage()->timeanddate( $timestamp, true );
@ -163,9 +158,6 @@ class AbuseFilterViewDiff extends AbuseFilterView {
return $link;
}
/**
* @return string
*/
function formatDiff() {
$oldVersion = $this->mOldVersion;
$newVersion = $this->mNewVersion;
@ -257,10 +249,6 @@ class AbuseFilterViewDiff extends AbuseFilterView {
return $html;
}
/**
* @param $actions
* @return array
*/
function stringifyActions( $actions ) {
$lines = array();
@ -276,10 +264,6 @@ class AbuseFilterViewDiff extends AbuseFilterView {
return $lines;
}
/**
* @param $msg
* @return String
*/
function getHeaderRow( $msg ) {
$html = wfMsgExt( $msg, 'parseinline' );
$html = Xml::tags( 'th', array( 'colspan' => 3 ), $html );
@ -288,13 +272,6 @@ class AbuseFilterViewDiff extends AbuseFilterView {
return $html;
}
/**
* @param $msg
* @param $old
* @param $new
* @param string $format
* @return string
*/
function getSimpleRow( $msg, $old, $new, $format = 'wikitext' ) {
$row = '';
@ -323,12 +300,6 @@ class AbuseFilterViewDiff extends AbuseFilterView {
return Xml::tags( 'tr', null, $row ) . "\n";
}
/**
* @param $msg
* @param $old
* @param $new
* @return string
*/
function getMultiLineRow( $msg, $old, $new ) {
if ( !is_array( $old ) ) {
$old = explode( "\n", preg_replace( "/\\\r\\\n?/", "\n", $old ) );

View file

@ -240,12 +240,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
}
}
/**
* @param $error
* @param $filter
* @param $history_id null
* @return bool|String
*/
function buildFilterEditor( $error, $filter, $history_id = null ) {
if ( $filter === null ) {
return false;
@ -255,13 +249,14 @@ class AbuseFilterViewEdit extends AbuseFilterView {
$out = $this->getOutput();
$lang = $this->getLanguage();
$user = $this->getUser();
$sk = $this->getSkin();
// Load from request OR database.
list( $row, $actions ) = $this->loadRequest( $filter, $history_id );
if ( !$row ) {
$out->addWikiMsg( 'abusefilter-edit-badfilter' );
$out->addHTML( Linker::link( $this->getTitle(), wfMsg( 'abusefilter-return' ) ) );
$out->addHTML( $sk->link( $this->getTitle(), wfMsg( 'abusefilter-return' ) ) );
return;
}
@ -306,7 +301,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
$count_display = wfMsgExt( 'abusefilter-hitcount', array( 'parseinline' ),
$lang->formatNum( $count )
);
$hitCount = Linker::makeKnownLinkObj(
$hitCount = $sk->makeKnownLinkObj(
SpecialPage::getTitleFor( 'AbuseLog' ),
$count_display,
'wpSearchFilter=' . $row->af_id
@ -392,7 +387,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
if ( $filter != 'new' && $user->isAllowed( 'abusefilter-revert' ) ) {
$tools .= Xml::tags(
'p', null,
Linker::link(
$sk->link(
$this->getTitle( 'revert/' . $filter ),
wfMsg( 'abusefilter-edit-revert' )
)
@ -403,15 +398,15 @@ class AbuseFilterViewEdit extends AbuseFilterView {
// Test link
$tools .= Xml::tags(
'p', null,
Linker::link(
$sk->link(
$this->getTitle( "test/$filter" ),
wfMsgExt( 'abusefilter-edit-test-link', 'parseinline' )
)
);
// Last modification details
$userLink =
Linker::userLink( $row->af_user, $row->af_user_text ) .
Linker::userToolLinks( $row->af_user, $row->af_user_text );
$sk->userLink( $row->af_user, $row->af_user_text ) .
$sk->userToolLinks( $row->af_user, $row->af_user_text );
$userName = $row->af_user_text;
$fields['abusefilter-edit-lastmod'] =
wfMsgExt(
@ -426,7 +421,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
);
$history_display = wfMsgExt( 'abusefilter-edit-viewhistory', array( 'parseinline' ) );
$fields['abusefilter-edit-history'] =
Linker::makeKnownLinkObj( $this->getTitle( 'history/' . $filter ), $history_display );
$sk->makeKnownLinkObj( $this->getTitle( 'history/' . $filter ), $history_display );
}
// Add export
@ -468,11 +463,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
return $output;
}
/**
* @param $row
* @param $actions
* @return string
*/
function buildConsequenceEditor( $row, $actions ) {
global $wgAbuseFilterAvailableActions;
@ -491,12 +481,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
return $output;
}
/**
* @param $action
* @param $set
* @param $parameters
* @return string
*/
function buildConsequenceSelector( $action, $set, $parameters ) {
global $wgAbuseFilterAvailableActions;
@ -657,10 +641,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
}
}
/**
* @param $warnMsg
* @return string
*/
function getExistingSelector( $warnMsg ) {
$existingSelector = new XmlSelect(
'wpFilterWarnMessage',
@ -698,10 +678,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
return $existingSelector->getHTML();
}
/**
* @param $id
* @return array|null
*/
function loadFilterData( $id ) {
if ( $id == 'new' ) {
$obj = new stdClass;
@ -761,11 +737,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
return array( $row, $actions );
}
/**
* @param $filter
* @param null $history_id
* @return array|null
*/
function loadRequest( $filter, $history_id = null ) {
static $row = null;
static $actions = null;
@ -866,10 +837,6 @@ class AbuseFilterViewEdit extends AbuseFilterView {
return array( $row, $actions );
}
/**
* @param $id
* @return array
*/
function loadHistoryItem( $id ) {
$dbr = wfGetDB( DB_SLAVE );

View file

@ -118,6 +118,7 @@ class AbuseFilterHistoryPager extends TablePager {
}
function formatValue( $name, $value ) {
$sk = $this->getSkin();
$lang = $this->getLanguage();
$row = $this->mCurrentRow;
@ -129,12 +130,12 @@ class AbuseFilterHistoryPager extends TablePager {
case 'afh_timestamp':
$title = SpecialPage::getTitleFor( 'AbuseFilter',
'history/' . $row->afh_filter . '/item/' . $row->afh_id );
$formatted = Linker::link( $title, $lang->timeanddate( $row->afh_timestamp, true ) );
$formatted = $sk->link( $title, $lang->timeanddate( $row->afh_timestamp, true ) );
break;
case 'afh_user_text':
$formatted =
Linker::userLink( $row->afh_user, $row->afh_user_text ) . ' ' .
Linker::userToolLinks( $row->afh_user, $row->afh_user_text );
$sk->userLink( $row->afh_user, $row->afh_user_text ) . ' ' .
$sk->userToolLinks( $row->afh_user, $row->afh_user_text );
break;
case 'afh_public_comments':
$formatted = $this->getOutput()->parse( $value );
@ -157,12 +158,12 @@ class AbuseFilterHistoryPager extends TablePager {
break;
case 'afh_filter':
$title = $this->mPage->getTitle( strval( $value ) );
$formatted = Linker::link( $title, $value );
$formatted = $sk->link( $title, $value );
break;
case 'afh_id':
$title = $this->mPage->getTitle(
'history/' . $row->afh_filter . "/diff/prev/$value" );
$formatted = Linker::link( $title, wfMsgExt( 'abusefilter-history-diff', 'parseinline' ) );
$formatted = $sk->link( $title, wfMsgExt( 'abusefilter-history-diff', 'parseinline' ) );
break;
default:
$formatted = "Unable to format $name";

View file

@ -9,6 +9,7 @@ class AbuseFilterViewRevert extends AbuseFilterView {
$user = $this->getUser();
$out = $this->getOutput();
$sk = $this->getSkin();
if ( !$user->isAllowed( 'abusefilter-revert' ) ) {
throw new PermissionsError( 'abusefilter-revert' );
@ -66,11 +67,11 @@ class AbuseFilterViewRevert extends AbuseFilterView {
array( 'parseinline', 'replaceafter' ),
array(
$lang->timeanddate( $result['timestamp'], true ),
Linker::userLink( $result['userid'], $result['user'] ),
$sk->userLink( $result['userid'], $result['user'] ),
$result['action'],
Linker::link( $result['title'] ),
$sk->link( $result['title'] ),
$lang->commaList( $displayActions ),
Linker::link(
$sk->link(
SpecialPage::getTitleFor( 'AbuseLog' ),
wfMsgNoTrans( 'abusefilter-log-detailslink' ),
array(),
@ -89,7 +90,7 @@ class AbuseFilterViewRevert extends AbuseFilterView {
Html::hidden( 'title', $this->getTitle( "revert/$filter" )->getPrefixedText() ) .
Html::hidden( 'wpPeriodStart', $this->origPeriodStart ) .
Html::hidden( 'wpPeriodEnd', $this->origPeriodEnd ) .
Xml::inputLabel(
Html::inputLabel(
wfMsg( 'abusefilter-revert-reasonfield' ),
'wpReason', 'wpReason', 45
) .

View file

@ -73,7 +73,6 @@ class ApiQueryAbuseLog extends ApiQueryBase {
$this->addFieldsIf( 'afl_var_dump', $fld_details );
$this->addFieldsIf( 'afl_actions', $fld_result );
$this->addFieldsIf( 'afl_deleted', $fld_hidden );
$this->addFields( 'afl_rev_id' );
if ( $fld_filter ) {
$this->addTables( 'abuse_filter' );
@ -111,11 +110,6 @@ class ApiQueryAbuseLog extends ApiQueryBase {
$this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->afl_timestamp ) );
break;
}
if ( SpecialAbuseLog::isHidden($row) &&
!SpecialAbuseLog::canSeeHidden( $user )
) {
continue;
}
$entry = array();
if ( $fld_ids ) {
$entry['id'] = intval( $row->afl_id );
@ -153,10 +147,7 @@ class ApiQueryAbuseLog extends ApiQueryBase {
}
if ( $fld_hidden ) {
$val = SpecialAbuseLog::isHidden($row);
if ( $val ) {
$entry['hidden'] = $val;
}
$entry['hidden'] = $row->afl_deleted;
}
if ( $entry ) {

View file

@ -1,10 +0,0 @@
-- Store the ID of successful actions in the abuse_filter_log table.
ALTER TABLE /*_*/abuse_filter_log
ADD COLUMN afl_rev_id int unsigned;
ALTER TABLE /*_*/abuse_filter_log
ADD KEY (afl_rev_id);
ALTER TABLE /*_*/abuse_filter_log
ADD COLUMN afl_log_id int unsigned;
ALTER TABLE /*_*/abuse_filter_log
ADD KEY (afl_log_id);

View file

@ -111,10 +111,6 @@ class SpecialAbuseLog extends SpecialPage {
$this->getOutput()->addHTML( $output );
}
/**
* @param $id
* @return mixed
*/
function showHideForm( $id ) {
if ( !$this->getUser()->isAllowed( 'abusefilter-hide-log' ) ) {
$this->getOutput()->addWikiMsg( 'abusefilter-log-hide-forbidden' );
@ -161,10 +157,6 @@ class SpecialAbuseLog extends SpecialPage {
$form->show();
}
/**
* @param $fields
* @return bool
*/
function saveHideForm( $fields ) {
$logid = $this->getRequest()->getVal( 'hide' );
@ -231,10 +223,6 @@ class SpecialAbuseLog extends SpecialPage {
}
}
/**
* @param $id
* @return mixed
*/
function showDetails( $id ) {
$out = $this->getOutput();
@ -264,7 +252,7 @@ class SpecialAbuseLog extends SpecialPage {
return;
}
if ( $this->isHidden( $row ) && !self::canSeeHidden() ) {
if ( $row->afl_deleted && !self::canSeeHidden() ) {
$out->addWikiMsg( 'abusefilter-log-details-hidden' );
return;
}
@ -345,8 +333,6 @@ class SpecialAbuseLog extends SpecialPage {
}
/**
* @param $filter_id null
* @param $filter_hidden null
* @return bool
*/
static function canSeeDetails( $filter_id = null, $filter_hidden = null ) {
@ -380,49 +366,25 @@ class SpecialAbuseLog extends SpecialPage {
return $wgUser->isAllowed( 'abusefilter-hidden-log' );
}
/**
* @param $row
* @param $li bool
* @return String
*/
function formatRow( $row, $li = true ) {
$user = $this->getUser();
$sk = $this->getSkin();
$lang = $this->getLanguage();
$actionLinks = array();
$title = Title::makeTitle( $row->afl_namespace, $row->afl_title );
$diffLink = false;
if ( self::isHidden($row) && ! $this->canSeeHidden() ) {
return '';
}
if ( !$row->afl_wiki ) {
$pageLink = Linker::link( $title );
if ( $row->afl_rev_id ) {
$diffLink = Linker::link( $title,
wfMessage('abusefilter-log-diff')->parse(), array(),
array( 'diff' => 'prev', 'oldid' => $row->afl_rev_id ) );
}
$pageLink = $sk->link( $title );
} else {
$pageLink = WikiMap::makeForeignLink( $row->afl_wiki, $row->afl_title );
if ( $row->afl_rev_id ) {
$diffUrl = WikiMap::getForeignURL( $row->afl_wiki, $row->afl_title );
$diffUrl = wfAppendQuery( $diffUrl,
array( 'diff' => 'prev', 'oldid' => $row->afl_rev_id ) );
$diffLink = Linker::makeExternalLink( $diffUrl,
wfMessage('abusefilter-log-diff')->parse() );
}
}
if ( !$row->afl_wiki ) {
// Local user
$userLink = Linker::userLink( $row->afl_user, $row->afl_user_text ) .
Linker::userToolLinks( $row->afl_user, $row->afl_user_text );
$userLink = $sk->userLink( $row->afl_user, $row->afl_user_text ) .
$sk->userToolLinks( $row->afl_user, $row->afl_user_text );
} else {
$userLink = WikiMap::foreignUserLink( $row->afl_wiki, $row->afl_user_text );
$userLink .= ' (' . WikiMap::getWikiName( $row->afl_wiki ) . ')';
@ -458,11 +420,11 @@ class SpecialAbuseLog extends SpecialPage {
if ( self::canSeeDetails( $row->afl_filter, $filter_hidden ) ) {
$examineTitle = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/log/' . $row->afl_id );
$detailsLink = Linker::makeKnownLinkObj(
$detailsLink = $sk->makeKnownLinkObj(
$this->getTitle($row->afl_id),
wfMsg( 'abusefilter-log-detailslink' )
);
$examineLink = Linker::link(
$examineLink = $sk->link(
$examineTitle,
wfMsgExt( 'abusefilter-changeslist-examine', 'parseinline' ),
array()
@ -471,11 +433,8 @@ class SpecialAbuseLog extends SpecialPage {
$actionLinks[] = $detailsLink;
$actionLinks[] = $examineLink;
if ($diffLink)
$actionLinks[] = $diffLink;
if ( $user->isAllowed( 'abusefilter-hide-log' ) ) {
$hideLink = Linker::link(
$hideLink = $sk->link(
$this->getTitle(),
wfMsg( 'abusefilter-log-hidelink' ),
array(),
@ -492,11 +451,11 @@ class SpecialAbuseLog extends SpecialPage {
'Special:AbuseFilter/' . $globalIndex );
$linkText = wfMessage( 'abusefilter-log-detailedentry-global' )->numParams( $globalIndex )->escaped();
$filterLink = Linker::makeExternalLink( $globalURL, $linkText );
$filterLink = $sk->makeExternalLink( $globalURL, $linkText );
} else {
$title = SpecialPage::getTitleFor( 'AbuseFilter', $row->afl_filter );
$linkText = wfMessage( 'abusefilter-log-detailedentry-local' )->numParams( $row->afl_filter )->escaped();
$filterLink = Linker::link( $title, $linkText );
$filterLink = $sk->link( $title, $linkText );
}
$description = wfMsgExt( 'abusefilter-log-detailedentry-meta',
array( 'parseinline', 'replaceafter' ),
@ -519,19 +478,16 @@ class SpecialAbuseLog extends SpecialPage {
$timestamp,
$userLink,
$row->afl_action,
Linker::link( $title ),
$sk->link( $title ),
$actions_taken,
$parsed_comments
)
);
}
if ( $this->isHidden($row) === true ) {
if ( $row->afl_deleted ) {
$description .= ' '.
wfMsgExt( 'abusefilter-log-hidden', 'parseinline' );
} elseif ( $this->isHidden($row) === 'implicit' ) {
$description .= ' '.
wfMsgExt( 'abusefilter-log-hidden-implicit', 'parseinline' );
}
return $li ? Xml::tags( 'li', null, $description ) : $description;
@ -551,25 +507,6 @@ class SpecialAbuseLog extends SpecialPage {
return $notDeletedCond;
}
/**
* Given a log entry row, decides whether or not it can be viewed by the public.
*
* @param $row object The abuse_filter_log row object.
*
* @return Mixed true if the item is explicitly hidden, false if it is not.
* The string 'implicit' if it is hidden because the corresponding revision is hidden.
*/
public static function isHidden( $row ) {
if ( $row->afl_rev_id ) {
$revision = Revision::newFromId( $row->afl_rev_id );
if ( $revision && $revision->getVisibility() != 0 ) {
return 'implicit';
}
}
return (bool)$row->afl_deleted;
}
}
class AbuseLogPager extends ReverseChronologicalPager {
@ -584,11 +521,6 @@ class AbuseLogPager extends ReverseChronologicalPager {
*/
public $mConds;
/**
* @param $form
* @param array $conds
* @param bool $details
*/
function __construct( $form, $conds = array(), $details = false ) {
$this->mForm = $form;
$this->mConds = $conds;