r90751 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90750‎ | r90751 | r90752 >
Date:03:50, 25 June 2011
Author:reedy
Status:ok
Tags:
Comment:
Followup r89576, and other related revisions

Move SHA1 has validation functions in ApiQueryBase
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllimages.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryFilearchive.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -514,6 +514,22 @@
515515 }
516516
517517 /**
 518+ * @param $hash string
 519+ * @return bool
 520+ */
 521+ public function validateSha1Hash( $hash ) {
 522+ return preg_match( '/[a-fA-F0-9]{40}/', $hash );
 523+ }
 524+
 525+ /**
 526+ * @param $hash string
 527+ * @return bool
 528+ */
 529+ public function validateSha1Base36Hash( $hash ) {
 530+ return preg_match( '/[a-zA-Z0-9]{31}/', $hash );
 531+ }
 532+
 533+ /**
518534 * @return array
519535 */
520536 public function getPossibleErrors() {
Index: trunk/phase3/includes/api/ApiQueryFilearchive.php
@@ -95,12 +95,12 @@
9696
9797 $sha1 = false;
9898 if ( $sha1Set ) {
99 - if ( !ApiQueryAllimages::validateSha1Hash( $params['sha1'] ) ) {
 99+ if ( !$this->validateSha1Hash( $params['sha1'] ) ) {
100100 $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
101101 }
102102 $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 );
103103 } elseif ( $sha1base36Set ) {
104 - if ( !ApiQueryAllimages::validateSha1Base36Hash( $params['sha1base36'] ) ) {
 104+ if ( !$this->validateSha1Base36Hash( $params['sha1base36'] ) ) {
105105 $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' );
106106 }
107107 $sha1 = $params['sha1base36'];
Index: trunk/phase3/includes/api/ApiQueryAllimages.php
@@ -109,13 +109,13 @@
110110
111111 $sha1 = false;
112112 if ( isset( $params['sha1'] ) ) {
113 - if ( !self::validateSha1Hash( $params['sha1'] ) ) {
 113+ if ( !$this->validateSha1Hash( $params['sha1'] ) ) {
114114 $this->dieUsage( 'The SHA1 hash provided is not valid', 'invalidsha1hash' );
115115 }
116116 $sha1 = wfBaseConvert( $params['sha1'], 16, 36, 31 );
117117 } elseif ( isset( $params['sha1base36'] ) ) {
118118 $sha1 = $params['sha1base36'];
119 - if ( !self::validateSha1Base36Hash( $sha1 ) ) {
 119+ if ( !$this->validateSha1Base36Hash( $sha1 ) ) {
120120 $this->dieUsage( 'The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash' );
121121 }
122122 }
@@ -181,22 +181,6 @@
182182 }
183183 }
184184
185 - /**
186 - * @param $hash string
187 - * @return bool
188 - */
189 - public static function validateSha1Hash( $hash ) {
190 - return preg_match( '/[a-fA-F0-9]{40}/', $hash );
191 - }
192 -
193 - /**
194 - * @param $hash string
195 - * @return bool
196 - */
197 - public static function validateSha1Base36Hash( $hash ) {
198 - return preg_match( '/[a-zA-Z0-9]{31}/', $hash );
199 - }
200 -
201185 public function getAllowedParams() {
202186 return array (
203187 'from' => null,

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89576Followup r89542, validate hashesreedy16:06, 6 June 2011

Status & tagging log