From 79d982679f1c87d9141ad4c5c64abfbb95bc1ebe Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 25 Jun 2011 03:50:41 +0000 Subject: [PATCH] Followup r89576, and other related revisions Move SHA1 has validation functions in ApiQueryBase --- includes/api/ApiQueryAllimages.php | 20 ++------------------ includes/api/ApiQueryBase.php | 16 ++++++++++++++++ includes/api/ApiQueryFilearchive.php | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/includes/api/ApiQueryAllimages.php b/includes/api/ApiQueryAllimages.php index fbfdeca4a6..9cb5b545bb 100644 --- a/includes/api/ApiQueryAllimages.php +++ b/includes/api/ApiQueryAllimages.php @@ -109,13 +109,13 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { $sha1 = false; if ( isset( $params['sha1'] ) ) { - if ( !self::validateSha1Hash( $params['sha1'] ) ) { + if ( !$this->validateSha1Hash( $params['sha1'] ) ) { $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' ); } $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 ); } elseif ( isset( $params['sha1base36'] ) ) { $sha1 = $params['sha1base36']; - if ( !self::validateSha1Base36Hash( $sha1 ) ) { + if ( !$this->validateSha1Base36Hash( $sha1 ) ) { $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' ); } } @@ -181,22 +181,6 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { } } - /** - * @param $hash string - * @return bool - */ - public static function validateSha1Hash( $hash ) { - return preg_match( '/[a-fA-F0-9]{40}/', $hash ); - } - - /** - * @param $hash string - * @return bool - */ - public static function validateSha1Base36Hash( $hash ) { - return preg_match( '/[a-zA-Z0-9]{31}/', $hash ); - } - public function getAllowedParams() { return array ( 'from' => null, diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 90e10dfa8a..628611d445 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -513,6 +513,22 @@ abstract class ApiQueryBase extends ApiBase { } } + /** + * @param $hash string + * @return bool + */ + public function validateSha1Hash( $hash ) { + return preg_match( '/[a-fA-F0-9]{40}/', $hash ); + } + + /** + * @param $hash string + * @return bool + */ + public function validateSha1Base36Hash( $hash ) { + return preg_match( '/[a-zA-Z0-9]{31}/', $hash ); + } + /** * @return array */ diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index 81db1639e6..6c3b5c58cd 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -95,12 +95,12 @@ class ApiQueryFilearchive extends ApiQueryBase { $sha1 = false; if ( $sha1Set ) { - if ( !ApiQueryAllimages::validateSha1Hash( $params['sha1'] ) ) { + if ( !$this->validateSha1Hash( $params['sha1'] ) ) { $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' ); } $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 ); } elseif ( $sha1base36Set ) { - if ( !ApiQueryAllimages::validateSha1Base36Hash( $params['sha1base36'] ) ) { + if ( !$this->validateSha1Base36Hash( $params['sha1base36'] ) ) { $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' ); } $sha1 = $params['sha1base36']; -- 2.20.1