if (is_array($allowedValues)) {
# Check for unknown values
$unknown = array_diff($valuesList, $allowedValues);
- if(!empty($unknown))
+ if(count($unknown))
{
if($allowMultiple)
{
$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);
$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));
$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);
$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);
}
}
- 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));
public static function makeHelpMsgHeader($module, $paramName) {
$modulePrefix = $module->getModulePrefix();
- if (!empty($modulePrefix))
+ if (strval($modulePrefix) !== '')
$modulePrefix = "($modulePrefix) ";
return "* $paramName={$module->getModuleName()} $modulePrefix*";
}
private function initFromPageIds($pageids) {
- if(empty($pageids))
+ if(!count($pageids))
return;
$pageids = array_map('intval', $pageids); // paranoia
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));
private function initFromRevIDs($revids) {
- if(empty($revids))
+ if(!count($revids))
return;
$db = $this->getDB();
// 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
$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
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 {
$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'));
$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']))
$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));
);
}
- if (!empty ($normValues)) {
+ if (count($normValues)) {
$result->setIndexedTagName($normValues, 'n');
$result->addValue('query', 'normalized', $normValues);
}
);
}
- if (!empty ($intrwValues)) {
+ if (count($intrwValues)) {
$result->setIndexedTagName($intrwValues, 'i');
$result->addValue('query', 'interwiki', $intrwValues);
}
);
}
- if (!empty ($redirValues)) {
+ if (count($redirValues)) {
$result->setIndexedTagName($redirValues, 'r');
$result->addValue('query', 'redirects', $redirValues);
}
// Missing revision elements
//
$missingRevIDs = $pageSet->getMissingRevisionIDs();
- if (!empty ($missingRevIDs)) {
+ if (count($missingRevIDs)) {
$revids = array ();
foreach ($missingRevIDs as $revid) {
$revids[$revid] = array (
$pages[$pageid] = $vals;
}
- if (!empty ($pages)) {
+ if (count($pages)) {
if ($this->params['indexpageids']) {
$pageIDs = array_keys($pages);
}
$db->freeResult($res);
- if($this->redirect && !empty($this->redirTitles))
+ if($this->redirect && count($this->redirTitles))
{
$this->resetQueryParams();
$this->prepareSecondQuery($resultPageSet);
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();
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');
// 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 ) {
$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));
}
// 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
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
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;
}
$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)
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. */
$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;
}
if ($this->fld_comment) {
$comment = $revision->getComment();
- if (!empty($comment))
+ if (strval($comment) !== '')
$vals['comment'] = $comment;
}
$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();
$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;
else
$goodNames[] = $n;
}
- if(empty($goodNames))
+ if(!count($goodNames))
return $retval;
$db = $this->getDb();
$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;
}
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");
}
}
- if (empty($name))
+ if (!$name)
$data[] = $value; // Add list element
else
ApiResult :: setElement($data, $name, $value); // Add named element
$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) {
$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));
$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;