Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ApiBase often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ApiBase, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 39 | abstract class ApiBase extends ContextSource { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @name Constants for ::getAllowedParams() arrays |
||
| 43 | * These constants are keys in the arrays returned by ::getAllowedParams() |
||
| 44 | * and accepted by ::getParameterFromSettings() that define how the |
||
| 45 | * parameters coming in from the request are to be interpreted. |
||
| 46 | * @{ |
||
| 47 | */ |
||
| 48 | |||
| 49 | /** (null|boolean|integer|string) Default value of the parameter. */ |
||
| 50 | const PARAM_DFLT = 0; |
||
| 51 | |||
| 52 | /** (boolean) Accept multiple pipe-separated values for this parameter (e.g. titles)? */ |
||
| 53 | const PARAM_ISMULTI = 1; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * (string|string[]) Either an array of allowed value strings, or a string |
||
| 57 | * type as described below. If not specified, will be determined from the |
||
| 58 | * type of PARAM_DFLT. |
||
| 59 | * |
||
| 60 | * Supported string types are: |
||
| 61 | * - boolean: A boolean parameter, returned as false if the parameter is |
||
| 62 | * omitted and true if present (even with a falsey value, i.e. it works |
||
| 63 | * like HTML checkboxes). PARAM_DFLT must be boolean false, if specified. |
||
| 64 | * Cannot be used with PARAM_ISMULTI. |
||
| 65 | * - integer: An integer value. See also PARAM_MIN, PARAM_MAX, and |
||
| 66 | * PARAM_RANGE_ENFORCE. |
||
| 67 | * - limit: An integer or the string 'max'. Default lower limit is 0 (but |
||
| 68 | * see PARAM_MIN), and requires that PARAM_MAX and PARAM_MAX2 be |
||
| 69 | * specified. Cannot be used with PARAM_ISMULTI. |
||
| 70 | * - namespace: An integer representing a MediaWiki namespace. |
||
| 71 | * - NULL: Any string. |
||
| 72 | * - password: Any non-empty string. Input value is private or sensitive. |
||
| 73 | * <input type="password"> would be an appropriate HTML form field. |
||
| 74 | * - string: Any non-empty string, not expected to be very long or contain newlines. |
||
| 75 | * <input type="text"> would be an appropriate HTML form field. |
||
| 76 | * - submodule: The name of a submodule of this module, see PARAM_SUBMODULE_MAP. |
||
| 77 | * - tags: A string naming an existing, explicitly-defined tag. Should usually be |
||
| 78 | * used with PARAM_ISMULTI. |
||
| 79 | * - text: Any non-empty string, expected to be very long or contain newlines. |
||
| 80 | * <textarea> would be an appropriate HTML form field. |
||
| 81 | * - timestamp: A timestamp in any format recognized by MWTimestamp, or the |
||
| 82 | * string 'now' representing the current timestamp. Will be returned in |
||
| 83 | * TS_MW format. |
||
| 84 | * - user: A MediaWiki username or IP. Will be returned normalized but not canonicalized. |
||
| 85 | * - upload: An uploaded file. Will be returned as a WebRequestUpload object. |
||
| 86 | * Cannot be used with PARAM_ISMULTI. |
||
| 87 | */ |
||
| 88 | const PARAM_TYPE = 2; |
||
| 89 | |||
| 90 | /** (integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'. */ |
||
| 91 | const PARAM_MAX = 3; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * (integer) Max value allowed for the parameter for users with the |
||
| 95 | * apihighlimits right, for PARAM_TYPE 'limit'. |
||
| 96 | */ |
||
| 97 | const PARAM_MAX2 = 4; |
||
| 98 | |||
| 99 | /** (integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'. */ |
||
| 100 | const PARAM_MIN = 5; |
||
| 101 | |||
| 102 | /** (boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true? */ |
||
| 103 | const PARAM_ALLOW_DUPLICATES = 6; |
||
| 104 | |||
| 105 | /** (boolean) Is the parameter deprecated (will show a warning)? */ |
||
| 106 | const PARAM_DEPRECATED = 7; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * (boolean) Is the parameter required? |
||
| 110 | * @since 1.17 |
||
| 111 | */ |
||
| 112 | const PARAM_REQUIRED = 8; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * (boolean) For PARAM_TYPE 'integer', enforce PARAM_MIN and PARAM_MAX? |
||
| 116 | * @since 1.17 |
||
| 117 | */ |
||
| 118 | const PARAM_RANGE_ENFORCE = 9; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * (string|array|Message) Specify an alternative i18n documentation message |
||
| 122 | * for this parameter. Default is apihelp-{$path}-param-{$param}. |
||
| 123 | * @since 1.25 |
||
| 124 | */ |
||
| 125 | const PARAM_HELP_MSG = 10; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * ((string|array|Message)[]) Specify additional i18n messages to append to |
||
| 129 | * the normal message for this parameter. |
||
| 130 | * @since 1.25 |
||
| 131 | */ |
||
| 132 | const PARAM_HELP_MSG_APPEND = 11; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * (array) Specify additional information tags for the parameter. Value is |
||
| 136 | * an array of arrays, with the first member being the 'tag' for the info |
||
| 137 | * and the remaining members being the values. In the help, this is |
||
| 138 | * formatted using apihelp-{$path}-paraminfo-{$tag}, which is passed |
||
| 139 | * $1 = count, $2 = comma-joined list of values, $3 = module prefix. |
||
| 140 | * @since 1.25 |
||
| 141 | */ |
||
| 142 | const PARAM_HELP_MSG_INFO = 12; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * (string[]) When PARAM_TYPE is an array, this may be an array mapping |
||
| 146 | * those values to page titles which will be linked in the help. |
||
| 147 | * @since 1.25 |
||
| 148 | */ |
||
| 149 | const PARAM_VALUE_LINKS = 13; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * ((string|array|Message)[]) When PARAM_TYPE is an array, this is an array |
||
| 153 | * mapping those values to $msg for ApiBase::makeMessage(). Any value not |
||
| 154 | * having a mapping will use apihelp-{$path}-paramvalue-{$param}-{$value}. |
||
| 155 | * @since 1.25 |
||
| 156 | */ |
||
| 157 | const PARAM_HELP_MSG_PER_VALUE = 14; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * (string[]) When PARAM_TYPE is 'submodule', map parameter values to |
||
| 161 | * submodule paths. Default is to use all modules in |
||
| 162 | * $this->getModuleManager() in the group matching the parameter name. |
||
| 163 | * @since 1.26 |
||
| 164 | */ |
||
| 165 | const PARAM_SUBMODULE_MAP = 15; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * (string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix |
||
| 169 | * added by ApiQueryGeneratorBase (and similar if anything else ever does that). |
||
| 170 | * @since 1.26 |
||
| 171 | */ |
||
| 172 | const PARAM_SUBMODULE_PARAM_PREFIX = 16; |
||
| 173 | |||
| 174 | /**@}*/ |
||
| 175 | |||
| 176 | /** Fast query, standard limit. */ |
||
| 177 | const LIMIT_BIG1 = 500; |
||
| 178 | /** Fast query, apihighlimits limit. */ |
||
| 179 | const LIMIT_BIG2 = 5000; |
||
| 180 | /** Slow query, standard limit. */ |
||
| 181 | const LIMIT_SML1 = 50; |
||
| 182 | /** Slow query, apihighlimits limit. */ |
||
| 183 | const LIMIT_SML2 = 500; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * getAllowedParams() flag: When set, the result could take longer to generate, |
||
| 187 | * but should be more thorough. E.g. get the list of generators for ApiSandBox extension |
||
| 188 | * @since 1.21 |
||
| 189 | */ |
||
| 190 | const GET_VALUES_FOR_HELP = 1; |
||
| 191 | |||
| 192 | /** @var array Maps extension paths to info arrays */ |
||
| 193 | private static $extensionInfo = null; |
||
| 194 | |||
| 195 | /** @var ApiMain */ |
||
| 196 | private $mMainModule; |
||
| 197 | /** @var string */ |
||
| 198 | private $mModuleName, $mModulePrefix; |
||
|
|
|||
| 199 | private $mSlaveDB = null; |
||
| 200 | private $mParamCache = []; |
||
| 201 | /** @var array|null|bool */ |
||
| 202 | private $mModuleSource = false; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param ApiMain $mainModule |
||
| 206 | * @param string $moduleName Name of this module |
||
| 207 | * @param string $modulePrefix Prefix to use for parameter names |
||
| 208 | */ |
||
| 209 | public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) { |
||
| 218 | |||
| 219 | /************************************************************************//** |
||
| 220 | * @name Methods to implement |
||
| 221 | * @{ |
||
| 222 | */ |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Evaluates the parameters, performs the requested query, and sets up |
||
| 226 | * the result. Concrete implementations of ApiBase must override this |
||
| 227 | * method to provide whatever functionality their module offers. |
||
| 228 | * Implementations must not produce any output on their own and are not |
||
| 229 | * expected to handle any errors. |
||
| 230 | * |
||
| 231 | * The execute() method will be invoked directly by ApiMain immediately |
||
| 232 | * before the result of the module is output. Aside from the |
||
| 233 | * constructor, implementations should assume that no other methods |
||
| 234 | * will be called externally on the module before the result is |
||
| 235 | * processed. |
||
| 236 | * |
||
| 237 | * The result data should be stored in the ApiResult object available |
||
| 238 | * through getResult(). |
||
| 239 | */ |
||
| 240 | abstract public function execute(); |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Get the module manager, or null if this module has no sub-modules |
||
| 244 | * @since 1.21 |
||
| 245 | * @return ApiModuleManager |
||
| 246 | */ |
||
| 247 | public function getModuleManager() { |
||
| 250 | |||
| 251 | /** |
||
| 252 | * If the module may only be used with a certain format module, |
||
| 253 | * it should override this method to return an instance of that formatter. |
||
| 254 | * A value of null means the default format will be used. |
||
| 255 | * @note Do not use this just because you don't want to support non-json |
||
| 256 | * formats. This should be used only when there is a fundamental |
||
| 257 | * requirement for a specific format. |
||
| 258 | * @return mixed Instance of a derived class of ApiFormatBase, or null |
||
| 259 | */ |
||
| 260 | public function getCustomPrinter() { |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Returns usage examples for this module. |
||
| 266 | * |
||
| 267 | * Return value has query strings as keys, with values being either strings |
||
| 268 | * (message key), arrays (message key + parameter), or Message objects. |
||
| 269 | * |
||
| 270 | * Do not call this base class implementation when overriding this method. |
||
| 271 | * |
||
| 272 | * @since 1.25 |
||
| 273 | * @return array |
||
| 274 | */ |
||
| 275 | protected function getExamplesMessages() { |
||
| 276 | // Fall back to old non-localised method |
||
| 277 | $ret = []; |
||
| 278 | |||
| 279 | $examples = $this->getExamples(); |
||
| 280 | if ( $examples ) { |
||
| 281 | if ( !is_array( $examples ) ) { |
||
| 282 | $examples = [ $examples ]; |
||
| 283 | } elseif ( $examples && ( count( $examples ) & 1 ) == 0 && |
||
| 284 | array_keys( $examples ) === range( 0, count( $examples ) - 1 ) && |
||
| 285 | !preg_match( '/^\s*api\.php\?/', $examples[0] ) |
||
| 286 | ) { |
||
| 287 | // Fix up the ugly "even numbered elements are description, odd |
||
| 288 | // numbered elemts are the link" format (see doc for self::getExamples) |
||
| 289 | $tmp = []; |
||
| 290 | $examplesCount = count( $examples ); |
||
| 291 | for ( $i = 0; $i < $examplesCount; $i += 2 ) { |
||
| 292 | $tmp[$examples[$i + 1]] = $examples[$i]; |
||
| 293 | } |
||
| 294 | $examples = $tmp; |
||
| 295 | } |
||
| 296 | |||
| 297 | foreach ( $examples as $k => $v ) { |
||
| 298 | if ( is_numeric( $k ) ) { |
||
| 299 | $qs = $v; |
||
| 300 | $msg = ''; |
||
| 301 | } else { |
||
| 302 | $qs = $k; |
||
| 303 | $msg = self::escapeWikiText( $v ); |
||
| 304 | if ( is_array( $msg ) ) { |
||
| 305 | $msg = implode( ' ', $msg ); |
||
| 306 | } |
||
| 307 | } |
||
| 308 | |||
| 309 | $qs = preg_replace( '/^\s*api\.php\?/', '', $qs ); |
||
| 310 | $ret[$qs] = $this->msg( 'api-help-fallback-example', [ $msg ] ); |
||
| 311 | } |
||
| 312 | } |
||
| 313 | |||
| 314 | return $ret; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Return links to more detailed help pages about the module. |
||
| 319 | * @since 1.25, returning boolean false is deprecated |
||
| 320 | * @return string|array |
||
| 321 | */ |
||
| 322 | public function getHelpUrls() { |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Returns an array of allowed parameters (parameter name) => (default |
||
| 328 | * value) or (parameter name) => (array with PARAM_* constants as keys) |
||
| 329 | * Don't call this function directly: use getFinalParams() to allow |
||
| 330 | * hooks to modify parameters as needed. |
||
| 331 | * |
||
| 332 | * Some derived classes may choose to handle an integer $flags parameter |
||
| 333 | * in the overriding methods. Callers of this method can pass zero or |
||
| 334 | * more OR-ed flags like GET_VALUES_FOR_HELP. |
||
| 335 | * |
||
| 336 | * @return array |
||
| 337 | */ |
||
| 338 | protected function getAllowedParams( /* $flags = 0 */ ) { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Indicates if this module needs maxlag to be checked |
||
| 346 | * @return bool |
||
| 347 | */ |
||
| 348 | public function shouldCheckMaxlag() { |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Indicates whether this module requires read rights |
||
| 354 | * @return bool |
||
| 355 | */ |
||
| 356 | public function isReadMode() { |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Indicates whether this module requires write mode |
||
| 362 | * @return bool |
||
| 363 | */ |
||
| 364 | public function isWriteMode() { |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Indicates whether this module must be called with a POST request |
||
| 370 | * @return bool |
||
| 371 | */ |
||
| 372 | public function mustBePosted() { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Indicates whether this module is deprecated |
||
| 378 | * @since 1.25 |
||
| 379 | * @return bool |
||
| 380 | */ |
||
| 381 | public function isDeprecated() { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Indicates whether this module is "internal" |
||
| 387 | * Internal API modules are not (yet) intended for 3rd party use and may be unstable. |
||
| 388 | * @since 1.25 |
||
| 389 | * @return bool |
||
| 390 | */ |
||
| 391 | public function isInternal() { |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Returns the token type this module requires in order to execute. |
||
| 397 | * |
||
| 398 | * Modules are strongly encouraged to use the core 'csrf' type unless they |
||
| 399 | * have specialized security needs. If the token type is not one of the |
||
| 400 | * core types, you must use the ApiQueryTokensRegisterTypes hook to |
||
| 401 | * register it. |
||
| 402 | * |
||
| 403 | * Returning a non-falsey value here will force the addition of an |
||
| 404 | * appropriate 'token' parameter in self::getFinalParams(). Also, |
||
| 405 | * self::mustBePosted() must return true when tokens are used. |
||
| 406 | * |
||
| 407 | * In previous versions of MediaWiki, true was a valid return value. |
||
| 408 | * Returning true will generate errors indicating that the API module needs |
||
| 409 | * updating. |
||
| 410 | * |
||
| 411 | * @return string|false |
||
| 412 | */ |
||
| 413 | public function needsToken() { |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Fetch the salt used in the Web UI corresponding to this module. |
||
| 419 | * |
||
| 420 | * Only override this if the Web UI uses a token with a non-constant salt. |
||
| 421 | * |
||
| 422 | * @since 1.24 |
||
| 423 | * @param array $params All supplied parameters for the module |
||
| 424 | * @return string|array|null |
||
| 425 | */ |
||
| 426 | protected function getWebUITokenSalt( array $params ) { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Returns data for HTTP conditional request mechanisms. |
||
| 432 | * |
||
| 433 | * @since 1.26 |
||
| 434 | * @param string $condition Condition being queried: |
||
| 435 | * - last-modified: Return a timestamp representing the maximum of the |
||
| 436 | * last-modified dates for all resources involved in the request. See |
||
| 437 | * RFC 7232 § 2.2 for semantics. |
||
| 438 | * - etag: Return an entity-tag representing the state of all resources involved |
||
| 439 | * in the request. Quotes must be included. See RFC 7232 § 2.3 for semantics. |
||
| 440 | * @return string|boolean|null As described above, or null if no value is available. |
||
| 441 | */ |
||
| 442 | public function getConditionalRequestData( $condition ) { |
||
| 445 | |||
| 446 | /**@}*/ |
||
| 447 | |||
| 448 | /************************************************************************//** |
||
| 449 | * @name Data access methods |
||
| 450 | * @{ |
||
| 451 | */ |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Get the name of the module being executed by this instance |
||
| 455 | * @return string |
||
| 456 | */ |
||
| 457 | public function getModuleName() { |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Get parameter prefix (usually two letters or an empty string). |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | public function getModulePrefix() { |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Get the main module |
||
| 471 | * @return ApiMain |
||
| 472 | */ |
||
| 473 | public function getMain() { |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Returns true if this module is the main module ($this === $this->mMainModule), |
||
| 479 | * false otherwise. |
||
| 480 | * @return bool |
||
| 481 | */ |
||
| 482 | public function isMain() { |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get the parent of this module |
||
| 488 | * @since 1.25 |
||
| 489 | * @return ApiBase|null |
||
| 490 | */ |
||
| 491 | public function getParent() { |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Returns true if the current request breaks the same-origin policy. |
||
| 497 | * |
||
| 498 | * For example, json with callbacks. |
||
| 499 | * |
||
| 500 | * https://en.wikipedia.org/wiki/Same-origin_policy |
||
| 501 | * |
||
| 502 | * @since 1.25 |
||
| 503 | * @return bool |
||
| 504 | */ |
||
| 505 | public function lacksSameOriginSecurity() { |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Get the path to this module |
||
| 511 | * |
||
| 512 | * @since 1.25 |
||
| 513 | * @return string |
||
| 514 | */ |
||
| 515 | public function getModulePath() { |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Get a module from its module path |
||
| 527 | * |
||
| 528 | * @since 1.25 |
||
| 529 | * @param string $path |
||
| 530 | * @return ApiBase|null |
||
| 531 | * @throws UsageException |
||
| 532 | */ |
||
| 533 | public function getModuleFromPath( $path ) { |
||
| 534 | $module = $this->getMain(); |
||
| 535 | if ( $path === 'main' ) { |
||
| 536 | return $module; |
||
| 537 | } |
||
| 538 | |||
| 539 | $parts = explode( '+', $path ); |
||
| 540 | if ( count( $parts ) === 1 ) { |
||
| 541 | // In case the '+' was typed into URL, it resolves as a space |
||
| 542 | $parts = explode( ' ', $path ); |
||
| 543 | } |
||
| 544 | |||
| 545 | $count = count( $parts ); |
||
| 546 | for ( $i = 0; $i < $count; $i++ ) { |
||
| 547 | $parent = $module; |
||
| 548 | $manager = $parent->getModuleManager(); |
||
| 549 | if ( $manager === null ) { |
||
| 550 | $errorPath = implode( '+', array_slice( $parts, 0, $i ) ); |
||
| 551 | $this->dieUsage( "The module \"$errorPath\" has no submodules", 'badmodule' ); |
||
| 552 | } |
||
| 553 | $module = $manager->getModule( $parts[$i] ); |
||
| 554 | |||
| 555 | if ( $module === null ) { |
||
| 556 | $errorPath = $i ? implode( '+', array_slice( $parts, 0, $i ) ) : $parent->getModuleName(); |
||
| 557 | $this->dieUsage( |
||
| 558 | "The module \"$errorPath\" does not have a submodule \"{$parts[$i]}\"", |
||
| 559 | 'badmodule' |
||
| 560 | ); |
||
| 561 | } |
||
| 562 | } |
||
| 563 | |||
| 564 | return $module; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Get the result object |
||
| 569 | * @return ApiResult |
||
| 570 | */ |
||
| 571 | public function getResult() { |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Get the error formatter |
||
| 583 | * @return ApiErrorFormatter |
||
| 584 | */ |
||
| 585 | public function getErrorFormatter() { |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Gets a default slave database connection object |
||
| 597 | * @return DatabaseBase |
||
| 598 | */ |
||
| 599 | protected function getDB() { |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Get the continuation manager |
||
| 609 | * @return ApiContinuationManager|null |
||
| 610 | */ |
||
| 611 | public function getContinuationManager() { |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Set the continuation manager |
||
| 623 | * @param ApiContinuationManager|null |
||
| 624 | */ |
||
| 625 | public function setContinuationManager( $manager ) { |
||
| 634 | |||
| 635 | /**@}*/ |
||
| 636 | |||
| 637 | /************************************************************************//** |
||
| 638 | * @name Parameter handling |
||
| 639 | * @{ |
||
| 640 | */ |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Indicate if the module supports dynamically-determined parameters that |
||
| 644 | * cannot be included in self::getAllowedParams(). |
||
| 645 | * @return string|array|Message|null Return null if the module does not |
||
| 646 | * support additional dynamic parameters, otherwise return a message |
||
| 647 | * describing them. |
||
| 648 | */ |
||
| 649 | public function dynamicParameterDocumentation() { |
||
| 652 | |||
| 653 | /** |
||
| 654 | * This method mangles parameter name based on the prefix supplied to the constructor. |
||
| 655 | * Override this method to change parameter name during runtime |
||
| 656 | * @param string $paramName Parameter name |
||
| 657 | * @return string Prefixed parameter name |
||
| 658 | */ |
||
| 659 | public function encodeParamName( $paramName ) { |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Using getAllowedParams(), this function makes an array of the values |
||
| 665 | * provided by the user, with key being the name of the variable, and |
||
| 666 | * value - validated value from user or default. limits will not be |
||
| 667 | * parsed if $parseLimit is set to false; use this when the max |
||
| 668 | * limit is not definitive yet, e.g. when getting revisions. |
||
| 669 | * @param bool $parseLimit True by default |
||
| 670 | * @return array |
||
| 671 | */ |
||
| 672 | public function extractRequestParams( $parseLimit = true ) { |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Get a value for the given parameter |
||
| 692 | * @param string $paramName Parameter name |
||
| 693 | * @param bool $parseLimit See extractRequestParams() |
||
| 694 | * @return mixed Parameter value |
||
| 695 | */ |
||
| 696 | protected function getParameter( $paramName, $parseLimit = true ) { |
||
| 697 | $paramSettings = $this->getFinalParams()[$paramName]; |
||
| 698 | |||
| 699 | return $this->getParameterFromSettings( $paramName, $paramSettings, $parseLimit ); |
||
| 700 | } |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Die if none or more than one of a certain set of parameters is set and not false. |
||
| 704 | * |
||
| 705 | * @param array $params User provided set of parameters, as from $this->extractRequestParams() |
||
| 706 | * @param string $required,... Names of parameters of which exactly one must be set |
||
| 707 | */ |
||
| 708 | public function requireOnlyOneParameter( $params, $required /*...*/ ) { |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Die if more than one of a certain set of parameters is set and not false. |
||
| 730 | * |
||
| 731 | * @param array $params User provided set of parameters, as from $this->extractRequestParams() |
||
| 732 | * @param string $required,... Names of parameters of which at most one must be set |
||
| 733 | */ |
||
| 734 | View Code Duplication | public function requireMaxOneParameter( $params, $required /*...*/ ) { |
|
| 749 | |||
| 750 | /** |
||
| 751 | * Die if none of a certain set of parameters is set and not false. |
||
| 752 | * |
||
| 753 | * @since 1.23 |
||
| 754 | * @param array $params User provided set of parameters, as from $this->extractRequestParams() |
||
| 755 | * @param string $required,... Names of parameters of which at least one must be set |
||
| 756 | */ |
||
| 757 | View Code Duplication | public function requireAtLeastOneParameter( $params, $required /*...*/ ) { |
|
| 772 | |||
| 773 | /** |
||
| 774 | * Callback function used in requireOnlyOneParameter to check whether required parameters are set |
||
| 775 | * |
||
| 776 | * @param object $x Parameter to check is not null/false |
||
| 777 | * @return bool |
||
| 778 | */ |
||
| 779 | private function parameterNotEmpty( $x ) { |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Get a WikiPage object from a title or pageid param, if possible. |
||
| 785 | * Can die, if no param is set or if the title or page id is not valid. |
||
| 786 | * |
||
| 787 | * @param array $params |
||
| 788 | * @param bool|string $load Whether load the object's state from the database: |
||
| 789 | * - false: don't load (if the pageid is given, it will still be loaded) |
||
| 790 | * - 'fromdb': load from a slave database |
||
| 791 | * - 'fromdbmaster': load from the master database |
||
| 792 | * @return WikiPage |
||
| 793 | */ |
||
| 794 | public function getTitleOrPageId( $params, $load = false ) { |
||
| 822 | |||
| 823 | /** |
||
| 824 | * Return true if we're to watch the page, false if not, null if no change. |
||
| 825 | * @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange' |
||
| 826 | * @param Title $titleObj The page under consideration |
||
| 827 | * @param string $userOption The user option to consider when $watchlist=preferences. |
||
| 828 | * If not set will use watchdefault always and watchcreations if $titleObj doesn't exist. |
||
| 829 | * @return bool |
||
| 830 | */ |
||
| 831 | protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) { |
||
| 863 | |||
| 864 | /** |
||
| 865 | * Using the settings determine the value for the given parameter |
||
| 866 | * |
||
| 867 | * @param string $paramName Parameter name |
||
| 868 | * @param array|mixed $paramSettings Default value or an array of settings |
||
| 869 | * using PARAM_* constants. |
||
| 870 | * @param bool $parseLimit Parse limit? |
||
| 871 | * @return mixed Parameter value |
||
| 872 | */ |
||
| 873 | protected function getParameterFromSettings( $paramName, $paramSettings, $parseLimit ) { |
||
| 874 | // Some classes may decide to change parameter names |
||
| 875 | $encParamName = $this->encodeParamName( $paramName ); |
||
| 876 | |||
| 877 | if ( !is_array( $paramSettings ) ) { |
||
| 878 | $default = $paramSettings; |
||
| 879 | $multi = false; |
||
| 880 | $type = gettype( $paramSettings ); |
||
| 881 | $dupes = false; |
||
| 882 | $deprecated = false; |
||
| 883 | $required = false; |
||
| 884 | } else { |
||
| 885 | $default = isset( $paramSettings[self::PARAM_DFLT] ) |
||
| 886 | ? $paramSettings[self::PARAM_DFLT] |
||
| 887 | : null; |
||
| 888 | $multi = isset( $paramSettings[self::PARAM_ISMULTI] ) |
||
| 889 | ? $paramSettings[self::PARAM_ISMULTI] |
||
| 890 | : false; |
||
| 891 | $type = isset( $paramSettings[self::PARAM_TYPE] ) |
||
| 892 | ? $paramSettings[self::PARAM_TYPE] |
||
| 893 | : null; |
||
| 894 | $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] ) |
||
| 895 | ? $paramSettings[self::PARAM_ALLOW_DUPLICATES] |
||
| 896 | : false; |
||
| 897 | $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] ) |
||
| 898 | ? $paramSettings[self::PARAM_DEPRECATED] |
||
| 899 | : false; |
||
| 900 | $required = isset( $paramSettings[self::PARAM_REQUIRED] ) |
||
| 901 | ? $paramSettings[self::PARAM_REQUIRED] |
||
| 902 | : false; |
||
| 903 | |||
| 904 | // When type is not given, and no choices, the type is the same as $default |
||
| 905 | if ( !isset( $type ) ) { |
||
| 906 | if ( isset( $default ) ) { |
||
| 907 | $type = gettype( $default ); |
||
| 908 | } else { |
||
| 909 | $type = 'NULL'; // allow everything |
||
| 910 | } |
||
| 911 | } |
||
| 912 | } |
||
| 913 | |||
| 914 | if ( $type == 'boolean' ) { |
||
| 915 | if ( isset( $default ) && $default !== false ) { |
||
| 916 | // Having a default value of anything other than 'false' is not allowed |
||
| 917 | ApiBase::dieDebug( |
||
| 918 | __METHOD__, |
||
| 919 | "Boolean param $encParamName's default is set to '$default'. " . |
||
| 920 | 'Boolean parameters must default to false.' |
||
| 921 | ); |
||
| 922 | } |
||
| 923 | |||
| 924 | $value = $this->getMain()->getCheck( $encParamName ); |
||
| 925 | } elseif ( $type == 'upload' ) { |
||
| 926 | if ( isset( $default ) ) { |
||
| 927 | // Having a default value is not allowed |
||
| 928 | ApiBase::dieDebug( |
||
| 929 | __METHOD__, |
||
| 930 | "File upload param $encParamName's default is set to " . |
||
| 931 | "'$default'. File upload parameters may not have a default." ); |
||
| 932 | } |
||
| 933 | if ( $multi ) { |
||
| 934 | ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); |
||
| 935 | } |
||
| 936 | $value = $this->getMain()->getUpload( $encParamName ); |
||
| 937 | if ( !$value->exists() ) { |
||
| 938 | // This will get the value without trying to normalize it |
||
| 939 | // (because trying to normalize a large binary file |
||
| 940 | // accidentally uploaded as a field fails spectacularly) |
||
| 941 | $value = $this->getMain()->getRequest()->unsetVal( $encParamName ); |
||
| 942 | if ( $value !== null ) { |
||
| 943 | $this->dieUsage( |
||
| 944 | "File upload param $encParamName is not a file upload; " . |
||
| 945 | 'be sure to use multipart/form-data for your POST and include ' . |
||
| 946 | 'a filename in the Content-Disposition header.', |
||
| 947 | "badupload_{$encParamName}" |
||
| 948 | ); |
||
| 949 | } |
||
| 950 | } |
||
| 951 | } else { |
||
| 952 | $value = $this->getMain()->getVal( $encParamName, $default ); |
||
| 953 | |||
| 954 | if ( isset( $value ) && $type == 'namespace' ) { |
||
| 955 | $type = MWNamespace::getValidNamespaces(); |
||
| 956 | } |
||
| 957 | View Code Duplication | if ( isset( $value ) && $type == 'submodule' ) { |
|
| 958 | if ( isset( $paramSettings[self::PARAM_SUBMODULE_MAP] ) ) { |
||
| 959 | $type = array_keys( $paramSettings[self::PARAM_SUBMODULE_MAP] ); |
||
| 960 | } else { |
||
| 961 | $type = $this->getModuleManager()->getNames( $paramName ); |
||
| 962 | } |
||
| 963 | } |
||
| 964 | } |
||
| 965 | |||
| 966 | if ( isset( $value ) && ( $multi || is_array( $type ) ) ) { |
||
| 967 | $value = $this->parseMultiValue( |
||
| 968 | $encParamName, |
||
| 969 | $value, |
||
| 970 | $multi, |
||
| 971 | is_array( $type ) ? $type : null |
||
| 972 | ); |
||
| 973 | } |
||
| 974 | |||
| 975 | // More validation only when choices were not given |
||
| 976 | // choices were validated in parseMultiValue() |
||
| 977 | if ( isset( $value ) ) { |
||
| 978 | if ( !is_array( $type ) ) { |
||
| 979 | switch ( $type ) { |
||
| 980 | case 'NULL': // nothing to do |
||
| 981 | break; |
||
| 982 | case 'string': |
||
| 983 | case 'text': |
||
| 984 | case 'password': |
||
| 985 | if ( $required && $value === '' ) { |
||
| 986 | $this->dieUsageMsg( [ 'missingparam', $paramName ] ); |
||
| 987 | } |
||
| 988 | break; |
||
| 989 | case 'integer': // Force everything using intval() and optionally validate limits |
||
| 990 | $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : null; |
||
| 991 | $max = isset( $paramSettings[self::PARAM_MAX] ) ? $paramSettings[self::PARAM_MAX] : null; |
||
| 992 | $enforceLimits = isset( $paramSettings[self::PARAM_RANGE_ENFORCE] ) |
||
| 993 | ? $paramSettings[self::PARAM_RANGE_ENFORCE] : false; |
||
| 994 | |||
| 995 | if ( is_array( $value ) ) { |
||
| 996 | $value = array_map( 'intval', $value ); |
||
| 997 | View Code Duplication | if ( !is_null( $min ) || !is_null( $max ) ) { |
|
| 998 | foreach ( $value as &$v ) { |
||
| 999 | $this->validateLimit( $paramName, $v, $min, $max, null, $enforceLimits ); |
||
| 1000 | } |
||
| 1001 | } |
||
| 1002 | View Code Duplication | } else { |
|
| 1003 | $value = intval( $value ); |
||
| 1004 | if ( !is_null( $min ) || !is_null( $max ) ) { |
||
| 1005 | $this->validateLimit( $paramName, $value, $min, $max, null, $enforceLimits ); |
||
| 1006 | } |
||
| 1007 | } |
||
| 1008 | break; |
||
| 1009 | case 'limit': |
||
| 1010 | if ( !$parseLimit ) { |
||
| 1011 | // Don't do any validation whatsoever |
||
| 1012 | break; |
||
| 1013 | } |
||
| 1014 | if ( !isset( $paramSettings[self::PARAM_MAX] ) |
||
| 1015 | || !isset( $paramSettings[self::PARAM_MAX2] ) |
||
| 1016 | ) { |
||
| 1017 | ApiBase::dieDebug( |
||
| 1018 | __METHOD__, |
||
| 1019 | "MAX1 or MAX2 are not defined for the limit $encParamName" |
||
| 1020 | ); |
||
| 1021 | } |
||
| 1022 | if ( $multi ) { |
||
| 1023 | ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); |
||
| 1024 | } |
||
| 1025 | $min = isset( $paramSettings[self::PARAM_MIN] ) ? $paramSettings[self::PARAM_MIN] : 0; |
||
| 1026 | if ( $value == 'max' ) { |
||
| 1027 | $value = $this->getMain()->canApiHighLimits() |
||
| 1028 | ? $paramSettings[self::PARAM_MAX2] |
||
| 1029 | : $paramSettings[self::PARAM_MAX]; |
||
| 1030 | $this->getResult()->addParsedLimit( $this->getModuleName(), $value ); |
||
| 1031 | } else { |
||
| 1032 | $value = intval( $value ); |
||
| 1033 | $this->validateLimit( |
||
| 1034 | $paramName, |
||
| 1035 | $value, |
||
| 1036 | $min, |
||
| 1037 | $paramSettings[self::PARAM_MAX], |
||
| 1038 | $paramSettings[self::PARAM_MAX2] |
||
| 1039 | ); |
||
| 1040 | } |
||
| 1041 | break; |
||
| 1042 | case 'boolean': |
||
| 1043 | if ( $multi ) { |
||
| 1044 | ApiBase::dieDebug( __METHOD__, "Multi-values not supported for $encParamName" ); |
||
| 1045 | } |
||
| 1046 | break; |
||
| 1047 | View Code Duplication | case 'timestamp': |
|
| 1048 | if ( is_array( $value ) ) { |
||
| 1049 | foreach ( $value as $key => $val ) { |
||
| 1050 | $value[$key] = $this->validateTimestamp( $val, $encParamName ); |
||
| 1051 | } |
||
| 1052 | } else { |
||
| 1053 | $value = $this->validateTimestamp( $value, $encParamName ); |
||
| 1054 | } |
||
| 1055 | break; |
||
| 1056 | View Code Duplication | case 'user': |
|
| 1057 | if ( is_array( $value ) ) { |
||
| 1058 | foreach ( $value as $key => $val ) { |
||
| 1059 | $value[$key] = $this->validateUser( $val, $encParamName ); |
||
| 1060 | } |
||
| 1061 | } else { |
||
| 1062 | $value = $this->validateUser( $value, $encParamName ); |
||
| 1063 | } |
||
| 1064 | break; |
||
| 1065 | case 'upload': // nothing to do |
||
| 1066 | break; |
||
| 1067 | case 'tags': |
||
| 1068 | // If change tagging was requested, check that the tags are valid. |
||
| 1069 | if ( !is_array( $value ) && !$multi ) { |
||
| 1070 | $value = [ $value ]; |
||
| 1071 | } |
||
| 1072 | $tagsStatus = ChangeTags::canAddTagsAccompanyingChange( $value ); |
||
| 1073 | if ( !$tagsStatus->isGood() ) { |
||
| 1074 | $this->dieStatus( $tagsStatus ); |
||
| 1075 | } |
||
| 1076 | break; |
||
| 1077 | default: |
||
| 1078 | ApiBase::dieDebug( __METHOD__, "Param $encParamName's type is unknown - $type" ); |
||
| 1079 | } |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | // Throw out duplicates if requested |
||
| 1083 | if ( !$dupes && is_array( $value ) ) { |
||
| 1084 | $value = array_unique( $value ); |
||
| 1085 | } |
||
| 1086 | |||
| 1087 | // Set a warning if a deprecated parameter has been passed |
||
| 1088 | if ( $deprecated && $value !== false ) { |
||
| 1089 | $this->setWarning( "The $encParamName parameter has been deprecated." ); |
||
| 1090 | |||
| 1091 | $feature = $encParamName; |
||
| 1092 | $m = $this; |
||
| 1093 | while ( !$m->isMain() ) { |
||
| 1094 | $p = $m->getParent(); |
||
| 1095 | $name = $m->getModuleName(); |
||
| 1096 | $param = $p->encodeParamName( $p->getModuleManager()->getModuleGroup( $name ) ); |
||
| 1097 | $feature = "{$param}={$name}&{$feature}"; |
||
| 1098 | $m = $p; |
||
| 1099 | } |
||
| 1100 | $this->logFeatureUsage( $feature ); |
||
| 1101 | } |
||
| 1102 | } elseif ( $required ) { |
||
| 1103 | $this->dieUsageMsg( [ 'missingparam', $paramName ] ); |
||
| 1104 | } |
||
| 1105 | |||
| 1106 | return $value; |
||
| 1107 | } |
||
| 1108 | |||
| 1109 | /** |
||
| 1110 | * Return an array of values that were given in a 'a|b|c' notation, |
||
| 1111 | * after it optionally validates them against the list allowed values. |
||
| 1112 | * |
||
| 1113 | * @param string $valueName The name of the parameter (for error |
||
| 1114 | * reporting) |
||
| 1115 | * @param mixed $value The value being parsed |
||
| 1116 | * @param bool $allowMultiple Can $value contain more than one value |
||
| 1117 | * separated by '|'? |
||
| 1118 | * @param string[]|null $allowedValues An array of values to check against. If |
||
| 1119 | * null, all values are accepted. |
||
| 1120 | * @return string|string[] (allowMultiple ? an_array_of_values : a_single_value) |
||
| 1121 | */ |
||
| 1122 | protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues ) { |
||
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Validate the value against the minimum and user/bot maximum limits. |
||
| 1178 | * Prints usage info on failure. |
||
| 1179 | * @param string $paramName Parameter name |
||
| 1180 | * @param int $value Parameter value |
||
| 1181 | * @param int|null $min Minimum value |
||
| 1182 | * @param int|null $max Maximum value for users |
||
| 1183 | * @param int $botMax Maximum value for sysops/bots |
||
| 1184 | * @param bool $enforceLimits Whether to enforce (die) if value is outside limits |
||
| 1185 | */ |
||
| 1186 | protected function validateLimit( $paramName, &$value, $min, $max, $botMax = null, |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Validate and normalize of parameters of type 'timestamp' |
||
| 1221 | * @param string $value Parameter value |
||
| 1222 | * @param string $encParamName Parameter name |
||
| 1223 | * @return string Validated and normalized parameter |
||
| 1224 | */ |
||
| 1225 | protected function validateTimestamp( $value, $encParamName ) { |
||
| 1254 | |||
| 1255 | /** |
||
| 1256 | * Validate the supplied token. |
||
| 1257 | * |
||
| 1258 | * @since 1.24 |
||
| 1259 | * @param string $token Supplied token |
||
| 1260 | * @param array $params All supplied parameters for the module |
||
| 1261 | * @return bool |
||
| 1262 | * @throws MWException |
||
| 1263 | */ |
||
| 1264 | final public function validateToken( $token, array $params ) { |
||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * Validate and normalize of parameters of type 'user' |
||
| 1295 | * @param string $value Parameter value |
||
| 1296 | * @param string $encParamName Parameter name |
||
| 1297 | * @return string Validated and normalized parameter |
||
| 1298 | */ |
||
| 1299 | private function validateUser( $value, $encParamName ) { |
||
| 1310 | |||
| 1311 | /**@}*/ |
||
| 1312 | |||
| 1313 | /************************************************************************//** |
||
| 1314 | * @name Utility methods |
||
| 1315 | * @{ |
||
| 1316 | */ |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Set a watch (or unwatch) based the based on a watchlist parameter. |
||
| 1320 | * @param string $watch Valid values: 'watch', 'unwatch', 'preferences', 'nochange' |
||
| 1321 | * @param Title $titleObj The article's title to change |
||
| 1322 | * @param string $userOption The user option to consider when $watch=preferences |
||
| 1323 | */ |
||
| 1324 | protected function setWatch( $watch, $titleObj, $userOption = null ) { |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * Truncate an array to a certain length. |
||
| 1335 | * @param array $arr Array to truncate |
||
| 1336 | * @param int $limit Maximum length |
||
| 1337 | * @return bool True if the array was truncated, false otherwise |
||
| 1338 | */ |
||
| 1339 | public static function truncateArray( &$arr, $limit ) { |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Gets the user for whom to get the watchlist |
||
| 1351 | * |
||
| 1352 | * @param array $params |
||
| 1353 | * @return User |
||
| 1354 | */ |
||
| 1355 | public function getWatchlistUser( $params ) { |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * A subset of wfEscapeWikiText for BC texts |
||
| 1383 | * |
||
| 1384 | * @since 1.25 |
||
| 1385 | * @param string|array $v |
||
| 1386 | * @return string|array |
||
| 1387 | */ |
||
| 1388 | View Code Duplication | private static function escapeWikiText( $v ) { |
|
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Create a Message from a string or array |
||
| 1402 | * |
||
| 1403 | * A string is used as a message key. An array has the message key as the |
||
| 1404 | * first value and message parameters as subsequent values. |
||
| 1405 | * |
||
| 1406 | * @since 1.25 |
||
| 1407 | * @param string|array|Message $msg |
||
| 1408 | * @param IContextSource $context |
||
| 1409 | * @param array $params |
||
| 1410 | * @return Message|null |
||
| 1411 | */ |
||
| 1412 | public static function makeMessage( $msg, IContextSource $context, array $params = null ) { |
||
| 1429 | |||
| 1430 | /**@}*/ |
||
| 1431 | |||
| 1432 | /************************************************************************//** |
||
| 1433 | * @name Warning and error reporting |
||
| 1434 | * @{ |
||
| 1435 | */ |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Set warning section for this module. Users should monitor this |
||
| 1439 | * section to notice any changes in API. Multiple calls to this |
||
| 1440 | * function will result in the warning messages being separated by |
||
| 1441 | * newlines |
||
| 1442 | * @param string $warning Warning message |
||
| 1443 | */ |
||
| 1444 | public function setWarning( $warning ) { |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Adds a warning to the output, else dies |
||
| 1451 | * |
||
| 1452 | * @param string $msg Message to show as a warning, or error message if dying |
||
| 1453 | * @param bool $enforceLimits Whether this is an enforce (die) |
||
| 1454 | */ |
||
| 1455 | private function warnOrDie( $msg, $enforceLimits = false ) { |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Throw a UsageException, which will (if uncaught) call the main module's |
||
| 1465 | * error handler and die with an error message. |
||
| 1466 | * |
||
| 1467 | * @param string $description One-line human-readable description of the |
||
| 1468 | * error condition, e.g., "The API requires a valid action parameter" |
||
| 1469 | * @param string $errorCode Brief, arbitrary, stable string to allow easy |
||
| 1470 | * automated identification of the error, e.g., 'unknown_action' |
||
| 1471 | * @param int $httpRespCode HTTP response code |
||
| 1472 | * @param array|null $extradata Data to add to the "<error>" element; array in ApiResult format |
||
| 1473 | * @throws UsageException always |
||
| 1474 | */ |
||
| 1475 | public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) { |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Throw a UsageException, which will (if uncaught) call the main module's |
||
| 1486 | * error handler and die with an error message including block info. |
||
| 1487 | * |
||
| 1488 | * @since 1.27 |
||
| 1489 | * @param Block $block The block used to generate the UsageException |
||
| 1490 | * @throws UsageException always |
||
| 1491 | */ |
||
| 1492 | public function dieBlocked( Block $block ) { |
||
| 1510 | |||
| 1511 | /** |
||
| 1512 | * Get error (as code, string) from a Status object. |
||
| 1513 | * |
||
| 1514 | * @since 1.23 |
||
| 1515 | * @param Status $status |
||
| 1516 | * @param array|null &$extraData Set if extra data from IApiMessage is available (since 1.27) |
||
| 1517 | * @return array Array of code and error string |
||
| 1518 | * @throws MWException |
||
| 1519 | */ |
||
| 1520 | public function getErrorFromStatus( $status, &$extraData = null ) { |
||
| 1556 | |||
| 1557 | /** |
||
| 1558 | * Throw a UsageException based on the errors in the Status object. |
||
| 1559 | * |
||
| 1560 | * @since 1.22 |
||
| 1561 | * @param Status $status |
||
| 1562 | * @throws UsageException always |
||
| 1563 | */ |
||
| 1564 | public function dieStatus( $status ) { |
||
| 1569 | |||
| 1570 | // @codingStandardsIgnoreStart Allow long lines. Cannot split these. |
||
| 1571 | /** |
||
| 1572 | * Array that maps message keys to error messages. $1 and friends are replaced. |
||
| 1573 | */ |
||
| 1574 | public static $messageMap = [ |
||
| 1575 | // This one MUST be present, or dieUsageMsg() will recurse infinitely |
||
| 1576 | 'unknownerror' => [ 'code' => 'unknownerror', 'info' => "Unknown error: \"\$1\"" ], |
||
| 1577 | 'unknownerror-nocode' => [ 'code' => 'unknownerror', 'info' => 'Unknown error' ], |
||
| 1578 | |||
| 1579 | // Messages from Title::getUserPermissionsErrors() |
||
| 1580 | 'ns-specialprotected' => [ |
||
| 1581 | 'code' => 'unsupportednamespace', |
||
| 1582 | 'info' => "Pages in the Special namespace can't be edited" |
||
| 1583 | ], |
||
| 1584 | 'protectedinterface' => [ |
||
| 1585 | 'code' => 'protectednamespace-interface', |
||
| 1586 | 'info' => "You're not allowed to edit interface messages" |
||
| 1587 | ], |
||
| 1588 | 'namespaceprotected' => [ |
||
| 1589 | 'code' => 'protectednamespace', |
||
| 1590 | 'info' => "You're not allowed to edit pages in the \"\$1\" namespace" |
||
| 1591 | ], |
||
| 1592 | 'customcssprotected' => [ |
||
| 1593 | 'code' => 'customcssprotected', |
||
| 1594 | 'info' => "You're not allowed to edit custom CSS pages" |
||
| 1595 | ], |
||
| 1596 | 'customjsprotected' => [ |
||
| 1597 | 'code' => 'customjsprotected', |
||
| 1598 | 'info' => "You're not allowed to edit custom JavaScript pages" |
||
| 1599 | ], |
||
| 1600 | 'cascadeprotected' => [ |
||
| 1601 | 'code' => 'cascadeprotected', |
||
| 1602 | 'info' => "The page you're trying to edit is protected because it's included in a cascade-protected page" |
||
| 1603 | ], |
||
| 1604 | 'protectedpagetext' => [ |
||
| 1605 | 'code' => 'protectedpage', |
||
| 1606 | 'info' => "The \"\$1\" right is required to edit this page" |
||
| 1607 | ], |
||
| 1608 | 'protect-cantedit' => [ |
||
| 1609 | 'code' => 'cantedit', |
||
| 1610 | 'info' => "You can't protect this page because you can't edit it" |
||
| 1611 | ], |
||
| 1612 | 'deleteprotected' => [ |
||
| 1613 | 'code' => 'cantedit', |
||
| 1614 | 'info' => "You can't delete this page because it has been protected" |
||
| 1615 | ], |
||
| 1616 | 'badaccess-group0' => [ |
||
| 1617 | 'code' => 'permissiondenied', |
||
| 1618 | 'info' => 'Permission denied' |
||
| 1619 | ], // Generic permission denied message |
||
| 1620 | 'badaccess-groups' => [ |
||
| 1621 | 'code' => 'permissiondenied', |
||
| 1622 | 'info' => 'Permission denied' |
||
| 1623 | ], |
||
| 1624 | 'titleprotected' => [ |
||
| 1625 | 'code' => 'protectedtitle', |
||
| 1626 | 'info' => 'This title has been protected from creation' |
||
| 1627 | ], |
||
| 1628 | 'nocreate-loggedin' => [ |
||
| 1629 | 'code' => 'cantcreate', |
||
| 1630 | 'info' => "You don't have permission to create new pages" |
||
| 1631 | ], |
||
| 1632 | 'nocreatetext' => [ |
||
| 1633 | 'code' => 'cantcreate-anon', |
||
| 1634 | 'info' => "Anonymous users can't create new pages" |
||
| 1635 | ], |
||
| 1636 | 'movenologintext' => [ |
||
| 1637 | 'code' => 'cantmove-anon', |
||
| 1638 | 'info' => "Anonymous users can't move pages" |
||
| 1639 | ], |
||
| 1640 | 'movenotallowed' => [ |
||
| 1641 | 'code' => 'cantmove', |
||
| 1642 | 'info' => "You don't have permission to move pages" |
||
| 1643 | ], |
||
| 1644 | 'confirmedittext' => [ |
||
| 1645 | 'code' => 'confirmemail', |
||
| 1646 | 'info' => 'You must confirm your email address before you can edit' |
||
| 1647 | ], |
||
| 1648 | 'blockedtext' => [ |
||
| 1649 | 'code' => 'blocked', |
||
| 1650 | 'info' => 'You have been blocked from editing' |
||
| 1651 | ], |
||
| 1652 | 'autoblockedtext' => [ |
||
| 1653 | 'code' => 'autoblocked', |
||
| 1654 | 'info' => 'Your IP address has been blocked automatically, because it was used by a blocked user' |
||
| 1655 | ], |
||
| 1656 | |||
| 1657 | // Miscellaneous interface messages |
||
| 1658 | 'actionthrottledtext' => [ |
||
| 1659 | 'code' => 'ratelimited', |
||
| 1660 | 'info' => "You've exceeded your rate limit. Please wait some time and try again" |
||
| 1661 | ], |
||
| 1662 | 'alreadyrolled' => [ |
||
| 1663 | 'code' => 'alreadyrolled', |
||
| 1664 | 'info' => 'The page you tried to rollback was already rolled back' |
||
| 1665 | ], |
||
| 1666 | 'cantrollback' => [ |
||
| 1667 | 'code' => 'onlyauthor', |
||
| 1668 | 'info' => 'The page you tried to rollback only has one author' |
||
| 1669 | ], |
||
| 1670 | 'readonlytext' => [ |
||
| 1671 | 'code' => 'readonly', |
||
| 1672 | 'info' => 'The wiki is currently in read-only mode' |
||
| 1673 | ], |
||
| 1674 | 'sessionfailure' => [ |
||
| 1675 | 'code' => 'badtoken', |
||
| 1676 | 'info' => 'Invalid token' ], |
||
| 1677 | 'cannotdelete' => [ |
||
| 1678 | 'code' => 'cantdelete', |
||
| 1679 | 'info' => "Couldn't delete \"\$1\". Maybe it was deleted already by someone else" |
||
| 1680 | ], |
||
| 1681 | 'notanarticle' => [ |
||
| 1682 | 'code' => 'missingtitle', |
||
| 1683 | 'info' => "The page you requested doesn't exist" |
||
| 1684 | ], |
||
| 1685 | 'selfmove' => [ 'code' => 'selfmove', 'info' => "Can't move a page to itself" |
||
| 1686 | ], |
||
| 1687 | 'immobile_namespace' => [ |
||
| 1688 | 'code' => 'immobilenamespace', |
||
| 1689 | 'info' => 'You tried to move pages from or to a namespace that is protected from moving' |
||
| 1690 | ], |
||
| 1691 | 'articleexists' => [ |
||
| 1692 | 'code' => 'articleexists', |
||
| 1693 | 'info' => 'The destination article already exists and is not a redirect to the source article' |
||
| 1694 | ], |
||
| 1695 | 'protectedpage' => [ |
||
| 1696 | 'code' => 'protectedpage', |
||
| 1697 | 'info' => "You don't have permission to perform this move" |
||
| 1698 | ], |
||
| 1699 | 'hookaborted' => [ |
||
| 1700 | 'code' => 'hookaborted', |
||
| 1701 | 'info' => 'The modification you tried to make was aborted by an extension hook' |
||
| 1702 | ], |
||
| 1703 | 'cantmove-titleprotected' => [ |
||
| 1704 | 'code' => 'protectedtitle', |
||
| 1705 | 'info' => 'The destination article has been protected from creation' |
||
| 1706 | ], |
||
| 1707 | 'imagenocrossnamespace' => [ |
||
| 1708 | 'code' => 'nonfilenamespace', |
||
| 1709 | 'info' => "Can't move a file to a non-file namespace" |
||
| 1710 | ], |
||
| 1711 | 'imagetypemismatch' => [ |
||
| 1712 | 'code' => 'filetypemismatch', |
||
| 1713 | 'info' => "The new file extension doesn't match its type" |
||
| 1714 | ], |
||
| 1715 | // 'badarticleerror' => shouldn't happen |
||
| 1716 | // 'badtitletext' => shouldn't happen |
||
| 1717 | 'ip_range_invalid' => [ 'code' => 'invalidrange', 'info' => 'Invalid IP range' ], |
||
| 1718 | 'range_block_disabled' => [ |
||
| 1719 | 'code' => 'rangedisabled', |
||
| 1720 | 'info' => 'Blocking IP ranges has been disabled' |
||
| 1721 | ], |
||
| 1722 | 'nosuchusershort' => [ |
||
| 1723 | 'code' => 'nosuchuser', |
||
| 1724 | 'info' => "The user you specified doesn't exist" |
||
| 1725 | ], |
||
| 1726 | 'badipaddress' => [ 'code' => 'invalidip', 'info' => 'Invalid IP address specified' ], |
||
| 1727 | 'ipb_expiry_invalid' => [ 'code' => 'invalidexpiry', 'info' => 'Invalid expiry time' ], |
||
| 1728 | 'ipb_already_blocked' => [ |
||
| 1729 | 'code' => 'alreadyblocked', |
||
| 1730 | 'info' => 'The user you tried to block was already blocked' |
||
| 1731 | ], |
||
| 1732 | 'ipb_blocked_as_range' => [ |
||
| 1733 | 'code' => 'blockedasrange', |
||
| 1734 | 'info' => "IP address \"\$1\" was blocked as part of range \"\$2\". You can't unblock the IP individually, but you can unblock the range as a whole." |
||
| 1735 | ], |
||
| 1736 | 'ipb_cant_unblock' => [ |
||
| 1737 | 'code' => 'cantunblock', |
||
| 1738 | 'info' => 'The block you specified was not found. It may have been unblocked already' |
||
| 1739 | ], |
||
| 1740 | 'mailnologin' => [ |
||
| 1741 | 'code' => 'cantsend', |
||
| 1742 | 'info' => 'You are not logged in, you do not have a confirmed email address, or you are not allowed to send email to other users, so you cannot send email' |
||
| 1743 | ], |
||
| 1744 | 'ipbblocked' => [ |
||
| 1745 | 'code' => 'ipbblocked', |
||
| 1746 | 'info' => 'You cannot block or unblock users while you are yourself blocked' |
||
| 1747 | ], |
||
| 1748 | 'ipbnounblockself' => [ |
||
| 1749 | 'code' => 'ipbnounblockself', |
||
| 1750 | 'info' => 'You are not allowed to unblock yourself' |
||
| 1751 | ], |
||
| 1752 | 'usermaildisabled' => [ |
||
| 1753 | 'code' => 'usermaildisabled', |
||
| 1754 | 'info' => 'User email has been disabled' |
||
| 1755 | ], |
||
| 1756 | 'blockedemailuser' => [ |
||
| 1757 | 'code' => 'blockedfrommail', |
||
| 1758 | 'info' => 'You have been blocked from sending email' |
||
| 1759 | ], |
||
| 1760 | 'notarget' => [ |
||
| 1761 | 'code' => 'notarget', |
||
| 1762 | 'info' => 'You have not specified a valid target for this action' |
||
| 1763 | ], |
||
| 1764 | 'noemail' => [ |
||
| 1765 | 'code' => 'noemail', |
||
| 1766 | 'info' => 'The user has not specified a valid email address, or has chosen not to receive email from other users' |
||
| 1767 | ], |
||
| 1768 | 'rcpatroldisabled' => [ |
||
| 1769 | 'code' => 'patroldisabled', |
||
| 1770 | 'info' => 'Patrolling is disabled on this wiki' |
||
| 1771 | ], |
||
| 1772 | 'markedaspatrollederror-noautopatrol' => [ |
||
| 1773 | 'code' => 'noautopatrol', |
||
| 1774 | 'info' => "You don't have permission to patrol your own changes" |
||
| 1775 | ], |
||
| 1776 | 'delete-toobig' => [ |
||
| 1777 | 'code' => 'bigdelete', |
||
| 1778 | 'info' => "You can't delete this page because it has more than \$1 revisions" |
||
| 1779 | ], |
||
| 1780 | 'movenotallowedfile' => [ |
||
| 1781 | 'code' => 'cantmovefile', |
||
| 1782 | 'info' => "You don't have permission to move files" |
||
| 1783 | ], |
||
| 1784 | 'userrights-no-interwiki' => [ |
||
| 1785 | 'code' => 'nointerwikiuserrights', |
||
| 1786 | 'info' => "You don't have permission to change user rights on other wikis" |
||
| 1787 | ], |
||
| 1788 | 'userrights-nodatabase' => [ |
||
| 1789 | 'code' => 'nosuchdatabase', |
||
| 1790 | 'info' => "Database \"\$1\" does not exist or is not local" |
||
| 1791 | ], |
||
| 1792 | 'nouserspecified' => [ 'code' => 'invaliduser', 'info' => "Invalid username \"\$1\"" ], |
||
| 1793 | 'noname' => [ 'code' => 'invaliduser', 'info' => "Invalid username \"\$1\"" ], |
||
| 1794 | 'summaryrequired' => [ 'code' => 'summaryrequired', 'info' => 'Summary required' ], |
||
| 1795 | 'import-rootpage-invalid' => [ |
||
| 1796 | 'code' => 'import-rootpage-invalid', |
||
| 1797 | 'info' => 'Root page is an invalid title' |
||
| 1798 | ], |
||
| 1799 | 'import-rootpage-nosubpage' => [ |
||
| 1800 | 'code' => 'import-rootpage-nosubpage', |
||
| 1801 | 'info' => 'Namespace "$1" of the root page does not allow subpages' |
||
| 1802 | ], |
||
| 1803 | |||
| 1804 | // API-specific messages |
||
| 1805 | 'readrequired' => [ |
||
| 1806 | 'code' => 'readapidenied', |
||
| 1807 | 'info' => 'You need read permission to use this module' |
||
| 1808 | ], |
||
| 1809 | 'writedisabled' => [ |
||
| 1810 | 'code' => 'noapiwrite', |
||
| 1811 | 'info' => "Editing of this wiki through the API is disabled. Make sure the \$wgEnableWriteAPI=true; statement is included in the wiki's LocalSettings.php file" |
||
| 1812 | ], |
||
| 1813 | 'writerequired' => [ |
||
| 1814 | 'code' => 'writeapidenied', |
||
| 1815 | 'info' => "You're not allowed to edit this wiki through the API" |
||
| 1816 | ], |
||
| 1817 | 'missingparam' => [ 'code' => 'no$1', 'info' => "The \$1 parameter must be set" ], |
||
| 1818 | 'invalidtitle' => [ 'code' => 'invalidtitle', 'info' => "Bad title \"\$1\"" ], |
||
| 1819 | 'nosuchpageid' => [ 'code' => 'nosuchpageid', 'info' => "There is no page with ID \$1" ], |
||
| 1820 | 'nosuchrevid' => [ 'code' => 'nosuchrevid', 'info' => "There is no revision with ID \$1" ], |
||
| 1821 | 'nosuchuser' => [ 'code' => 'nosuchuser', 'info' => "User \"\$1\" doesn't exist" ], |
||
| 1822 | 'invaliduser' => [ 'code' => 'invaliduser', 'info' => "Invalid username \"\$1\"" ], |
||
| 1823 | 'invalidexpiry' => [ 'code' => 'invalidexpiry', 'info' => "Invalid expiry time \"\$1\"" ], |
||
| 1824 | 'pastexpiry' => [ 'code' => 'pastexpiry', 'info' => "Expiry time \"\$1\" is in the past" ], |
||
| 1825 | 'create-titleexists' => [ |
||
| 1826 | 'code' => 'create-titleexists', |
||
| 1827 | 'info' => "Existing titles can't be protected with 'create'" |
||
| 1828 | ], |
||
| 1829 | 'missingtitle-createonly' => [ |
||
| 1830 | 'code' => 'missingtitle-createonly', |
||
| 1831 | 'info' => "Missing titles can only be protected with 'create'" |
||
| 1832 | ], |
||
| 1833 | 'cantblock' => [ 'code' => 'cantblock', |
||
| 1834 | 'info' => "You don't have permission to block users" |
||
| 1835 | ], |
||
| 1836 | 'canthide' => [ |
||
| 1837 | 'code' => 'canthide', |
||
| 1838 | 'info' => "You don't have permission to hide user names from the block log" |
||
| 1839 | ], |
||
| 1840 | 'cantblock-email' => [ |
||
| 1841 | 'code' => 'cantblock-email', |
||
| 1842 | 'info' => "You don't have permission to block users from sending email through the wiki" |
||
| 1843 | ], |
||
| 1844 | 'unblock-notarget' => [ |
||
| 1845 | 'code' => 'notarget', |
||
| 1846 | 'info' => 'Either the id or the user parameter must be set' |
||
| 1847 | ], |
||
| 1848 | 'unblock-idanduser' => [ |
||
| 1849 | 'code' => 'idanduser', |
||
| 1850 | 'info' => "The id and user parameters can't be used together" |
||
| 1851 | ], |
||
| 1852 | 'cantunblock' => [ |
||
| 1853 | 'code' => 'permissiondenied', |
||
| 1854 | 'info' => "You don't have permission to unblock users" |
||
| 1855 | ], |
||
| 1856 | 'cannotundelete' => [ |
||
| 1857 | 'code' => 'cantundelete', |
||
| 1858 | 'info' => "Couldn't undelete: the requested revisions may not exist, or may have been undeleted already" |
||
| 1859 | ], |
||
| 1860 | 'permdenied-undelete' => [ |
||
| 1861 | 'code' => 'permissiondenied', |
||
| 1862 | 'info' => "You don't have permission to restore deleted revisions" |
||
| 1863 | ], |
||
| 1864 | 'createonly-exists' => [ |
||
| 1865 | 'code' => 'articleexists', |
||
| 1866 | 'info' => 'The article you tried to create has been created already' |
||
| 1867 | ], |
||
| 1868 | 'nocreate-missing' => [ |
||
| 1869 | 'code' => 'missingtitle', |
||
| 1870 | 'info' => "The article you tried to edit doesn't exist" |
||
| 1871 | ], |
||
| 1872 | 'cantchangecontentmodel' => [ |
||
| 1873 | 'code' => 'cantchangecontentmodel', |
||
| 1874 | 'info' => "You don't have permission to change the content model of a page" |
||
| 1875 | ], |
||
| 1876 | 'nosuchrcid' => [ |
||
| 1877 | 'code' => 'nosuchrcid', |
||
| 1878 | 'info' => "There is no change with rcid \"\$1\"" |
||
| 1879 | ], |
||
| 1880 | 'nosuchlogid' => [ |
||
| 1881 | 'code' => 'nosuchlogid', |
||
| 1882 | 'info' => "There is no log entry with ID \"\$1\"" |
||
| 1883 | ], |
||
| 1884 | 'protect-invalidaction' => [ |
||
| 1885 | 'code' => 'protect-invalidaction', |
||
| 1886 | 'info' => "Invalid protection type \"\$1\"" |
||
| 1887 | ], |
||
| 1888 | 'protect-invalidlevel' => [ |
||
| 1889 | 'code' => 'protect-invalidlevel', |
||
| 1890 | 'info' => "Invalid protection level \"\$1\"" |
||
| 1891 | ], |
||
| 1892 | 'toofewexpiries' => [ |
||
| 1893 | 'code' => 'toofewexpiries', |
||
| 1894 | 'info' => "\$1 expiry timestamps were provided where \$2 were needed" |
||
| 1895 | ], |
||
| 1896 | 'cantimport' => [ |
||
| 1897 | 'code' => 'cantimport', |
||
| 1898 | 'info' => "You don't have permission to import pages" |
||
| 1899 | ], |
||
| 1900 | 'cantimport-upload' => [ |
||
| 1901 | 'code' => 'cantimport-upload', |
||
| 1902 | 'info' => "You don't have permission to import uploaded pages" |
||
| 1903 | ], |
||
| 1904 | 'importnofile' => [ 'code' => 'nofile', 'info' => "You didn't upload a file" ], |
||
| 1905 | 'importuploaderrorsize' => [ |
||
| 1906 | 'code' => 'filetoobig', |
||
| 1907 | 'info' => 'The file you uploaded is bigger than the maximum upload size' |
||
| 1908 | ], |
||
| 1909 | 'importuploaderrorpartial' => [ |
||
| 1910 | 'code' => 'partialupload', |
||
| 1911 | 'info' => 'The file was only partially uploaded' |
||
| 1912 | ], |
||
| 1913 | 'importuploaderrortemp' => [ |
||
| 1914 | 'code' => 'notempdir', |
||
| 1915 | 'info' => 'The temporary upload directory is missing' |
||
| 1916 | ], |
||
| 1917 | 'importcantopen' => [ |
||
| 1918 | 'code' => 'cantopenfile', |
||
| 1919 | 'info' => "Couldn't open the uploaded file" |
||
| 1920 | ], |
||
| 1921 | 'import-noarticle' => [ |
||
| 1922 | 'code' => 'badinterwiki', |
||
| 1923 | 'info' => 'Invalid interwiki title specified' |
||
| 1924 | ], |
||
| 1925 | 'importbadinterwiki' => [ |
||
| 1926 | 'code' => 'badinterwiki', |
||
| 1927 | 'info' => 'Invalid interwiki title specified' |
||
| 1928 | ], |
||
| 1929 | 'import-unknownerror' => [ |
||
| 1930 | 'code' => 'import-unknownerror', |
||
| 1931 | 'info' => "Unknown error on import: \"\$1\"" |
||
| 1932 | ], |
||
| 1933 | 'cantoverwrite-sharedfile' => [ |
||
| 1934 | 'code' => 'cantoverwrite-sharedfile', |
||
| 1935 | 'info' => 'The target file exists on a shared repository and you do not have permission to override it' |
||
| 1936 | ], |
||
| 1937 | 'sharedfile-exists' => [ |
||
| 1938 | 'code' => 'fileexists-sharedrepo-perm', |
||
| 1939 | 'info' => 'The target file exists on a shared repository. Use the ignorewarnings parameter to override it.' |
||
| 1940 | ], |
||
| 1941 | 'mustbeposted' => [ |
||
| 1942 | 'code' => 'mustbeposted', |
||
| 1943 | 'info' => "The \$1 module requires a POST request" |
||
| 1944 | ], |
||
| 1945 | 'show' => [ |
||
| 1946 | 'code' => 'show', |
||
| 1947 | 'info' => 'Incorrect parameter - mutually exclusive values may not be supplied' |
||
| 1948 | ], |
||
| 1949 | 'specialpage-cantexecute' => [ |
||
| 1950 | 'code' => 'specialpage-cantexecute', |
||
| 1951 | 'info' => "You don't have permission to view the results of this special page" |
||
| 1952 | ], |
||
| 1953 | 'invalidoldimage' => [ |
||
| 1954 | 'code' => 'invalidoldimage', |
||
| 1955 | 'info' => 'The oldimage parameter has invalid format' |
||
| 1956 | ], |
||
| 1957 | 'nodeleteablefile' => [ |
||
| 1958 | 'code' => 'nodeleteablefile', |
||
| 1959 | 'info' => 'No such old version of the file' |
||
| 1960 | ], |
||
| 1961 | 'fileexists-forbidden' => [ |
||
| 1962 | 'code' => 'fileexists-forbidden', |
||
| 1963 | 'info' => 'A file with name "$1" already exists, and cannot be overwritten.' |
||
| 1964 | ], |
||
| 1965 | 'fileexists-shared-forbidden' => [ |
||
| 1966 | 'code' => 'fileexists-shared-forbidden', |
||
| 1967 | 'info' => 'A file with name "$1" already exists in the shared file repository, and cannot be overwritten.' |
||
| 1968 | ], |
||
| 1969 | 'filerevert-badversion' => [ |
||
| 1970 | 'code' => 'filerevert-badversion', |
||
| 1971 | 'info' => 'There is no previous local version of this file with the provided timestamp.' |
||
| 1972 | ], |
||
| 1973 | |||
| 1974 | // ApiEditPage messages |
||
| 1975 | 'noimageredirect-anon' => [ |
||
| 1976 | 'code' => 'noimageredirect-anon', |
||
| 1977 | 'info' => "Anonymous users can't create image redirects" |
||
| 1978 | ], |
||
| 1979 | 'noimageredirect-logged' => [ |
||
| 1980 | 'code' => 'noimageredirect', |
||
| 1981 | 'info' => "You don't have permission to create image redirects" |
||
| 1982 | ], |
||
| 1983 | 'spamdetected' => [ |
||
| 1984 | 'code' => 'spamdetected', |
||
| 1985 | 'info' => "Your edit was refused because it contained a spam fragment: \"\$1\"" |
||
| 1986 | ], |
||
| 1987 | 'contenttoobig' => [ |
||
| 1988 | 'code' => 'contenttoobig', |
||
| 1989 | 'info' => "The content you supplied exceeds the article size limit of \$1 kilobytes" |
||
| 1990 | ], |
||
| 1991 | 'noedit-anon' => [ 'code' => 'noedit-anon', 'info' => "Anonymous users can't edit pages" ], |
||
| 1992 | 'noedit' => [ 'code' => 'noedit', 'info' => "You don't have permission to edit pages" ], |
||
| 1993 | 'wasdeleted' => [ |
||
| 1994 | 'code' => 'pagedeleted', |
||
| 1995 | 'info' => 'The page has been deleted since you fetched its timestamp' |
||
| 1996 | ], |
||
| 1997 | 'blankpage' => [ |
||
| 1998 | 'code' => 'emptypage', |
||
| 1999 | 'info' => 'Creating new, empty pages is not allowed' |
||
| 2000 | ], |
||
| 2001 | 'editconflict' => [ 'code' => 'editconflict', 'info' => 'Edit conflict detected' ], |
||
| 2002 | 'hashcheckfailed' => [ 'code' => 'badmd5', 'info' => 'The supplied MD5 hash was incorrect' ], |
||
| 2003 | 'missingtext' => [ |
||
| 2004 | 'code' => 'notext', |
||
| 2005 | 'info' => 'One of the text, appendtext, prependtext and undo parameters must be set' |
||
| 2006 | ], |
||
| 2007 | 'emptynewsection' => [ |
||
| 2008 | 'code' => 'emptynewsection', |
||
| 2009 | 'info' => 'Creating empty new sections is not possible.' |
||
| 2010 | ], |
||
| 2011 | 'revwrongpage' => [ |
||
| 2012 | 'code' => 'revwrongpage', |
||
| 2013 | 'info' => "r\$1 is not a revision of \"\$2\"" |
||
| 2014 | ], |
||
| 2015 | 'undo-failure' => [ |
||
| 2016 | 'code' => 'undofailure', |
||
| 2017 | 'info' => 'Undo failed due to conflicting intermediate edits' |
||
| 2018 | ], |
||
| 2019 | 'content-not-allowed-here' => [ |
||
| 2020 | 'code' => 'contentnotallowedhere', |
||
| 2021 | 'info' => 'Content model "$1" is not allowed at title "$2"' |
||
| 2022 | ], |
||
| 2023 | |||
| 2024 | // Messages from WikiPage::doEit(] |
||
| 2025 | 'edit-hook-aborted' => [ |
||
| 2026 | 'code' => 'edit-hook-aborted', |
||
| 2027 | 'info' => 'Your edit was aborted by an ArticleSave hook' |
||
| 2028 | ], |
||
| 2029 | 'edit-gone-missing' => [ |
||
| 2030 | 'code' => 'edit-gone-missing', |
||
| 2031 | 'info' => "The page you tried to edit doesn't seem to exist anymore" |
||
| 2032 | ], |
||
| 2033 | 'edit-conflict' => [ 'code' => 'editconflict', 'info' => 'Edit conflict detected' ], |
||
| 2034 | 'edit-already-exists' => [ |
||
| 2035 | 'code' => 'edit-already-exists', |
||
| 2036 | 'info' => 'It seems the page you tried to create already exist' |
||
| 2037 | ], |
||
| 2038 | |||
| 2039 | // uploadMsgs |
||
| 2040 | 'invalid-file-key' => [ 'code' => 'invalid-file-key', 'info' => 'Not a valid file key' ], |
||
| 2041 | 'nouploadmodule' => [ 'code' => 'nouploadmodule', 'info' => 'No upload module set' ], |
||
| 2042 | 'uploaddisabled' => [ |
||
| 2043 | 'code' => 'uploaddisabled', |
||
| 2044 | 'info' => 'Uploads are not enabled. Make sure $wgEnableUploads is set to true in LocalSettings.php and the PHP ini setting file_uploads is true' |
||
| 2045 | ], |
||
| 2046 | 'copyuploaddisabled' => [ |
||
| 2047 | 'code' => 'copyuploaddisabled', |
||
| 2048 | 'info' => 'Uploads by URL is not enabled. Make sure $wgAllowCopyUploads is set to true in LocalSettings.php.' |
||
| 2049 | ], |
||
| 2050 | 'copyuploadbaddomain' => [ |
||
| 2051 | 'code' => 'copyuploadbaddomain', |
||
| 2052 | 'info' => 'Uploads by URL are not allowed from this domain.' |
||
| 2053 | ], |
||
| 2054 | 'copyuploadbadurl' => [ |
||
| 2055 | 'code' => 'copyuploadbadurl', |
||
| 2056 | 'info' => 'Upload not allowed from this URL.' |
||
| 2057 | ], |
||
| 2058 | |||
| 2059 | 'filename-tooshort' => [ |
||
| 2060 | 'code' => 'filename-tooshort', |
||
| 2061 | 'info' => 'The filename is too short' |
||
| 2062 | ], |
||
| 2063 | 'filename-toolong' => [ 'code' => 'filename-toolong', 'info' => 'The filename is too long' ], |
||
| 2064 | 'illegal-filename' => [ |
||
| 2065 | 'code' => 'illegal-filename', |
||
| 2066 | 'info' => 'The filename is not allowed' |
||
| 2067 | ], |
||
| 2068 | 'filetype-missing' => [ |
||
| 2069 | 'code' => 'filetype-missing', |
||
| 2070 | 'info' => 'The file is missing an extension' |
||
| 2071 | ], |
||
| 2072 | |||
| 2073 | 'mustbeloggedin' => [ 'code' => 'mustbeloggedin', 'info' => 'You must be logged in to $1.' ] |
||
| 2074 | ]; |
||
| 2075 | // @codingStandardsIgnoreEnd |
||
| 2076 | |||
| 2077 | /** |
||
| 2078 | * Helper function for readonly errors |
||
| 2079 | * |
||
| 2080 | * @throws UsageException always |
||
| 2081 | */ |
||
| 2082 | public function dieReadOnly() { |
||
| 2087 | |||
| 2088 | /** |
||
| 2089 | * Output the error message related to a certain array |
||
| 2090 | * @param array|string $error Element of a getUserPermissionsErrors()-style array |
||
| 2091 | * @throws UsageException always |
||
| 2092 | */ |
||
| 2093 | public function dieUsageMsg( $error ) { |
||
| 2103 | |||
| 2104 | /** |
||
| 2105 | * Will only set a warning instead of failing if the global $wgDebugAPI |
||
| 2106 | * is set to true. Otherwise behaves exactly as dieUsageMsg(). |
||
| 2107 | * @param array|string $error Element of a getUserPermissionsErrors()-style array |
||
| 2108 | * @throws UsageException |
||
| 2109 | * @since 1.21 |
||
| 2110 | */ |
||
| 2111 | public function dieUsageMsgOrDebug( $error ) { |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * Die with the $prefix.'badcontinue' error. This call is common enough to |
||
| 2125 | * make it into the base method. |
||
| 2126 | * @param bool $condition Will only die if this value is true |
||
| 2127 | * @throws UsageException |
||
| 2128 | * @since 1.21 |
||
| 2129 | */ |
||
| 2130 | protected function dieContinueUsageIf( $condition ) { |
||
| 2137 | |||
| 2138 | /** |
||
| 2139 | * Return the error message related to a certain array |
||
| 2140 | * @param array $error Element of a getUserPermissionsErrors()-style array |
||
| 2141 | * @return array('code' => code, 'info' => info) |
||
| 2142 | */ |
||
| 2143 | public function parseMsg( $error ) { |
||
| 2172 | |||
| 2173 | /** |
||
| 2174 | * Internal code errors should be reported with this method |
||
| 2175 | * @param string $method Method or function name |
||
| 2176 | * @param string $message Error message |
||
| 2177 | * @throws MWException always |
||
| 2178 | */ |
||
| 2179 | protected static function dieDebug( $method, $message ) { |
||
| 2182 | |||
| 2183 | /** |
||
| 2184 | * Write logging information for API features to a debug log, for usage |
||
| 2185 | * analysis. |
||
| 2186 | * @param string $feature Feature being used. |
||
| 2187 | */ |
||
| 2188 | protected function logFeatureUsage( $feature ) { |
||
| 2197 | |||
| 2198 | /**@}*/ |
||
| 2199 | |||
| 2200 | /************************************************************************//** |
||
| 2201 | * @name Help message generation |
||
| 2202 | * @{ |
||
| 2203 | */ |
||
| 2204 | |||
| 2205 | /** |
||
| 2206 | * Return the description message. |
||
| 2207 | * |
||
| 2208 | * @return string|array|Message |
||
| 2209 | */ |
||
| 2210 | protected function getDescriptionMessage() { |
||
| 2213 | |||
| 2214 | /** |
||
| 2215 | * Get final module description, after hooks have had a chance to tweak it as |
||
| 2216 | * needed. |
||
| 2217 | * |
||
| 2218 | * @since 1.25, returns Message[] rather than string[] |
||
| 2219 | * @return Message[] |
||
| 2220 | */ |
||
| 2221 | public function getFinalDescription() { |
||
| 2245 | |||
| 2246 | /** |
||
| 2247 | * Get final list of parameters, after hooks have had a chance to |
||
| 2248 | * tweak it as needed. |
||
| 2249 | * |
||
| 2250 | * @param int $flags Zero or more flags like GET_VALUES_FOR_HELP |
||
| 2251 | * @return array|bool False on no parameters |
||
| 2252 | * @since 1.21 $flags param added |
||
| 2253 | */ |
||
| 2254 | public function getFinalParams( $flags = 0 ) { |
||
| 2275 | |||
| 2276 | /** |
||
| 2277 | * Get final parameter descriptions, after hooks have had a chance to tweak it as |
||
| 2278 | * needed. |
||
| 2279 | * |
||
| 2280 | * @since 1.25, returns array of Message[] rather than array of string[] |
||
| 2281 | * @return array Keys are parameter names, values are arrays of Message objects |
||
| 2282 | */ |
||
| 2283 | public function getFinalParamDescription() { |
||
| 2284 | $prefix = $this->getModulePrefix(); |
||
| 2285 | $name = $this->getModuleName(); |
||
| 2286 | $path = $this->getModulePath(); |
||
| 2287 | |||
| 2288 | $desc = $this->getParamDescription(); |
||
| 2289 | Hooks::run( 'APIGetParamDescription', [ &$this, &$desc ] ); |
||
| 2290 | |||
| 2291 | if ( !$desc ) { |
||
| 2292 | $desc = []; |
||
| 2293 | } |
||
| 2294 | $desc = self::escapeWikiText( $desc ); |
||
| 2295 | |||
| 2296 | $params = $this->getFinalParams( ApiBase::GET_VALUES_FOR_HELP ); |
||
| 2297 | $msgs = []; |
||
| 2298 | foreach ( $params as $param => $settings ) { |
||
| 2299 | if ( !is_array( $settings ) ) { |
||
| 2300 | $settings = []; |
||
| 2301 | } |
||
| 2302 | |||
| 2303 | $d = isset( $desc[$param] ) ? $desc[$param] : ''; |
||
| 2304 | if ( is_array( $d ) ) { |
||
| 2305 | // Special handling for prop parameters |
||
| 2306 | $d = array_map( function ( $line ) { |
||
| 2307 | if ( preg_match( '/^\s+(\S+)\s+-\s+(.+)$/', $line, $m ) ) { |
||
| 2308 | $line = "\n;{$m[1]}:{$m[2]}"; |
||
| 2309 | } |
||
| 2310 | return $line; |
||
| 2311 | }, $d ); |
||
| 2312 | $d = implode( ' ', $d ); |
||
| 2313 | } |
||
| 2314 | |||
| 2315 | if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) { |
||
| 2316 | $msg = $settings[ApiBase::PARAM_HELP_MSG]; |
||
| 2317 | } else { |
||
| 2318 | $msg = $this->msg( "apihelp-{$path}-param-{$param}" ); |
||
| 2319 | if ( !$msg->exists() ) { |
||
| 2320 | $msg = $this->msg( 'api-help-fallback-parameter', $d ); |
||
| 2321 | } |
||
| 2322 | } |
||
| 2323 | $msg = ApiBase::makeMessage( $msg, $this->getContext(), |
||
| 2324 | [ $prefix, $param, $name, $path ] ); |
||
| 2325 | if ( !$msg ) { |
||
| 2326 | self::dieDebug( __METHOD__, |
||
| 2327 | 'Value in ApiBase::PARAM_HELP_MSG is not valid' ); |
||
| 2328 | } |
||
| 2329 | $msgs[$param] = [ $msg ]; |
||
| 2330 | |||
| 2331 | if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { |
||
| 2332 | if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { |
||
| 2333 | self::dieDebug( __METHOD__, |
||
| 2334 | 'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' ); |
||
| 2335 | } |
||
| 2336 | if ( !is_array( $settings[ApiBase::PARAM_TYPE] ) ) { |
||
| 2337 | self::dieDebug( __METHOD__, |
||
| 2338 | 'ApiBase::PARAM_HELP_MSG_PER_VALUE may only be used when ' . |
||
| 2339 | 'ApiBase::PARAM_TYPE is an array' ); |
||
| 2340 | } |
||
| 2341 | |||
| 2342 | $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE]; |
||
| 2343 | foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) { |
||
| 2344 | if ( isset( $valueMsgs[$value] ) ) { |
||
| 2345 | $msg = $valueMsgs[$value]; |
||
| 2346 | } else { |
||
| 2347 | $msg = "apihelp-{$path}-paramvalue-{$param}-{$value}"; |
||
| 2348 | } |
||
| 2349 | $m = ApiBase::makeMessage( $msg, $this->getContext(), |
||
| 2350 | [ $prefix, $param, $name, $path, $value ] ); |
||
| 2351 | if ( $m ) { |
||
| 2352 | $m = new ApiHelpParamValueMessage( |
||
| 2353 | $value, |
||
| 2354 | [ $m->getKey(), 'api-help-param-no-description' ], |
||
| 2355 | $m->getParams() |
||
| 2356 | ); |
||
| 2357 | $msgs[$param][] = $m->setContext( $this->getContext() ); |
||
| 2358 | } else { |
||
| 2359 | self::dieDebug( __METHOD__, |
||
| 2360 | "Value in ApiBase::PARAM_HELP_MSG_PER_VALUE for $value is not valid" ); |
||
| 2361 | } |
||
| 2362 | } |
||
| 2363 | } |
||
| 2364 | |||
| 2365 | if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { |
||
| 2366 | if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { |
||
| 2367 | self::dieDebug( __METHOD__, |
||
| 2368 | 'Value for ApiBase::PARAM_HELP_MSG_APPEND is not an array' ); |
||
| 2369 | } |
||
| 2370 | foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $m ) { |
||
| 2371 | $m = ApiBase::makeMessage( $m, $this->getContext(), |
||
| 2372 | [ $prefix, $param, $name, $path ] ); |
||
| 2373 | if ( $m ) { |
||
| 2374 | $msgs[$param][] = $m; |
||
| 2375 | } else { |
||
| 2376 | self::dieDebug( __METHOD__, |
||
| 2377 | 'Value in ApiBase::PARAM_HELP_MSG_APPEND is not valid' ); |
||
| 2378 | } |
||
| 2379 | } |
||
| 2380 | } |
||
| 2381 | } |
||
| 2382 | |||
| 2383 | Hooks::run( 'APIGetParamDescriptionMessages', [ $this, &$msgs ] ); |
||
| 2384 | |||
| 2385 | return $msgs; |
||
| 2386 | } |
||
| 2387 | |||
| 2388 | /** |
||
| 2389 | * Generates the list of flags for the help screen and for action=paraminfo |
||
| 2390 | * |
||
| 2391 | * Corresponding messages: api-help-flag-deprecated, |
||
| 2392 | * api-help-flag-internal, api-help-flag-readrights, |
||
| 2393 | * api-help-flag-writerights, api-help-flag-mustbeposted |
||
| 2394 | * |
||
| 2395 | * @return string[] |
||
| 2396 | */ |
||
| 2397 | protected function getHelpFlags() { |
||
| 2418 | |||
| 2419 | /** |
||
| 2420 | * Returns information about the source of this module, if known |
||
| 2421 | * |
||
| 2422 | * Returned array is an array with the following keys: |
||
| 2423 | * - path: Install path |
||
| 2424 | * - name: Extension name, or "MediaWiki" for core |
||
| 2425 | * - namemsg: (optional) i18n message key for a display name |
||
| 2426 | * - license-name: (optional) Name of license |
||
| 2427 | * |
||
| 2428 | * @return array|null |
||
| 2429 | */ |
||
| 2430 | protected function getModuleSourceInfo() { |
||
| 2505 | |||
| 2506 | /** |
||
| 2507 | * Called from ApiHelp before the pieces are joined together and returned. |
||
| 2508 | * |
||
| 2509 | * This exists mainly for ApiMain to add the Permissions and Credits |
||
| 2510 | * sections. Other modules probably don't need it. |
||
| 2511 | * |
||
| 2512 | * @param string[] &$help Array of help data |
||
| 2513 | * @param array $options Options passed to ApiHelp::getHelp |
||
| 2514 | * @param array &$tocData If a TOC is being generated, this array has keys |
||
| 2515 | * as anchors in the page and values as for Linker::generateTOC(). |
||
| 2516 | */ |
||
| 2517 | public function modifyHelp( array &$help, array $options, array &$tocData ) { |
||
| 2519 | |||
| 2520 | /**@}*/ |
||
| 2521 | |||
| 2522 | /************************************************************************//** |
||
| 2523 | * @name Deprecated |
||
| 2524 | * @{ |
||
| 2525 | */ |
||
| 2526 | |||
| 2527 | /** |
||
| 2528 | * Returns the description string for this module |
||
| 2529 | * |
||
| 2530 | * Ignored if an i18n message exists for |
||
| 2531 | * "apihelp-{$this->getModulePath()}-description". |
||
| 2532 | * |
||
| 2533 | * @deprecated since 1.25 |
||
| 2534 | * @return Message|string|array |
||
| 2535 | */ |
||
| 2536 | protected function getDescription() { |
||
| 2539 | |||
| 2540 | /** |
||
| 2541 | * Returns an array of parameter descriptions. |
||
| 2542 | * |
||
| 2543 | * For each parameter, ignored if an i18n message exists for the parameter. |
||
| 2544 | * By default that message is |
||
| 2545 | * "apihelp-{$this->getModulePath()}-param-{$param}", but it may be |
||
| 2546 | * overridden using ApiBase::PARAM_HELP_MSG in the data returned by |
||
| 2547 | * self::getFinalParams(). |
||
| 2548 | * |
||
| 2549 | * @deprecated since 1.25 |
||
| 2550 | * @return array|bool False on no parameter descriptions |
||
| 2551 | */ |
||
| 2552 | protected function getParamDescription() { |
||
| 2555 | |||
| 2556 | /** |
||
| 2557 | * Returns usage examples for this module. |
||
| 2558 | * |
||
| 2559 | * Return value as an array is either: |
||
| 2560 | * - numeric keys with partial URLs ("api.php?" plus a query string) as |
||
| 2561 | * values |
||
| 2562 | * - sequential numeric keys with even-numbered keys being display-text |
||
| 2563 | * and odd-numbered keys being partial urls |
||
| 2564 | * - partial URLs as keys with display-text (string or array-to-be-joined) |
||
| 2565 | * as values |
||
| 2566 | * Return value as a string is the same as an array with a numeric key and |
||
| 2567 | * that value, and boolean false means "no examples". |
||
| 2568 | * |
||
| 2569 | * @deprecated since 1.25, use getExamplesMessages() instead |
||
| 2570 | * @return bool|string|array |
||
| 2571 | */ |
||
| 2572 | protected function getExamples() { |
||
| 2575 | |||
| 2576 | /** |
||
| 2577 | * Generates help message for this module, or false if there is no description |
||
| 2578 | * @deprecated since 1.25 |
||
| 2579 | * @return string|bool |
||
| 2580 | */ |
||
| 2581 | public function makeHelpMsg() { |
||
| 2645 | |||
| 2646 | /** |
||
| 2647 | * @deprecated since 1.25 |
||
| 2648 | * @param string $item |
||
| 2649 | * @return string |
||
| 2650 | */ |
||
| 2651 | private function indentExampleText( $item ) { |
||
| 2654 | |||
| 2655 | /** |
||
| 2656 | * @deprecated since 1.25 |
||
| 2657 | * @param string $prefix Text to split output items |
||
| 2658 | * @param string $title What is being output |
||
| 2659 | * @param string|array $input |
||
| 2660 | * @return string |
||
| 2661 | */ |
||
| 2662 | protected function makeHelpArrayToString( $prefix, $title, $input ) { |
||
| 2684 | |||
| 2685 | /** |
||
| 2686 | * Generates the parameter descriptions for this module, to be displayed in the |
||
| 2687 | * module's help. |
||
| 2688 | * @deprecated since 1.25 |
||
| 2689 | * @return string|bool |
||
| 2690 | */ |
||
| 2691 | public function makeHelpMsgParameters() { |
||
| 2844 | |||
| 2845 | /** |
||
| 2846 | * @deprecated since 1.25, always returns empty string |
||
| 2847 | * @param IDatabase|bool $db |
||
| 2848 | * @return string |
||
| 2849 | */ |
||
| 2850 | public function getModuleProfileName( $db = false ) { |
||
| 2854 | |||
| 2855 | /** |
||
| 2856 | * @deprecated since 1.25 |
||
| 2857 | */ |
||
| 2858 | public function profileIn() { |
||
| 2862 | |||
| 2863 | /** |
||
| 2864 | * @deprecated since 1.25 |
||
| 2865 | */ |
||
| 2866 | public function profileOut() { |
||
| 2870 | |||
| 2871 | /** |
||
| 2872 | * @deprecated since 1.25 |
||
| 2873 | */ |
||
| 2874 | public function safeProfileOut() { |
||
| 2877 | |||
| 2878 | /** |
||
| 2879 | * @deprecated since 1.25, always returns 0 |
||
| 2880 | * @return float |
||
| 2881 | */ |
||
| 2882 | public function getProfileTime() { |
||
| 2886 | |||
| 2887 | /** |
||
| 2888 | * @deprecated since 1.25 |
||
| 2889 | */ |
||
| 2890 | public function profileDBIn() { |
||
| 2893 | |||
| 2894 | /** |
||
| 2895 | * @deprecated since 1.25 |
||
| 2896 | */ |
||
| 2897 | public function profileDBOut() { |
||
| 2900 | |||
| 2901 | /** |
||
| 2902 | * @deprecated since 1.25, always returns 0 |
||
| 2903 | * @return float |
||
| 2904 | */ |
||
| 2905 | public function getProfileDBTime() { |
||
| 2909 | |||
| 2910 | /** |
||
| 2911 | * Get the result data array (read-only) |
||
| 2912 | * @deprecated since 1.25, use $this->getResult() methods instead |
||
| 2913 | * @return array |
||
| 2914 | */ |
||
| 2915 | public function getResultData() { |
||
| 2919 | |||
| 2920 | /** |
||
| 2921 | * Call wfTransactionalTimeLimit() if this request was POSTed |
||
| 2922 | * @since 1.26 |
||
| 2923 | */ |
||
| 2924 | protected function useTransactionalTimeLimit() { |
||
| 2929 | |||
| 2930 | /**@}*/ |
||
| 2931 | } |
||
| 2932 | |||
| 2937 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.