X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBase.php;h=6a9be24f0873dc74693ad771776f35b05bad1ecc;hb=8f390bcfac38ec47e8a1068ea016e5c654bf7be9;hp=f0386a1b35d934fa14481117f2e49f40dc523be7;hpb=f34f7bfd56ac92a53b9d5687cf51293908272ed5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index f0386a1b35..6a9be24f08 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -56,6 +56,11 @@ abstract class ApiBase extends ContextSource { /// @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 @@ -572,6 +577,51 @@ abstract class ApiBase extends ContextSource { 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.