*
* Created on Sep 5, 2006
*
- * Copyright © 2006, 2010 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006, 2010 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
/// @since 1.17
const PARAM_RANGE_ENFORCE = 9; // Boolean, if MIN/MAX are set, enforce (die) these? Only applies if TYPE='integer' Use with extreme caution
+ const PROP_ROOT = 'ROOT'; // Name of property group that is on the root element of the result, i.e. not part of a list
+ const PROP_LIST = 'LIST'; // Boolean, is the result multiple items? Defaults to true for query modules, to false for other modules
+ const PROP_TYPE = 0; // Type of the property, uses same format as PARAM_TYPE
+ const PROP_NULLABLE = 1; // Boolean, can the property be not included in the result? Defaults to false
+
const LIMIT_BIG1 = 500; // Fast query, std user limit
const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit
const LIMIT_SML1 = 50; // Slow query, std user limit
/**
* Get the name of the module as shown in the profiler log
*
- * @param $db DatabaseBase
+ * @param $db DatabaseBase|bool
*
* @return string
*/
return $desc;
}
+ /**
+ * Returns possible properties in the result, grouped by the value of the prop parameter
+ * that shows them.
+ *
+ * Properties that are shown always are in a group with empty string as a key.
+ * Properties that can be shown by several values of prop are included multiple times.
+ * If some properties are part of a list and some are on the root object (see ApiQueryQueryPage),
+ * those on the root object are under the key PROP_ROOT.
+ * The array can also contain a boolean under the key PROP_LIST,
+ * indicating whether the result is a list.
+ *
+ * Don't call this functon directly: use getFinalResultProperties() to
+ * allow hooks to modify descriptions as needed.
+ *
+ * @return array|bool False on no properties
+ */
+ protected function getResultProperties() {
+ return false;
+ }
+
+ /**
+ * Get final possible result properties, after hooks have had a chance to tweak it as
+ * needed.
+ *
+ * @return array
+ */
+ public function getFinalResultProperties() {
+ $properties = $this->getResultProperties();
+ wfRunHooks( 'APIGetResultProperties', array( $this, &$properties ) );
+ return $properties;
+ }
+
+ /**
+ * Add token properties to the array used by getResultProperties,
+ * based on a token functions mapping.
+ */
+ protected static function addTokenProperties( &$props, $tokenFunctions ) {
+ foreach ( array_keys( $tokenFunctions ) as $token ) {
+ $props[''][$token . 'token'] = array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ );
+ }
+ }
+
/**
* Get final module description, after hooks have had a chance to tweak it as
* needed.
*/
protected function getWatchlistValue ( $watchlist, $titleObj, $userOption = null ) {
- $userWatching = $titleObj->userIsWatching();
+ $userWatching = $this->getUser()->isWatched( $titleObj );
switch ( $watchlist ) {
case 'watch':
* @param $errorCode string Brief, arbitrary, stable string to allow easy
* automated identification of the error, e.g., 'unknown_action'
* @param $httpRespCode int HTTP response code
- * @param $extradata array Data to add to the <error> element; array in ApiResult format
+ * @param $extradata array Data to add to the "<error>" element; array in ApiResult format
+ * @throws UsageException
*/
public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) {
Profiler::instance()->close();
'specialpage-cantexecute' => array( 'code' => 'specialpage-cantexecute', 'info' => "You don't have permission to view the results of this special page" ),
'invalidoldimage' => array( 'code' => 'invalidoldimage', 'info' => 'The oldimage parameter has invalid format' ),
'nodeleteablefile' => array( 'code' => 'nodeleteablefile', 'info' => 'No such old version of the file' ),
+ 'fileexists-forbidden' => array( 'code' => 'fileexists-forbidden', 'info' => 'A file with name "$1" already exists, and cannot be overwritten.' ),
+ 'fileexists-shared-forbidden' => array( 'code' => 'fileexists-shared-forbidden', 'info' => 'A file with name "$1" already exists in the shared file repository, and cannot be overwritten.' ),
// ApiEditPage messages
'noimageredirect-anon' => array( 'code' => 'noimageredirect-anon', 'info' => "Anonymous users can't create image redirects" ),