API Cleanup: renamed '_badcontinue'->'badcontinue', one die()
[lhc/web/wiklou.git] / includes / api / ApiQueryBase.php
index 92fabdd..e36109a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Sep 7, 2006
  *
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -374,6 +374,19 @@ abstract class ApiQueryBase extends ApiBase {
                $result->enableSizeCheck();
        }
 
+       /**
+        * Die with the $prefix.'badcontinue' error. This call is common enough to make it into the base method.
+        * @param $condition boolean will only die if this value is true
+        * @since 1.21
+        */
+       protected function dieContinueUsageIf( $condition ) {
+               if ( $condition ) {
+                       $this->dieUsage(
+                               'Invalid continue param. You should pass the original value returned by the previous query',
+                               'badcontinue' );
+               }
+       }
+
        /**
         * Get the Query database connection (read-only)
         * @return DatabaseBase
@@ -534,7 +547,7 @@ abstract class ApiQueryBase extends ApiBase {
         * @return bool
         */
        public function validateSha1Hash( $hash ) {
-               return preg_match( '/[a-fA-F0-9]{40}/', $hash );
+               return preg_match( '/^[a-f0-9]{40}$/', $hash );
        }
 
        /**
@@ -542,17 +555,28 @@ abstract class ApiQueryBase extends ApiBase {
         * @return bool
         */
        public function validateSha1Base36Hash( $hash ) {
-               return preg_match( '/[a-zA-Z0-9]{31}/', $hash );
+               return preg_match( '/^[a-z0-9]{31}$/', $hash );
        }
 
        /**
         * @return array
         */
        public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
+               $errors = parent::getPossibleErrors();
+               $errors = array_merge( $errors, array(
                        array( 'invalidtitle', 'title' ),
                        array( 'invalidtitle', 'key' ),
                ) );
+               $params = $this->getFinalParams();
+               if ( array_key_exists( 'continue', $params ) ) {
+                       $errors = array_merge( $errors, array(
+                               array(
+                                       'code' => 'badcontinue',
+                                       'info' => 'Invalid continue param. You should pass the original value returned by the previous query'
+                               ),
+                       ) );
+               }
+               return $errors;
        }
 
        /**
@@ -571,6 +595,11 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase {
 
        private $mIsGenerator;
 
+       /**
+        * @param $query ApiBase
+        * @param $moduleName string
+        * @param $paramPrefix string
+        */
        public function __construct( $query, $moduleName, $paramPrefix = '' ) {
                parent::__construct( $query, $moduleName, $paramPrefix );
                $this->mIsGenerator = false;