From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/api/ApiQueryBase.php | 104 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 20 deletions(-) (limited to 'includes/api/ApiQueryBase.php') 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 @@ 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 * @@ -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 ) ) { @@ -449,6 +453,47 @@ abstract class ApiQueryBase extends ApiBase { return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 ); } + /** + * 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 $'; } } -- cgit v1.2.3-54-g00ecf