r47829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47828‎ | r47829 | r47830 >
Date:12:15, 26 February 2009
Author:werdna
Status:ok
Tags:
Comment:
Improve AbuseFilter performance by implementing lazy initialisation of computed variables.
This has been done by replacing simple associative arrays with an AbuseFilterVariableHolder, which recognises helper classes called AFComputedVariables.
Computation may occur during the abuse filter analysis, or later when testing and reviewing filters.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.hooks.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewExamine.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -337,7 +337,7 @@
338338 $this->mParams = array();
339339 $this->mCode = '';
340340 $this->mTokens = array();
341 - $this->mVars = array();
 341+ $this->mVars = new AbuseFilterVariableHolder;
342342 $this->mPos = 0;
343343 }
344344
@@ -350,17 +350,19 @@
351351 return true;
352352 }
353353
354 - public function setVar( $name, $var ) {
 354+ public function setVar( $name, $value ) {
355355 $name = strtolower($name);
356 - $this->mVars[$name] = AFPData::newFromPHPVar( $var );
 356+ $this->mVars->setVar( $name, $value );
357357 }
358358
359359 public function setVars( $vars ) {
360 - wfProfileIn( __METHOD__ );
361 - foreach( $vars as $name => $var ) {
362 - $this->setVar( $name, $var );
 360+ if ( is_array( $vars ) ) {
 361+ foreach( $vars as $name => $var ) {
 362+ $this->setVar( $name, $var );
 363+ }
 364+ } elseif ( $vars instanceof AbuseFilterVariableHolder ) {
 365+ $this->mVars->addHolder( $vars );
363366 }
364 - wfProfileOut( __METHOD__ );
365367 }
366368
367369 protected function move( ) {
@@ -643,20 +645,7 @@
644646 switch( $this->mCur->type ) {
645647 case AFPToken::TID:
646648 $var = strtolower($tok);
647 - if( isset( $this->mVars[$var] ) ) {
648 - $result = $this->mVars[$var];
649 - } elseif (
650 - array_key_exists( strtolower($var),
651 - AbuseFilter::$builderValues['vars'] )
652 - ) {
653 - // If the variable is valid but not set, return null
654 - $result = new AFPData();
655 - } else {
656 - // If the variable is invalid, throw an exception
657 - throw new AFPUserVisibleException( 'unrecognisedvar',
658 - $this->mCur->pos,
659 - array( $var ) );
660 - }
 649+ $result = $this->getVarValue( $var );
661650 break;
662651 case AFPToken::TString:
663652 $result = new AFPData( AFPData::DString, $tok );
@@ -694,6 +683,18 @@
695684 wfProfileOut( __METHOD__ );
696685 }
697686
 687+ protected function getVarValue( $var ) {
 688+ $var = strtolower($var);
 689+ if ( ! array_key_exists( $var, AbuseFilter::$builderValues['vars'] ) ) {
 690+ // If the variable is invalid, throw an exception
 691+ throw new AFPUserVisibleException( 'unrecognisedvar',
 692+ $this->mCur->pos,
 693+ array( $var ) );
 694+ } else {
 695+ return $this->mVars->getVar( $var );
 696+ }
 697+ }
 698+
698699 /* End of levels */
699700
700701 static function nextToken( $code, $offset ) {
Index: trunk/extensions/AbuseFilter/AbuseFilter.php
@@ -44,6 +44,9 @@
4545 $wgAutoloadClasses['AbuseFilterViewTestBatch'] = "$dir/Views/AbuseFilterViewTestBatch.php";
4646 $wgAutoloadClasses['AbuseFilterViewExamine'] = "$dir/Views/AbuseFilterViewExamine.php";
4747 $wgAutoloadClasses['AbuseFilterChangesList'] = "$dir/Views/AbuseFilterViewExamine.php";
 48+$wgAutoloadClasses['AbuseFilterVariableHolder'] = "$dir/AbuseFilterVariableHolder.php";
 49+$wgAutoloadClasses['AFComputedVariable'] = "$dir/AbuseFilterVariableHolder.php";
 50+$wgAutoloadClasses['AFPData'] = "$dir/AbuseFilter.parser.php";
4851
4952 $wgSpecialPages['AbuseLog'] = 'SpecialAbuseLog';
5053 $wgSpecialPages['AbuseFilter'] = 'SpecialAbuseFilter';
@@ -55,7 +58,6 @@
5659 $wgHooks['AbortMove'][] = 'AbuseFilterHooks::onAbortMove';
5760 $wgHooks['AbortNewAccount'][] = 'AbuseFilterHooks::onAbortNewAccount';
5861 $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete';
59 -$wgHooks['AbortDeleteQueueNominate'][] = 'AbuseFilterHooks::onAbortDeleteQueueNominate';
6062 $wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave';
6163 $wgHooks['ListDefinedTags'][] = 'AbuseFilterHooks::onListDefinedTags';
6264 $wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onLoadExtensionSchemaUpdates';
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewExamine.php
@@ -126,7 +126,7 @@
127127 }
128128
129129 $vars = unserialize( $row->afl_var_dump );
130 -
 130+
131131 $this->showExaminer( $vars );
132132 }
133133
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -96,23 +96,25 @@
9797 'article_restrictions_edit' => 'restrictions-edit',
9898 'article_restrictions_move' => 'restrictions-move',
9999 'article_recent_contributors' => 'recent-contributors',
 100+ 'old_text' => 'old-text-stripped',
 101+ 'old_html' => 'old-html',
 102+ 'old_links' => 'old-links',
100103 ),
101104 );
102105
103106 public static function generateUserVars( $user ) {
104 - $vars = array();
 107+ $vars = new AbuseFilterVariableHolder;
105108
106 - // Load all the data we want.
107 - $user->load();
 109+ $vars->setLazyLoadVar( 'user_editcount', 'simple-user-accessor',
 110+ array( 'user' => $user->getName(), 'method' => 'getEditCount' ) );
 111+ $vars->setVar( 'user_name', $user->getName() );
 112+ $vars->setLazyLoadVar( 'user_emailconfirm', 'simple-user-accessor',
 113+ array( 'user' => $user->getName(), 'method' => 'getEmailAuthenticationTimestamp' ) );
108114
109 - $vars['USER_EDITCOUNT'] = $user->getEditCount();
110 - $vars['USER_AGE'] = time() - wfTimestampOrNull( TS_UNIX, $user->getRegistration() );
111 - $vars['USER_NAME'] = $user->getName();
112 - $vars['USER_GROUPS'] = implode(',', $user->getEffectiveGroups() );
113 - $vars['USER_EMAILCONFIRM'] = $user->getEmailAuthenticationTimestamp();
 115+ $vars->setLazyLoadVar( 'user_age', 'user-age',
 116+ array( 'user' => $user->getName(), 'asof' => wfTimestampNow() ) );
 117+ $vars->setLazyLoadVar( 'user_groups', 'user-groups', array( 'user' => $user->getName() ) );
114118
115 - // More to come
116 -
117119 return $vars;
118120 }
119121
@@ -181,36 +183,34 @@
182184 }
183185
184186 public static function generateTitleVars( $title, $prefix ) {
185 - $vars = array();
 187+ $vars = new AbuseFilterVariableHolder;
186188
187189 if (!$title)
188190 return array();
189191
190 - $vars[$prefix."_ARTICLEID"] = $title->getArticleId();
191 - $vars[$prefix."_NAMESPACE"] = $title->getNamespace();
192 - $vars[$prefix."_TEXT"] = $title->getText();
193 - $vars[$prefix."_PREFIXEDTEXT"] = $title->getPrefixedText();
 192+ $vars->setVar( $prefix."_ARTICLEID", $title->getArticleId() );
 193+ $vars->setVar( $prefix."_NAMESPACE", $title->getNamespace() );
 194+ $vars->setVar( $prefix."_TEXT", $title->getText() );
 195+ $vars->setVar( $prefix."_PREFIXEDTEXT", $title->getPrefixedText() );
194196
195197 // Use restrictions.
196 - if ($title->mRestrictionsLoaded) {
197 - // Don't bother if they're unloaded
198 - foreach( $title->mRestrictions as $action => $rights ) {
199 - $rights = count($rights) ? $rights : array();
200 - $vars[$prefix."_RESTRICTIONS_".$action] = implode(',', $rights );
201 - }
 198+ global $wgRestrictionTypes;
 199+ foreach( $wgRestrictionTypes as $action ) {
 200+ $vars->setLazyLoadVar( "{$prefix}_restrictions_$action", 'get-page-restrictions',
 201+ array( 'title' => $title->getText(),
 202+ 'namespace' => $title->getNamespace(),
 203+ 'action' => $action
 204+ )
 205+ );
202206 }
203207
204 - // Find last 5 authors.
205 - $dbr = wfGetDB( DB_SLAVE );
206 - $res = $dbr->select( 'revision', 'distinct rev_user_text',
207 - array( 'rev_page' => $title->getArticleId() ), __METHOD__,
208 - array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 10 ) );
209 - $users = array();
210 - while ($user = $dbr->fetchRow($res)) {
211 - $users[] = $user[0];
212 - }
213 - $vars[$prefix."_RECENT_CONTRIBUTORS"] = implode(',', $users);
214 -
 208+ $vars->setLazyLoadVar( "{$prefix}_recent_contributors", 'load-recent-authors',
 209+ array(
 210+ 'cutoff' => wfTimestampNow(),
 211+ 'title' => $title->getText(),
 212+ 'namespace' => $title->getNamespace()
 213+ ) );
 214+
215215 return $vars;
216216 }
217217
@@ -446,7 +446,7 @@
447447 'afl_title' => $title->getDBKey(),
448448 'afl_ip' => wfGetIp() );
449449
450 - self::addLogEntries( $actions_taken, $log_template, $vars['ACTION'] );
 450+ self::addLogEntries( $actions_taken, $log_template, $vars->getVar( 'ACTION' )->toString() );
451451
452452 $error_msg = $error_msg == '' ? true : $error_msg;
453453
@@ -632,7 +632,8 @@
633633 global $wgUser;
634634
635635 $actionID = implode( '-', array(
636 - $title->getPrefixedText(), $wgUser->getName(), $vars['ACTION']
 636+ $title->getPrefixedText(), $wgUser->getName(),
 637+ $vars->getVar( 'ACTION' )->toString()
637638 ) );
638639
639640 AbuseFilter::$tagsToSet[$actionID] = $parameters;
@@ -1000,40 +1001,41 @@
10011002 }
10021003
10031004 public static function getEditVarsFromRCRow( $row ) {
1004 - $vars = array();
 1005+ $vars = new AbuseFilterVariableHolder;
10051006 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
10061007
10071008 if ($row->rc_user)
1008 - $user = User::newFromId( $row->rc_user );
 1009+ $user = User::newFromName( $row->rc_user_text );
10091010 else {
10101011 $user = new User;
10111012 $user->setName( $row->rc_user_text );
10121013 }
10131014
1014 - $vars = array_merge( $vars, self::generateUserVars( $user ) );
 1015+ $vars->addHolder( self::generateUserVars( $user ) );
10151016
1016 - $vars = array_merge( $vars, self::generateTitleVars( $title, 'ARTICLE' ) );
1017 - $vars['ACTION'] = 'edit';
1018 - $vars['SUMMARY'] = $row->rc_comment;
 1017+ $vars->addHolder( self::generateTitleVars( $title, 'ARTICLE' ) );
 1018+ $vars->setVar( 'ACTION', 'edit' );
 1019+ $vars->setVar( 'SUMMARY', $row->rc_comment );
10191020
1020 - $newRev = Revision::newFromId( $row->rc_this_oldid );
1021 - $new_text = $newRev->getText();
 1021+
 1022+ $vars->setLazyLoadVar( 'new_wikitext', 'revision-text-by-id',
 1023+ array( 'revid' => $row->rc_this_oldid ) );
10221024
10231025 if ($row->rc_last_oldid) {
1024 - $oldRev = Revision::newFromId( $row->rc_last_oldid );
1025 - $old_text = $oldRev->getText();
 1026+ $vars->setLazyLoadVar( 'old_wikitext', 'revision-text-by-id',
 1027+ array( 'revid' => $row->rc_last_oldid ) );
10261028 } else {
1027 - $old_text = '';
 1029+ $vars->setVar( 'old_wikitext', '' );
10281030 }
10291031
1030 - $vars = array_merge( $vars, self::getEditVars(
1031 - $title, $old_text, $new_text, null, $row->rc_this_oldid, $row->rc_last_oldid ) );
 1032+ $vars->addHolder( self::getEditVars(
 1033+ $title, $row->rc_this_oldid, $row->rc_last_oldid ) );
10321034
10331035 return $vars;
10341036 }
10351037
10361038 public static function getMoveVarsFromRCRow( $row ) {
1037 - $vars = array();
 1039+ $vars = new AbuseFilterVariableHolder;
10381040
10391041 if ($row->rc_user)
10401042 $user = User::newFromId( $row->rc_user );
@@ -1045,76 +1047,81 @@
10461048 $oldTitle = Title::makeTitle( $row->rc_namespace, $row->rc_title );
10471049 $newTitle = Title::newFromText( trim($row->rc_params) );
10481050
1049 - $vars = array_merge( $vars, AbuseFilter::generateUserVars( $user ),
 1051+ $vars = AbuseFilterVariableHolder::merge(
 1052+ $vars,
 1053+ AbuseFilter::generateUserVars( $user ),
10501054 AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ),
1051 - AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) );
 1055+ AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' )
 1056+ );
10521057
1053 - $vars['SUMMARY'] = $row->rc_comment;
1054 - $vars['ACTION'] = 'move';
 1058+ $vars->setVar( 'SUMMARY', $row->rc_comment );
 1059+ $vars->setVar( 'ACTION', 'move' );
10551060
10561061 return $vars;
10571062 }
10581063
1059 - public static function getEditVars( $title, $old_text, $new_text, $oldLinks = null,
1060 - $revid=null, $oldid=null )
 1064+ public static function getEditVars( $title )
10611065 {
1062 - $vars = array();
 1066+ $vars = new AbuseFilterVariableHolder;
10631067 $article = new Article( $title );
10641068
1065 - $vars['EDIT_DELTA'] = strlen($new_text) - strlen($old_text);
1066 - $vars['OLD_SIZE'] = strlen($old_text);
1067 - $diff = wfDiff( $old_text, $new_text );
1068 - $diff = trim( str_replace( '\No newline at end of file', '', $diff ) );
1069 - $vars['EDIT_DIFF'] = $diff;
1070 - $vars['NEW_SIZE'] = strlen($new_text);
 1069+ $vars->setLazyLoadVar( 'edit_diff', 'diff',
 1070+ array( 'oldtext-var' => 'old_text', 'newtext-var' => 'new_text' ) );
 1071+ $vars->setLazyLoadVar( 'new_size', 'length', array( 'length-var' => 'new_wikitext' ) );
 1072+ $vars->setLazyLoadVar( 'old_size', 'length', array( 'length-var' => 'old_wikitext' ) );
 1073+ $vars->setLazyLoadVar( 'edit_delta', 'subtract',
 1074+ array( 'val1-var' => 'new_size', 'val2-var' => 'old_size' ) );
10711075
1072 - $vars['OLD_WIKITEXT'] = $old_text;
1073 - $vars['NEW_WIKITEXT'] = $new_text;
1074 -
10751076 // Some more specific/useful details about the changes.
1076 - $diff_lines = explode( "\n", $diff );
1077 - $added_lines = array();
1078 - $removed_lines = array();
1079 - foreach( $diff_lines as $line ) {
1080 - if (strpos( $line, '-' )===0) {
1081 - $removed_lines[] = substr($line,1);
1082 - } elseif (strpos( $line, '+' )===0) {
1083 - $added_lines[] = substr($line,1);
1084 - }
1085 - }
1086 - $vars['ADDED_LINES'] = implode( "\n", $added_lines );
1087 - $vars['REMOVED_LINES'] = implode( "\n", $removed_lines );
 1077+ $vars->setLazyLoadVar( 'added_lines', 'diff-split',
 1078+ array( 'diff-var' => 'edit_diff', 'line-prefix' => '+' ) );
 1079+ $vars->setLazyLoadVar( 'removed_lines', 'diff-split',
 1080+ array( 'diff-var' => 'edit_diff', 'line-prefix' => '-' ) );
10881081
1089 - if ($oldLinks === null && $oldid) {
1090 - $oldInfo = $article->prepareTextForEdit( $old_text, $oldid );
1091 - $oldLinks = $oldInfo->output->getExternalLinks();
1092 - } elseif ($oldLinks === null) {
1093 - $oldLinks = array();
1094 - }
 1082+ // Links
 1083+ $vars->setLazyLoadVar( 'all_links', 'links-from-wikitext',
 1084+ array(
 1085+ 'namespace' => $title->getNamespace(),
 1086+ 'title' => $title->getText(),
 1087+ 'text-var' => 'new_wikitext'
 1088+ ) );
 1089+ $vars->setLazyLoadVar( 'old_links', 'links-from-wikitext-nonedit',
 1090+ array(
 1091+ 'namespace' => $title->getNamespace(),
 1092+ 'title' => $title->getText(),
 1093+ 'text-var' => 'old_wikitext'
 1094+ ) );
 1095+ $vars->setLazyLoadVar( 'added_links', 'link-diff-added',
 1096+ array( 'oldlink-var' => 'old_links', 'newlink-var' => 'all_links' ) );
 1097+ $vars->setLazyLoadVar( 'removed_links', 'link-diff-removed',
 1098+ array( 'oldlink-var' => 'old_links', 'newlink-var' => 'all_links' ) );
 1099+
 1100+ $vars->setLazyLoadVar( 'new_html', 'parse-wikitext',
 1101+ array(
 1102+ 'namespace' => $title->getNamespace(),
 1103+ 'title' => $title->getText(),
 1104+ 'wikitext-var' => 'new_wikitext'
 1105+ ) );
 1106+ $vars->setLazyLoadVar( 'new_text', 'strip-html',
 1107+ array( 'html-var' => 'new_html' ) );
 1108+ $vars->setLazyLoadVar( 'old_html', 'parse-wikitext-nonedit',
 1109+ array(
 1110+ 'namespace' => $title->getNamespace(),
 1111+ 'title' => $title->getText(),
 1112+ 'wikitext-var' => 'old_wikitext'
 1113+ ) );
 1114+ $vars->setLazyLoadVar( 'old_text', 'strip-html',
 1115+ array( 'html-var' => 'old_html' ) );
10951116
1096 - // Added links...
1097 - $editInfo = $article->prepareTextForEdit( $new_text, $revid );
1098 - $newLinks = array_keys( $editInfo->output->getExternalLinks() );
1099 - $vars['ALL_LINKS'] = implode( "\n", $newLinks );
1100 - $vars['ADDED_LINKS'] = implode( "\n",
1101 - array_diff( $newLinks, array_intersect( $newLinks, $oldLinks ) ) );
1102 - $vars['REMOVED_LINKS'] = implode( "\n",
1103 - array_diff( $oldLinks, array_intersect( $newLinks, $oldLinks ) ) );
1104 -
1105 - // Pull other useful stuff from $editInfo.
1106 - $newHTML = $editInfo->output->getText();
1107 -
1108 - // Kill the PP limit comments. Ideally we'd just remove these by not setting the
1109 - // parser option, but then we can't share a parse operation with the edit, which is bad.
1110 - $newHTML = preg_replace( '/<!--\s*NewPP limit report[^>]*-->\s*$/si', '', $newHTML );
1111 - $vars['NEW_HTML'] = $newHTML;
1112 -
1113 - $newText = $vars['NEW_TEXT'] = preg_replace( '/<[^>]+>/', '', $newHTML );
1114 -
11151117 return $vars;
11161118 }
11171119
11181120 public static function buildVarDumpTable( $vars ) {
 1121+ // Export all values
 1122+
 1123+ if ($vars instanceof AbuseFilterVariableHolder )
 1124+ $vars = $vars->exportAllVars();
 1125+
11191126 $output = '';
11201127
11211128 // I don't want to change the names of the pre-existing messages
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -264,7 +264,10 @@
265265 'abusefilter-edit-builder-vars-recent-contributors' => 'Last ten users to contribute to the page',
266266 'abusefilter-edit-builder-vars-restrictions-edit' => 'Edit protection level of the page',
267267 'abusefilter-edit-builder-vars-restrictions-move' => 'Move protection level of the page',
268 -
 268+ 'abusefilter-edit-builder-vars-old-text-stripped' => 'Old page text, stripped of any markup',
 269+ 'abusefilter-edit-builder-vars-old-links' => 'Links in the article, before the edit',
 270+ 'abusefilter-edit-builder-vars-old-html' => 'Old page wikitext, parsed into HTML',
 271+
269272 // Filter history
270273 'abusefilter-filter-log' => 'Recent filter changes',
271274 'abusefilter-history' => 'Change history for Abuse Filter #$1',
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -9,22 +9,26 @@
1010
1111 public static function onEditFilter($editor, $text, $section, &$error, $summary) {
1212 // Load vars
13 - $vars = array();
 13+ $vars = new AbuseFilterVariableHolder;
1414
1515 global $wgUser;
16 - $vars = array_merge( $vars, AbuseFilter::generateUserVars( $wgUser ) );
17 - $vars = array_merge( $vars, AbuseFilter::generateTitleVars( $editor->mTitle , 'ARTICLE' ));
18 - $vars['ACTION'] = 'edit';
19 - $vars['SUMMARY'] = $summary;
 16+ $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) );
 17+ $vars->addHolder( AbuseFilter::generateTitleVars( $editor->mTitle , 'ARTICLE' ) );
 18+ $vars->setVar( 'ACTION', 'edit' );
 19+ $vars->setVar( 'SUMMARY', $summary );
2020
21 - $old_text = $editor->getBaseRevision() ? $editor->getBaseRevision()->getText() : '';
22 - $new_text = $editor->textbox1;
23 - $oldLinks = self::getOldLinks( $editor->mTitle );
 21+ $vars->setLazyLoadVar( 'old_wikitext', 'revision-text-by-timestamp',
 22+ array(
 23+ 'timestamp' => $editor->edittime,
 24+ 'namespace' => $editor->mTitle->getNamespace(),
 25+ 'title' => $editor->mTitle->getText(),
 26+ ) );
 27+
 28+ $vars->setVar( 'new_wikitext', $editor->textbox1 );
2429
25 - $vars = array_merge( $vars,
26 - AbuseFilter::getEditVars( $editor->mTitle, $old_text, $new_text, $oldLinks ) );
 30+ $vars->addHolder( AbuseFilter::getEditVars( $editor->mTitle ) );
2731
28 - $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle, $oldLinks );
 32+ $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle );
2933
3034 if( $filter_result !== true ){
3135 global $wgOut;
@@ -35,22 +39,6 @@
3640 return true;
3741 }
3842
39 - /**
40 - * Load external links from the externallinks table
41 - * Stolen from ConfirmEdit
42 - */
43 - static function getOldLinks( $title ) {
44 - $dbr = wfGetDB( DB_SLAVE );
45 - $id = $title->getArticleId(); // should be zero queries
46 - $res = $dbr->select( 'externallinks', array( 'el_to' ),
47 - array( 'el_from' => $id ), __METHOD__ );
48 - $links = array();
49 - while ( $row = $dbr->fetchObject( $res ) ) {
50 - $links[] = $row->el_to;
51 - }
52 - return $links;
53 - }
54 -
5543 public static function onGetAutoPromoteGroups( $user, &$promote ) {
5644 global $wgMemc;
5745
@@ -64,14 +52,16 @@
6553 }
6654
6755 public static function onAbortMove( $oldTitle, $newTitle, $user, &$error, $reason ) {
68 - $vars = array();
 56+ $vars = new AbuseFilterVariableHolder;
6957
7058 global $wgUser;
71 - $vars = array_merge( $vars, AbuseFilter::generateUserVars( $wgUser ),
72 - AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ),
73 - AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) );
74 - $vars['SUMMARY'] = $reason;
75 - $vars['ACTION'] = 'move';
 59+ $vars->addHolder( AbuseFilterVariableHolder::merge(
 60+ AbuseFilter::generateUserVars( $wgUser ),
 61+ AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ),
 62+ AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' )
 63+ ) );
 64+ $vars->setVar( 'SUMMARY', $reason );
 65+ $vars->setVar( 'ACTION', 'move' );
7666
7767 $filter_result = AbuseFilter::filterAction( $vars, $oldTitle );
7868
@@ -81,13 +71,13 @@
8272 }
8373
8474 public static function onArticleDelete( &$article, &$user, &$reason, &$error ) {
85 - $vars = array();
 75+ $vars = new AbuseFilterVariableHolder;
8676
8777 global $wgUser;
88 - $vars = array_merge( $vars, AbuseFilter::generateUserVars( $wgUser ),
89 - AbuseFilter::generateTitleVars( $article->mTitle, 'ARTICLE' ) );
90 - $vars['SUMMARY'] = $reason;
91 - $vars['ACTION'] = 'delete';
 78+ $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) );
 79+ $vars->addHolder( AbuseFilter::generateTitleVars( $article->mTitle, 'ARTICLE' ) );
 80+ $vars->setVar( 'SUMMARY', $reason );
 81+ $vars->setVar( 'ACTION', 'delete' );
9282
9383 $filter_result = AbuseFilter::filterAction( $vars, $article->mTitle );
9484
@@ -104,8 +94,8 @@
10595 }
10696 $vars = array();
10797
108 - $vars['ACTION'] = 'createaccount';
109 - $vars['ACCOUNTNAME'] = $vars['USER_NAME'] = $user->getName();
 98+ $vars->setVar( 'ACTION', 'createaccount' );
 99+ $vars->setVar( 'ACCOUNTNAME', $user->getName() );
110100
111101 $filter_result = AbuseFilter::filterAction(
112102 $vars, SpecialPage::getTitleFor( 'Userlogin' ) );
@@ -114,22 +104,6 @@
115105
116106 return $filter_result == '' || $filter_result === true;
117107 }
118 -
119 - public static function onAbortDeleteQueueNominate( $user, $article, $queue, $reason, &$error ) {
120 - $vars = array();
121 -
122 - $vars = array_merge( $vars,
123 - AbuseFilter::generateUserVars( $user ),
124 - AbuseFilter::generateTitleVars( $article->mTitle, 'ARTICLE' ) );
125 - $vars['SUMMARY'] = $reason;
126 - $vars['ACTION'] = 'delnom';
127 - $vars['QUEUE'] = $queue;
128 -
129 - $filter_result = AbuseFilter::filterAction( $vars, $article->mTitle );
130 - $error = $filter_result;
131 -
132 - return $filter_result == '' || $filter_result === true;
133 - }
134108
135109 public static function onRecentChangeSave( $recentChange ) {
136110 $title = Title::makeTitle(

Status & tagging log