r50879 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50878‎ | r50879 | r50880 >
Date:06:42, 22 May 2009
Author:tstarling
Status:deferred
Tags:
Comment:
Code formatting and comments.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.parser.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php (modified) (history)
  • /trunk/extensions/AbuseFilter/SpecialAbuseLog.php (modified) (history)
  • /trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php
@@ -546,6 +546,7 @@
547547 } while ($this->mCur->type == AFPToken::TStatementSeparator);
548548 }
549549
 550+ /** Handles multiple expressions */
550551 protected function doLevelSet( &$result ) {
551552 if( $this->mCur->type == AFPToken::TID ) {
552553 $varname = $this->mCur->value;
@@ -565,13 +566,14 @@
566567 }
567568 $list = $this->mVars->getVar( $varname );
568569 if( $list->type != AFPData::DList )
569 - throw new AFPUserVisibleException( 'notlist', $this->mCur->pos, array() );
 570+ throw new AFPUserVisibleException( 'notlist', $this->mCur->pos, array() );
570571 $list = $list->toList();
571572 $this->move();
572573 if( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == ']' ) {
573574 $idx = 'new';
574575 } else {
575 - $this->setState( $prev ); $this->move();
 576+ $this->setState( $prev );
 577+ $this->move();
576578 $idx = new AFPData();
577579 $this->doLevelSemicolon( $idx );
578580 $idx = $idx->toInt();
Index: trunk/extensions/AbuseFilter/SpecialAbuseLog.php
@@ -37,7 +37,7 @@
3838 }
3939
4040 $detailsid = $wgRequest->getIntOrNull( 'details' );
41 - if ($detailsid) {
 41+ if ( $detailsid ) {
4242 $this->showDetails( $detailsid );
4343 } else {
4444 // Show the search form.
@@ -54,13 +54,16 @@
5555 $this->mSearchUser = $wgRequest->getText( 'wpSearchUser' );
5656
5757 $t = Title::newFromText( trim($this->mSearchUser) );
58 - if ($t) {
 58+ if ( $t ) {
5959 $this->mSearchUser = $t->getText(); // Username normalisation
60 - } else $this->mSearchUser = null;
 60+ } else {
 61+ $this->mSearchUser = null;
 62+ }
6163
6264 $this->mSearchTitle = $wgRequest->getText( 'wpSearchTitle' );
63 - if ($this->canSeeDetails())
 65+ if ( $this->canSeeDetails() ) {
6466 $this->mSearchFilter = $wgRequest->getIntOrNull( 'wpSearchFilter' );
 67+ }
6568 }
6669
6770 function searchForm() {
@@ -96,13 +99,15 @@
97100 // Generate conditions list.
98101 $conds = array();
99102
100 - if (!empty($this->mSearchUser))
 103+ if ( !empty( $this->mSearchUser ) ) {
101104 $conds['afl_user_text'] = $this->mSearchUser;
102 - if (!empty($this->mSearchFilter))
 105+ }
 106+ if ( !empty( $this->mSearchFilter ) ) {
103107 $conds['afl_filter'] = $this->mSearchFilter;
 108+ }
104109
105110 $searchTitle = Title::newFromText( $this->mSearchTitle );
106 - if ($this->mSearchTitle && $searchTitle) {
 111+ if ( $this->mSearchTitle && $searchTitle ) {
107112 $conds['afl_namespace'] = $searchTitle->getNamespace();
108113 $conds['afl_title'] = $searchTitle->getDBKey();
109114 }
@@ -116,7 +121,7 @@
117122 }
118123
119124 function showDetails( $id ) {
120 - if (!$this->canSeeDetails()) {
 125+ if ( !$this->canSeeDetails() ) {
121126 return;
122127 }
123128
@@ -126,8 +131,9 @@
127132 array( 'afl_id' => $id ), __METHOD__,
128133 array( 'abuse_filter' => array( 'left join', 'af_id=afl_filter') ) );
129134
130 - if (!$row)
 135+ if ( !$row ) {
131136 return;
 137+ }
132138
133139 $output = '';
134140
@@ -177,7 +183,7 @@
178184 // Build a table.
179185 $output .= AbuseFilter::buildVarDumpTable( $vars );
180186
181 - if ($this->canSeePrivate()) {
 187+ if ( $this->canSeePrivate() ) {
182188 // Private stuff, like IPs.
183189 $header =
184190 Xml::element( 'th', null, wfMsg( 'abusefilter-log-details-var' ) ) .
@@ -214,8 +220,8 @@
215221
216222 function canSeeDetails() {
217223 global $wgUser;
218 - return !count($this->getTitle()->getUserPermissionsErrors(
219 - 'abusefilter-log-detail', $wgUser, true, array( 'ns-specialprotected' ) ));
 224+ return !count( $this->getTitle()->getUserPermissionsErrors(
 225+ 'abusefilter-log-detail', $wgUser, true, array( 'ns-specialprotected' ) ) );
220226 }
221227
222228 function canSeePrivate() {
@@ -231,19 +237,19 @@
232238 ## One-time setup
233239 static $sk=null;
234240
235 - if (is_null($sk)) {
 241+ if ( is_null( $sk ) ) {
236242 $sk = $wgUser->getSkin();
237243 }
238244
239245 $title = Title::makeTitle( $row->afl_namespace, $row->afl_title );
240246
241 - if (!$row->afl_wiki) {
 247+ if ( !$row->afl_wiki ) {
242248 $pageLink = $sk->link( $title );
243249 } else {
244250 $pageLink = WikiMap::makeForeignLink( $row->afl_wiki, $row->afl_title );
245251 }
246252
247 - if (!$row->afl_wiki) {
 253+ if ( !$row->afl_wiki ) {
248254 // Local user
249255 $user = $sk->userLink( $row->afl_user, $row->afl_user_text ) .
250256 $sk->userToolLinks( $row->afl_user, $row->afl_user_text );
@@ -257,10 +263,10 @@
258264 $timestamp = $wgLang->timeanddate( $row->afl_timestamp, true );
259265
260266 $actions_taken = $row->afl_actions;
261 - if ( !strlen( trim( $actions_taken) ) ) {
 267+ if ( !strlen( trim( $actions_taken ) ) ) {
262268 $actions_taken = wfMsg( 'abusefilter-log-noactions' );
263269 } else {
264 - $actions = explode(',', $actions_taken);
 270+ $actions = explode( ',', $actions_taken );
265271 $displayActions = array();
266272
267273 foreach( $actions as $action ) {
@@ -272,7 +278,7 @@
273279 $globalIndex = AbuseFilter::decodeGlobalName( $row->afl_filter );
274280
275281 global $wgOut;
276 - if ($globalIndex) {
 282+ if ( $globalIndex ) {
277283 // Pull global filter description
278284 $parsed_comments =
279285 $wgOut->parseInline( AbuseFilter::getGlobalFilterDescription( $globalIndex ) );
@@ -280,7 +286,7 @@
281287 $parsed_comments = $wgOut->parseInline( $row->af_public_comments );
282288 }
283289
284 - if ($this->canSeeDetails()) {
 290+ if ( $this->canSeeDetails() ) {
285291 $examineTitle = SpecialPage::getTitleFor( 'AbuseFilter', "examine/log/".$row->afl_id );
286292 $detailsLink = $sk->makeKnownLinkObj(
287293 $this->getTitle(),
@@ -291,7 +297,7 @@
292298 wfMsgExt( 'abusefilter-changeslist-examine', 'parseinline' ),
293299 array() );
294300
295 - if ($globalIndex) {
 301+ if ( $globalIndex ) {
296302 global $wgAbuseFilterCentralDB;
297303 $globalURL =
298304 WikiMap::getForeignURL( $wgAbuseFilterCentralDB,
Index: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
@@ -22,7 +22,7 @@
2323 $didEdit = $this->canEdit()
2424 && $wgUser->matchEditToken( $editToken, array( 'abusefilter', $filter ) );
2525
26 - if ($didEdit) {
 26+ if ( $didEdit ) {
2727 // Check syntax
2828 $syntaxerr = AbuseFilter::checkSyntax( $wgRequest->getVal( 'wpFilterRules' ) );
2929 if ($syntaxerr !== true ) {
Index: trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php
@@ -6,7 +6,7 @@
77
88 function setVar( $variable, $datum ) {
99 $variable = strtolower( $variable );
10 - if (!( $datum instanceof AFPData || $datum instanceof AFComputedVariable ) ) {
 10+ if ( !( $datum instanceof AFPData || $datum instanceof AFComputedVariable ) ) {
1111 $datum = AFPData::newFromPHPVar( $datum );
1212 }
1313
@@ -20,15 +20,14 @@
2121
2222 function getVar( $variable ) {
2323 $variable = strtolower( $variable );
24 - if ( isset($this->mVars[$variable]) ) {
25 -
26 - if ($this->mVars[$variable] instanceof AFComputedVariable) {
 24+ if ( isset( $this->mVars[$variable] ) ) {
 25+ if ( $this->mVars[$variable] instanceof AFComputedVariable ) {
2726 $value = $this->mVars[$variable]->compute( $this );
2827 $this->setVar( $variable, $value );
29 -
3028 return $value;
31 - } elseif ($this->mVars[$variable] instanceof AFPData)
 29+ } elseif ( $this->mVars[$variable] instanceof AFPData ) {
3230 return $this->mVars[$variable];
 31+ }
3332 } else {
3433 return new AFPData();
3534 }
@@ -45,8 +44,9 @@
4645 }
4746
4847 function addHolder( $addHolder ) {
49 - if ( !is_object($addHolder) )
 48+ if ( !is_object( $addHolder ) ) {
5049 throw new MWException( "Invalid argument to AbuseFilterVariableHolder::addHolder" );
 50+ }
5151 $this->mVars = array_merge( $this->mVars, $addHolder->mVars );
5252 }
5353
@@ -60,8 +60,9 @@
6161 $exported = array();
6262
6363 foreach( $allVarNames as $varName ) {
64 - if (!in_array( $varName, self::$varBlacklist ) )
 64+ if ( !in_array( $varName, self::$varBlacklist ) ) {
6565 $exported[$varName] = $this->getVar( $varName )->toString();
 66+ }
6667 }
6768
6869 return $exported;
@@ -80,7 +81,7 @@
8182 'revision-text-by-timestamp' );
8283
8384 foreach( $this->mVars as $name => $value ) {
84 - if ($value instanceof AFComputedVariable &&
 85+ if ( $value instanceof AFComputedVariable &&
8586 in_array( $value->mMethod, $dbTypes ) ) {
8687 $value = $value->compute( $this );
8788 $this->setVar( $name, $value );
@@ -106,8 +107,9 @@
107108
108109 $cacheKey = md5($wikitext).':'.$article->mTitle->getPrefixedText();
109110
110 - if ( isset( $cache[$cacheKey] ) )
 111+ if ( isset( $cache[$cacheKey] ) ) {
111112 return $cache[$cacheKey];
 113+ }
112114
113115 global $wgParser;
114116 $edit = (object)array();
@@ -120,15 +122,17 @@
121123 }
122124
123125 static function userObjectFromName( $username ) {
124 - if ( isset( self::$userCache[$username] ) )
 126+ if ( isset( self::$userCache[$username] ) ) {
125127 return self::$userCache[$username];
 128+ }
126129
127130 wfDebug( "Couldn't find user $username in cache\n" );
128131
129 - if (IP::isIPAddress( $username )) {
 132+ if ( IP::isIPAddress( $username ) ) {
130133 $u = new User;
131134 $u->setName( $username );
132 - return self::$userCache[$username] = $u;
 135+ self::$userCache[$username] = $u;
 136+ return $u;
133137 }
134138
135139 $user = User::newFromName( $username );
@@ -139,8 +143,9 @@
140144 }
141145
142146 static function articleFromTitle( $namespace, $title ) {
143 - if ( isset( self::$articleCache["$namespace:$title"] ) )
 147+ if ( isset( self::$articleCache["$namespace:$title"] ) ) {
144148 return self::$articleCache["$namespace:$title"];
 149+ }
145150
146151 wfDebug( "Creating article object for $namespace:$title in cache\n" );
147152
@@ -153,7 +158,9 @@
154159 static function getLinksFromDB( $article ) {
155160 // Stolen from ConfirmEdit
156161 $id = $article->getId();
157 - if (!$id) return array();
 162+ if ( !$id ) {
 163+ return array();
 164+ }
158165
159166 $dbr = wfGetDB( DB_SLAVE );
160167 $res = $dbr->select( 'externallinks', array( 'el_to' ),
@@ -260,7 +267,7 @@
261268 $textVar = $parameters['wikitext-var'];
262269
263270 $text = $vars->getVar( $textVar )->toString();
264 - $editInfo = $this->parseNonEditWIkitext( $text, $article );
 271+ $editInfo = $this->parseNonEditWikitext( $text, $article );
265272
266273 $result = $editInfo->output->getText();
267274 break;

Status & tagging log