*
* 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
* @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( 'ApiBase.php' );
-}
-
/**
* This is a base class for all Query modules.
* It provides some common functionality such as constructing various SQL
private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds;
+ /**
+ * @param $query ApiBase
+ * @param $moduleName string
+ * @param $paramPrefix string
+ */
public function __construct( ApiBase $query, $moduleName, $paramPrefix = '' ) {
parent::__construct( $query->getMain(), $moduleName, $paramPrefix );
$this->mQueryModule = $query;
*
* Public caching will only be allowed if *all* the modules that supply
* data for a given request return a cache mode of public.
+ *
+ * @param $params
+ * @return string
*/
public function getCacheMode( $params ) {
return 'private';
$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
*
/**
* 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 ) ) {
/**
* 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
*/
if ( $sort ) {
$order = $field . ( $isDirNewer ? '' : ' DESC' );
- if ( !isset( $this->options['ORDER BY'] ) ) {
- $this->addOption( 'ORDER BY', $order );
- } else {
- $this->addOption( 'ORDER BY', $this->options['ORDER BY'] . ', ' . $order );
- }
+ // Append ORDER BY
+ $optionOrderBy = isset( $this->options['ORDER BY'] ) ? (array)$this->options['ORDER BY'] : array();
+ $optionOrderBy[] = $order;
+ $this->addOption( 'ORDER BY', $optionOrderBy );
}
}
+ /**
+ * Add a WHERE clause corresponding to a range, similar to addWhereRange,
+ * but converts $start and $end to database timestamps.
+ * @see addWhereRange
+ * @param $field
+ * @param $dir
+ * @param $start
+ * @param $end
+ * @param $sort bool
+ */
+ protected function addTimestampWhereRange( $field, $dir, $start, $end, $sort = true ) {
+ $db = $this->getDb();
+ $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
* before, the old value will be overwritten
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 ) ) {
* @param $name string Name to assign to the database connection
* @param $db int One of the DB_* constants
* @param $groups array Query groups
- * @return Database
+ * @return DatabaseBase
*/
public function selectNamedDB( $name, $db, $groups ) {
$this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups );
* @return void
*/
public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
- global $wgUser;
- $userCanViewHiddenUsers = $wgUser->isAllowed( 'hideuser' );
+ $userCanViewHiddenUsers = $this->getUser()->isAllowed( 'hideuser' );
if ( $showBlockInfo || !$userCanViewHiddenUsers ) {
$this->addTables( 'ipblocks' );
$this->addFields( 'ipb_deleted' );
if ( $showBlockInfo ) {
- $this->addFields( array( 'ipb_reason', 'ipb_by_text', 'ipb_expiry' ) );
+ $this->addFields( array( 'ipb_id', 'ipb_by', 'ipb_by_text', 'ipb_reason', 'ipb_expiry' ) );
}
// Don't show hidden names
}
}
+ /**
+ * @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' ),
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;