r86257 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86256‎ | r86257 | r86258 >
Date:12:41, 17 April 2011
Author:catrope
Status:ok
Tags:
Comment:
API: BREAKING CHANGE: (bug 28541) Output of binary ICU sortkeys is broken. Change sortkey fields in prop=categories and list=categorymembers to hexadecimal strings, that way we don't have any issues with scary binary stuff. Also change cmcontinue to take hex-encoded sortkeys and swap the order back to normal (previously sortkey was at the end because it could contain pipe characters, but that's not an issue with hex).
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryCategories.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryMembers.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryCategoryMembers.php
@@ -123,7 +123,6 @@
124124 $this->addOption( 'USE INDEX', 'cl_timestamp' );
125125 } else {
126126 if ( $params['continue'] ) {
127 - // type|from|sortkey
128127 $cont = explode( '|', $params['continue'], 3 );
129128 if ( count( $cont ) != 3 ) {
130129 $this->dieUsage( 'Invalid continue param. You should pass the original value returned '.
@@ -136,8 +135,9 @@
137136 $queryTypes = array_slice( $queryTypes, $contTypeIndex );
138137
139138 // Add a WHERE clause for sortkey and from
140 - $from = intval( $cont[1] );
141 - $escSortkey = $this->getDB()->addQuotes( $cont[2] );
 139+ // pack( "H*", $foo ) is used to convert hex back to binary
 140+ $escSortkey = $this->getDB()->addQuotes( pack( "H*", $cont[1] ) );
 141+ $from = intval( $cont[2] );
142142 $op = $dir == 'newer' ? '>' : '<';
143143 // $contWhere is used further down
144144 $contWhere = "cl_sortkey $op $escSortkey OR " .
@@ -197,12 +197,9 @@
198198 if ( $params['sort'] == 'timestamp' ) {
199199 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->cl_timestamp ) );
200200 } else {
201 - // Continue format is type|from|sortkey
202 - // The order is a bit weird but it's convenient to put the sortkey at the end
203 - // because we don't have to worry about pipes in the sortkey that way
204 - // (and type and from can't contain pipes anyway)
 201+ $sortkey = bin2hex( $row->cl_sortkey );
205202 $this->setContinueEnumParameter( 'continue',
206 - "{$row->cl_type}|{$row->cl_from}|{$row->cl_sortkey}"
 203+ "{$row->cl_type}|$sortkey|{$row->cl_from}"
207204 );
208205 }
209206 break;
@@ -226,7 +223,7 @@
227224 ApiQueryBase::addTitleInfo( $vals, $title );
228225 }
229226 if ( $fld_sortkey ) {
230 - $vals['sortkey'] = $row->cl_sortkey;
 227+ $vals['sortkey'] = bin2hex( $row->cl_sortkey );
231228 }
232229 if ( $fld_sortkeyprefix ) {
233230 $vals['sortkeyprefix'] = $row->cl_sortkey_prefix;
@@ -243,8 +240,9 @@
244241 if ( $params['sort'] == 'timestamp' ) {
245242 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->cl_timestamp ) );
246243 } else {
 244+ $sortkey = bin2hex( $row->cl_sortkey );
247245 $this->setContinueEnumParameter( 'continue',
248 - "{$row->cl_type}|{$row->cl_from}|{$row->cl_sortkey}"
 246+ "{$row->cl_type}|$sortkey|{$row->cl_from}"
249247 );
250248 }
251249 break;
@@ -336,7 +334,7 @@
337335 'What pieces of information to include',
338336 ' ids - Adds the page ID',
339337 ' title - Adds the title and namespace ID of the page',
340 - ' sortkey - Adds the sortkey used for sorting in the category (may not be human-readble)',
 338+ ' sortkey - Adds the sortkey used for sorting in the category (hexadecimal string)',
341339 ' sortkeyprefix - Adds the sortkey prefix used for sorting in the category (human-readable part of the sortkey)',
342340 ' type - Adds the type that the page has been categorised as (page, subcat or file)',
343341 ' timestamp - Adds the timestamp of when the page was included',
Index: trunk/phase3/includes/api/ApiQueryCategories.php
@@ -70,7 +70,7 @@
7171 'cl_to'
7272 ) );
7373
74 - $this->addFieldsIf( 'cl_sortkey', isset( $prop['sortkey'] ) );
 74+ $this->addFieldsIf( array( 'cl_sortkey', 'cl_sortkey_prefix' ), isset( $prop['sortkey'] ) );
7575 $this->addFieldsIf( 'cl_timestamp', isset( $prop['timestamp'] ) );
7676
7777 $this->addTables( 'categorylinks' );
@@ -151,7 +151,8 @@
152152 $vals = array();
153153 ApiQueryBase::addTitleInfo( $vals, $title );
154154 if ( isset( $prop['sortkey'] ) ) {
155 - $vals['sortkey'] = $row->cl_sortkey;
 155+ $vals['sortkey'] = bin2hex( $row->cl_sortkey );
 156+ $vals['sortkeyprefix'] = $row->cl_sortkey_prefix;
156157 }
157158 if ( isset( $prop['timestamp'] ) ) {
158159 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
@@ -219,7 +220,7 @@
220221 return array(
221222 'prop' => array(
222223 'Which additional properties to get for each category',
223 - ' sortkey - Adds the sortkey for the category',
 224+ ' sortkey - Adds the sortkey (hexadecimal string) and sortkey prefix (human-readable part) for the category',
224225 ' timestamp - Adds timestamp of when the category was added',
225226 ' hidden - Tags categories that are hidden with __HIDDENCAT__',
226227 ),

Sign-offs

UserFlagDate
Reedyinspected12:05, 20 April 2011
Reedytested12:05, 20 April 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r864741.17: MFT r81731, r85377, r85547, r85555, r85583, r85803, r85881, r86100, r86...catrope13:22, 20 April 2011
r922831.17wmf1: MFT r86257reedy19:15, 15 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86130(follow-up r69626) Make it so the intl normalizer_normalize function is not...bawolff18:39, 15 April 2011

Status & tagging log