Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -97,8 +97,8 @@ |
98 | 98 | 'article_restrictions_edit' => 'restrictions-edit', |
99 | 99 | 'article_restrictions_move' => 'restrictions-move', |
100 | 100 | 'article_recent_contributors' => 'recent-contributors', |
101 | | - 'old_text' => 'old-text-stripped', |
102 | | - 'old_html' => 'old-html', |
| 101 | +# 'old_text' => 'old-text-stripped', ## Disabled, performance |
| 102 | +# 'old_html' => 'old-html', ## Disabled, performance |
103 | 103 | 'old_links' => 'old-links', |
104 | 104 | 'minor_edit' => 'minor-edit', |
105 | 105 | ), |
— | — | @@ -342,6 +342,8 @@ |
343 | 343 | } catch (Exception $excep) { |
344 | 344 | // Sigh. |
345 | 345 | $result = false; |
| 346 | + |
| 347 | + wfDebugLog( 'AbuseFilter', "AbuseFilter parser error: ".$excep->getMessage()."\n" ); |
346 | 348 | |
347 | 349 | if (!$ignoreError) { |
348 | 350 | throw $excep; |
— | — | @@ -506,6 +508,9 @@ |
507 | 509 | |
508 | 510 | // Add vars from extensions |
509 | 511 | wfRunHooks( 'AbuseFilter-filterAction', array( &$vars, $title ) ); |
| 512 | + |
| 513 | + // Set context |
| 514 | + $vars->setVar( 'context', 'filter' ); |
510 | 515 | |
511 | 516 | $dbr = wfGetDB( DB_SLAVE ); |
512 | 517 | |
— | — | @@ -1184,12 +1189,14 @@ |
1185 | 1190 | public static function getVarsFromRCRow( $row ) { |
1186 | 1191 | if ($row->rc_this_oldid) { |
1187 | 1192 | // It's an edit. |
1188 | | - return self::getEditVarsFromRCRow( $row ); |
| 1193 | + $vars = self::getEditVarsFromRCRow( $row ); |
1189 | 1194 | } elseif ( $row->rc_log_type == 'move' ) { |
1190 | | - return self::getMoveVarsFromRCRow( $row ); |
| 1195 | + $vars = self::getMoveVarsFromRCRow( $row ); |
1191 | 1196 | } elseif ( $row->rc_log_type == 'newusers' ) { |
1192 | | - return self::getCreateVarsFromRCRow( $row ); |
| 1197 | + $vars = self::getCreateVarsFromRCRow( $row ); |
1193 | 1198 | } |
| 1199 | + $vars->setVar( 'context', 'generated' ); |
| 1200 | + return $vars; |
1194 | 1201 | } |
1195 | 1202 | |
1196 | 1203 | public static function getCreateVarsFromRCRow( $row ) { |
— | — | @@ -1287,7 +1294,7 @@ |
1288 | 1295 | 'title' => $title->getText(), |
1289 | 1296 | 'text-var' => 'new_wikitext' |
1290 | 1297 | ) ); |
1291 | | - $vars->setLazyLoadVar( 'old_links', 'links-from-wikitext-nonedit', |
| 1298 | + $vars->setLazyLoadVar( 'old_links', 'links-from-wikitext-or-database', |
1292 | 1299 | array( |
1293 | 1300 | 'namespace' => $title->getNamespace(), |
1294 | 1301 | 'title' => $title->getText(), |
Index: trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | |
4 | 4 | class AbuseFilterVariableHolder { |
5 | 5 | var $mVars = array(); |
| 6 | + static $varBlacklist = array( 'context' ); |
6 | 7 | |
7 | 8 | function setVar( $variable, $datum ) { |
8 | 9 | $variable = strtolower( $variable ); |
— | — | @@ -49,13 +50,20 @@ |
50 | 51 | $this->mVars = array_merge( $this->mVars, $addHolder->mVars ); |
51 | 52 | } |
52 | 53 | |
| 54 | + function __wakeup() { |
| 55 | + // Reset the context. |
| 56 | + $this->setVar( 'context', 'stored' ); |
| 57 | + } |
| 58 | + |
53 | 59 | function exportAllVars() { |
54 | 60 | $allVarNames = array_keys( $this->mVars ); |
55 | 61 | $exported = array(); |
56 | 62 | |
57 | 63 | foreach( $allVarNames as $varName ) { |
58 | | - $exported[$varName] = $this->getVar( $varName )->toString(); |
| 64 | + if (!in_array( $varName, self::$varBlacklist ) ) |
| 65 | + $exported[$varName] = $this->getVar( $varName )->toString(); |
59 | 66 | } |
| 67 | + |
60 | 68 | return $exported; |
61 | 69 | } |
62 | 70 | |
— | — | @@ -121,6 +129,21 @@ |
122 | 130 | return self::$articleCache["$namespace:$title"]; |
123 | 131 | } |
124 | 132 | |
| 133 | + static function getLinksFromDB( $article ) { |
| 134 | + // Stolen from ConfirmEdit |
| 135 | + $id = $article->getId(); |
| 136 | + if (!$id) return array(); |
| 137 | + |
| 138 | + $dbr = wfGetDB( DB_SLAVE ); |
| 139 | + $res = $dbr->select( 'externallinks', array( 'el_to' ), |
| 140 | + array( 'el_from' => $id ), __METHOD__ ); |
| 141 | + $links = array(); |
| 142 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 143 | + $links[] = $row->el_to; |
| 144 | + } |
| 145 | + return $links; |
| 146 | + } |
| 147 | + |
125 | 148 | function compute( $vars ) { |
126 | 149 | $parameters = $this->mParameters; |
127 | 150 | $result = null; |
— | — | @@ -146,7 +169,8 @@ |
147 | 170 | $result = implode( "\n", $interest_lines ); |
148 | 171 | break; |
149 | 172 | case 'links-from-wikitext': |
150 | | - $article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] ); |
| 173 | + $article = self::articleFromTitle( $parameters['namespace'], |
| 174 | + $parameters['title'] ); |
151 | 175 | $textVar = $parameters['text-var']; |
152 | 176 | |
153 | 177 | $new_text = $vars->getVar( $textVar )->toString(); |
— | — | @@ -154,13 +178,22 @@ |
155 | 179 | $links = array_keys( $editInfo->output->getExternalLinks() ); |
156 | 180 | $result = implode( "\n", $links ); |
157 | 181 | break; |
158 | | - case 'links-from-wikitext-nonedit': |
159 | | - $article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] ); |
160 | | - $textVar = $parameters['text-var']; |
| 182 | + case 'links-from-wikitext-or-database': |
| 183 | + $article = self::articleFromTitle( $parameters['namespace'], |
| 184 | + $parameters['title'] ); |
161 | 185 | |
162 | | - $wikitext = $vars->getVar( $textVar )->toString(); |
163 | | - $editInfo = $this->parseNonEditWikitext( $wikitext, $article ); |
164 | | - $links = array_keys( $editInfo->output->getExternalLinks() ); |
| 186 | + if ($vars->getVar( 'context' )->toString() == 'filter') { |
| 187 | + $links = $this->getLinksFromDB( $article ); |
| 188 | + wfDebug( "AbuseFilter: loading old links from DB\n" ); |
| 189 | + } else { |
| 190 | + wfDebug( "AbuseFilter: loading old links from Parser\n" ); |
| 191 | + $textVar = $parameters['text-var']; |
| 192 | + |
| 193 | + $wikitext = $vars->getVar( $textVar )->toString(); |
| 194 | + $editInfo = $this->parseNonEditWikitext( $wikitext, $article ); |
| 195 | + $links = array_keys( $editInfo->output->getExternalLinks() ); |
| 196 | + } |
| 197 | + |
165 | 198 | $result = implode( "\n", $links ); |
166 | 199 | break; |
167 | 200 | case 'link-diff-added': |