r39939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39938‎ | r39939 | r39940 >
Date:06:57, 25 August 2008
Author:dantman
Status:old
Tags:
Comment:
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?).
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -324,14 +324,10 @@
325325 * @return string Page title with underscores
326326 */
327327 public function titleToKey($title) {
 328+ # Don't throw an error if we got an empty string
 329+ if(trim($title) == '') return '';
328330 $t = Title::newFromText($title);
329 - if(!$t)
330 - {
331 - # Don't throw an error if we got an empty string
332 - if($title == '')
333 - return '';
334 - $this->dieUsageMsg(array('invalidtitle', $title));
335 - }
 331+ if(!$t) $this->dieUsageMsg(array('invalidtitle', $title));
336332 return $t->getDbKey();
337333 }
338334
@@ -341,15 +337,11 @@
342338 * @return string Page title with spaces
343339 */
344340 public function keyToTitle($key) {
 341+ # Don't throw an error if we got an empty string
 342+ if(trim($key) == '') return '';
345343 $t = Title::newFromDbKey($key);
346344 # This really shouldn't happen but we gotta check anyway
347 - if(!$t)
348 - {
349 - # Don't throw an error if we got an empty string
350 - if($key == '')
351 - return '';
352 - $this->dieUsageMsg(array('invalidtitle', $key));
353 - }
 345+ if(!$t) $this->dieUsageMsg(array('invalidtitle', $key));
354346 return $t->getPrefixedText();
355347 }
356348

Status & tagging log