From: Tim Starling Date: Sat, 25 Oct 2008 14:04:43 +0000 (+0000) Subject: Removed all instances of empty() where error suppression was not intended. Replaced... X-Git-Tag: 1.31.0-rc.0~44605 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=f48c6070dfec6a3c3c14efbf2b71b08afb72b0f4;p=lhc%2Fweb%2Fwiklou.git Removed all instances of empty() where error suppression was not intended. Replaced with conversion to boolean, count() or empty string check as appropriate. Fixes a number of bugs due to incorrect conversion to boolean: suppressed edit summaries containing '0', ignored titles called '0', searches for '0' ignored, etc. --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index fafecfe7bd..aa6ca2e27f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -572,7 +572,7 @@ abstract class ApiBase { if (is_array($allowedValues)) { # Check for unknown values $unknown = array_diff($valuesList, $allowedValues); - if(!empty($unknown)) + if(count($unknown)) { if($allowMultiple) { diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 7dd658ff90..a760002de8 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -88,7 +88,7 @@ class ApiBlock extends ApiBase { $userID = $expiry = null; $retval = $form->doBlock($userID, $expiry); - if(!empty($retval)) + if(count($retval)) // We don't care about multiple errors, just report one of them $this->dieUsageMsg($retval); diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 98b2467fa4..ae1d94dbd7 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -73,15 +73,15 @@ class ApiDelete extends ApiBase { $reason = (isset($params['reason']) ? $params['reason'] : NULL); if ($titleObj->getNamespace() == NS_IMAGE) { - $retval = self::deletefile($params['token'], $titleObj, $params['oldimage'], $reason, false); - if(!empty($retval)) + $retval = self::deleteFile($params['token'], $titleObj, $params['oldimage'], $reason, false); + if(count($retval)) // We don't care about multiple errors, just report one of them $this->dieUsageMsg(current($retval)); } else { $articleObj = new Article($titleObj); $retval = self::delete($articleObj, $params['token'], $reason); - if(!empty($retval)) + if(count($retval)) // We don't care about multiple errors, just report one of them $this->dieUsageMsg(current($retval)); diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 9220f6d80c..acd657979d 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -68,7 +68,7 @@ class ApiEditPage extends ApiBase { $errors = $titleObj->getUserPermissionsErrors('edit', $wgUser); if(!$titleObj->exists()) $errors = array_merge($errors, $titleObj->getUserPermissionsErrors('create', $wgUser)); - if(!empty($errors)) + if(count($errors)) $this->dieUsageMsg($errors[0]); $articleObj = new Article($titleObj); @@ -145,7 +145,7 @@ class ApiEditPage extends ApiBase { $r = array(); if(!wfRunHooks('APIEditBeforeSave', array(&$ep, $ep->textbox1, &$r))) { - if(!empty($r)) + if(count($r)) { $r['result'] = "Failure"; $this->getResult()->addValue(null, $this->getModuleName(), $r); diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index 6f0bb3f1af..9514cfc3fc 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -114,15 +114,15 @@ class ApiFormatXml extends ApiFormatBase { } } - if (is_null($subElemIndName) && !empty ($indElements)) + if (is_null($subElemIndName) && count($indElements)) ApiBase :: dieDebug(__METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()."); - if (!empty ($subElements) && !empty ($indElements) && !is_null($subElemContent)) + if (count($subElements) && count($indElements) && !is_null($subElemContent)) ApiBase :: dieDebug(__METHOD__, "($elemName, ...) has content and subelements"); if (!is_null($subElemContent)) { $this->printText($indstr . wfElement($elemName, $elemValue, $subElemContent)); - } elseif (empty ($indElements) && empty ($subElements)) { + } elseif (!count($indElements) && !count($subElements)) { $this->printText($indstr . wfElement($elemName, $elemValue)); } else { $this->printText($indstr . wfElement($elemName, $elemValue, null)); diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 5c5c0bdbb2..1fc65f3154 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -590,7 +590,7 @@ class ApiMain extends ApiBase { public static function makeHelpMsgHeader($module, $paramName) { $modulePrefix = $module->getModulePrefix(); - if (!empty($modulePrefix)) + if (strval($modulePrefix) !== '') $modulePrefix = "($modulePrefix) "; return "* $paramName={$module->getModuleName()} $modulePrefix*"; diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 32d4500fd9..908ca220e2 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -368,7 +368,7 @@ class ApiPageSet extends ApiQueryBase { } private function initFromPageIds($pageids) { - if(empty($pageids)) + if(!count($pageids)) return; $pageids = array_map('intval', $pageids); // paranoia @@ -440,7 +440,7 @@ class ApiPageSet extends ApiQueryBase { else { // The remaining pageids do not exist - if(empty($this->mMissingPageIDs)) + if(!$this->mMissingPageIDs) $this->mMissingPageIDs = array_keys($remaining); else $this->mMissingPageIDs = array_merge($this->mMissingPageIDs, array_keys($remaining)); @@ -450,7 +450,7 @@ class ApiPageSet extends ApiQueryBase { private function initFromRevIDs($revids) { - if(empty($revids)) + if(!count($revids)) return; $db = $this->getDB(); @@ -488,7 +488,7 @@ class ApiPageSet extends ApiQueryBase { // Repeat until all redirects have been resolved // The infinite loop is prevented by keeping all known pages in $this->mAllPages - while (!empty ($this->mPendingRedirectIDs)) { + while ($this->mPendingRedirectIDs) { // Resolve redirects by querying the pagelinks table, and repeat the process // Create a new linkBatch object for the next pass @@ -537,7 +537,7 @@ class ApiPageSet extends ApiQueryBase { $this->mRedirectTitles[$from] = $to; } $db->freeResult($res); - if(!empty($this->mPendingRedirectIDs)) + if($this->mPendingRedirectIDs) { # We found pages that aren't in the redirect table # Add them @@ -580,7 +580,7 @@ class ApiPageSet extends ApiQueryBase { continue; // There's nothing else we can do } $iw = $titleObj->getInterwiki(); - if (!empty($iw)) { + if (strval($iw) !== '') { // This title is an interwiki link. $this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw; } else { diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php index 5e11ddfdca..872a22bbdd 100644 --- a/includes/api/ApiPatrol.php +++ b/includes/api/ApiPatrol.php @@ -57,7 +57,7 @@ class ApiPatrol extends ApiBase { $this->dieUsageMsg(array('nosuchrcid', $params['rcid'])); $retval = RecentChange::markPatrolled($params['rcid']); - if(!empty($retval)) + if($retval) $this->dieUsageMsg(current($retval)); $result = array('rcid' => $rc->getAttribute('rc_id')); diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 0ffd3437c1..f6eb32c572 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -46,7 +46,7 @@ class ApiProtect extends ApiBase { $this->dieUsageMsg(array('missingparam', 'title')); if(!isset($params['token'])) $this->dieUsageMsg(array('missingparam', 'token')); - if(!isset($params['protections']) || empty($params['protections'])) + if(empty($params['protections'])) $this->dieUsageMsg(array('missingparam', 'protections')); if(!$wgUser->matchEditToken($params['token'])) @@ -57,7 +57,7 @@ class ApiProtect extends ApiBase { $this->dieUsageMsg(array('invalidtitle', $params['title'])); $errors = $titleObj->getUserPermissionsErrors('protect', $wgUser); - if(!empty($errors)) + if($errors) // We don't care about multiple errors, just report one of them $this->dieUsageMsg(current($errors)); diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index bcec619f6f..db2c86732a 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -256,7 +256,7 @@ class ApiQuery extends ApiBase { ); } - if (!empty ($normValues)) { + if (count($normValues)) { $result->setIndexedTagName($normValues, 'n'); $result->addValue('query', 'normalized', $normValues); } @@ -270,7 +270,7 @@ class ApiQuery extends ApiBase { ); } - if (!empty ($intrwValues)) { + if (count($intrwValues)) { $result->setIndexedTagName($intrwValues, 'i'); $result->addValue('query', 'interwiki', $intrwValues); } @@ -284,7 +284,7 @@ class ApiQuery extends ApiBase { ); } - if (!empty ($redirValues)) { + if (count($redirValues)) { $result->setIndexedTagName($redirValues, 'r'); $result->addValue('query', 'redirects', $redirValues); } @@ -293,7 +293,7 @@ class ApiQuery extends ApiBase { // Missing revision elements // $missingRevIDs = $pageSet->getMissingRevisionIDs(); - if (!empty ($missingRevIDs)) { + if (count($missingRevIDs)) { $revids = array (); foreach ($missingRevIDs as $revid) { $revids[$revid] = array ( @@ -335,7 +335,7 @@ class ApiQuery extends ApiBase { $pages[$pageid] = $vals; } - if (!empty ($pages)) { + if (count($pages)) { if ($this->params['indexpageids']) { $pageIDs = array_keys($pages); diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 258a482c0a..df4daf9ef5 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -211,7 +211,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } $db->freeResult($res); - if($this->redirect && !empty($this->redirTitles)) + if($this->redirect && count($this->redirTitles)) { $this->resetQueryParams(); $this->prepareSecondQuery($resultPageSet); diff --git a/includes/api/ApiQueryCategoryInfo.php b/includes/api/ApiQueryCategoryInfo.php index aae727985a..ead2af0138 100644 --- a/includes/api/ApiQueryCategoryInfo.php +++ b/includes/api/ApiQueryCategoryInfo.php @@ -41,9 +41,10 @@ class ApiQueryCategoryInfo extends ApiQueryBase { public function execute() { $alltitles = $this->getPageSet()->getAllTitlesByNamespace(); - $categories = $alltitles[NS_CATEGORY]; - if(empty($categories)) + if ( empty( $alltitles[NS_CATEGORY] ) ) { return; + } + $categories = $alltitles[NS_CATEGORY]; $titles = $this->getPageSet()->getGoodTitles() + $this->getPageSet()->getMissingTitles(); diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index 026566e4e6..3d201d3eec 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -50,9 +50,10 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { private function run($resultPageSet = null) { $params = $this->extractRequestParams(); $namespaces = $this->getPageSet()->getAllTitlesByNamespace(); - $images = $namespaces[NS_IMAGE]; - if(empty($images)) + if ( empty( $namespaces[NS_IMAGE] ) ) { return; + } + $images = $namespaces[NS_IMAGE]; $this->addTables('image', 'i1'); $this->addTables('image', 'i2'); diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index 149c125afd..7dd92fa495 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -54,7 +54,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { // Find the right prefix global $wgUrlProtocols; - if(!is_null($protocol) && !empty($protocol) && !in_array($protocol, $wgUrlProtocols)) + if($protocol && !in_array($protocol, $wgUrlProtocols)) { foreach ($wgUrlProtocols as $p) { if( substr( $p, 0, strlen( $protocol ) ) === $protocol ) { diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 13828cf577..e8b35633db 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -197,7 +197,7 @@ class ApiQueryInfo extends ApiQueryBase { $pageLength = $pageSet->getCustomField('page_len'); $db = $this->getDB(); - if ($fld_protection && !empty($titles)) { + if ($fld_protection && count($titles)) { $this->addTables('page_restrictions'); $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade')); $this->addWhereFld('pr_page', array_keys($titles)); @@ -273,7 +273,7 @@ class ApiQueryInfo extends ApiQueryBase { } // We don't need to check for pt stuff if there are no nonexistent titles - if($fld_protection && !empty($missing)) + if($fld_protection && count($missing)) { $this->resetQueryParams(); // Construct a custom WHERE clause that matches all titles in $missing @@ -367,7 +367,7 @@ class ApiQueryInfo extends ApiQueryBase { else if($fld_talkid) $talktitles[] = $t->getTalkPage(); } - if(!empty($talktitles) || !empty($subjecttitles)) + if(count($talktitles) || count($subjecttitles)) { // Construct a custom WHERE clause that matches // all titles in $talktitles and $subjecttitles diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 492da5d392..4dd82e1de5 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -213,7 +213,7 @@ class ApiQueryLogEvents extends ApiQueryBase { if ($this->fld_timestamp) { $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->log_timestamp); } - if ($this->fld_comment && !empty ($row->log_comment)) { + if ($this->fld_comment && isset($row->log_comment)) { $vals['comment'] = $row->log_comment; } diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 6f87dff530..0798f3b700 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -100,7 +100,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { $this->addWhereRange('rc_timestamp', $dir, $start, $end); $this->addWhereFld('rc_namespace', $namespace); $this->addWhereFld('rc_deleted', 0); - if(!empty($titles)) + if($titles) { $lb = new LinkBatch; foreach($titles as $t) @@ -256,7 +256,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { private function extractRowInfo($row) { /* If page was moved somewhere, get the title of the move target. */ $movedToTitle = false; - if (!empty($row->rc_moved_to_title)) + if (isset($row->rc_moved_to_title) && $row->rc_moved_to_title !== '') $movedToTitle = Title :: makeTitle($row->rc_moved_to_ns, $row->rc_moved_to_title); /* Determine the title of the page that has been changed. */ @@ -320,7 +320,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rc_timestamp); /* Add edit summary / log summary. */ - if ($this->fld_comment && !empty ($row->rc_comment)) { + if ($this->fld_comment && isset($row->rc_comment)) { $vals['comment'] = $row->rc_comment; } diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index a6818c5db2..9a0166c8de 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -288,7 +288,7 @@ class ApiQueryRevisions extends ApiQueryBase { if ($this->fld_comment) { $comment = $revision->getComment(); - if (!empty($comment)) + if (strval($comment) !== '') $vals['comment'] = $comment; } diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 85d4ec8e63..639079c2d5 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -54,7 +54,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $limit = $params['limit']; $query = $params['search']; $what = $params['what']; - if (is_null($query) || empty($query)) + if (strval($query) === '') $this->dieUsage("empty search string is not allowed", 'param-search'); $search = SearchEngine::create(); diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index da832c9d01..e7af8d83e2 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -227,7 +227,7 @@ class ApiQueryContributions extends ApiQueryBase { $vals['top'] = ''; } - if ($this->fld_comment && !empty ($row->rev_comment)) + if ($this->fld_comment && isset( $row->rev_comment ) ) $vals['comment'] = $row->rev_comment; return $vals; diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index 4a60a1968a..9a0bde061a 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -68,7 +68,7 @@ if (!defined('MEDIAWIKI')) { else $goodNames[] = $n; } - if(empty($goodNames)) + if(!count($goodNames)) return $retval; $db = $this->getDb(); diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 17467e041d..ca63347b8e 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -237,7 +237,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $vals['newlen'] = intval($row->rc_new_len); } - if ($this->fld_comment && !empty ($row->rc_comment)) + if ($this->fld_comment && isset( $row->rc_comment )) $vals['comment'] = $row->rc_comment; return $vals; diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index f34780d1ae..a3a1209b10 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -100,7 +100,7 @@ class ApiResult extends ApiBase { } elseif (is_array($arr[$name]) && is_array($value)) { $merged = array_intersect_key($arr[$name], $value); - if (empty ($merged)) + if (!count($merged)) $arr[$name] += $value; else ApiBase :: dieDebug(__METHOD__, "Attempting to merge element $name"); @@ -180,7 +180,7 @@ class ApiResult extends ApiBase { } } - if (empty($name)) + if (!$name) $data[] = $value; // Add list element else ApiResult :: setElement($data, $name, $value); // Add named element @@ -201,7 +201,7 @@ if (!function_exists('array_intersect_key')) { $argc = func_num_args(); if ($argc > 2) { - for ($i = 1; !empty($isec) && $i < $argc; $i++) { + for ($i = 1; $isec && $i < $argc; $i++) { $arr = func_get_arg($i); foreach (array_keys($isec) as $key) { diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 70d803576a..7a0573c814 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -66,7 +66,7 @@ class ApiRollback extends ApiBase { $details = null; $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details); - if(!empty($retval)) + if($retval) // We don't care about multiple errors, just report one of them $this->dieUsageMsg(current($retval)); diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index acfeb9a1c9..5d58804fd6 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -69,7 +69,7 @@ class ApiUnblock extends ApiBase { $user = $params['user']; $reason = (is_null($params['reason']) ? '' : $params['reason']); $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range); - if(!empty($retval)) + if($retval) $this->dieUsageMsg($retval); $res['id'] = $id;