Removed all instances of empty() where error suppression was not intended. Replaced...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 25 Oct 2008 14:04:43 +0000 (14:04 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 25 Oct 2008 14:04:43 +0000 (14:04 +0000)
25 files changed:
includes/api/ApiBase.php
includes/api/ApiBlock.php
includes/api/ApiDelete.php
includes/api/ApiEditPage.php
includes/api/ApiFormatXml.php
includes/api/ApiMain.php
includes/api/ApiPageSet.php
includes/api/ApiPatrol.php
includes/api/ApiProtect.php
includes/api/ApiQuery.php
includes/api/ApiQueryBacklinks.php
includes/api/ApiQueryCategoryInfo.php
includes/api/ApiQueryDuplicateFiles.php
includes/api/ApiQueryExtLinksUsage.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQuerySearch.php
includes/api/ApiQueryUserContributions.php
includes/api/ApiQueryUsers.php
includes/api/ApiQueryWatchlist.php
includes/api/ApiResult.php
includes/api/ApiRollback.php
includes/api/ApiUnblock.php

index fafecfe..aa6ca2e 100644 (file)
@@ -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)
                                {
index 7dd658f..a760002 100644 (file)
@@ -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);
 
index 98b2467..ae1d94d 100644 (file)
@@ -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));
                        
index 9220f6d..acd6579 100644 (file)
@@ -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);
index 6f0bb3f..9514cfc 100644 (file)
@@ -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));
index 5c5c0bd..1fc65f3 100644 (file)
@@ -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*";
index 32d4500..908ca22 100644 (file)
@@ -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 {
index 5e11ddf..872a22b 100644 (file)
@@ -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'));
index 0ffd343..f6eb32c 100644 (file)
@@ -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));
 
index bcec619..db2c867 100644 (file)
@@ -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);
index 258a482..df4daf9 100644 (file)
@@ -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);
index aae7279..ead2af0 100644 (file)
@@ -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();
index 026566e..3d201d3 100644 (file)
@@ -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');
index 149c125..7dd92fa 100644 (file)
@@ -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 ) {
index 13828cf..e8b3563 100644 (file)
@@ -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
index 492da5d..4dd82e1 100644 (file)
@@ -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;
                }
 
index 6f87dff..0798f3b 100644 (file)
@@ -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;
                }
 
index a6818c5..9a0166c 100644 (file)
@@ -288,7 +288,7 @@ class ApiQueryRevisions extends ApiQueryBase {
 
                if ($this->fld_comment) {
                        $comment = $revision->getComment();
-                       if (!empty($comment))           
+                       if (strval($comment) !== '')
                                $vals['comment'] = $comment;
                }
 
index 85d4ec8..639079c 100644 (file)
@@ -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();
index da832c9..e7af8d8 100644 (file)
@@ -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;
index 4a60a19..9a0bde0 100644 (file)
@@ -68,7 +68,7 @@ if (!defined('MEDIAWIKI')) {
                         else
                                $goodNames[] = $n;
                }
-               if(empty($goodNames))
+               if(!count($goodNames))
                        return $retval;
 
                $db = $this->getDb();
index 17467e0..ca63347 100644 (file)
@@ -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;
index f34780d..a3a1209 100644 (file)
@@ -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) {
index 70d8035..7a0573c 100644 (file)
@@ -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));
 
index acfeb9a..5d58804 100644 (file)
@@ -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;