r102497 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102496‎ | r102497 | r102498 >
Date:08:36, 9 November 2011
Author:ialex
Status:ok
Tags:
Comment:
* (bug 29092) Removed usage of $wgArticle from AbuseFilter extension
Instead pass the Article object from the EditFilterMerged hook to the AFComputedVariable object and see whether the object is present to do a parse operation since other code paths won't pass an Article object

Also simplified the fallback code in AFComputedVariable::compute() to simply continue instead of calling the function again.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.hooks.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -1508,8 +1508,7 @@
15091509 $vars->setVar( 'old_wikitext', '' );
15101510 }
15111511
1512 - $vars->addHolder( self::getEditVars(
1513 - $title, $row->rc_this_oldid, $row->rc_last_oldid ) );
 1512+ $vars->addHolder( self::getEditVars( $title ) );
15141513
15151514 return $vars;
15161515 }
@@ -1547,7 +1546,7 @@
15481547 * @param $title Title
15491548 * @return AbuseFilterVariableHolder
15501549 */
1551 - public static function getEditVars( $title ) {
 1550+ public static function getEditVars( $title, $article = null ) {
15521551 $vars = new AbuseFilterVariableHolder;
15531552
15541553 $vars->setLazyLoadVar( 'edit_diff', 'diff',
@@ -1568,7 +1567,8 @@
15691568 array(
15701569 'namespace' => $title->getNamespace(),
15711570 'title' => $title->getText(),
1572 - 'text-var' => 'new_wikitext'
 1571+ 'text-var' => 'new_wikitext',
 1572+ 'article' => $article
15731573 ) );
15741574 $vars->setLazyLoadVar( 'old_links', 'links-from-wikitext-or-database',
15751575 array(
@@ -1585,7 +1585,8 @@
15861586 array(
15871587 'namespace' => $title->getNamespace(),
15881588 'title' => $title->getText(),
1589 - 'wikitext-var' => 'new_wikitext'
 1589+ 'wikitext-var' => 'new_wikitext',
 1590+ 'article' => $article
15901591 ) );
15911592 $vars->setLazyLoadVar( 'new_text', 'strip-html',
15921593 array( 'html-var' => 'new_html' ) );
Index: trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php
@@ -224,26 +224,18 @@
225225 break;
226226 case 'links-from-wikitext':
227227 // This should ONLY be used when sharing a parse operation with the edit.
228 - global $wgArticle;
229228
230 - $article = self::articleFromTitle(
231 - $parameters['namespace'],
232 - $parameters['title']
233 - );
234 -
235 - if ( $wgArticle && $article->getTitle()->equals( $wgArticle->getTitle() ) ) {
 229+ $article = $parameters['article'];
 230+ if ( $article ) {
236231 $textVar = $parameters['text-var'];
237232
238233 $new_text = $vars->getVar( $textVar )->toString();
239234 $editInfo = $article->prepareTextForEdit( $new_text );
240235 $links = array_keys( $editInfo->output->getExternalLinks() );
241236 $result = $links;
242 - } else {
243 - // Change to links-from-wikitext-nonedit.
244 - $this->mMethod = 'links-from-wikitext-nonedit';
245 - $result = $this->compute( $vars );
 237+ break;
246238 }
247 - break;
 239+ // Otherwise fall back to database
248240 case 'links-from-wikitext-nonedit':
249241 case 'links-from-wikitext-or-database':
250242 $article = self::articleFromTitle(
@@ -285,10 +277,9 @@
286278 break;
287279 case 'parse-wikitext':
288280 // Should ONLY be used when sharing a parse operation with the edit.
289 - global $wgArticle;
290 - $article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] );
291 -
292 - if ( $wgArticle && $article->getTitle() === $wgArticle->getTitle() ) {
 281+
 282+ $article = $parameters['article'];
 283+ if ( $article ) {
293284 $textVar = $parameters['wikitext-var'];
294285
295286 $new_text = $vars->getVar( $textVar )->toString();
@@ -297,12 +288,9 @@
298289 // Kill the PP limit comments. Ideally we'd just remove these by not setting the
299290 // parser option, but then we can't share a parse operation with the edit, which is bad.
300291 $result = preg_replace( '/<!--\s*NewPP limit report[^>]*-->\s*$/si', '', $newHTML );
301 - } else {
302 - // Change to parse-wikitext-nonedit.
303 - $this->mMethod = 'parse-wikitext-nonedit';
304 - $result = $this->compute( $vars );
 292+ break;
305293 }
306 - break;
 294+ // Otherwise fall back to database
307295 case 'parse-wikitext-nonedit':
308296 $article = self::articleFromTitle( $parameters['namespace'], $parameters['title'] );
309297 $textVar = $parameters['wikitext-var'];
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -23,15 +23,16 @@
2424 // Check for null edits.
2525 $oldtext = '';
2626
27 - if ( $editor->mArticle->exists() ) {
 27+ $article = $editor->getArticle();
 28+ if ( $article->exists() ) {
2829 // Make sure we load the latest text saved in database (bug 31656)
29 - $oldtext = $editor->mArticle->getRevision()->getRawText();
 30+ $oldtext = $article->getRevision()->getRawText();
3031 }
3132
3233 // Cache article object so we can share a parse operation
3334 $title = $editor->mTitle;
3435 $articleCacheKey = $title->getNamespace() . ':' . $title->getText();
35 - AFComputedVariable::$articleCache[$articleCacheKey] = $editor->mArticle;
 36+ AFComputedVariable::$articleCache[$articleCacheKey] = $article;
3637
3738 if ( strcmp( $oldtext, $text ) == 0 ) {
3839 // Don't trigger for null edits.
@@ -40,7 +41,7 @@
4142
4243 global $wgUser;
4344 $vars->addHolder( AbuseFilter::generateUserVars( $wgUser ) );
44 - $vars->addHolder( AbuseFilter::generateTitleVars( $editor->mTitle , 'ARTICLE' ) );
 45+ $vars->addHolder( AbuseFilter::generateTitleVars( $title , 'ARTICLE' ) );
4546 $vars->setVar( 'ACTION', 'edit' );
4647 $vars->setVar( 'SUMMARY', $summary );
4748 $vars->setVar( 'minor_edit', $editor->minoredit );
@@ -48,9 +49,9 @@
4950 $vars->setVar( 'old_wikitext', $oldtext );
5051 $vars->setVar( 'new_wikitext', $text );
5152
52 - $vars->addHolder( AbuseFilter::getEditVars( $editor->mTitle ) );
 53+ $vars->addHolder( AbuseFilter::getEditVars( $title, $article ) );
5354
54 - $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle );
 55+ $filter_result = AbuseFilter::filterAction( $vars, $title );
5556
5657 if ( $filter_result !== true ) {
5758 global $wgOut;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88589Followup r88588 ($wgArticle fixes)...demon18:00, 22 May 2011

Status & tagging log