From d4bebe41ceb31118a546e791101cd001044da0f2 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 10 Jul 2008 14:13:11 +0000 Subject: [PATCH] API: Some cleanup and fixes before 1.13 is released: * Fix regression from r37270: prop=categories paging was broken in generator mode. * Fix drlimit=max, which was broken since r31384 * Use titleToKey() and keyToTitle() on title parts of the continue parameters in prop={links,templatelinks,categories,images} * Use addQuotes() rather than strencode() in those same modules * Don't trim message names in ammessages, it's stupid and undocumented * Add $wgAPI{Meta,Prop,List}Modules to DefaultSettings.php explicitly --- includes/DefaultSettings.php | 3 +++ includes/api/ApiQueryAllmessages.php | 1 - includes/api/ApiQueryCategories.php | 8 +++++--- includes/api/ApiQueryDeletedrevs.php | 4 ++-- includes/api/ApiQueryImages.php | 8 +++++--- includes/api/ApiQueryLinks.php | 8 +++++--- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index fbc0d54232..cc49ba6f34 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3141,6 +3141,9 @@ $wgEnableWriteAPI = false; * Extension modules may override the core modules. */ $wgAPIModules = array(); +$wgAPIMetaModules = array(); +$wgAPIPropModules = array(); +$wgAPIListModules = array(); /** * Maximum amount of rows to scan in a DB query in the API diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index fce16b52d0..8f0be01591 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -75,7 +75,6 @@ class ApiQueryAllmessages extends ApiQueryBase { //Get all requested messages $messages = array(); foreach( $messages_target as $message ) { - $message = trim( $message ); //Message list can be formatted like "msg1 | msg2 | msg3", so let's trim() it $messages[$message] = wfMsg( $message ); } diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index 5e1f983f5d..51d4a5ffc8 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -86,7 +86,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $this->dieUsage("Invalid continue param. You should pass the " . "original value returned by the previous query", "_badcontinue"); $clfrom = intval($cont[0]); - $clto = $this->getDb()->strencode($cont[1]); + $clto = $this->getDb()->addQuotes($this->titleToKey($cont[1])); $this->addWhere("cl_from > $clfrom OR ". "(cl_from = $clfrom AND ". "cl_to >= '$clto')"); @@ -109,7 +109,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { if (++$count > $params['limit']) { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... - $this->setContinueEnumParameter('continue', "{$row->cl_from}|{$row->cl_to}"); + $this->setContinueEnumParameter('continue', $row->cl_from . + '|' . $this->keyToTitle($row->cl_to)); break; } if ($lastId != $row->cl_from) { @@ -143,7 +144,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { if (++$count > $params['limit']) { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... - $this->setContinueEnumParameter('continue', "{$row->il_from}|{$row->il_to}"); + $this->setContinueEnumParameter('continue', $row->cl_from . + '|' . $this->keyToTitle($row->cl_to)); break; } diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index b63fc0034d..0d434e70a6 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -109,7 +109,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $this->addWhere($where); } - $this->addOption('LIMIT', $params['limit'] + 1); + $this->addOption('LIMIT', $limit + 1); $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']); $res = $this->select(__METHOD__); $pages = array(); @@ -117,7 +117,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { // First populate the $pages array while($row = $db->fetchObject($res)) { - if($count++ == $params['limit']) + if(++$count > $limit) { // We've had enough $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp)); diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index 7aed6eb5ca..edc5e204ed 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -66,7 +66,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase { $this->dieUsage("Invalid continue param. You should pass the " . "original value returned by the previous query", "_badcontinue"); $ilfrom = intval($cont[0]); - $ilto = $this->getDb()->strencode($cont[1]); + $ilto = $this->getDb()->addQuotes($this->titleToKey($cont[1])); $this->addWhere("il_from > $ilfrom OR ". "(il_from = $ilfrom AND ". "il_to >= '$ilto')"); @@ -90,7 +90,8 @@ class ApiQueryImages extends ApiQueryGeneratorBase { if (++$count > $params['limit']) { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... - $this->setContinueEnumParameter('continue', "{$row->il_from}|{$row->il_to}"); + $this->setContinueEnumParameter('continue', $row->il_from . + '|' . $this->keyToTitle($row->il_to)); break; } if ($lastId != $row->il_from) { @@ -118,7 +119,8 @@ class ApiQueryImages extends ApiQueryGeneratorBase { if (++$count > $params['limit']) { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... - $this->setContinueEnumParameter('continue', "{$row->il_from}|{$row->il_to}"); + $this->setContinueEnumParameter('continue', $row->il_from . + '|' . $this->keyToTitle($row->il_to)); break; } $titles[] = Title :: makeTitle(NS_IMAGE, $row->il_to); diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 0761d913b6..01671b3fcb 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -92,7 +92,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { "original value returned by the previous query", "_badcontinue"); $plfrom = intval($cont[0]); $plns = intval($cont[1]); - $pltitle = $this->getDb()->strencode($cont[2]); + $pltitle = $this->getDb()->addQuotes($this->titleToKey($cont[2])); $this->addWhere("{$this->prefix}_from > $plfrom OR ". "({$this->prefix}_from = $plfrom AND ". "({$this->prefix}_namespace > $plns OR ". @@ -128,7 +128,8 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... $this->setContinueEnumParameter('continue', - "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}"); + "{$row->pl_from}|{$row->pl_namespace}|" . + $this->keyToTitle($row->pl_title)); break; } if ($lastId != $row->pl_from) { @@ -157,7 +158,8 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { // We've reached the one extra which shows that // there are additional pages to be had. Stop here... $this->setContinueEnumParameter('continue', - "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}"); + "{$row->pl_from}|{$row->pl_namespace}|" . + $this->keyToTitle($row->pl_title)); break; } $titles[] = Title :: makeTitle($row->pl_namespace, $row->pl_title); -- 2.20.1