Revert 39936 and 39935;
[lhc/web/wiklou.git] / 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();
        }
 
        /**