diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php index 1eba147da..c213fb6b5 100644 --- a/AbuseFilter.class.php +++ b/AbuseFilter.class.php @@ -1869,7 +1869,7 @@ class AbuseFilter { // Add user data if the account was created by a registered user if ( $row->rc_user && $name != $row->rc_user_text ) { $user = User::newFromName( $row->rc_user_text ); - $vars->addHolder( self::generateUserVars( $user ) ); + $vars->addHolders( self::generateUserVars( $user ) ); } $vars->setVar( 'accountname', $name ); @@ -1891,9 +1891,11 @@ class AbuseFilter { $user->setName( $row->rc_user_text ); } - $vars->addHolder( self::generateUserVars( $user ) ); + $vars->addHolders( + self::generateUserVars( $user ), + self::generateTitleVars( $title, 'ARTICLE' ) + ); - $vars->addHolder( self::generateTitleVars( $title, 'ARTICLE' ) ); $vars->setVar( 'ACTION', 'edit' ); $vars->setVar( 'SUMMARY', $row->rc_comment ); $vars->setVar( 'minor_edit', $row->rc_minor ); @@ -1908,7 +1910,7 @@ class AbuseFilter { $vars->setVar( 'old_wikitext', '' ); } - $vars->addHolder( self::getEditVars( $title ) ); + $vars->addHolders( self::getEditVars( $title ) ); return $vars; } diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php index 469036849..5843457a6 100644 --- a/AbuseFilter.hooks.php +++ b/AbuseFilter.hooks.php @@ -114,8 +114,10 @@ class AbuseFilterHooks { return true; } - $vars->addHolder( AbuseFilter::generateUserVars( $user ) ); - $vars->addHolder( AbuseFilter::generateTitleVars( $title , 'ARTICLE' ) ); + $vars->addHolders( + AbuseFilter::generateUserVars( $user ), + AbuseFilter::generateTitleVars( $title , 'ARTICLE' ) + ); $vars->setVar( 'action', 'edit' ); $vars->setVar( 'summary', $summary ); @@ -126,7 +128,7 @@ class AbuseFilterHooks { // TODO: set old_content and new_content vars, use them - $vars->addHolder( AbuseFilter::getEditVars( $title, $page ) ); + $vars->addHolders( AbuseFilter::getEditVars( $title, $page ) ); $filter_result = AbuseFilter::filterAction( $vars, $title ); @@ -242,12 +244,10 @@ class AbuseFilterHooks { $vars = new AbuseFilterVariableHolder; global $wgUser; - $vars->addHolder( - AbuseFilterVariableHolder::merge( - AbuseFilter::generateUserVars( $wgUser ), - AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ), - AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) - ) + $vars->addHolders( + AbuseFilter::generateUserVars( $wgUser ), + AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ), + AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) ); $vars->setVar( 'SUMMARY', $reason ); $vars->setVar( 'ACTION', 'move' ); @@ -270,8 +270,11 @@ class AbuseFilterHooks { $vars = new AbuseFilterVariableHolder; global $wgUser; - $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) ); - $vars->addHolder( AbuseFilter::generateTitleVars( $article->getTitle(), 'ARTICLE' ) ); + $vars->addHolders( + AbuseFilter::generateUserVars( $wgUser ), + AbuseFilter::generateTitleVars( $article->getTitle(), 'ARTICLE' ) + ); + $vars->setVar( 'SUMMARY', $reason ); $vars->setVar( 'ACTION', 'delete' ); @@ -302,7 +305,7 @@ class AbuseFilterHooks { // new users won't be exposed global $wgUser; if ( $wgUser->getId() ) { - $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) ); + $vars->addHolders( AbuseFilter::generateUserVars( $wgUser ) ); } $vars->setVar( 'ACTION', $autocreate ? 'autocreateaccount' : 'createaccount' ); @@ -500,11 +503,9 @@ class AbuseFilterHooks { global $wgUser; $title = Title::makeTitle( NS_FILE, $saveName ); - $vars->addHolder( - AbuseFilterVariableHolder::merge( - AbuseFilter::generateUserVars( $wgUser ), - AbuseFilter::generateTitleVars( $title, 'FILE' ) - ) + $vars->addHolders( + AbuseFilter::generateUserVars( $wgUser ), + AbuseFilter::generateTitleVars( $title, 'FILE' ) ); $vars->setVar( 'ACTION', 'upload' ); diff --git a/AbuseFilter.parser.php b/AbuseFilter.parser.php index 84e764fa6..dc03761dc 100644 --- a/AbuseFilter.parser.php +++ b/AbuseFilter.parser.php @@ -698,7 +698,7 @@ class AbuseFilterParser { $this->setVar( $name, $var ); } } elseif ( $vars instanceof AbuseFilterVariableHolder ) { - $this->mVars->addHolder( $vars ); + $this->mVars->addHolders( $vars ); } } diff --git a/AbuseFilterVariableHolder.php b/AbuseFilterVariableHolder.php index 2c43451fd..4089b5e17 100644 --- a/AbuseFilterVariableHolder.php +++ b/AbuseFilterVariableHolder.php @@ -1,6 +1,8 @@ addHolder( $addHolder ); - } + call_user_func_array( array( $newHolder, "addHolders" ), func_get_args() ); return $newHolder; } @@ -62,12 +61,26 @@ class AbuseFilterVariableHolder { /** * @param $addHolder * @throws MWException + * @deprecated use addHolders() instead */ - function addHolder( $addHolder ) { - if ( !is_object( $addHolder ) ) { - throw new MWException( 'Invalid argument to AbuseFilterVariableHolder::addHolder' ); + public function addHolder( $addHolder ) { + $this->addHolders( $addHolder ); + } + + /** + * Merge any number of holders given as arguments into this holder. + * + * @throws MWException + */ + public function addHolders() { + $holders = func_get_args(); + + foreach ( $holders as $addHolder ) { + if ( !is_object( $addHolder ) ) { + throw new MWException( 'Invalid argument to AbuseFilterVariableHolder::addHolders' ); + } + $this->mVars = array_merge( $this->mVars, $addHolder->mVars ); } - $this->mVars = array_merge( $this->mVars, $addHolder->mVars ); } function __wakeup() {