http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89273
Revision: 89273
Author: reedy
Date: 2011-06-01 16:40:59 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
Add some documentation
Swap if ( $foo ) { $this->addFields( 'foo' ); } for $this->addFieldsIf( 'foo',
$foo ); etc
Also swap $this->addFieldsIf( 'foo', $foo ); $this->addFieldsIf( 'foo2', $foo
); for $this->addFieldsIf( array( 'foo', 'foo2' ), $foo );
Micro-optimisation and readability!
Modified Paths:
--------------
trunk/phase3/includes/api/ApiQueryBase.php
trunk/phase3/includes/api/ApiQueryBlocks.php
trunk/phase3/includes/api/ApiQueryDeletedrevs.php
trunk/phase3/includes/api/ApiQueryFilearchive.php
trunk/phase3/includes/api/ApiQueryLogEvents.php
trunk/phase3/includes/api/ApiQueryRecentChanges.php
trunk/phase3/includes/api/ApiQueryTags.php
trunk/phase3/includes/api/ApiQueryUserContributions.php
trunk/phase3/includes/api/ApiQueryWatchlist.php
Modified: trunk/phase3/includes/api/ApiQueryBase.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryBase.php 2011-06-01 16:27:46 UTC (rev
89272)
+++ trunk/phase3/includes/api/ApiQueryBase.php 2011-06-01 16:40:59 UTC (rev
89273)
@@ -111,7 +111,7 @@
/**
* Add a set of fields to select to the internal array
- * @param $value mixed Field name or array of field names
+ * @param $value array|string Field name or array of field names
*/
protected function addFields( $value ) {
if ( is_array( $value ) ) {
@@ -123,7 +123,7 @@
/**
* Same as addFields(), but add the fields only if a condition is met
- * @param $value mixed See addFields()
+ * @param $value array|string See addFields()
* @param $condition bool If false, do nothing
* @return bool $condition
*/
Modified: trunk/phase3/includes/api/ApiQueryBlocks.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryBlocks.php 2011-06-01 16:27:46 UTC
(rev 89272)
+++ trunk/phase3/includes/api/ApiQueryBlocks.php 2011-06-01 16:40:59 UTC
(rev 89273)
@@ -70,33 +70,17 @@
$this->addTables( 'ipblocks' );
$this->addFields( 'ipb_auto' );
- if ( $fld_id ) {
- $this->addFields( 'ipb_id' );
- }
- if ( $fld_user || $fld_userid ) {
- $this->addFields( array( 'ipb_address', 'ipb_user' ) );
- }
- if ( $fld_by ) {
- $this->addFields( 'ipb_by_text' );
- }
- if ( $fld_byid ) {
- $this->addFields( 'ipb_by' );
- }
- if ( $fld_timestamp ) {
- $this->addFields( 'ipb_timestamp' );
- }
- if ( $fld_expiry ) {
- $this->addFields( 'ipb_expiry' );
- }
- if ( $fld_reason ) {
- $this->addFields( 'ipb_reason' );
- }
- if ( $fld_range ) {
- $this->addFields( array( 'ipb_range_start',
'ipb_range_end' ) );
- }
- if ( $fld_flags ) {
- $this->addFields( array( 'ipb_anon_only',
'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted',
'ipb_allow_usertalk' ) );
- }
+ $this->addFieldsIf ( 'ipb_id', $fld_id );
+ $this->addFieldsIf( array( 'ipb_address', 'ipb_user' ),
$fld_user || $fld_userid );
+ $this->addFieldsIf( 'ipb_by_text', $fld_by );
+ $this->addFieldsIf( 'ipb_by', $fld_byid );
+ $this->addFieldsIf( 'ipb_timestamp', $fld_timestamp );
+ $this->addFieldsIf( 'ipb_expiry', $fld_expiry );
+ $this->addFieldsIf( 'ipb_reason', $fld_reason );
+ $this->addFieldsIf( array( 'ipb_range_start', 'ipb_range_end'
), $fld_range );
+ $this->addFieldsIf( array( 'ipb_anon_only',
'ipb_create_account', 'ipb_enable_autoblock',
+
'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk' ),
+ $fld_flags );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$this->addWhereRange( 'ipb_timestamp', $params['dir'],
$params['start'], $params['end'] );
Modified: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryDeletedrevs.php 2011-06-01 16:27:46 UTC
(rev 89272)
+++ trunk/phase3/includes/api/ApiQueryDeletedrevs.php 2011-06-01 16:40:59 UTC
(rev 89273)
@@ -99,27 +99,14 @@
$this->addWhere( 'ar_deleted = 0' );
$this->addFields( array( 'ar_title', 'ar_namespace',
'ar_timestamp' ) );
- if ( $fld_parentid ) {
- $this->addFields( 'ar_parent_id' );
- }
- if ( $fld_revid ) {
- $this->addFields( 'ar_rev_id' );
- }
- if ( $fld_user ) {
- $this->addFields( 'ar_user_text' );
- }
- if ( $fld_userid ) {
- $this->addFields( 'ar_user' );
- }
- if ( $fld_comment || $fld_parsedcomment ) {
- $this->addFields( 'ar_comment' );
- }
- if ( $fld_minor ) {
- $this->addFields( 'ar_minor_edit' );
- }
- if ( $fld_len ) {
- $this->addFields( 'ar_len' );
- }
+ $this->addFieldsIf( 'ar_parent_id', $fld_parentid );
+ $this->addFieldsIf( 'ar_rev_id', $fld_revid );
+ $this->addFieldsIf( 'ar_user_text', $fld_user );
+ $this->addFieldsIf( 'ar_user', $fld_userid );
+ $this->addFieldsIf( 'ar_comment', $fld_comment ||
$fld_parsedcomment );
+ $this->addFieldsIf( 'ar_minor_edit', $fld_minor );
+ $this->addFieldsIf( 'ar_len', $fld_len );
+
if ( $fld_content ) {
$this->addTables( 'text' );
$this->addFields( array( 'ar_text', 'ar_text_id',
'old_text', 'old_flags' ) );
Modified: trunk/phase3/includes/api/ApiQueryFilearchive.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryFilearchive.php 2011-06-01 16:27:46 UTC
(rev 89272)
+++ trunk/phase3/includes/api/ApiQueryFilearchive.php 2011-06-01 16:40:59 UTC
(rev 89273)
@@ -69,21 +69,10 @@
$this->addFields( array( 'fa_name', 'fa_deleted' ) );
$this->addFieldsIf( 'fa_storage_key', $fld_sha1 );
$this->addFieldsIf( 'fa_timestamp', $fld_timestamp );
-
- if ( $fld_user ) {
- $this->addFields( array( 'fa_user', 'fa_user_text' ) );
- }
-
- if ( $fld_dimensions || $fld_size ) {
- $this->addFields( array( 'fa_height', 'fa_width',
'fa_size' ) );
- }
-
+ $this->addFieldsIf( array( 'fa_user', 'fa_user_text' ),
$fld_user );
+ $this->addFieldsIf( array( 'fa_height', 'fa_width', 'fa_size'
), $fld_dimensions || $fld_size );
$this->addFieldsIf( 'fa_description', $fld_description );
-
- if ( $fld_mime ) {
- $this->addFields( array( 'fa_major_mime',
'fa_minor_mime' ) );
- }
-
+ $this->addFieldsIf( array( 'fa_major_mime', 'fa_minor_mime' ),
$fld_mime );
$this->addFieldsIf( 'fa_metadata', $fld_metadata );
$this->addFieldsIf( 'fa_bits', $fld_bitdepth );
Modified: trunk/phase3/includes/api/ApiQueryLogEvents.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryLogEvents.php 2011-06-01 16:27:46 UTC
(rev 89272)
+++ trunk/phase3/includes/api/ApiQueryLogEvents.php 2011-06-01 16:40:59 UTC
(rev 89273)
@@ -86,13 +86,10 @@
'log_deleted',
) );
- $this->addFieldsIf( 'log_id', $this->fld_ids );
- $this->addFieldsIf( 'page_id', $this->fld_ids );
- $this->addFieldsIf( 'log_user', $this->fld_user );
- $this->addFieldsIf( 'user_name', $this->fld_user );
+ $this->addFieldsIf( array( 'log_id', 'page_id' ),
$this->fld_ids );
+ $this->addFieldsIf( array( 'log_user', 'user_name' ),
$this->fld_user );
$this->addFieldsIf( 'user_id', $this->fld_userid );
- $this->addFieldsIf( 'log_namespace', $this->fld_title ||
$this->fld_parsedcomment );
- $this->addFieldsIf( 'log_title', $this->fld_title ||
$this->fld_parsedcomment );
+ $this->addFieldsIf( array( 'log_namespace', 'log_title' ),
$this->fld_title || $this->fld_parsedcomment );
$this->addFieldsIf( 'log_comment', $this->fld_comment ||
$this->fld_parsedcomment );
$this->addFieldsIf( 'log_params', $this->fld_details );
Modified: trunk/phase3/includes/api/ApiQueryRecentChanges.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryRecentChanges.php 2011-06-01 16:27:46 UTC
(rev 89272)
+++ trunk/phase3/includes/api/ApiQueryRecentChanges.php 2011-06-01 16:40:59 UTC
(rev 89273)
@@ -224,22 +224,14 @@
}
/* Add fields to our query if they are specified as a
needed parameter. */
- $this->addFieldsIf( 'rc_id', $this->fld_ids );
- $this->addFieldsIf( 'rc_this_oldid', $this->fld_ids );
- $this->addFieldsIf( 'rc_last_oldid', $this->fld_ids );
+ $this->addFieldsIf( array( 'rc_id', 'rc_this_oldid',
'rc_last_oldid' ), $this->fld_ids );
$this->addFieldsIf( 'rc_comment', $this->fld_comment ||
$this->fld_parsedcomment );
$this->addFieldsIf( 'rc_user', $this->fld_user );
$this->addFieldsIf( 'rc_user_text', $this->fld_user ||
$this->fld_userid );
- $this->addFieldsIf( 'rc_minor', $this->fld_flags );
- $this->addFieldsIf( 'rc_bot', $this->fld_flags );
- $this->addFieldsIf( 'rc_new', $this->fld_flags );
- $this->addFieldsIf( 'rc_old_len', $this->fld_sizes );
- $this->addFieldsIf( 'rc_new_len', $this->fld_sizes );
+ $this->addFieldsIf( array( 'rc_minor', 'rc_new',
'rc_bot' ) , $this->fld_flags );
+ $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len'
), $this->fld_sizes );
$this->addFieldsIf( 'rc_patrolled',
$this->fld_patrolled );
- $this->addFieldsIf( 'rc_logid', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_log_type', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_log_action', $this->fld_loginfo
);
- $this->addFieldsIf( 'rc_params', $this->fld_loginfo );
+ $this->addFieldsIf( array( 'rc_logid', 'rc_log_type',
'rc_log_action', 'rc_params' ), $this->fld_loginfo );
$showRedirects = $this->fld_redirect || isset(
$show['redirect'] ) || isset( $show['!redirect'] );
}
Modified: trunk/phase3/includes/api/ApiQueryTags.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryTags.php 2011-06-01 16:27:46 UTC (rev
89272)
+++ trunk/phase3/includes/api/ApiQueryTags.php 2011-06-01 16:40:59 UTC (rev
89273)
@@ -64,9 +64,7 @@
$this->addTables( 'change_tag' );
$this->addFields( 'ct_tag' );
- if ( $this->fld_hitcount ) {
- $this->addFields( 'count(*) AS hitcount' );
- }
+ $this->addFieldsIf( 'count(*) AS hitcount', $this->fld_hitcount
);
$this->addOption( 'LIMIT', $this->limit + 1 );
$this->addOption( 'GROUP BY', 'ct_tag' );
Modified: trunk/phase3/includes/api/ApiQueryUserContributions.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryUserContributions.php 2011-06-01
16:27:46 UTC (rev 89272)
+++ trunk/phase3/includes/api/ApiQueryUserContributions.php 2011-06-01
16:40:59 UTC (rev 89273)
@@ -249,8 +249,7 @@
// $this->addFieldsIf( 'rev_text_id', $this->fld_ids ); //
Should this field be exposed?
$this->addFieldsIf( 'rev_comment', $this->fld_comment ||
$this->fld_parsedcomment );
$this->addFieldsIf( 'rev_len', $this->fld_size );
- $this->addFieldsIf( 'rev_minor_edit', $this->fld_flags );
- $this->addFieldsIf( 'rev_parent_id', $this->fld_flags );
+ $this->addFieldsIf( array( 'rev_minor_edit', 'rev_parent_id' ),
$this->fld_flags );
$this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
if ( $this->fld_tags ) {
Modified: trunk/phase3/includes/api/ApiQueryWatchlist.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryWatchlist.php 2011-06-01 16:27:46 UTC
(rev 89272)
+++ trunk/phase3/includes/api/ApiQueryWatchlist.php 2011-06-01 16:40:59 UTC
(rev 89273)
@@ -101,20 +101,14 @@
'rc_last_oldid',
) );
- $this->addFieldsIf( 'rc_new', $this->fld_flags );
- $this->addFieldsIf( 'rc_minor', $this->fld_flags );
- $this->addFieldsIf( 'rc_bot', $this->fld_flags );
+ $this->addFieldsIf( array( 'rc_new', 'rc_minor',
'rc_bot' ), $this->fld_flags );
$this->addFieldsIf( 'rc_user', $this->fld_user ||
$this->fld_userid );
$this->addFieldsIf( 'rc_user_text', $this->fld_user );
$this->addFieldsIf( 'rc_comment', $this->fld_comment ||
$this->fld_parsedcomment );
$this->addFieldsIf( 'rc_patrolled', $this->fld_patrol );
- $this->addFieldsIf( 'rc_old_len', $this->fld_sizes );
- $this->addFieldsIf( 'rc_new_len', $this->fld_sizes );
+ $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len'
), $this->fld_sizes );
$this->addFieldsIf( 'wl_notificationtimestamp',
$this->fld_notificationtimestamp );
- $this->addFieldsIf( 'rc_logid', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_log_type', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_log_action', $this->fld_loginfo
);
- $this->addFieldsIf( 'rc_params', $this->fld_loginfo );
+ $this->addFieldsIf( array( 'rc_logid', 'rc_log_type',
'rc_log_action', 'rc_params' ), $this->fld_loginfo );
} elseif ( $params['allrev'] ) {
$this->addFields( 'rc_this_oldid' );
} else {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs