r39938 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39937‎ | r39938 | r39939 >
Date:06:50, 25 August 2008
Author:dantman
Status:old
Tags:
Comment:
Revert 39936 and 39935;
This 'fix' is merely a bad workaround and creates more issues rather than simply fixing.
A) Part of the Title class is being /duplicated/ meaning more bugs are going to show up when someone improves stuff inside Title and doesn't know stuff is duplicated here.
B) This change breaks cases as $wgCaptialLinks is now a per-namespace array, not a boolean.
C) This is the wrong way to 'fix' the issue, titleToKey and keyToTitle are meant to handle full titles, not prefixes, the issue is not that they break prefixes, it's that they are being misused and thus outputting something other than expected. The best way to fix this issue, would probably be to pad the title with something like '.' and then strip that single character off the db key.
D) Because whitespace is no longer being trimmed actual titles aren't being normalized properly in the other modules causing 'foobar ' to attempt to use the db key 'foobar_' which cannot exist.
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -324,10 +324,15 @@
325325 * @return string Page title with underscores
326326 */
327327 public function titleToKey($title) {
328 - global $wgContLang, $wgCapitalLinks;
329 - if($wgCaptialLinks)
330 - $title = $wgContLang->ucfirst($title);
331 - return str_replace(' ', '_', $title);
 328+ $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+ }
 336+ return $t->getDbKey();
332337 }
333338
334339 /**
@@ -336,7 +341,16 @@
337342 * @return string Page title with spaces
338343 */
339344 public function keyToTitle($key) {
340 - return str_replace('_', ' ', $key);
 345+ $t = Title::newFromDbKey($key);
 346+ # 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+ }
 354+ return $t->getPrefixedText();
341355 }
342356
343357 /**

Status & tagging log