r71396 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71395‎ | r71396 | r71397 >
Date:12:00, 21 August 2010
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks
Modified paths:
  • /trunk/phase3/includes/LogPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogPage.php
@@ -43,17 +43,17 @@
4444 var $updateRecentChanges, $sendToUDP;
4545
4646 /**
47 - * Constructor
48 - *
49 - * @param $type String: one of '', 'block', 'protect', 'rights', 'delete',
50 - * 'upload', 'move'
51 - * @param $rc Boolean: whether to update recent changes as well as the logging table
52 - * @param $udp String: pass 'UDP' to send to the UDP feed if NOT sent to RC
53 - */
 47+ * Constructor
 48+ *
 49+ * @param $type String: one of '', 'block', 'protect', 'rights', 'delete',
 50+ * 'upload', 'move'
 51+ * @param $rc Boolean: whether to update recent changes as well as the logging table
 52+ * @param $udp String: pass 'UDP' to send to the UDP feed if NOT sent to RC
 53+ */
5454 public function __construct( $type, $rc = true, $udp = 'skipUDP' ) {
5555 $this->type = $type;
5656 $this->updateRecentChanges = $rc;
57 - $this->sendToUDP = ($udp == 'UDP');
 57+ $this->sendToUDP = ( $udp == 'UDP' );
5858 }
5959
6060 protected function saveContent() {
@@ -77,23 +77,29 @@
7878 'log_params' => $this->params
7979 );
8080 $dbw->insert( 'logging', $data, __METHOD__ );
81 - $newId = !is_null($log_id) ? $log_id : $dbw->insertId();
 81+ $newId = !is_null( $log_id ) ? $log_id : $dbw->insertId();
8282
8383 # And update recentchanges
8484 if( $this->updateRecentChanges ) {
8585 $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
86 - RecentChange::notifyLog( $now, $titleObj, $this->doer, $this->getRcComment(), '', $this->type,
87 - $this->action, $this->target, $this->comment, $this->params, $newId );
88 - } else if( $this->sendToUDP ) {
 86+ RecentChange::notifyLog(
 87+ $now, $titleObj, $this->doer, $this->getRcComment(), '',
 88+ $this->type, $this->action, $this->target, $this->comment,
 89+ $this->params, $newId
 90+ );
 91+ } elseif( $this->sendToUDP ) {
8992 # Don't send private logs to UDP
90 - if( isset($wgLogRestrictions[$this->type]) && $wgLogRestrictions[$this->type] !='*' ) {
 93+ if( isset( $wgLogRestrictions[$this->type] ) && $wgLogRestrictions[$this->type] != '*' ) {
9194 return true;
9295 }
9396 # Notify external application via UDP.
9497 # We send this to IRC but do not want to add it the RC table.
9598 $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
96 - $rc = RecentChange::newLogEntry( $now, $titleObj, $this->doer, $this->getRcComment(), '',
97 - $this->type, $this->action, $this->target, $this->comment, $this->params, $newId );
 99+ $rc = RecentChange::newLogEntry(
 100+ $now, $titleObj, $this->doer, $this->getRcComment(), '',
 101+ $this->type, $this->action, $this->target, $this->comment,
 102+ $this->params, $newId
 103+ );
98104 $rc->notifyRC2UDP();
99105 }
100106 return $newId;
@@ -105,10 +111,11 @@
106112 public function getRcComment() {
107113 $rcComment = $this->actionText;
108114 if( $this->comment != '' ) {
109 - if ($rcComment == '')
 115+ if ( $rcComment == '' ) {
110116 $rcComment = $this->comment;
111 - else
 117+ } else {
112118 $rcComment .= wfMsgForContent( 'colon-separator' ) . $this->comment;
 119+ }
113120 }
114121 return $rcComment;
115122 }
@@ -166,7 +173,7 @@
167174 */
168175 public static function logHeader( $type ) {
169176 global $wgLogHeaders;
170 - return wfMsgExt($wgLogHeaders[$type], array( 'parseinline' ) );
 177+ return wfMsgExt( $wgLogHeaders[$type], array( 'parseinline' ) );
171178 }
172179
173180 /**
@@ -176,13 +183,13 @@
177184 * @param $action String: log action
178185 * @param $title Mixed: Title object or null
179186 * @param $skin Mixed: Skin object or null. If null, we want to use the wiki
180 - * content language, since that will go to the irc feed.
 187+ * content language, since that will go to the IRC feed.
181188 * @param $params Array: parameters
182189 * @param $filterWikilinks Boolean: whether to filter wiki links
183190 * @return HTML string
184191 */
185192 public static function actionText( $type, $action, $title = null, $skin = null,
186 - $params = array(), $filterWikilinks = false )
 193+ $params = array(), $filterWikilinks = false )
187194 {
188195 global $wgLang, $wgContLang, $wgLogActions;
189196
@@ -207,10 +214,12 @@
208215 } else {
209216 $rightsnone = wfMsgForContent( 'rightsnone' );
210217 }
211 - if( !isset( $params[0] ) || trim( $params[0] ) == '' )
 218+ if( !isset( $params[0] ) || trim( $params[0] ) == '' ) {
212219 $params[0] = $rightsnone;
213 - if( !isset( $params[1] ) || trim( $params[1] ) == '' )
 220+ }
 221+ if( !isset( $params[1] ) || trim( $params[1] ) == '' ) {
214222 $params[1] = $rightsnone;
 223+ }
215224 }
216225 if( count( $params ) == 0 ) {
217226 if ( $skin ) {
@@ -224,16 +233,16 @@
225234 // User suppression
226235 if ( preg_match( '/^(block|suppress)\/(block|reblock)$/', $key ) ) {
227236 if ( $skin ) {
228 - $params[1] = '<span title="' . htmlspecialchars( $params[1] ). '">' .
 237+ $params[1] = '<span title="' . htmlspecialchars( $params[1] ). '">' .
229238 $wgLang->translateBlockExpiry( $params[1] ) . '</span>';
230239 } else {
231240 $params[1] = $wgContLang->translateBlockExpiry( $params[1] );
232241 }
233 - $params[2] = isset( $params[2] ) ?
 242+ $params[2] = isset( $params[2] ) ?
234243 self::formatBlockFlags( $params[2], is_null( $skin ) ) : '';
235244
236245 // Page protections
237 - } else if ( $type == 'protect' && count($params) == 3 ) {
 246+ } elseif ( $type == 'protect' && count($params) == 3 ) {
238247 // Restrictions and expiries
239248 if( $skin ) {
240249 $details .= htmlspecialchars( " {$params[1]}" );
@@ -243,14 +252,14 @@
244253 // Cascading flag...
245254 if( $params[2] ) {
246255 if ( $skin ) {
247 - $details .= ' ['.wfMsg('protect-summary-cascade').']';
 256+ $details .= ' [' . wfMsg( 'protect-summary-cascade' ) . ']';
248257 } else {
249 - $details .= ' ['.wfMsgForContent('protect-summary-cascade').']';
 258+ $details .= ' [' . wfMsgForContent( 'protect-summary-cascade' ) . ']';
250259 }
251260 }
252261
253262 // Page moves
254 - } else if ( $type == 'move' && count( $params ) == 3 && $action != 'move_rev' ) {
 263+ } elseif ( $type == 'move' && count( $params ) == 3 && $action != 'move_rev' ) {
255264 if( $params[2] ) {
256265 if ( $skin ) {
257266 $details .= ' [' . wfMsg( 'move-redirect-suppressed' ) . ']';
@@ -260,18 +269,18 @@
261270 }
262271
263272 // Revision deletion
264 - } else if ( preg_match( '/^(delete|suppress)\/revision$/', $key ) && count( $params ) == 5 ) {
 273+ } elseif ( preg_match( '/^(delete|suppress)\/revision$/', $key ) && count( $params ) == 5 ) {
265274 $count = substr_count( $params[2], ',' ) + 1; // revisions
266275 $ofield = intval( substr( $params[3], 7 ) ); // <ofield=x>
267276 $nfield = intval( substr( $params[4], 7 ) ); // <nfield=x>
268 - $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, false, is_null($skin) );
 277+ $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, false, is_null( $skin ) );
269278
270279 // Log deletion
271 - } else if ( preg_match( '/^(delete|suppress)\/event$/', $key ) && count( $params ) == 4 ) {
 280+ } elseif ( preg_match( '/^(delete|suppress)\/event$/', $key ) && count( $params ) == 4 ) {
272281 $count = substr_count( $params[1], ',' ) + 1; // log items
273282 $ofield = intval( substr( $params[2], 7 ) ); // <ofield=x>
274283 $nfield = intval( substr( $params[3], 7 ) ); // <nfield=x>
275 - $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, true, is_null($skin) );
 284+ $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, true, is_null( $skin ) );
276285 }
277286
278287 if ( $skin ) {
@@ -291,24 +300,24 @@
292301 $rv = "$action";
293302 }
294303 }
295 -
 304+
296305 // For the perplexed, this feature was added in r7855 by Erik.
297 - // The feature was added because we liked adding [[$1]] in our log entries
298 - // but the log entries are parsed as Wikitext on RecentChanges but as HTML
299 - // on Special:Log. The hack is essentially that [[$1]] represented a link
300 - // to the title in question. The first parameter to the HTML version (Special:Log)
301 - // is that link in HTML form, and so this just gets rid of the ugly [[]].
302 - // However, this is a horrible hack and it doesn't work like you expect if, say,
303 - // you want to link to something OTHER than the title of the log entry.
304 - // The real problem, which Erik was trying to fix (and it sort-of works now) is
305 - // that the same messages are being treated as both wikitext *and* HTML.
 306+ // The feature was added because we liked adding [[$1]] in our log entries
 307+ // but the log entries are parsed as Wikitext on RecentChanges but as HTML
 308+ // on Special:Log. The hack is essentially that [[$1]] represented a link
 309+ // to the title in question. The first parameter to the HTML version (Special:Log)
 310+ // is that link in HTML form, and so this just gets rid of the ugly [[]].
 311+ // However, this is a horrible hack and it doesn't work like you expect if, say,
 312+ // you want to link to something OTHER than the title of the log entry.
 313+ // The real problem, which Erik was trying to fix (and it sort-of works now) is
 314+ // that the same messages are being treated as both wikitext *and* HTML.
306315 if( $filterWikilinks ) {
307 - $rv = str_replace( "[[", "", $rv );
308 - $rv = str_replace( "]]", "", $rv );
 316+ $rv = str_replace( '[[', '', $rv );
 317+ $rv = str_replace( ']]', '', $rv );
309318 }
310319 return $rv;
311320 }
312 -
 321+
313322 protected static function getTitleLink( $type, $skin, $title, &$params ) {
314323 global $wgLang, $wgContLang, $wgUserrightsInterwikiDelimiter;
315324 if( !$skin ) {
@@ -317,7 +326,7 @@
318327 switch( $type ) {
319328 case 'move':
320329 $titleLink = $skin->link(
321 - $title,
 330+ $title,
322331 htmlspecialchars( $title->getPrefixedText() ),
323332 array(),
324333 array( 'redirect' => 'no' )
@@ -350,8 +359,9 @@
351360 if ( count( $parts ) == 2 ) {
352361 $titleLink = WikiMap::foreignUserLink( $parts[1], $parts[0],
353362 htmlspecialchars( $title->getPrefixedText() ) );
354 - if ( $titleLink !== false )
 363+ if ( $titleLink !== false ) {
355364 break;
 365+ }
356366 }
357367 $titleLink = $skin->link( Title::makeTitle( NS_USER, $text ) );
358368 break;
@@ -373,7 +383,7 @@
374384 list( $name, $par ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
375385 # Use the language name for log titles, rather than Log/X
376386 if( $name == 'Log' ) {
377 - $titleLink = '('.$skin->link( $title, LogPage::logName( $par ) ).')';
 387+ $titleLink = '(' . $skin->link( $title, LogPage::logName( $par ) ) . ')';
378388 } else {
379389 $titleLink = $skin->link( $title );
380390 }
@@ -398,27 +408,29 @@
399409 $params = array( $params );
400410 }
401411
402 - if ( $comment === null ) $comment = "";
 412+ if ( $comment === null ) {
 413+ $comment = '';
 414+ }
403415
404416 $this->action = $action;
405417 $this->target = $target;
406418 $this->comment = $comment;
407419 $this->params = LogPage::makeParamBlob( $params );
408 -
409 - if ($doer === null) {
 420+
 421+ if ( $doer === null ) {
410422 global $wgUser;
411423 $doer = $wgUser;
412 - } elseif (!is_object( $doer ) ) {
 424+ } elseif ( !is_object( $doer ) ) {
413425 $doer = User::newFromId( $doer );
414426 }
415 -
 427+
416428 $this->doer = $doer;
417429
418430 $this->actionText = LogPage::actionText( $this->type, $action, $target, null, $params );
419431
420432 return $this->saveContent();
421433 }
422 -
 434+
423435 /**
424436 * Add relations to log_search table
425437 *
@@ -428,11 +440,16 @@
429441 * @return Boolean
430442 */
431443 public function addRelations( $field, $values, $logid ) {
432 - if( !strlen($field) || empty($values) )
 444+ if( !strlen( $field ) || empty( $values ) ) {
433445 return false; // nothing
 446+ }
434447 $data = array();
435448 foreach( $values as $value ) {
436 - $data[] = array('ls_field' => $field,'ls_value' => $value,'ls_log_id' => $logid);
 449+ $data[] = array(
 450+ 'ls_field' => $field,
 451+ 'ls_value' => $value,
 452+ 'ls_log_id' => $logid
 453+ );
437454 }
438455 $dbw = wfGetDB( DB_MASTER );
439456 $dbw->insert( 'log_search', $data, __METHOD__, 'IGNORE' );
@@ -477,8 +494,9 @@
478495
479496 $flags = explode( ',', trim( $flags ) );
480497 if( count( $flags ) > 0 ) {
481 - for( $i = 0; $i < count( $flags ); $i++ )
 498+ for( $i = 0; $i < count( $flags ); $i++ ) {
482499 $flags[$i] = self::formatBlockFlag( $flags[$i], $forContent );
 500+ }
483501 return '(' . $wgLang->commaList( $flags ) . ')';
484502 } else {
485503 return '';
@@ -497,10 +515,11 @@
498516 static $messages = array();
499517 if( !isset( $messages[$flag] ) ) {
500518 $k = 'block-log-flags-' . $flag;
501 - if( $forContent )
 519+ if( $forContent ) {
502520 $msg = wfMsgForContent( $k );
503 - else
 521+ } else {
504522 $msg = wfMsg( $k );
 523+ }
505524 $messages[$flag] = htmlspecialchars( wfEmptyMsg( $k, $msg ) ? $flag : $msg );
506525 }
507526 return $messages[$flag];

Status & tagging log