summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryBase.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryBase.php')
-rw-r--r--includes/api/ApiQueryBase.php104
1 files changed, 84 insertions, 20 deletions
diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php
index 61a5b4c8..69e0a893 100644
--- a/includes/api/ApiQueryBase.php
+++ b/includes/api/ApiQueryBase.php
@@ -1,6 +1,6 @@
<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on Sep 7, 2006
*
@@ -54,6 +54,8 @@ abstract class ApiQueryBase extends ApiBase {
*
* Public caching will only be allowed if *all* the modules that supply
* data for a given request return a cache mode of public.
+ *
+ * @return string
*/
public function getCacheMode( $params ) {
return 'private';
@@ -84,23 +86,14 @@ abstract class ApiQueryBase extends ApiBase {
$this->tables = array_merge( $this->tables, $tables );
} else {
if ( !is_null( $alias ) ) {
- $tables = $this->getAliasedName( $tables, $alias );
+ $this->tables[$alias] = $tables;
+ } else {
+ $this->tables[] = $tables;
}
- $this->tables[] = $tables;
}
}
/**
- * Get the SQL for a table name with alias
- * @param $table string Table name
- * @param $alias string Alias
- * @return string SQL
- */
- protected function getAliasedName( $table, $alias ) {
- return $this->getDB()->tableName( $table ) . ' ' . $alias;
- }
-
- /**
* Add a set of JOIN conditions to the internal array
*
* JOIN conditions are formatted as array( tablename => array(jointype,
@@ -118,7 +111,7 @@ abstract class ApiQueryBase extends ApiBase {
/**
* Add a set of fields to select to the internal array
- * @param $value mixed Field name or array of field names
+ * @param $value array|string Field name or array of field names
*/
protected function addFields( $value ) {
if ( is_array( $value ) ) {
@@ -130,7 +123,7 @@ abstract class ApiQueryBase extends ApiBase {
/**
* Same as addFields(), but add the fields only if a condition is met
- * @param $value mixed See addFields()
+ * @param $value array|string See addFields()
* @param $condition bool If false, do nothing
* @return bool $condition
*/
@@ -227,6 +220,16 @@ abstract class ApiQueryBase extends ApiBase {
}
}
}
+ /**
+ * Add a WHERE clause corresponding to a range, similar to addWhereRange,
+ * but converts $start and $end to database timestamps.
+ * @see addWhereRange
+ */
+ protected function addTimestampWhereRange( $field, $dir, $start, $end, $sort = true ) {
+ $db = $this->getDb();
+ return $this->addWhereRange( $field, $dir,
+ $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort );
+ }
/**
* Add an option such as LIMIT or USE INDEX. If an option was set
@@ -359,14 +362,15 @@ abstract class ApiQueryBase extends ApiBase {
protected function setContinueEnumParameter( $paramName, $paramValue ) {
$paramName = $this->encodeParamName( $paramName );
$msg = array( $paramName => $paramValue );
- $this->getResult()->disableSizeCheck();
- $this->getResult()->addValue( 'query-continue', $this->getModuleName(), $msg );
- $this->getResult()->enableSizeCheck();
+ $result = $this->getResult();
+ $result->disableSizeCheck();
+ $result->addValue( 'query-continue', $this->getModuleName(), $msg );
+ $result->enableSizeCheck();
}
/**
* Get the Query database connection (read-only)
- * @return Database
+ * @return DatabaseBase
*/
protected function getDB() {
if ( is_null( $this->mDb ) ) {
@@ -450,6 +454,47 @@ abstract class ApiQueryBase extends ApiBase {
}
/**
+ * Gets the personalised direction parameter description
+ *
+ * @param string $p ModulePrefix
+ * @param string $extraDirText Any extra text to be appended on the description
+ * @return array
+ */
+ public function getDirectionDescription( $p = '', $extraDirText = '' ) {
+ return array(
+ "In which direction to enumerate{$extraDirText}",
+ " newer - List oldest first. Note: {$p}start has to be before {$p}end.",
+ " older - List newest first (default). Note: {$p}start has to be later than {$p}end.",
+ );
+ }
+
+ /**
+ * @param $query String
+ * @param $protocol String
+ * @return null|string
+ */
+ public function prepareUrlQuerySearchString( $query = null, $protocol = null) {
+ $db = $this->getDb();
+ if ( !is_null( $query ) || $query != '' ) {
+ if ( is_null( $protocol ) ) {
+ $protocol = 'http://';
+ }
+
+ $likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
+ if ( !$likeQuery ) {
+ $this->dieUsage( 'Invalid query', 'bad_query' );
+ }
+
+ $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
+ return 'el_index ' . $db->buildLike( $likeQuery );
+ } elseif ( !is_null( $protocol ) ) {
+ return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() );
+ }
+
+ return null;
+ }
+
+ /**
* Filters hidden users (where the user doesn't have the right to view them)
* Also adds relevant block information
*
@@ -479,6 +524,25 @@ 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
+ */
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'invalidtitle', 'title' ),
@@ -491,7 +555,7 @@ abstract class ApiQueryBase extends ApiBase {
* @return string
*/
public static function getBaseVersion() {
- return __CLASS__ . ': $Id: ApiQueryBase.php 85435 2011-04-05 14:00:08Z demon $';
+ return __CLASS__ . ': $Id: ApiQueryBase.php 103029 2011-11-14 20:58:30Z reedy $';
}
}