From: Sam Reed Date: Wed, 1 Jun 2011 16:40:59 +0000 (+0000) Subject: Add some documentation X-Git-Tag: 1.31.0-rc.0~29800 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=289af6c964b8309e77545dc8c3797dc6f160975a;p=lhc%2Fweb%2Fwiklou.git 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! --- diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 8d43479785..74e8ae60e1 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -111,7 +111,7 @@ abstract class ApiQueryBase extends ApiBase { /** * 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 @@ abstract class ApiQueryBase extends ApiBase { /** * 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 */ diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index 9cea45fb19..3eed9567ee 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -70,33 +70,17 @@ class ApiQueryBlocks extends ApiQueryBase { $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'] ); diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index d774733fb9..486b9a90f1 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -99,27 +99,14 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $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' ) ); diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index 5cde9b7650..0f53141b5d 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -69,21 +69,10 @@ class ApiQueryFilearchive extends ApiQueryBase { $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 ); diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 234d47c6d0..837024426a 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -86,13 +86,10 @@ class ApiQueryLogEvents extends ApiQueryBase { '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 ); diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 0260212033..2712bea89e 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -224,22 +224,14 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { } /* 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'] ); } diff --git a/includes/api/ApiQueryTags.php b/includes/api/ApiQueryTags.php index 61b34669db..12f3eed297 100644 --- a/includes/api/ApiQueryTags.php +++ b/includes/api/ApiQueryTags.php @@ -64,9 +64,7 @@ class ApiQueryTags extends ApiQueryBase { $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' ); diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index b294589543..0b7a5f9071 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -249,8 +249,7 @@ class ApiQueryContributions extends ApiQueryBase { // $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 ) { diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 0443eeb183..e5507f622f 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -101,20 +101,14 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { '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 {