Revert 39936 and 39935;
authorDaniel Friesen <dantman@users.mediawiki.org>
Mon, 25 Aug 2008 06:50:31 +0000 (06:50 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Mon, 25 Aug 2008 06:50:31 +0000 (06:50 +0000)
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.

includes/api/ApiQueryBase.php

index af71a56..b1e6752 100644 (file)
@@ -324,10 +324,15 @@ abstract class ApiQueryBase extends ApiBase {
         * @return string Page title with underscores
         */
        public function titleToKey($title) {
-               global $wgContLang, $wgCapitalLinks;
-               if($wgCaptialLinks)
-                       $title = $wgContLang->ucfirst($title);
-               return str_replace(' ', '_', $title);
+               $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));
+               }
+               return $t->getDbKey();
        }
 
        /**
@@ -336,7 +341,16 @@ abstract class ApiQueryBase extends ApiBase {
         * @return string Page title with spaces
         */
        public function keyToTitle($key) {
-               return str_replace('_', ' ', $key);
+               $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));
+               }
+               return $t->getPrefixedText();
        }
 
        /**