* Add titlePartToKey() and keyPartToTitle() which use the substr() hack to preserve trailing spaces
* Migrate function calls where needed. ??continue parameters still use titleToKey() because they're generated using keyToTitle() and therefore can't contain trailing spaces
$this->addFields('cat_title');
if (!is_null($params['from']))
- $this->addWhere('cat_title>=' . $db->addQuotes($this->titleToKey($params['from'])));
+ $this->addWhere('cat_title>=' . $db->addQuotes($this->titlePartToKey($params['from'])));
if (isset ($params['prefix']))
- $this->addWhere("cat_title LIKE '" . $db->escapeLike($this->titleToKey($params['prefix'])) . "%'");
+ $this->addWhere("cat_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
$this->addOption('LIMIT', $params['limit']+1);
$this->addOption('ORDER BY', 'cat_title' . ($params['dir'] == 'descending' ? ' DESC' : ''));
}
if (!is_null($params['from']))
- $this->addWhere('pl_title>=' . $db->addQuotes($this->titleToKey($params['from'])));
+ $this->addWhere('pl_title>=' . $db->addQuotes($this->titlePartToKey($params['from'])));
if (isset ($params['prefix']))
- $this->addWhere("pl_title LIKE '" . $db->escapeLike($this->titleToKey($params['prefix'])) . "%'");
+ $this->addWhere("pl_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
$this->addFields(array (
'pl_namespace',
// Image filters
if (!is_null($params['from']))
- $this->addWhere('img_name>=' . $db->addQuotes($this->titleToKey($params['from'])));
+ $this->addWhere('img_name>=' . $db->addQuotes($this->titlePartToKey($params['from'])));
if (isset ($params['prefix']))
- $this->addWhere("img_name LIKE '" . $db->escapeLike($this->titleToKey($params['prefix'])) . "%'");
+ $this->addWhere("img_name LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
if (isset ($params['minsize'])) {
$this->addWhere('img_size>=' . intval($params['minsize']));
$this->addWhereIf('page_is_redirect = 0', $params['filterredir'] === 'nonredirects');
$this->addWhereFld('page_namespace', $params['namespace']);
$dir = ($params['dir'] == 'descending' ? 'older' : 'newer');
- $from = (is_null($params['from']) ? null : $this->titleToKey($params['from']));
+ $from = (is_null($params['from']) ? null : $this->titlePartToKey($params['from']));
$this->addWhereRange('page_title', $dir, $from, null);
if (isset ($params['prefix']))
- $this->addWhere("page_title LIKE '" . $db->escapeLike($this->titleToKey($params['prefix'])) . "%'");
+ $this->addWhere("page_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
$forceNameTitleIndex = true;
if (isset ($params['minsize'])) {
*/
public function titleToKey($title) {
# Don't throw an error if we got an empty string
- if(trim($title) == '') return '';
+ if(trim($title) == '')
+ return '';
$t = Title::newFromText($title);
- if(!$t) $this->dieUsageMsg(array('invalidtitle', $title));
+ if(!$t)
+ $this->dieUsageMsg(array('invalidtitle', $title));
return $t->getDbKey();
}
*/
public function keyToTitle($key) {
# Don't throw an error if we got an empty string
- if(trim($key) == '') return '';
+ if(trim($key) == '')
+ return '';
$t = Title::newFromDbKey($key);
# This really shouldn't happen but we gotta check anyway
- if(!$t) $this->dieUsageMsg(array('invalidtitle', $key));
+ if(!$t)
+ $this->dieUsageMsg(array('invalidtitle', $key));
return $t->getPrefixedText();
}
+
+ /**
+ * An alternative to titleToKey() that doesn't trim trailing spaces
+ * @param string $titlePart Title part with spaces
+ * @return string Title part with underscores
+ */
+ public function titlePartToKey($titlePart) {
+ return substr($this->titleToKey($titlePart . '.'), 0, -1);
+ }
+
+ /**
+ * An alternative to keyToTitle() that doesn't trim trailing spaces
+ * @param string $keyPart Key part with spaces
+ * @return string Key part with underscores
+ */
+ public function keyPartToTitle($keyPart) {
+ return substr($this->keyToTitle($keyPart . '.'), 0, -1);
+ }
/**
* Get version string for use in the API help output