Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php |
— | — | @@ -337,7 +337,7 @@ |
338 | 338 | $this->mParams = array(); |
339 | 339 | $this->mCode = ''; |
340 | 340 | $this->mTokens = array(); |
341 | | - $this->mVars = array(); |
| 341 | + $this->mVars = new AbuseFilterVariableHolder; |
342 | 342 | $this->mPos = 0; |
343 | 343 | } |
344 | 344 | |
— | — | @@ -350,17 +350,19 @@ |
351 | 351 | return true; |
352 | 352 | } |
353 | 353 | |
354 | | - public function setVar( $name, $var ) { |
| 354 | + public function setVar( $name, $value ) { |
355 | 355 | $name = strtolower($name); |
356 | | - $this->mVars[$name] = AFPData::newFromPHPVar( $var ); |
| 356 | + $this->mVars->setVar( $name, $value ); |
357 | 357 | } |
358 | 358 | |
359 | 359 | 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 ); |
363 | 366 | } |
364 | | - wfProfileOut( __METHOD__ ); |
365 | 367 | } |
366 | 368 | |
367 | 369 | protected function move( ) { |
— | — | @@ -643,20 +645,7 @@ |
644 | 646 | switch( $this->mCur->type ) { |
645 | 647 | case AFPToken::TID: |
646 | 648 | $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 ); |
661 | 650 | break; |
662 | 651 | case AFPToken::TString: |
663 | 652 | $result = new AFPData( AFPData::DString, $tok ); |
— | — | @@ -694,6 +683,18 @@ |
695 | 684 | wfProfileOut( __METHOD__ ); |
696 | 685 | } |
697 | 686 | |
| 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 | + |
698 | 699 | /* End of levels */ |
699 | 700 | |
700 | 701 | static function nextToken( $code, $offset ) { |
Index: trunk/extensions/AbuseFilter/AbuseFilter.php |
— | — | @@ -44,6 +44,9 @@ |
45 | 45 | $wgAutoloadClasses['AbuseFilterViewTestBatch'] = "$dir/Views/AbuseFilterViewTestBatch.php"; |
46 | 46 | $wgAutoloadClasses['AbuseFilterViewExamine'] = "$dir/Views/AbuseFilterViewExamine.php"; |
47 | 47 | $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"; |
48 | 51 | |
49 | 52 | $wgSpecialPages['AbuseLog'] = 'SpecialAbuseLog'; |
50 | 53 | $wgSpecialPages['AbuseFilter'] = 'SpecialAbuseFilter'; |
— | — | @@ -55,7 +58,6 @@ |
56 | 59 | $wgHooks['AbortMove'][] = 'AbuseFilterHooks::onAbortMove'; |
57 | 60 | $wgHooks['AbortNewAccount'][] = 'AbuseFilterHooks::onAbortNewAccount'; |
58 | 61 | $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete'; |
59 | | -$wgHooks['AbortDeleteQueueNominate'][] = 'AbuseFilterHooks::onAbortDeleteQueueNominate'; |
60 | 62 | $wgHooks['RecentChange_save'][] = 'AbuseFilterHooks::onRecentChangeSave'; |
61 | 63 | $wgHooks['ListDefinedTags'][] = 'AbuseFilterHooks::onListDefinedTags'; |
62 | 64 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onLoadExtensionSchemaUpdates'; |
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewExamine.php |
— | — | @@ -126,7 +126,7 @@ |
127 | 127 | } |
128 | 128 | |
129 | 129 | $vars = unserialize( $row->afl_var_dump ); |
130 | | - |
| 130 | + |
131 | 131 | $this->showExaminer( $vars ); |
132 | 132 | } |
133 | 133 | |
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -96,23 +96,25 @@ |
97 | 97 | 'article_restrictions_edit' => 'restrictions-edit', |
98 | 98 | 'article_restrictions_move' => 'restrictions-move', |
99 | 99 | 'article_recent_contributors' => 'recent-contributors', |
| 100 | + 'old_text' => 'old-text-stripped', |
| 101 | + 'old_html' => 'old-html', |
| 102 | + 'old_links' => 'old-links', |
100 | 103 | ), |
101 | 104 | ); |
102 | 105 | |
103 | 106 | public static function generateUserVars( $user ) { |
104 | | - $vars = array(); |
| 107 | + $vars = new AbuseFilterVariableHolder; |
105 | 108 | |
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' ) ); |
108 | 114 | |
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() ) ); |
114 | 118 | |
115 | | - // More to come |
116 | | - |
117 | 119 | return $vars; |
118 | 120 | } |
119 | 121 | |
— | — | @@ -181,36 +183,34 @@ |
182 | 184 | } |
183 | 185 | |
184 | 186 | public static function generateTitleVars( $title, $prefix ) { |
185 | | - $vars = array(); |
| 187 | + $vars = new AbuseFilterVariableHolder; |
186 | 188 | |
187 | 189 | if (!$title) |
188 | 190 | return array(); |
189 | 191 | |
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() ); |
194 | 196 | |
195 | 197 | // 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 | + ); |
202 | 206 | } |
203 | 207 | |
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 | + |
215 | 215 | return $vars; |
216 | 216 | } |
217 | 217 | |
— | — | @@ -446,7 +446,7 @@ |
447 | 447 | 'afl_title' => $title->getDBKey(), |
448 | 448 | 'afl_ip' => wfGetIp() ); |
449 | 449 | |
450 | | - self::addLogEntries( $actions_taken, $log_template, $vars['ACTION'] ); |
| 450 | + self::addLogEntries( $actions_taken, $log_template, $vars->getVar( 'ACTION' )->toString() ); |
451 | 451 | |
452 | 452 | $error_msg = $error_msg == '' ? true : $error_msg; |
453 | 453 | |
— | — | @@ -632,7 +632,8 @@ |
633 | 633 | global $wgUser; |
634 | 634 | |
635 | 635 | $actionID = implode( '-', array( |
636 | | - $title->getPrefixedText(), $wgUser->getName(), $vars['ACTION'] |
| 636 | + $title->getPrefixedText(), $wgUser->getName(), |
| 637 | + $vars->getVar( 'ACTION' )->toString() |
637 | 638 | ) ); |
638 | 639 | |
639 | 640 | AbuseFilter::$tagsToSet[$actionID] = $parameters; |
— | — | @@ -1000,40 +1001,41 @@ |
1001 | 1002 | } |
1002 | 1003 | |
1003 | 1004 | public static function getEditVarsFromRCRow( $row ) { |
1004 | | - $vars = array(); |
| 1005 | + $vars = new AbuseFilterVariableHolder; |
1005 | 1006 | $title = Title::makeTitle( $row->rc_namespace, $row->rc_title ); |
1006 | 1007 | |
1007 | 1008 | if ($row->rc_user) |
1008 | | - $user = User::newFromId( $row->rc_user ); |
| 1009 | + $user = User::newFromName( $row->rc_user_text ); |
1009 | 1010 | else { |
1010 | 1011 | $user = new User; |
1011 | 1012 | $user->setName( $row->rc_user_text ); |
1012 | 1013 | } |
1013 | 1014 | |
1014 | | - $vars = array_merge( $vars, self::generateUserVars( $user ) ); |
| 1015 | + $vars->addHolder( self::generateUserVars( $user ) ); |
1015 | 1016 | |
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 ); |
1019 | 1020 | |
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 ) ); |
1022 | 1024 | |
1023 | 1025 | 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 ) ); |
1026 | 1028 | } else { |
1027 | | - $old_text = ''; |
| 1029 | + $vars->setVar( 'old_wikitext', '' ); |
1028 | 1030 | } |
1029 | 1031 | |
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 ) ); |
1032 | 1034 | |
1033 | 1035 | return $vars; |
1034 | 1036 | } |
1035 | 1037 | |
1036 | 1038 | public static function getMoveVarsFromRCRow( $row ) { |
1037 | | - $vars = array(); |
| 1039 | + $vars = new AbuseFilterVariableHolder; |
1038 | 1040 | |
1039 | 1041 | if ($row->rc_user) |
1040 | 1042 | $user = User::newFromId( $row->rc_user ); |
— | — | @@ -1045,76 +1047,81 @@ |
1046 | 1048 | $oldTitle = Title::makeTitle( $row->rc_namespace, $row->rc_title ); |
1047 | 1049 | $newTitle = Title::newFromText( trim($row->rc_params) ); |
1048 | 1050 | |
1049 | | - $vars = array_merge( $vars, AbuseFilter::generateUserVars( $user ), |
| 1051 | + $vars = AbuseFilterVariableHolder::merge( |
| 1052 | + $vars, |
| 1053 | + AbuseFilter::generateUserVars( $user ), |
1050 | 1054 | AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ), |
1051 | | - AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) ); |
| 1055 | + AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) |
| 1056 | + ); |
1052 | 1057 | |
1053 | | - $vars['SUMMARY'] = $row->rc_comment; |
1054 | | - $vars['ACTION'] = 'move'; |
| 1058 | + $vars->setVar( 'SUMMARY', $row->rc_comment ); |
| 1059 | + $vars->setVar( 'ACTION', 'move' ); |
1055 | 1060 | |
1056 | 1061 | return $vars; |
1057 | 1062 | } |
1058 | 1063 | |
1059 | | - public static function getEditVars( $title, $old_text, $new_text, $oldLinks = null, |
1060 | | - $revid=null, $oldid=null ) |
| 1064 | + public static function getEditVars( $title ) |
1061 | 1065 | { |
1062 | | - $vars = array(); |
| 1066 | + $vars = new AbuseFilterVariableHolder; |
1063 | 1067 | $article = new Article( $title ); |
1064 | 1068 | |
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' ) ); |
1071 | 1075 | |
1072 | | - $vars['OLD_WIKITEXT'] = $old_text; |
1073 | | - $vars['NEW_WIKITEXT'] = $new_text; |
1074 | | - |
1075 | 1076 | // 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' => '-' ) ); |
1088 | 1081 | |
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' ) ); |
1095 | 1116 | |
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 | | - |
1115 | 1117 | return $vars; |
1116 | 1118 | } |
1117 | 1119 | |
1118 | 1120 | public static function buildVarDumpTable( $vars ) { |
| 1121 | + // Export all values |
| 1122 | + |
| 1123 | + if ($vars instanceof AbuseFilterVariableHolder ) |
| 1124 | + $vars = $vars->exportAllVars(); |
| 1125 | + |
1119 | 1126 | $output = ''; |
1120 | 1127 | |
1121 | 1128 | // I don't want to change the names of the pre-existing messages |
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php |
— | — | @@ -264,7 +264,10 @@ |
265 | 265 | 'abusefilter-edit-builder-vars-recent-contributors' => 'Last ten users to contribute to the page', |
266 | 266 | 'abusefilter-edit-builder-vars-restrictions-edit' => 'Edit protection level of the page', |
267 | 267 | '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 | + |
269 | 272 | // Filter history |
270 | 273 | 'abusefilter-filter-log' => 'Recent filter changes', |
271 | 274 | 'abusefilter-history' => 'Change history for Abuse Filter #$1', |
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php |
— | — | @@ -9,22 +9,26 @@ |
10 | 10 | |
11 | 11 | public static function onEditFilter($editor, $text, $section, &$error, $summary) { |
12 | 12 | // Load vars |
13 | | - $vars = array(); |
| 13 | + $vars = new AbuseFilterVariableHolder; |
14 | 14 | |
15 | 15 | 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 ); |
20 | 20 | |
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 ); |
24 | 29 | |
25 | | - $vars = array_merge( $vars, |
26 | | - AbuseFilter::getEditVars( $editor->mTitle, $old_text, $new_text, $oldLinks ) ); |
| 30 | + $vars->addHolder( AbuseFilter::getEditVars( $editor->mTitle ) ); |
27 | 31 | |
28 | | - $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle, $oldLinks ); |
| 32 | + $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle ); |
29 | 33 | |
30 | 34 | if( $filter_result !== true ){ |
31 | 35 | global $wgOut; |
— | — | @@ -35,22 +39,6 @@ |
36 | 40 | return true; |
37 | 41 | } |
38 | 42 | |
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 | | - |
55 | 43 | public static function onGetAutoPromoteGroups( $user, &$promote ) { |
56 | 44 | global $wgMemc; |
57 | 45 | |
— | — | @@ -64,14 +52,16 @@ |
65 | 53 | } |
66 | 54 | |
67 | 55 | public static function onAbortMove( $oldTitle, $newTitle, $user, &$error, $reason ) { |
68 | | - $vars = array(); |
| 56 | + $vars = new AbuseFilterVariableHolder; |
69 | 57 | |
70 | 58 | 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' ); |
76 | 66 | |
77 | 67 | $filter_result = AbuseFilter::filterAction( $vars, $oldTitle ); |
78 | 68 | |
— | — | @@ -81,13 +71,13 @@ |
82 | 72 | } |
83 | 73 | |
84 | 74 | public static function onArticleDelete( &$article, &$user, &$reason, &$error ) { |
85 | | - $vars = array(); |
| 75 | + $vars = new AbuseFilterVariableHolder; |
86 | 76 | |
87 | 77 | 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' ); |
92 | 82 | |
93 | 83 | $filter_result = AbuseFilter::filterAction( $vars, $article->mTitle ); |
94 | 84 | |
— | — | @@ -104,8 +94,8 @@ |
105 | 95 | } |
106 | 96 | $vars = array(); |
107 | 97 | |
108 | | - $vars['ACTION'] = 'createaccount'; |
109 | | - $vars['ACCOUNTNAME'] = $vars['USER_NAME'] = $user->getName(); |
| 98 | + $vars->setVar( 'ACTION', 'createaccount' ); |
| 99 | + $vars->setVar( 'ACCOUNTNAME', $user->getName() ); |
110 | 100 | |
111 | 101 | $filter_result = AbuseFilter::filterAction( |
112 | 102 | $vars, SpecialPage::getTitleFor( 'Userlogin' ) ); |
— | — | @@ -114,22 +104,6 @@ |
115 | 105 | |
116 | 106 | return $filter_result == '' || $filter_result === true; |
117 | 107 | } |
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 | | - } |
134 | 108 | |
135 | 109 | public static function onRecentChangeSave( $recentChange ) { |
136 | 110 | $title = Title::makeTitle( |