r48042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48041‎ | r48042 | r48043 >
Date:02:43, 5 March 2009
Author:werdna
Status:ok
Tags:
Comment:
Add an interface for extensions to add variables into the variable list (only for ones generated for filtering, for now). Includes an implementation in the TorBlock extension
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)
  • /trunk/extensions/TorBlock/TorBlock.class.php (modified) (history)
  • /trunk/extensions/TorBlock/TorBlock.i18n.php (modified) (history)
  • /trunk/extensions/TorBlock/TorBlock.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TorBlock/TorBlock.i18n.php
@@ -17,6 +17,7 @@
1818 'right-torunblocked' => 'Bypass automatic blocks of tor exit nodes',
1919 'tag-tor-description' => 'If this tag is set, an edit was made from a Tor exit node.',
2020 'tag-tor' => 'Made through tor',
 21+ 'abusefilter-edit-builder-vars-tor-exit-node' => 'Whether or not the change was made through a tor exit node.',
2122 );
2223
2324 /** Message documentation (Message documentation)
Index: trunk/extensions/TorBlock/TorBlock.php
@@ -35,6 +35,8 @@
3636 $wgHooks['AutopromoteCondition'][] = 'TorBlock::onAutopromoteCondition';
3737 $wgHooks['RecentChange_save'][] = 'TorBlock::onRecentChangeSave';
3838 $wgHooks['ListDefinedTags'][] = 'TorBlock::onListDefinedTags';
 39+$wgHooks['AbuseFilter-filterAction'][] = 'TorBlock::onAbuseFilterFilterAction';
 40+$wgHooks['AbuseFilter-builder'][] = 'TorBlock::onAbuseFilterBuilder';
3941
4042 // Define new autopromote condition
4143 define('APCOND_TOR', 'tor'); // Numbers won't work, we'll get collisions
Index: trunk/extensions/TorBlock/TorBlock.class.php
@@ -40,6 +40,17 @@
4141
4242 return true;
4343 }
 44+
 45+ public static function onAbuseFilterFilterAction( &$vars, $title ) {
 46+ $vars->setVar( 'tor_exit_node', self::isExitNode() ? 1 : 0 );
 47+ return true;
 48+ }
 49+
 50+ public static function onAbuseFilterBuilder( &$builder ) {
 51+ wfLoadExtensionMessages( 'TorBlock' );
 52+ $builder['vars']['tor_exit_node'] = 'tor-exit-node';
 53+ return true;
 54+ }
4455
4556 public static function getExitNodes() {
4657 if (is_array(self::$mExitNodes)) {
Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -685,7 +685,8 @@
686686
687687 protected function getVarValue( $var ) {
688688 $var = strtolower($var);
689 - if ( ! array_key_exists( $var, AbuseFilter::$builderValues['vars'] ) ) {
 689+ $builderValues = AbuseFilter::getBuilderValues();
 690+ if ( ! array_key_exists( $var, $builderValues['vars'] ) ) {
690691 // If the variable is invalid, throw an exception
691692 throw new AFPUserVisibleException( 'unrecognisedvar',
692693 $this->mCur->pos,
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -119,6 +119,17 @@
120120 return $vars;
121121 }
122122
 123+ public static function getBuilderValues() {
 124+ static $realValues = null;
 125+
 126+ if ($realValues) return $realValues;
 127+
 128+ $realValues = self::$builderValues;
 129+ wfRunHooks( 'AbuseFilter-builder', array( &$realValues ) );
 130+
 131+ return $realValues;
 132+ }
 133+
123134 public static function ajaxCheckSyntax( $filter ) {
124135 wfLoadExtensionMessages( 'AbuseFilter' );
125136
@@ -424,6 +435,9 @@
425436
426437 public static function filterAction( $vars, $title ) {
427438 global $wgUser,$wgMemc;
 439+
 440+ // Add vars from extensions
 441+ wfRunHooks( 'AbuseFilter-filterAction', array( &$vars, $title ) );
428442
429443 $dbr = wfGetDB( DB_SLAVE );
430444
@@ -940,7 +954,7 @@
941955
942956 $rules = Xml::textarea( $textName, $rules );
943957
944 - $dropDown = self::$builderValues;
 958+ $dropDown = self::getBuilderValues();
945959
946960 // Generate builder drop-down
947961 $builder = '';
@@ -1221,7 +1235,8 @@
12221236 // I don't want to change the names of the pre-existing messages
12231237 // describing the variables, nor do I want to rewrite them, so I'm just
12241238 // mapping the variable names to builder messages with a pre-existing array.
1225 - $variableMessageMappings = self::$builderValues['vars'];
 1239+ $variableMessageMappings = self::getBuilderValues();
 1240+ $variableMessageMappings = $variableMessageMappings['vars'];
12261241
12271242 $output .=
12281243 Xml::openElement( 'table', array( 'class' => 'mw-abuselog-details' ) ) .

Status & tagging log