From: Daniel Friesen Date: Mon, 25 Aug 2008 06:57:15 +0000 (+0000) Subject: ApiQueryBase::titleToKey and ApiQueryBase::keyToTitle; X-Git-Tag: 1.31.0-rc.0~45683 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;h=69e49e832ef17d6458ec28db33d9b2c3d4475433;p=lhc%2Fweb%2Fwiklou.git ApiQueryBase::titleToKey and ApiQueryBase::keyToTitle; Don't bother constructing a title object when the $title/$key is ''. (Why were we doing this check after creating the title object, there's no point in even creating a big object if we're just going to check the old string we already had to see if it's empty) And as a bonus, use trim() so that user input such as ' ' does not dish out an error (There really isn't much difference between "&title=" and "&title= " if one shouldn't output an error, why should the other?). --- diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index b1e67522f5..fc1e7dc02a 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -324,14 +324,10 @@ abstract class ApiQueryBase extends ApiBase { * @return string Page title with underscores */ public function titleToKey($title) { + # Don't throw an error if we got an empty string + if(trim($title) == '') return ''; $t = Title::newFromText($title); - if(!$t) - { - # Don't throw an error if we got an empty string - if($title == '') - return ''; - $this->dieUsageMsg(array('invalidtitle', $title)); - } + if(!$t) $this->dieUsageMsg(array('invalidtitle', $title)); return $t->getDbKey(); } @@ -341,15 +337,11 @@ abstract class ApiQueryBase extends ApiBase { * @return string Page title with spaces */ public function keyToTitle($key) { + # Don't throw an error if we got an empty string + if(trim($key) == '') return ''; $t = Title::newFromDbKey($key); # This really shouldn't happen but we gotta check anyway - if(!$t) - { - # Don't throw an error if we got an empty string - if($key == '') - return ''; - $this->dieUsageMsg(array('invalidtitle', $key)); - } + if(!$t) $this->dieUsageMsg(array('invalidtitle', $key)); return $t->getPrefixedText(); }