r40491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40490‎ | r40491 | r40492 >
Date:14:27, 5 September 2008
Author:werdna
Status:old
Tags:
Comment:
Add basic functionality to delete filters (not really a deletion, just moved to another list)
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/SpecialAbuseFilter.php (modified) (history)
  • /trunk/extensions/AbuseFilter/abusefilter.tables.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -752,7 +752,8 @@
753753
754754 $float = in_string( '.', $tok );
755755
756 - return array( $float ? doubleval( $tok ) : intval( $tok ), $float ? AFPToken::TFloat : AFPToken::TInt, $code, $pos );
 756+ if (strlen($tok))
 757+ return array( $float ? doubleval( $tok ) : intval( $tok ), $float ? AFPToken::TFloat : AFPToken::TInt, $code, $pos );
757758 }
758759
759760 if( ctype_punct( $code[0] ) ) {
Index: trunk/extensions/AbuseFilter/AbuseFilter.php
@@ -42,6 +42,7 @@
4343 $wgHooks['AbortMove'][] = 'AbuseFilterHooks::onAbortMove';
4444 $wgHooks['AbortNewAccount'][] = 'AbuseFilterHooks::onAbortNewAccount';
4545 $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete';
 46+$wgHooks['LoadExtensionSchemaUpdates'][] = 'AbuseFilterHooks::onSchemaUpdate';
4647
4748 $wgAvailableRights[] = 'abusefilter-modify';
4849 $wgAvailableRights[] = 'abusefilter-log-detail';
Index: trunk/extensions/AbuseFilter/SpecialAbuseFilter.php
@@ -23,9 +23,9 @@
2424 $wgOut->enableClientCache( false );
2525
2626 // Are we allowed?
27 - if ( count( $errors = $this->getTitle()->getUserPermissionsErrors( 'abusefilter-view', $wgUser, true, array( 'ns-specialprotected' ) ) ) ) {
 27+ if ( !$wgUser->isAllowed( 'abusefilter-view' ) ) {
2828 // Go away.
29 - $wgOut->showPermissionsErrorPage( $errors, 'abusefilter-view' );
 29+ $this->displayRestrictionError();
3030 return;
3131 }
3232
@@ -46,14 +46,45 @@
4747 return;
4848 }
4949
50 -
51 - $wgOut->addWikiMsg( 'abusefilter-tools' );
5250 // Show list of filters.
5351 $this->showStatus();
5452
 53+ // Quick links
 54+ $wgOut->addWikiMsg( 'abusefilter-links' );
 55+ $lists = array( 'active', 'deleted', 'all', 'tools' );
 56+ $links = '';
 57+ $sk = $wgUser->getSkin();
 58+ foreach( $lists as $list ) {
 59+ $title = $this->getTitle( $list );
 60+
 61+ $link = $sk->link( $title, wfMsg( "abusefilter-show-$list" ) );
 62+ $links .= Xml::tags( 'li', null, $link ) . "\n";
 63+ }
 64+ $links .= Xml::tags( 'li', null, $sk->link( SpecialPage::getTitleFor( 'AbuseLog' ), wfMsg( 'abusefilter-loglink' ) ) );
 65+ $links = Xml::tags( 'ul', null, $links );
 66+ $wgOut->addHTML( $links );
 67+
 68+ if ($subpage == 'deleted') {
 69+ $this->showDeleted();
 70+ return;
 71+ }
 72+
 73+ if ($subpage == 'active') {
 74+ $this->showActive();
 75+ return;
 76+ }
 77+
5578 $this->showList();
5679 }
5780
 81+ function showDeleted() {
 82+ $this->showList( array( 'af_deleted' => 1 ) );
 83+ }
 84+
 85+ function showActive() {
 86+ $this->showList( array( 'af_deleted' => 0, 'af_enabled' => 1 ) );
 87+ }
 88+
5889 function showHistory() {
5990 global $wgRequest,$wgOut;
6091
@@ -192,7 +223,7 @@
193224 $actionsRows = array();
194225 foreach( $wgAbuseFilterAvailableActions as $action ) {
195226 // Check if it's set
196 - $enabled = (bool)$actions[$action];
 227+ $enabled = isset($actions[$action]) && (bool)$actions[$action];
197228
198229 if ($enabled) {
199230 $parameters = $actions[$action]['parameters'];
@@ -205,7 +236,7 @@
206237 }
207238
208239 // Create a history row
209 - $history_mappings = array( 'af_pattern' => 'afh_pattern', 'af_user' => 'afh_user', 'af_user_text' => 'afh_user_text', 'af_timestamp' => 'afh_timestamp', 'af_comments' => 'afh_comments', 'af_public_comments' => 'afh_public_comments' );
 240+ $history_mappings = array( 'af_pattern' => 'afh_pattern', 'af_user' => 'afh_user', 'af_user_text' => 'afh_user_text', 'af_timestamp' => 'afh_timestamp', 'af_comments' => 'afh_comments', 'af_public_comments' => 'afh_public_comments', 'af_deleted' => 'afh_deleted' );
210241
211242 $afh_row = array();
212243
@@ -226,6 +257,8 @@
227258 $flags[] = wfMsgForContent( 'abusefilter-history-hidden' );
228259 if ($newRow['af_enabled'])
229260 $flags[] = wfMsgForContent( 'abusefilter-history-enabled' );
 261+ if ($newRow['af_deleted'])
 262+ $flags[] = wfMsgForContent( 'abusefilter-history-deleted' );
230263
231264 $afh_row['afh_flags'] = implode( ",", $flags );
232265
@@ -311,7 +344,7 @@
312345 $fields['abusefilter-edit-notes'] = Xml::textarea( 'wpFilterNotes', ( isset( $row->af_comments ) ? $row->af_comments."\n" : "\n" ) );
313346
314347 // Build checkboxen
315 - $checkboxes = array( 'hidden', 'enabled' );
 348+ $checkboxes = array( 'hidden', 'enabled', 'deleted' );
316349 $flags = '';
317350
318351 if (isset($row->af_throttled) && $row->af_throttled) {
@@ -506,7 +539,8 @@
507540 $row->$col = $wgRequest->getVal( $field );
508541 }
509542
510 - $row->af_enabled = $wgRequest->getBool( 'wpFilterEnabled' );
 543+ $row->af_deleted = $wgRequest->getBool( 'wpFilterDeleted' );
 544+ $row->af_enabled = $wgRequest->getBool( 'wpFilterEnabled' ) && !$row->af_deleted;
511545 $row->af_hidden = $wgRequest->getBool( 'wpFilterHidden' );
512546
513547 // Actions
@@ -550,7 +584,7 @@
551585 return $canEdit;
552586 }
553587
554 - function showList() {
 588+ function showList( $conds = array( 'af_deleted' => 0 )) {
555589 global $wgOut,$wgUser;
556590
557591 $sk = $this->mSkin = $wgUser->getSkin();
@@ -562,7 +596,7 @@
563597 // We shouldn't have more than 100 filters, so don't bother paging.
564598 $dbr = wfGetDB( DB_SLAVE );
565599 $abuse_filter = $dbr->tableName( 'abuse_filter' );
566 - $res = $dbr->select( array('abuse_filter', 'abuse_filter_action'), $abuse_filter.'.*,group_concat(afa_consequence) AS consequences', array( ), __METHOD__, array( 'LIMIT' => 100, 'GROUP BY' => 'af_id' ),
 600+ $res = $dbr->select( array('abuse_filter', 'abuse_filter_action'), $abuse_filter.'.*,group_concat(afa_consequence) AS consequences', $conds, __METHOD__, array( 'LIMIT' => 100, 'GROUP BY' => 'af_id' ),
567601 array( 'abuse_filter_action' => array('LEFT OUTER JOIN', 'afa_filter=af_id' ) ) );
568602 $list = '';
569603 $editLabel = $this->canEdit() ? 'abusefilter-list-edit' : 'abusefilter-list-details';
@@ -599,8 +633,12 @@
600634 // Build a table row
601635 $trow = '';
602636
603 - $status = $row->af_enabled ? 'abusefilter-enabled' : 'abusefilter-disabled';
604 - $status = wfMsgExt( $status, array( 'parseinline' ) );
 637+ if ($row->af_deleted) {
 638+ $status = wfMsgExt( 'abusefilter-deleted', array( 'parseinline' ) );
 639+ } else {
 640+ $status = $row->af_enabled ? 'abusefilter-enabled' : 'abusefilter-disabled';
 641+ $status = wfMsgExt( $status, array( 'parseinline' ) );
 642+ }
605643
606644 $visibility = $row->af_hidden ? 'abusefilter-hidden' : 'abusefilter-unhidden';
607645 $visibility = wfMsgExt( $visibility, array( 'parseinline' ) );
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -119,7 +119,7 @@
120120
121121 // Fetch from the database.
122122 $dbr = wfGetDB( DB_SLAVE );
123 - $res = $dbr->select( 'abuse_filter', '*', array( 'af_enabled' => 1 ) );
 123+ $res = $dbr->select( 'abuse_filter', '*', array( 'af_enabled' => 1, 'af_deleted' => 0 ) );
124124
125125 $blocking_filters = array();
126126 $log_entries = array();
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -86,13 +86,19 @@
8787 'abusefilter-hidden' => 'Private',
8888 'abusefilter-unhidden' => 'Public',
8989 'abusefilter-enabled' => 'Enabled',
 90+ 'abusefilter-deleted' => 'Deleted',
9091 'abusefilter-disabled' => 'Disabled',
9192 'abusefilter-hitcount' => '$1 {{PLURAL:$1|hit|hits}}',
9293 'abusefilter-list-new' => 'New filter',
 94+ 'abusefilter-links' => 'Useful links:',
9395 'abusefilter-tools-modifiertest-submit' => 'Test',
 96+ 'abusefilter-show-deleted' => 'View deleted filters',
 97+ 'abusefilter-show-all' => 'Show all undeleted filters',
 98+ 'abusefilter-show-active' => 'Hide disabled filters',
 99+ 'abusefilter-show-tools' => 'Abuse filter tools',
 100+ 'abusefilter-loglink' => 'View the abuse log',
94101
95102 // Abuse filter tools
96 - 'abusefilter-tools' => 'Some [[Special:AbuseFilter/tools|tools]] are available to assist in formulating and debugging abuse filters.',
97103 'abusefilter-tools-subtitle' => 'Tools',
98104 'abusefilter-tools-text' => 'Here are some tools which may be useful in formulating and debugging abuse filters. [[Special:AbuseFilter|Return to main menu]]',
99105 'abusefilter-tools-expr' => 'Expression tester',
@@ -112,6 +118,7 @@
113119 'abusefilter-edit-description' => "Description:\n:''(publicly viewable)''",
114120 'abusefilter-edit-flags' => 'Flags:',
115121 'abusefilter-edit-enabled' => 'Enable this filter',
 122+ 'abusefilter-edit-deleted' => 'Mark as deleted',
116123 'abusefilter-edit-hidden' => 'Hide details of this filter from public view',
117124 'abusefilter-edit-rules' => 'Conditions:',
118125 'abusefilter-edit-notes' => "Notes:\n:''(private)",
@@ -216,6 +223,7 @@
217224 'abusefilter-history-action' => '$1: $2',
218225 'abusefilter-history-backedit' => 'Back to filter editor',
219226 'abusefilter-history-backlist' => 'Back to filter list',
 227+ 'abusefilter-history-deleted' => 'Deleted',
220228 );
221229
222230 /** Message documentation (Message documentation)
Index: trunk/extensions/AbuseFilter/abusefilter.tables.sql
@@ -12,6 +12,7 @@
1313 af_hidden tinyint(1) not null default 0,
1414 af_hit_count bigint not null default 0,
1515 af_throttled tinyint(1) NOT NULL default 0,
 16+ af_deleted tinyint(1) NOT NULL DEFAULT 0,
1617
1718 PRIMARY KEY (af_id),
1819 KEY (af_user)
Index: trunk/extensions/AbuseFilter/AbuseFilter.hooks.php
@@ -105,4 +105,19 @@
106106
107107 return $filter_result == '' || $filter_result === true;
108108 }
 109+
 110+ public static function onSchemaUpdate() {
 111+ global $wgDatabase;
 112+
 113+ if ( !$wgDatabase->tableExists( 'abuse_filter' ) ) {
 114+ // Full tables
 115+ dbsource( dirname(__FILE__).'/abusefilter.tables.sql', $wgDatabase );
 116+ }
 117+
 118+ if ( ! $wgDatabase->fieldExists( 'abuse_filter', 'af_deleted' ) ) {
 119+ dbsource( dirname( __FILE__ ) . '/db_patches/patch-af_deleted.sql' );
 120+ }
 121+
 122+ return true;
 123+ }
109124 }