API: Deprecate binary sortkey input in ApiQueryCategoryMembers
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 11 Sep 2014 14:46:33 +0000 (10:46 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 11 Sep 2014 14:46:33 +0000 (10:46 -0400)
Depending on what method is being used to encode the binary sortkeys,
it's very possible that sending a binary value will be mangled by
WebRequest's UTF-8 normalization.

Rather than trying to fight it, let's just do what should have been done
in the first place when r86257 changed sortkey output to hex-encoded.
Too bad now we have to deprecate the old params and add
differently-named new ones instead of piggybacking on the original
breaking change.

Bug: 70690
Change-Id: I5a031e980967cbe574dddc261d56604cecc7147a

RELEASE-NOTES-1.24
includes/api/ApiQueryCategoryMembers.php

index 3301ca2..dc606d1 100644 (file)
@@ -254,6 +254,8 @@ production.
   parameter for each module is documented in the action=help output and is
   returned from action=paraminfo.
 * New action ClearHasMsg that can be used to clear HasMsg flag.
+* The cmstartsortkey and cmendsortkey parameters to list=categorymembers are
+  deprecated in favor of cmstarthexsortkey and cmendhexsortkey.
 
 === Action API internal changes in 1.24 ===
 * Methods for handling continuation are added to ApiResult, so actions other
index 17badb1..a88a9cb 100644 (file)
@@ -140,12 +140,22 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                $this->addWhereRange( 'cl_sortkey', $dir, null, null );
                                $this->addWhereRange( 'cl_from', $dir, null, null );
                        } else {
-                               $startsortkey = $params['startsortkeyprefix'] !== null ?
-                                       Collation::singleton()->getSortkey( $params['startsortkeyprefix'] ) :
-                                       $params['startsortkey'];
-                               $endsortkey = $params['endsortkeyprefix'] !== null ?
-                                       Collation::singleton()->getSortkey( $params['endsortkeyprefix'] ) :
-                                       $params['endsortkey'];
+                               if ( $params['startsortkeyprefix'] !== null ) {
+                                       $startsortkey = Collation::singleton()->getSortkey( $params['startsortkeyprefix'] );
+                               } elseif ( $params['starthexsortkey'] !== null ) {
+                                       $startsortkey = pack( 'H*', $params['starthexsortkey'] );
+                               } else {
+                                       $this->logFeatureUsage( 'list=categorymembers&cmstartsortkey' );
+                                       $startsortkey = $params['startsortkey'];
+                               }
+                               if ( $params['endsortkeyprefix'] !== null ) {
+                                       $endsortkey = Collation::singleton()->getSortkey( $params['endsortkeyprefix'] );
+                               } elseif ( $params['endhexsortkey'] !== null ) {
+                                       $endsortkey = pack( 'H*', $params['endhexsortkey'] );
+                               } else {
+                                       $this->logFeatureUsage( 'list=categorymembers&cmendsortkey' );
+                                       $endsortkey = $params['endsortkey'];
+                               }
 
                                // The below produces ORDER BY cl_sortkey, cl_from, possibly with DESC added to each of them
                                $this->addWhereRange( 'cl_sortkey',
@@ -330,10 +340,16 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                        'end' => array(
                                ApiBase::PARAM_TYPE => 'timestamp'
                        ),
-                       'startsortkey' => null,
-                       'endsortkey' => null,
+                       'starthexsortkey' => null,
+                       'endhexsortkey' => null,
                        'startsortkeyprefix' => null,
                        'endsortkeyprefix' => null,
+                       'startsortkey' => array(
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'endsortkey' => array(
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
                );
        }
 
@@ -359,15 +375,17 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                        'dir' => 'In which direction to sort',
                        'start' => "Timestamp to start listing from. Can only be used with {$p}sort=timestamp",
                        'end' => "Timestamp to end listing at. Can only be used with {$p}sort=timestamp",
-                       'startsortkey' => "Sortkey to start listing from. Must be given in " .
-                               "binary format. Can only be used with {$p}sort=sortkey",
-                       'endsortkey' => "Sortkey to end listing at. Must be given in binary " .
-                               "format. Can only be used with {$p}sort=sortkey",
+                       'starthexsortkey' => "Sortkey to start listing from, as returned by prop=sortkey. " .
+                               "Can only be used with {$p}sort=sortkey",
+                       'endhexsortkey' => "Sortkey to end listing from, as returned by prop=sortkey. " .
+                               "Can only be used with {$p}sort=sortkey",
                        'startsortkeyprefix' => "Sortkey prefix to start listing from. Can " .
-                               "only be used with {$p}sort=sortkey. Overrides {$p}startsortkey",
+                               "only be used with {$p}sort=sortkey. Overrides {$p}starthexsortkey",
                        'endsortkeyprefix' => "Sortkey prefix to end listing BEFORE (not at, " .
                                "if this value occurs it will not be included!). Can only be used with " .
-                               "{$p}sort=sortkey. Overrides {$p}endsortkey",
+                               "{$p}sort=sortkey. Overrides {$p}endhexsortkey",
+                       'startsortkey' => "Use starthexsortkey instead",
+                       'endsortkey' => "Use endhexsortkey instead",
                        'continue' => 'For large categories, give the value returned from previous query',
                        'limit' => 'The maximum number of pages to return.',
                );