Index: trunk/phase3/includes/ChangesList.php |
— | — | @@ -340,6 +340,9 @@ |
341 | 341 | } |
342 | 342 | |
343 | 343 | protected function insertTags( &$s, &$rc, &$classes ) { |
| 344 | + if ( empty($rc->mAttribs['ts_tags']) ) |
| 345 | + return; |
| 346 | + |
344 | 347 | list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' ); |
345 | 348 | $classes = array_merge( $classes, $newClasses ); |
346 | 349 | $s .= ' ' . $tagSummary; |
Index: trunk/extensions/AbuseFilter/AbuseFilter.php |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | $wgAutoloadClasses['AbuseFilterViewTools'] = "$dir/Views/AbuseFilterViewTools.php"; |
41 | 41 | $wgAutoloadClasses['AbuseFilterViewHistory'] = "$dir/Views/AbuseFilterViewHistory.php"; |
42 | 42 | $wgAutoloadClasses['AbuseFilterViewRevert'] = "$dir/Views/AbuseFilterViewRevert.php"; |
| 43 | +$wgAutoloadClasses['AbuseFilterViewTest'] = "$dir/Views/AbuseFilterViewTest.php"; |
43 | 44 | |
44 | 45 | $wgSpecialPages['AbuseLog'] = 'SpecialAbuseLog'; |
45 | 46 | $wgSpecialPages['AbuseFilter'] = 'SpecialAbuseFilter'; |
— | — | @@ -81,6 +82,7 @@ |
82 | 83 | $wgAjaxExportList[] = 'AbuseFilter::ajaxCheckSyntax'; |
83 | 84 | $wgAjaxExportList[] = 'AbuseFilter::ajaxEvaluateExpression'; |
84 | 85 | $wgAjaxExportList[] = 'AbuseFilter::ajaxReAutoconfirm'; |
| 86 | +$wgAjaxExportList[] = 'AbuseFilter::ajaxGetFilter'; |
85 | 87 | |
86 | 88 | // Bump the version number every time you change any of the .css/.js files |
87 | 89 | $wgAbuseFilterStyleVersion = 3; |
Index: trunk/extensions/AbuseFilter/SpecialAbuseFilter.php |
— | — | @@ -49,6 +49,10 @@ |
50 | 50 | $this->mFilter = $params[1]; |
51 | 51 | $view = 'AbuseFilterViewRevert'; |
52 | 52 | } |
| 53 | + |
| 54 | + if ( !empty($params[0]) && $params[0] == 'test' ) { |
| 55 | + $view = 'AbuseFilterViewTest'; |
| 56 | + } |
53 | 57 | |
54 | 58 | if (!empty($params[0]) && ($params[0] == 'history' || $params[0] == 'log') ) { |
55 | 59 | if (count($params) == 1) { |
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewList.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | |
16 | 16 | // Quick links |
17 | 17 | $wgOut->addWikiMsg( 'abusefilter-links' ); |
18 | | - $lists = array( 'tools' ); |
| 18 | + $lists = array( 'tools', 'test' ); |
19 | 19 | if ($this->canEdit()) |
20 | 20 | $lists[] = 'new'; |
21 | 21 | $links = ''; |
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewTest.php |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if (!defined( 'MEDIAWIKI' )) |
| 5 | + die(); |
| 6 | + |
| 7 | +class AbuseFilterViewTest extends AbuseFilterView { |
| 8 | + // Hard-coded for now. |
| 9 | + static $mChangeLimit = 100; |
| 10 | + |
| 11 | + function show( ) { |
| 12 | + global $wgOut, $wgUser, $wgRequest; |
| 13 | + |
| 14 | + AbuseFilter::disableConditionLimit(); |
| 15 | + |
| 16 | + $this->loadParameters(); |
| 17 | + |
| 18 | + $wgOut->setPageTitle( wfMsg( 'abusefilter-test' ) ); |
| 19 | + $wgOut->addWikiMsg( 'abusefilter-test-intro', self::$mChangeLimit ); |
| 20 | + |
| 21 | + $output = ''; |
| 22 | + $output .= AbuseFilter::buildEditBox( $this->mFilter, 'wpTestFilter' ) . "\n"; |
| 23 | + $output .= Xml::inputLabel( wfMsg( 'abusefilter-test-load-filter' ), 'wpInsertFilter', 'mw-abusefilter-load-filter', 10, '' ) . ' ' . |
| 24 | + Xml::element( 'input', array( 'type' => 'button', 'value' => wfMsg( 'abusefilter-test-load' ), 'id' => 'mw-abusefilter-load' ) ); |
| 25 | + $output = Xml::tags( 'div', array( 'id' => 'mw-abusefilter-test-editor' ), $output ); |
| 26 | + |
| 27 | + // Removed until I can distinguish between positives and negatives :) |
| 28 | +// $output .= Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'abusefilter-test-shownegative' ), 'wpShowNegative', 'wpShowNegative', $this->mShowNegative ) ); |
| 29 | + $output .= Xml::tags( 'p', null, Xml::submitButton( wfMsg( 'abusefilter-test-submit' ) ) ); |
| 30 | + $output .= Xml::hidden( 'title', $this->getTitle("test")->getPrefixedText() ); |
| 31 | + $output = Xml::tags( 'form', array( 'action' => $this->getTitle("test")->getLocalURL(), 'method' => 'POST' ), $output ); |
| 32 | + |
| 33 | + $output = Xml::fieldset( wfMsg( 'abusefilter-test-legend' ), $output ); |
| 34 | + |
| 35 | + $wgOut->addHTML( $output ); |
| 36 | + |
| 37 | + if ($wgRequest->wasPosted()) { |
| 38 | + $this->doTest(); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + function doTest() { |
| 43 | + // Quick syntax check. |
| 44 | + if ( ($result = AbuseFilter::checkSyntax( $this->mFilter )) !== true ) { |
| 45 | + $wgOut->addWikiMsg( 'abusefilter-test-syntaxerr' ); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + // Get our ChangesList |
| 50 | + global $wgUser, $wgOut; |
| 51 | + $changesList = ChangesList::newFromUser( $wgUser ); |
| 52 | + $output = $changesList->beginRecentChangesList(); |
| 53 | + |
| 54 | + $dbr = wfGetDB( DB_SLAVE ); |
| 55 | + $res = $dbr->select( 'recentchanges', '*', array(), __METHOD__, array( 'LIMIT' => self::$mChangeLimit, 'ORDER BY' => 'rc_timestamp asc' ) ); |
| 56 | + |
| 57 | + $counter = 1; |
| 58 | + |
| 59 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 60 | + $vars = AbuseFilter::getVarsFromRCRow( $row ); |
| 61 | + |
| 62 | + if (!$vars) |
| 63 | + continue; |
| 64 | + |
| 65 | + $result = AbuseFilter::checkConditions( $this->mFilter, $vars ); |
| 66 | + |
| 67 | + if ($result || $this->mShowNegative) { |
| 68 | + $rc = RecentChange::newFromRow( $row ); |
| 69 | + $rc->counter = $counter++; |
| 70 | + $output .= $changesList->recentChangesLine( $rc, false ); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + $output .= $changesList->endRecentChangesList(); |
| 75 | + |
| 76 | + $wgOut->addHTML( $output ); |
| 77 | + } |
| 78 | + |
| 79 | + function loadParameters() { |
| 80 | + global $wgRequest; |
| 81 | + |
| 82 | + $this->mFilter = $wgRequest->getText( 'wpTestFilter' ); |
| 83 | + $this->mShowNegative = $wgRequest->getBool( 'wpShowNegative' ); |
| 84 | + } |
| 85 | +} |
\ No newline at end of file |
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -52,6 +52,22 @@ |
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
| 56 | + public static function ajaxGetFilter( $filter ) { |
| 57 | + global $wgUser; |
| 58 | + if ( !$wgUser->isAllowed( 'abusefilter-view' ) ) { |
| 59 | + return false; |
| 60 | + } |
| 61 | + |
| 62 | + $dbr = wfGetDB( DB_SLAVE ); |
| 63 | + $row = $dbr->selectRow( 'abuse_filter', '*', array( 'af_id' => $filter ), __METHOD__ ); |
| 64 | + |
| 65 | + if ( $row->af_hidden && !$wgUser->isAllowed( 'abusefilter-modify' ) ) { |
| 66 | + return false; |
| 67 | + } |
| 68 | + |
| 69 | + return strval($row->af_pattern); |
| 70 | + } |
| 71 | + |
56 | 72 | public static function triggerLimiter( $val = 1 ) { |
57 | 73 | self::$condCount += $val; |
58 | 74 | |
— | — | @@ -759,4 +775,111 @@ |
760 | 776 | $display = wfEmptyMsg( "abusefilter-action-$action", $display ) ? $action : $display; |
761 | 777 | return $display; |
762 | 778 | } |
| 779 | + |
| 780 | + public static function getVarsFromRCRow( $row ) { |
| 781 | + if ($row->rc_this_oldid) { |
| 782 | + // It's an edit. |
| 783 | + return self::getEditVarsFromRCRow( $row ); |
| 784 | + } elseif ( $row->rc_log_type == 'move' ) { |
| 785 | + return self::getMoveVarsFromRCRow( $row ); |
| 786 | + } elseif ( $row->rc_log_type == 'newusers' ) { |
| 787 | + return self::getCreateVarsFromRCRow( $row ); |
| 788 | + } |
| 789 | + } |
| 790 | + |
| 791 | + public static function getCreateVarsFromRCRow( $row ) { |
| 792 | + $vars = array('ACTION' => 'createaccount'); |
| 793 | + $vars['USER_NAME'] = $vars['ACCOUNTNAME'] = Title::makeTitle( $row->rc_namespace, $row->rc_title )->getText(); |
| 794 | + return $vars; |
| 795 | + } |
| 796 | + |
| 797 | + public static function getEditVarsFromRCRow( $row ) { |
| 798 | + $vars = array(); |
| 799 | + $title = Title::makeTitle( $row->rc_namespace, $row->rc_title ); |
| 800 | + |
| 801 | + $vars = array_merge( $vars, self::generateUserVars( User::newFromId( $row->rc_user ) ) ); |
| 802 | + $vars = array_merge( $vars, self::generateTitleVars( $title, 'ARTICLE_' ) ); |
| 803 | + $vars['ACTION'] = 'edit'; |
| 804 | + $vars['SUMMARY'] = $row->rc_comment; |
| 805 | + |
| 806 | + $newRev = Revision::newFromId( $row->rc_this_oldid ); |
| 807 | + $new_text = $newRev->getText(); |
| 808 | + |
| 809 | + if ($row->rc_last_oldid) { |
| 810 | + $oldRev = Revision::newFromId( $row->rc_last_oldid ); |
| 811 | + $old_text = $oldRev->getText(); |
| 812 | + } else { |
| 813 | + $old_text = ''; |
| 814 | + } |
| 815 | + |
| 816 | + $vars = array_merge( $vars, self::getEditVars( $title, $old_text, $new_text, null, $row->rc_this_oldid, $row->rc_last_oldid ) ); |
| 817 | + |
| 818 | + return $vars; |
| 819 | + } |
| 820 | + |
| 821 | + public static function getMoveVarsFromRCRow( $row ) { |
| 822 | + $vars = array(); |
| 823 | + |
| 824 | + $user = User::newFromId( $row->rc_user ); |
| 825 | + $oldTitle = Title::makeTitle( $row->rc_namespace, $row->rc_title ); |
| 826 | + $newTitle = Title::newFromText( trim($row->rc_params) ); |
| 827 | + |
| 828 | + $vars = array_merge( $vars, AbuseFilter::generateUserVars( $user ), |
| 829 | + AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ), |
| 830 | + AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) ); |
| 831 | + |
| 832 | + $vars['SUMMARY'] = $row->rc_comment; |
| 833 | + $vars['ACTION'] = 'move'; |
| 834 | + |
| 835 | + return $vars; |
| 836 | + } |
| 837 | + |
| 838 | + public static function getEditVars( $title, $old_text, $new_text, $oldLinks = null, $revid=null, $oldid=null ) { |
| 839 | + $vars = array(); |
| 840 | + $article = new Article( $title ); |
| 841 | + |
| 842 | + $vars['EDIT_DELTA'] = strlen($new_text) - strlen($old_text); |
| 843 | + $vars['OLD_SIZE'] = strlen($old_text); |
| 844 | + $diff = wfDiff( $old_text, $new_text ); |
| 845 | + $diff = trim( str_replace( '\No newline at end of file', '', $diff ) ); |
| 846 | + $vars['EDIT_DIFF'] = $diff; |
| 847 | + $vars['NEW_SIZE'] = strlen($new_text); |
| 848 | + |
| 849 | + $vars['OLD_WIKITEXT'] = $old_text; |
| 850 | + $vars['NEW_WIKITEXT'] = $new_text; |
| 851 | + |
| 852 | + // Some more specific/useful details about the changes. |
| 853 | + $diff_lines = explode( "\n", $diff ); |
| 854 | + $added_lines = array(); |
| 855 | + $removed_lines = array(); |
| 856 | + foreach( $diff_lines as $line ) { |
| 857 | + if (strpos( $line, '-' )===0) { |
| 858 | + $removed_lines[] = substr($line,1); |
| 859 | + } elseif (strpos( $line, '+' )===0) { |
| 860 | + $added_lines[] = substr($line,1); |
| 861 | + } |
| 862 | + } |
| 863 | + $vars['ADDED_LINES'] = implode( "\n", $added_lines ); |
| 864 | + $vars['REMOVED_LINES'] = implode( "\n", $removed_lines ); |
| 865 | + |
| 866 | + if ($oldLinks === null && $oldid) { |
| 867 | + $oldInfo = $article->prepareTextForEdit( $old_text, $oldid ); |
| 868 | + $oldLinks = $oldInfo->output->getExternalLinks(); |
| 869 | + } elseif ($oldLinks === null) { |
| 870 | + $oldLinks = array(); |
| 871 | + } |
| 872 | + |
| 873 | + // Added links... |
| 874 | + $editInfo = $article->prepareTextForEdit( $old_text, $revid ); |
| 875 | + $newLinks = array_keys( $editInfo->output->getExternalLinks() ); |
| 876 | + $vars['ALL_LINKS'] = implode( "\n", $newLinks ); |
| 877 | + $vars['ADDED_LINKS'] = implode( "\n", array_diff( $newLinks, array_intersect( $newLinks, $oldLinks ) ) ); |
| 878 | + $vars['REMOVED_LINKS'] = implode( "\n", array_diff( $oldLinks, array_intersect( $newLinks, $oldLinks ) ) ); |
| 879 | + |
| 880 | + // Pull other useful stuff from $editInfo. |
| 881 | + $newHTML = $vars['NEW_HTML'] = $editInfo->output->getText(); |
| 882 | + $newText = $vars['NEW_TEXT'] = preg_replace( '/<[^>]+>/', '', $newHTML ); |
| 883 | + |
| 884 | + return $vars; |
| 885 | + } |
763 | 886 | } |
Index: trunk/extensions/AbuseFilter/edit.js |
— | — | @@ -49,6 +49,15 @@ |
50 | 50 | document.getElementById('wpFilterBuilder').selectedIndex = 0; |
51 | 51 | } |
52 | 52 | |
| 53 | +function fetchFilter() { |
| 54 | + var filter = document.getElementById( 'mw-abusefilter-load-filter' ).value; |
| 55 | + |
| 56 | + sajax_do_call( 'AbuseFilter::ajaxGetFilter', [filter], function(request) { |
| 57 | + var filter = request.responseText; |
| 58 | + document.getElementById( wgFilterBoxName ).value = filter; |
| 59 | + } ); |
| 60 | +} |
| 61 | + |
53 | 62 | //From http://clipmarks.com/clipmark/CEFC94CB-94D6-4495-A7AA-791B7355E284/ |
54 | 63 | function insertAtCursor(myField, myValue) { |
55 | 64 | //IE support |
— | — | @@ -107,5 +116,10 @@ |
108 | 117 | } |
109 | 118 | } ); |
110 | 119 | |
| 120 | + var loader = document.getElementById( 'mw-abusefilter-load' ); |
| 121 | + if (loader) { |
| 122 | + addHandler( loader, 'click', fetchFilter ); |
| 123 | + } |
| 124 | + |
111 | 125 | setupActions(); |
112 | 126 | } ); |
\ No newline at end of file |
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php |
— | — | @@ -315,6 +315,13 @@ |
316 | 316 | 'abusefilter-revert-reason' => 'Automatic revert of all actions taken by the abuse filter due to filter $1. |
317 | 317 | Reason given: $2', |
318 | 318 | 'abusefilter-revert-reasonfield' => 'Reason for revert:', |
| 319 | + |
| 320 | + 'abusefilter-test' => 'Test a filter against previous edits', |
| 321 | + 'abusefilter-test-intro' => 'This page allows you to check a filter entered in the box below against the last $1 changes. To load an existing filter, type its filter ID into the box below the edit textbox, and click the "Load" button.', |
| 322 | + 'abusefilter-test-legend' => 'Filter testing', |
| 323 | + 'abusefilter-test-load-filter' => 'Load filter ID:', |
| 324 | + 'abusefilter-test-submit' => 'Test', |
| 325 | + 'abusefilter-test-load' => 'Load', |
319 | 326 | ); |
320 | 327 | |
321 | 328 | /** Message documentation (Message documentation) |
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php |
— | — | @@ -19,44 +19,11 @@ |
20 | 20 | |
21 | 21 | $old_text = $editor->getBaseRevision() ? $editor->getBaseRevision()->getText() : ''; |
22 | 22 | $new_text = $editor->textbox1; |
23 | | - |
24 | | - $vars['EDIT_DELTA'] = strlen($new_text) - strlen($old_text); |
25 | | - $vars['OLD_SIZE'] = strlen($old_text); |
26 | | - $diff = wfDiff( $old_text, $new_text ); |
27 | | - $diff = trim( str_replace( '\No newline at end of file', '', $diff ) ); |
28 | | - $vars['EDIT_DIFF'] = $diff; |
29 | | - $vars['NEW_SIZE'] = strlen($new_text); |
30 | | - |
31 | | - $vars['OLD_WIKITEXT'] = $old_text; |
32 | | - $vars['NEW_WIKITEXT'] = $new_text; |
33 | | - |
34 | | - // Some more specific/useful details about the changes. |
35 | | - $diff_lines = explode( "\n", $diff ); |
36 | | - $added_lines = array(); |
37 | | - $removed_lines = array(); |
38 | | - foreach( $diff_lines as $line ) { |
39 | | - if (strpos( $line, '-' )===0) { |
40 | | - $removed_lines[] = substr($line,1); |
41 | | - } elseif (strpos( $line, '+' )===0) { |
42 | | - $added_lines[] = substr($line,1); |
43 | | - } |
44 | | - } |
45 | | - $vars['ADDED_LINES'] = implode( "\n", $added_lines ); |
46 | | - $vars['REMOVED_LINES'] = implode( "\n", $removed_lines ); |
47 | | - |
48 | | - // Added links... |
49 | 23 | $oldLinks = self::getOldLinks( $editor->mTitle ); |
50 | | - $editInfo = $editor->mArticle->prepareTextForEdit( $text ); |
51 | | - $newLinks = array_keys( $editInfo->output->getExternalLinks() ); |
52 | | - $vars['ALL_LINKS'] = implode( "\n", $newLinks ); |
53 | | - $vars['ADDED_LINKS'] = implode( "\n", array_diff( $newLinks, array_intersect( $newLinks, $oldLinks ) ) ); |
54 | | - $vars['REMOVED_LINKS'] = implode( "\n", array_diff( $oldLinks, array_intersect( $newLinks, $oldLinks ) ) ); |
55 | 24 | |
56 | | - // Pull other useful stuff from $editInfo. |
57 | | - $newHTML = $vars['NEW_HTML'] = $editInfo->output->getText(); |
58 | | - $newText = $vars['NEW_TEXT'] = preg_replace( '/<[^>]+>/', '', $newHTML ); |
| 25 | + $vars = array_merge( $vars, AbuseFilter::getEditVars( $editor->mTitle, $old_text, $new_text, $oldLinks ) ); |
59 | 26 | |
60 | | - $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle ); |
| 27 | + $filter_result = AbuseFilter::filterAction( $vars, $editor->mTitle, $oldLinks ); |
61 | 28 | |
62 | 29 | if( $filter_result !== true ){ |
63 | 30 | $error = $filter_result; |