Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[lhc/web/wiklou.git] / includes / api / ApiQueryCategoryMembers.php
index ef455b4..3a8847c 100644 (file)
@@ -53,7 +53,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
         */
        private function validateHexSortkey( $hexSortkey ) {
                // A hex sortkey has an unbound number of 2 letter pairs
-               return preg_match( '/^(?:[a-fA-F0-9]{2})*$/', $hexSortkey );
+               return (bool)preg_match( '/^(?:[a-fA-F0-9]{2})*$/D', $hexSortkey );
        }
 
        /**
@@ -65,7 +65,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
 
                $categoryTitle = $this->getTitleOrPageId( $params )->getTitle();
                if ( $categoryTitle->getNamespace() != NS_CATEGORY ) {
-                       $this->dieUsage( 'The category name you entered is not valid', 'invalidcategory' );
+                       $this->dieWithError( 'apierror-invalidcategory' );
                }
 
                $prop = array_flip( $params['prop'] );
@@ -138,8 +138,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
 
                                // 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] ) );
+                               $escSortkey = $this->getDB()->addQuotes( hex2bin( $cont[1] ) );
                                $from = intval( $cont[2] );
                                $op = $dir == 'newer' ? '>' : '<';
                                // $contWhere is used further down
@@ -154,9 +153,10 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                        $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' );
+                                               $encParamName = $this->encodeParamName( 'starthexsortkey' );
+                                               $this->dieWithError( [ 'apierror-badparameter', $encParamName ], "badvalue_$encParamName" );
                                        }
-                                       $startsortkey = pack( 'H*', $params['starthexsortkey'] );
+                                       $startsortkey = hex2bin( $params['starthexsortkey'] );
                                } else {
                                        $startsortkey = $params['startsortkey'];
                                }
@@ -164,9 +164,10 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
                                        $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' );
+                                               $encParamName = $this->encodeParamName( 'endhexsortkey' );
+                                               $this->dieWithError( [ 'apierror-badparameter', $encParamName ], "badvalue_$encParamName" );
                                        }
-                                       $endsortkey = pack( 'H*', $params['endhexsortkey'] );
+                                       $endsortkey = hex2bin( $params['endhexsortkey'] );
                                } else {
                                        $endsortkey = $params['endsortkey'];
                                }