Merge "content: Recognise .json as JsonContent in User and MediaWiki namespace"
[lhc/web/wiklou.git] / includes / api / ApiQueryCategoryMembers.php
index 5b4a766..4042bd7 100644 (file)
@@ -47,6 +47,15 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param string $hexSortkey
+        * @return bool
+        */
+       private function validateHexSortkey( $hexSortkey ) {
+               // A hex sortkey has an unbound number of 2 letter pairs
+               return preg_match( '/^(?:[a-fA-F0-9]{2})*$/', $hexSortkey );
+       }
+
        /**
         * @param ApiPageSet $resultPageSet
         * @return void
@@ -128,6 +137,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                $queryTypes = array_slice( $queryTypes, $contTypeIndex );
 
                                // Add a WHERE clause for sortkey and from
+                               $this->dieContinueUsageIf( !$this->validateHexSortkey( $cont[1] ) );
                                // pack( "H*", $foo ) is used to convert hex back to binary
                                $escSortkey = $this->getDB()->addQuotes( pack( 'H*', $cont[1] ) );
                                $from = intval( $cont[2] );
@@ -143,17 +153,27 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                if ( $params['startsortkeyprefix'] !== null ) {
                                        $startsortkey = Collation::singleton()->getSortkey( $params['startsortkeyprefix'] );
                                } elseif ( $params['starthexsortkey'] !== null ) {
+                                       if ( !$this->validateHexSortkey( $params['starthexsortkey'] ) ) {
+                                               $this->dieUsage( 'The starthexsortkey provided is not valid', 'bad_starthexsortkey' );
+                                       }
                                        $startsortkey = pack( 'H*', $params['starthexsortkey'] );
                                } else {
-                                       $this->logFeatureUsage( 'list=categorymembers&cmstartsortkey' );
+                                       if ( $params['startsortkey'] !== null ) {
+                                               $this->logFeatureUsage( 'list=categorymembers&cmstartsortkey' );
+                                       }
                                        $startsortkey = $params['startsortkey'];
                                }
                                if ( $params['endsortkeyprefix'] !== null ) {
                                        $endsortkey = Collation::singleton()->getSortkey( $params['endsortkeyprefix'] );
                                } elseif ( $params['endhexsortkey'] !== null ) {
+                                       if ( !$this->validateHexSortkey( $params['endhexsortkey'] ) ) {
+                                               $this->dieUsage( 'The endhexsortkey provided is not valid', 'bad_endhexsortkey' );
+                                       }
                                        $endsortkey = pack( 'H*', $params['endhexsortkey'] );
                                } else {
-                                       $this->logFeatureUsage( 'list=categorymembers&cmendsortkey' );
+                                       if ( $params['endsortkey'] !== null ) {
+                                               $this->logFeatureUsage( 'list=categorymembers&cmendsortkey' );
+                                       }
                                        $endsortkey = $params['endsortkey'];
                                }
 
@@ -230,7 +250,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                        }
 
                        if ( is_null( $resultPageSet ) ) {
-                               $vals = array();
+                               $vals = array(
+                                       ApiResult::META_TYPE => 'assoc',
+                               );
                                if ( $fld_ids ) {
                                        $vals['pageid'] = intval( $row->page_id );
                                }
@@ -269,7 +291,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                }
 
                if ( is_null( $resultPageSet ) ) {
-                       $result->setIndexedTagName_internal(
+                       $result->addIndexedTagName(
                                array( 'query', $this->getModuleName() ), 'cm' );
                }
        }
@@ -363,7 +385,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                return $ret;
        }
 
-       public function getExamplesMessages() {
+       protected function getExamplesMessages() {
                return array(
                        'action=query&list=categorymembers&cmtitle=Category:Physics'
                                => 'apihelp-query+categorymembers-example-simple',