r36696 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36695‎ | r36696 | r36697 >
Date:07:21, 27 June 2008
Author:werdna
Status:old
Tags:
Comment:
Actually allow people to add filters...
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /trunk/extensions/AbuseFilter/SpecialAbuseFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -61,9 +61,11 @@
6262 'abusefilter-enabled' => 'Enabled',
6363 'abusefilter-disabled' => 'Disabled',
6464 'abusefilter-hitcount' => '$1 {{PLURAL:$1|hit|hits}}',
 65+ 'abusefilter-list-new' => 'New filter',
6566
6667 // The edit screen
6768 'abusefilter-edit-subtitle' => 'Editing filter $1',
 69+ 'abusefilter-edit-new' => 'New filter',
6870 'abusefilter-edit-save' => 'Save Filter',
6971 'abusefilter-edit-id' => 'Filter ID:',
7072 'abusefilter-edit-description' => "Description:\n:''(publicly viewable)''",
Index: trunk/extensions/AbuseFilter/SpecialAbuseFilter.php
@@ -45,7 +45,7 @@
4646 $filter = $this->mFilter;
4747
4848 $editToken = $wgRequest->getVal( 'wpEditToken' );
49 - $didEdit = $filter && $this->canEdit() && $wgUser->matchEditToken( $editToken, array( 'abusefilter', $filter ) );
 49+ $didEdit = $this->canEdit() && $wgUser->matchEditToken( $editToken, array( 'abusefilter', $filter ) );
5050
5151 if ($didEdit) {
5252 $dbw = wfGetDB( DB_MASTER );
@@ -104,7 +104,7 @@
105105 // Do the update
106106
107107 $dbw->begin();
108 - $dbw->update( 'abuse_filter', $newRow, array( 'af_id' => $filter ), __METHOD__ );
 108+ $dbw->replace( 'abuse_filter', array( 'af_id' ), $newRow, __METHOD__ );
109109 $dbw->delete( 'abuse_filter_action', array( 'afa_filter' => $filter, 'afa_consequence' => $deadActions ), __METHOD__ );
110110 $dbw->replace( 'abuse_filter_action', array( array( 'afa_filter', 'afa_consequence' ) ), $actionsRows, __METHOD__ );
111111 $dbw->commit();
@@ -119,7 +119,7 @@
120120 }
121121
122122 function buildFilterEditor( ) {
123 - if (!is_numeric($this->mFilter) || $this->mFilter<=0) {
 123+ if (!is_numeric($this->mFilter) && $this->mFilter != 'new') {
124124 return false;
125125 }
126126
@@ -130,6 +130,10 @@
131131
132132 list ($row, $actions) = $this->loadFilterData();
133133
 134+ if (!$row && $this->mFilter !== 'new') {
 135+ return false;
 136+ }
 137+
134138 if ($row->af_hidden && !$this->canEdit()) {
135139 return wfMsg( 'abusefilter-edit-hidden' );
136140 }
@@ -137,11 +141,11 @@
138142 $output = '';
139143 $fields = array();
140144
141 - $fields['abusefilter-edit-id'] = $this->mFilter;
 145+ $fields['abusefilter-edit-id'] = $this->mFilter == 'new' ? wfMsg( 'abusefilter-edit-new' ) : $this->mFilter;
142146 $fields['abusefilter-edit-description'] = Xml::input( 'wpFilterDescription', 20, $row->af_public_comments );
143147
144148 // Hit count display
145 - $count = $row->af_hit_count;
 149+ $count = (int)$row->af_hit_count;
146150 $count_display = wfMsgExt( 'abusefilter-hitcount', array( 'parseinline' ), array( $count ) );
147151 $hitCount = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'AbuseLog' ), $count_display, 'wpSearchFilter='.$row->af_id );
148152
@@ -165,9 +169,11 @@
166170 }
167171 $fields['abusefilter-edit-flags'] = $flags;
168172
169 - // Last modification details
170 - $fields['abusefilter-edit-lastmod'] = $wgLang->timeanddate( $row->af_timestamp );
171 - $fields['abusefilter-edit-lastuser'] = $sk->userLink( $row->af_user, $row->af_user_text ) . $sk->userToolLinks( $row->af_user, $row->af_user_text );
 173+ if ($this->mFilter != 'new') {
 174+ // Last modification details
 175+ $fields['abusefilter-edit-lastmod'] = $wgLang->timeanddate( $row->af_timestamp );
 176+ $fields['abusefilter-edit-lastuser'] = $sk->userLink( $row->af_user, $row->af_user_text ) . $sk->userToolLinks( $row->af_user, $row->af_user_text );
 177+ }
172178
173179 $form = Xml::buildForm( $fields );
174180 $form = Xml::fieldset( wfMsg( 'abusefilter-edit-main' ), $form );
@@ -265,10 +271,10 @@
266272
267273 $filter = $subpage;
268274
269 - if (!is_numeric($filter)) {
 275+ if (!is_numeric($filter) && $subpage != 'new') {
270276 $filter = $wgRequest->getIntOrNull( 'wpFilter' );
271277
272 - if (!$filter) {
 278+ if ($filter === null && $filter != 'new') {
273279 return;
274280 }
275281 }
@@ -287,9 +293,9 @@
288294 }
289295
290296 function showList() {
291 - global $wgOut,$wgUser;;
 297+ global $wgOut,$wgUser;
292298
293 - $this->mSkin = $wgUser->getSkin();
 299+ $sk = $this->mSkin = $wgUser->getSkin();
294300
295301 $output = '';
296302
@@ -316,6 +322,10 @@
317323
318324 $output .= Xml::tags( 'table', array( 'class' => 'wikitable' ), Xml::tags( 'tbody', null, $list ) );
319325
 326+ if ($this->canEdit()) {
 327+ $output .= $sk->makeKnownLinkObj( $this->getTitle( 'new' ), wfMsg( 'abusefilter-list-new' ) );
 328+ }
 329+
320330 $wgOut->addHTML( $output );
321331 }
322332

Status & tagging log