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 = '' ) { |
||
| 210 | $this->mMainModule = $mainModule; |
||
| 211 | $this->mModuleName = $moduleName; |
||
| 212 | $this->mModulePrefix = $modulePrefix; |
||
| 213 | |||
| 214 | if ( !$this->isMain() ) { |
||
| 215 | $this->setContext( $mainModule->getContext() ); |
||
| 216 | } |
||
| 217 | } |
||
| 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() { |
||
| 248 | return null; |
||
| 249 | } |
||
| 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() { |
||
| 261 | return null; |
||
| 262 | } |
||
| 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() { |
||
| 323 | return []; |
||
| 324 | } |
||
| 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 */ ) { |
||
| 339 | // int $flags is not declared because it causes "Strict standards" |
||
| 340 | // warning. Most derived classes do not implement it. |
||
| 341 | return []; |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Indicates if this module needs maxlag to be checked |
||
| 346 | * @return bool |
||
| 347 | */ |
||
| 348 | public function shouldCheckMaxlag() { |
||
| 349 | return true; |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Indicates whether this module requires read rights |
||
| 354 | * @return bool |
||
| 355 | */ |
||
| 356 | public function isReadMode() { |
||
| 357 | return true; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Indicates whether this module requires write mode |
||
| 362 | * @return bool |
||
| 363 | */ |
||
| 364 | public function isWriteMode() { |
||
| 365 | return false; |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Indicates whether this module must be called with a POST request |
||
| 370 | * @return bool |
||
| 371 | */ |
||
| 372 | public function mustBePosted() { |
||
| 373 | return $this->needsToken() !== false; |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Indicates whether this module is deprecated |
||
| 378 | * @since 1.25 |
||
| 379 | * @return bool |
||
| 380 | */ |
||
| 381 | public function isDeprecated() { |
||
| 382 | return false; |
||
| 383 | } |
||
| 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() { |
||
| 392 | return false; |
||
| 393 | } |
||
| 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() { |
||
| 414 | return false; |
||
| 415 | } |
||
| 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 ) { |
||
| 427 | return null; |
||
| 428 | } |
||
| 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|bool|null As described above, or null if no value is available. |
||
| 441 | */ |
||
| 442 | public function getConditionalRequestData( $condition ) { |
||
| 443 | return null; |
||
| 444 | } |
||
| 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() { |
||
| 458 | return $this->mModuleName; |
||
| 459 | } |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Get parameter prefix (usually two letters or an empty string). |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | public function getModulePrefix() { |
||
| 466 | return $this->mModulePrefix; |
||
| 467 | } |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Get the main module |
||
| 471 | * @return ApiMain |
||
| 472 | */ |
||
| 473 | public function getMain() { |
||
| 474 | return $this->mMainModule; |
||
| 475 | } |
||
| 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() { |
||
| 483 | return $this === $this->mMainModule; |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get the parent of this module |
||
| 488 | * @since 1.25 |
||
| 489 | * @return ApiBase|null |
||
| 490 | */ |
||
| 491 | public function getParent() { |
||
| 492 | return $this->isMain() ? null : $this->getMain(); |
||
| 493 | } |
||
| 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() { |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get the path to this module |
||
| 517 | * |
||
| 518 | * @since 1.25 |
||
| 519 | * @return string |
||
| 520 | */ |
||
| 521 | public function getModulePath() { |
||
| 522 | if ( $this->isMain() ) { |
||
| 523 | return 'main'; |
||
| 524 | } elseif ( $this->getParent()->isMain() ) { |
||
| 525 | return $this->getModuleName(); |
||
| 526 | } else { |
||
| 527 | return $this->getParent()->getModulePath() . '+' . $this->getModuleName(); |
||
| 528 | } |
||
| 529 | } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Get a module from its module path |
||
| 533 | * |
||
| 534 | * @since 1.25 |
||
| 535 | * @param string $path |
||
| 536 | * @return ApiBase|null |
||
| 537 | * @throws UsageException |
||
| 538 | */ |
||
| 539 | public function getModuleFromPath( $path ) { |
||
| 572 | |||
| 573 | /** |
||
| 574 | * Get the result object |
||
| 575 | * @return ApiResult |
||
| 576 | */ |
||
| 577 | public function getResult() { |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Get the error formatter |
||
| 589 | * @return ApiErrorFormatter |
||
| 590 | */ |
||
| 591 | public function getErrorFormatter() { |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Gets a default slave database connection object |
||
| 603 | * @return DatabaseBase |
||
| 604 | */ |
||
| 605 | protected function getDB() { |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Get the continuation manager |
||
| 615 | * @return ApiContinuationManager|null |
||
| 616 | */ |
||
| 617 | public function getContinuationManager() { |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Set the continuation manager |
||
| 629 | * @param ApiContinuationManager|null |
||
| 630 | */ |
||
| 631 | public function setContinuationManager( $manager ) { |
||
| 640 | |||
| 641 | /**@}*/ |
||
| 642 | |||
| 643 | /************************************************************************//** |
||
| 644 | * @name Parameter handling |
||
| 645 | * @{ |
||
| 646 | */ |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Indicate if the module supports dynamically-determined parameters that |
||
| 650 | * cannot be included in self::getAllowedParams(). |
||
| 651 | * @return string|array|Message|null Return null if the module does not |
||
| 652 | * support additional dynamic parameters, otherwise return a message |
||
| 653 | * describing them. |
||
| 654 | */ |
||
| 655 | public function dynamicParameterDocumentation() { |
||
| 658 | |||
| 659 | /** |
||
| 660 | * This method mangles parameter name based on the prefix supplied to the constructor. |
||
| 661 | * Override this method to change parameter name during runtime |
||
| 662 | * @param string $paramName Parameter name |
||
| 663 | * @return string Prefixed parameter name |
||
| 664 | */ |
||
| 665 | public function encodeParamName( $paramName ) { |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Using getAllowedParams(), this function makes an array of the values |
||
| 671 | * provided by the user, with key being the name of the variable, and |
||
| 672 | * value - validated value from user or default. limits will not be |
||
| 673 | * parsed if $parseLimit is set to false; use this when the max |
||
| 674 | * limit is not definitive yet, e.g. when getting revisions. |
||
| 675 | * @param bool $parseLimit True by default |
||
| 676 | * @return array |
||
| 677 | */ |
||
| 678 | public function extractRequestParams( $parseLimit = true ) { |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Get a value for the given parameter |
||
| 698 | * @param string $paramName Parameter name |
||
| 699 | * @param bool $parseLimit See extractRequestParams() |
||
| 700 | * @return mixed Parameter value |
||
| 701 | */ |
||
| 702 | protected function getParameter( $paramName, $parseLimit = true ) { |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Die if none or more than one of a certain set of parameters is set and not false. |
||
| 710 | * |
||
| 711 | * @param array $params User provided set of parameters, as from $this->extractRequestParams() |
||
| 712 | * @param string $required,... Names of parameters of which exactly one must be set |
||
| 713 | */ |
||
| 714 | public function requireOnlyOneParameter( $params, $required /*...*/ ) { |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Die if more than one of a certain set of parameters is set and not false. |
||
| 736 | * |
||
| 737 | * @param array $params User provided set of parameters, as from $this->extractRequestParams() |
||
| 738 | * @param string $required,... Names of parameters of which at most one must be set |
||
| 739 | */ |
||
| 740 | View Code Duplication | public function requireMaxOneParameter( $params, $required /*...*/ ) { |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Die if none of a certain set of parameters is set and not false. |
||
| 758 | * |
||
| 759 | * @since 1.23 |
||
| 760 | * @param array $params User provided set of parameters, as from $this->extractRequestParams() |
||
| 761 | * @param string $required,... Names of parameters of which at least one must be set |
||
| 762 | */ |
||
| 763 | View Code Duplication | public function requireAtLeastOneParameter( $params, $required /*...*/ ) { |
|
| 778 | |||
| 779 | /** |
||
| 780 | * Callback function used in requireOnlyOneParameter to check whether required parameters are set |
||
| 781 | * |
||
| 782 | * @param object $x Parameter to check is not null/false |
||
| 783 | * @return bool |
||
| 784 | */ |
||
| 785 | private function parameterNotEmpty( $x ) { |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Get a WikiPage object from a title or pageid param, if possible. |
||
| 791 | * Can die, if no param is set or if the title or page id is not valid. |
||
| 792 | * |
||
| 793 | * @param array $params |
||
| 794 | * @param bool|string $load Whether load the object's state from the database: |
||
| 795 | * - false: don't load (if the pageid is given, it will still be loaded) |
||
| 796 | * - 'fromdb': load from a slave database |
||
| 797 | * - 'fromdbmaster': load from the master database |
||
| 798 | * @return WikiPage |
||
| 799 | */ |
||
| 800 | public function getTitleOrPageId( $params, $load = false ) { |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Return true if we're to watch the page, false if not, null if no change. |
||
| 831 | * @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange' |
||
| 832 | * @param Title $titleObj The page under consideration |
||
| 833 | * @param string $userOption The user option to consider when $watchlist=preferences. |
||
| 834 | * If not set will use watchdefault always and watchcreations if $titleObj doesn't exist. |
||
| 835 | * @return bool |
||
| 836 | */ |
||
| 837 | protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) { |
||
| 869 | |||
| 870 | /** |
||
| 871 | * Using the settings determine the value for the given parameter |
||
| 872 | * |
||
| 873 | * @param string $paramName Parameter name |
||
| 874 | * @param array|mixed $paramSettings Default value or an array of settings |
||
| 875 | * using PARAM_* constants. |
||
| 876 | * @param bool $parseLimit Parse limit? |
||
| 877 | * @return mixed Parameter value |
||
| 878 | */ |
||
| 879 | protected function getParameterFromSettings( $paramName, $paramSettings, $parseLimit ) { |
||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Return an array of values that were given in a 'a|b|c' notation, |
||
| 1117 | * after it optionally validates them against the list allowed values. |
||
| 1118 | * |
||
| 1119 | * @param string $valueName The name of the parameter (for error |
||
| 1120 | * reporting) |
||
| 1121 | * @param mixed $value The value being parsed |
||
| 1122 | * @param bool $allowMultiple Can $value contain more than one value |
||
| 1123 | * separated by '|'? |
||
| 1124 | * @param string[]|null $allowedValues An array of values to check against. If |
||
| 1125 | * null, all values are accepted. |
||
| 1126 | * @return string|string[] (allowMultiple ? an_array_of_values : a_single_value) |
||
| 1127 | */ |
||
| 1128 | protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues ) { |
||
| 1181 | |||
| 1182 | /** |
||
| 1183 | * Validate the value against the minimum and user/bot maximum limits. |
||
| 1184 | * Prints usage info on failure. |
||
| 1185 | * @param string $paramName Parameter name |
||
| 1186 | * @param int $value Parameter value |
||
| 1187 | * @param int|null $min Minimum value |
||
| 1188 | * @param int|null $max Maximum value for users |
||
| 1189 | * @param int $botMax Maximum value for sysops/bots |
||
| 1190 | * @param bool $enforceLimits Whether to enforce (die) if value is outside limits |
||
| 1191 | */ |
||
| 1192 | protected function validateLimit( $paramName, &$value, $min, $max, $botMax = null, |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Validate and normalize of parameters of type 'timestamp' |
||
| 1227 | * @param string $value Parameter value |
||
| 1228 | * @param string $encParamName Parameter name |
||
| 1229 | * @return string Validated and normalized parameter |
||
| 1230 | */ |
||
| 1231 | protected function validateTimestamp( $value, $encParamName ) { |
||
| 1260 | |||
| 1261 | /** |
||
| 1262 | * Validate the supplied token. |
||
| 1263 | * |
||
| 1264 | * @since 1.24 |
||
| 1265 | * @param string $token Supplied token |
||
| 1266 | * @param array $params All supplied parameters for the module |
||
| 1267 | * @return bool |
||
| 1268 | * @throws MWException |
||
| 1269 | */ |
||
| 1270 | final public function validateToken( $token, array $params ) { |
||
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Validate and normalize of parameters of type 'user' |
||
| 1301 | * @param string $value Parameter value |
||
| 1302 | * @param string $encParamName Parameter name |
||
| 1303 | * @return string Validated and normalized parameter |
||
| 1304 | */ |
||
| 1305 | private function validateUser( $value, $encParamName ) { |
||
| 1316 | |||
| 1317 | /**@}*/ |
||
| 1318 | |||
| 1319 | /************************************************************************//** |
||
| 1320 | * @name Utility methods |
||
| 1321 | * @{ |
||
| 1322 | */ |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Set a watch (or unwatch) based the based on a watchlist parameter. |
||
| 1326 | * @param string $watch Valid values: 'watch', 'unwatch', 'preferences', 'nochange' |
||
| 1327 | * @param Title $titleObj The article's title to change |
||
| 1328 | * @param string $userOption The user option to consider when $watch=preferences |
||
| 1329 | */ |
||
| 1330 | protected function setWatch( $watch, $titleObj, $userOption = null ) { |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Truncate an array to a certain length. |
||
| 1341 | * @param array $arr Array to truncate |
||
| 1342 | * @param int $limit Maximum length |
||
| 1343 | * @return bool True if the array was truncated, false otherwise |
||
| 1344 | */ |
||
| 1345 | public static function truncateArray( &$arr, $limit ) { |
||
| 1354 | |||
| 1355 | /** |
||
| 1356 | * Gets the user for whom to get the watchlist |
||
| 1357 | * |
||
| 1358 | * @param array $params |
||
| 1359 | * @return User |
||
| 1360 | */ |
||
| 1361 | public function getWatchlistUser( $params ) { |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * A subset of wfEscapeWikiText for BC texts |
||
| 1389 | * |
||
| 1390 | * @since 1.25 |
||
| 1391 | * @param string|array $v |
||
| 1392 | * @return string|array |
||
| 1393 | */ |
||
| 1394 | View Code Duplication | private static function escapeWikiText( $v ) { |
|
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Create a Message from a string or array |
||
| 1408 | * |
||
| 1409 | * A string is used as a message key. An array has the message key as the |
||
| 1410 | * first value and message parameters as subsequent values. |
||
| 1411 | * |
||
| 1412 | * @since 1.25 |
||
| 1413 | * @param string|array|Message $msg |
||
| 1414 | * @param IContextSource $context |
||
| 1415 | * @param array $params |
||
| 1416 | * @return Message|null |
||
| 1417 | */ |
||
| 1418 | public static function makeMessage( $msg, IContextSource $context, array $params = null ) { |
||
| 1435 | |||
| 1436 | /**@}*/ |
||
| 1437 | |||
| 1438 | /************************************************************************//** |
||
| 1439 | * @name Warning and error reporting |
||
| 1440 | * @{ |
||
| 1441 | */ |
||
| 1442 | |||
| 1443 | /** |
||
| 1444 | * Set warning section for this module. Users should monitor this |
||
| 1445 | * section to notice any changes in API. Multiple calls to this |
||
| 1446 | * function will result in the warning messages being separated by |
||
| 1447 | * newlines |
||
| 1448 | * @param string $warning Warning message |
||
| 1449 | */ |
||
| 1450 | public function setWarning( $warning ) { |
||
| 1454 | |||
| 1455 | /** |
||
| 1456 | * Adds a warning to the output, else dies |
||
| 1457 | * |
||
| 1458 | * @param string $msg Message to show as a warning, or error message if dying |
||
| 1459 | * @param bool $enforceLimits Whether this is an enforce (die) |
||
| 1460 | */ |
||
| 1461 | private function warnOrDie( $msg, $enforceLimits = false ) { |
||
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Throw a UsageException, which will (if uncaught) call the main module's |
||
| 1471 | * error handler and die with an error message. |
||
| 1472 | * |
||
| 1473 | * @param string $description One-line human-readable description of the |
||
| 1474 | * error condition, e.g., "The API requires a valid action parameter" |
||
| 1475 | * @param string $errorCode Brief, arbitrary, stable string to allow easy |
||
| 1476 | * automated identification of the error, e.g., 'unknown_action' |
||
| 1477 | * @param int $httpRespCode HTTP response code |
||
| 1478 | * @param array|null $extradata Data to add to the "<error>" element; array in ApiResult format |
||
| 1479 | * @throws UsageException always |
||
| 1480 | */ |
||
| 1481 | public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) { |
||
| 1489 | |||
| 1490 | /** |
||
| 1491 | * Throw a UsageException, which will (if uncaught) call the main module's |
||
| 1492 | * error handler and die with an error message including block info. |
||
| 1493 | * |
||
| 1494 | * @since 1.27 |
||
| 1495 | * @param Block $block The block used to generate the UsageException |
||
| 1496 | * @throws UsageException always |
||
| 1497 | */ |
||
| 1498 | public function dieBlocked( Block $block ) { |
||
| 1516 | |||
| 1517 | /** |
||
| 1518 | * Get error (as code, string) from a Status object. |
||
| 1519 | * |
||
| 1520 | * @since 1.23 |
||
| 1521 | * @param Status $status |
||
| 1522 | * @param array|null &$extraData Set if extra data from IApiMessage is available (since 1.27) |
||
| 1523 | * @return array Array of code and error string |
||
| 1524 | * @throws MWException |
||
| 1525 | */ |
||
| 1526 | public function getErrorFromStatus( $status, &$extraData = null ) { |
||
| 1562 | |||
| 1563 | /** |
||
| 1564 | * Throw a UsageException based on the errors in the Status object. |
||
| 1565 | * |
||
| 1566 | * @since 1.22 |
||
| 1567 | * @param Status $status |
||
| 1568 | * @throws UsageException always |
||
| 1569 | */ |
||
| 1570 | public function dieStatus( $status ) { |
||
| 1575 | |||
| 1576 | // @codingStandardsIgnoreStart Allow long lines. Cannot split these. |
||
| 1577 | /** |
||
| 1578 | * Array that maps message keys to error messages. $1 and friends are replaced. |
||
| 1579 | */ |
||
| 1580 | public static $messageMap = [ |
||
| 1581 | // This one MUST be present, or dieUsageMsg() will recurse infinitely |
||
| 1582 | 'unknownerror' => [ 'code' => 'unknownerror', 'info' => "Unknown error: \"\$1\"" ], |
||
| 1583 | 'unknownerror-nocode' => [ 'code' => 'unknownerror', 'info' => 'Unknown error' ], |
||
| 1584 | |||
| 1585 | // Messages from Title::getUserPermissionsErrors() |
||
| 1586 | 'ns-specialprotected' => [ |
||
| 1587 | 'code' => 'unsupportednamespace', |
||
| 1588 | 'info' => "Pages in the Special namespace can't be edited" |
||
| 1589 | ], |
||
| 1590 | 'protectedinterface' => [ |
||
| 1591 | 'code' => 'protectednamespace-interface', |
||
| 1592 | 'info' => "You're not allowed to edit interface messages" |
||
| 1593 | ], |
||
| 1594 | 'namespaceprotected' => [ |
||
| 1595 | 'code' => 'protectednamespace', |
||
| 1596 | 'info' => "You're not allowed to edit pages in the \"\$1\" namespace" |
||
| 1597 | ], |
||
| 1598 | 'customcssprotected' => [ |
||
| 1599 | 'code' => 'customcssprotected', |
||
| 1600 | 'info' => "You're not allowed to edit custom CSS pages" |
||
| 1601 | ], |
||
| 1602 | 'customjsprotected' => [ |
||
| 1603 | 'code' => 'customjsprotected', |
||
| 1604 | 'info' => "You're not allowed to edit custom JavaScript pages" |
||
| 1605 | ], |
||
| 1606 | 'cascadeprotected' => [ |
||
| 1607 | 'code' => 'cascadeprotected', |
||
| 1608 | 'info' => "The page you're trying to edit is protected because it's included in a cascade-protected page" |
||
| 1609 | ], |
||
| 1610 | 'protectedpagetext' => [ |
||
| 1611 | 'code' => 'protectedpage', |
||
| 1612 | 'info' => "The \"\$1\" right is required to edit this page" |
||
| 1613 | ], |
||
| 1614 | 'protect-cantedit' => [ |
||
| 1615 | 'code' => 'cantedit', |
||
| 1616 | 'info' => "You can't protect this page because you can't edit it" |
||
| 1617 | ], |
||
| 1618 | 'deleteprotected' => [ |
||
| 1619 | 'code' => 'cantedit', |
||
| 1620 | 'info' => "You can't delete this page because it has been protected" |
||
| 1621 | ], |
||
| 1622 | 'badaccess-group0' => [ |
||
| 1623 | 'code' => 'permissiondenied', |
||
| 1624 | 'info' => 'Permission denied' |
||
| 1625 | ], // Generic permission denied message |
||
| 1626 | 'badaccess-groups' => [ |
||
| 1627 | 'code' => 'permissiondenied', |
||
| 1628 | 'info' => 'Permission denied' |
||
| 1629 | ], |
||
| 1630 | 'titleprotected' => [ |
||
| 1631 | 'code' => 'protectedtitle', |
||
| 1632 | 'info' => 'This title has been protected from creation' |
||
| 1633 | ], |
||
| 1634 | 'nocreate-loggedin' => [ |
||
| 1635 | 'code' => 'cantcreate', |
||
| 1636 | 'info' => "You don't have permission to create new pages" |
||
| 1637 | ], |
||
| 1638 | 'nocreatetext' => [ |
||
| 1639 | 'code' => 'cantcreate-anon', |
||
| 1640 | 'info' => "Anonymous users can't create new pages" |
||
| 1641 | ], |
||
| 1642 | 'movenologintext' => [ |
||
| 1643 | 'code' => 'cantmove-anon', |
||
| 1644 | 'info' => "Anonymous users can't move pages" |
||
| 1645 | ], |
||
| 1646 | 'movenotallowed' => [ |
||
| 1647 | 'code' => 'cantmove', |
||
| 1648 | 'info' => "You don't have permission to move pages" |
||
| 1649 | ], |
||
| 1650 | 'confirmedittext' => [ |
||
| 1651 | 'code' => 'confirmemail', |
||
| 1652 | 'info' => 'You must confirm your email address before you can edit' |
||
| 1653 | ], |
||
| 1654 | 'blockedtext' => [ |
||
| 1655 | 'code' => 'blocked', |
||
| 1656 | 'info' => 'You have been blocked from editing' |
||
| 1657 | ], |
||
| 1658 | 'autoblockedtext' => [ |
||
| 1659 | 'code' => 'autoblocked', |
||
| 1660 | 'info' => 'Your IP address has been blocked automatically, because it was used by a blocked user' |
||
| 1661 | ], |
||
| 1662 | |||
| 1663 | // Miscellaneous interface messages |
||
| 1664 | 'actionthrottledtext' => [ |
||
| 1665 | 'code' => 'ratelimited', |
||
| 1666 | 'info' => "You've exceeded your rate limit. Please wait some time and try again" |
||
| 1667 | ], |
||
| 1668 | 'alreadyrolled' => [ |
||
| 1669 | 'code' => 'alreadyrolled', |
||
| 1670 | 'info' => 'The page you tried to rollback was already rolled back' |
||
| 1671 | ], |
||
| 1672 | 'cantrollback' => [ |
||
| 1673 | 'code' => 'onlyauthor', |
||
| 1674 | 'info' => 'The page you tried to rollback only has one author' |
||
| 1675 | ], |
||
| 1676 | 'readonlytext' => [ |
||
| 1677 | 'code' => 'readonly', |
||
| 1678 | 'info' => 'The wiki is currently in read-only mode' |
||
| 1679 | ], |
||
| 1680 | 'sessionfailure' => [ |
||
| 1681 | 'code' => 'badtoken', |
||
| 1682 | 'info' => 'Invalid token' ], |
||
| 1683 | 'cannotdelete' => [ |
||
| 1684 | 'code' => 'cantdelete', |
||
| 1685 | 'info' => "Couldn't delete \"\$1\". Maybe it was deleted already by someone else" |
||
| 1686 | ], |
||
| 1687 | 'notanarticle' => [ |
||
| 1688 | 'code' => 'missingtitle', |
||
| 1689 | 'info' => "The page you requested doesn't exist" |
||
| 1690 | ], |
||
| 1691 | 'selfmove' => [ 'code' => 'selfmove', 'info' => "Can't move a page to itself" |
||
| 1692 | ], |
||
| 1693 | 'immobile_namespace' => [ |
||
| 1694 | 'code' => 'immobilenamespace', |
||
| 1695 | 'info' => 'You tried to move pages from or to a namespace that is protected from moving' |
||
| 1696 | ], |
||
| 1697 | 'articleexists' => [ |
||
| 1698 | 'code' => 'articleexists', |
||
| 1699 | 'info' => 'The destination article already exists and is not a redirect to the source article' |
||
| 1700 | ], |
||
| 1701 | 'protectedpage' => [ |
||
| 1702 | 'code' => 'protectedpage', |
||
| 1703 | 'info' => "You don't have permission to perform this move" |
||
| 1704 | ], |
||
| 1705 | 'hookaborted' => [ |
||
| 1706 | 'code' => 'hookaborted', |
||
| 1707 | 'info' => 'The modification you tried to make was aborted by an extension hook' |
||
| 1708 | ], |
||
| 1709 | 'cantmove-titleprotected' => [ |
||
| 1710 | 'code' => 'protectedtitle', |
||
| 1711 | 'info' => 'The destination article has been protected from creation' |
||
| 1712 | ], |
||
| 1713 | 'imagenocrossnamespace' => [ |
||
| 1714 | 'code' => 'nonfilenamespace', |
||
| 1715 | 'info' => "Can't move a file to a non-file namespace" |
||
| 1716 | ], |
||
| 1717 | 'imagetypemismatch' => [ |
||
| 1718 | 'code' => 'filetypemismatch', |
||
| 1719 | 'info' => "The new file extension doesn't match its type" |
||
| 1720 | ], |
||
| 1721 | // 'badarticleerror' => shouldn't happen |
||
| 1722 | // 'badtitletext' => shouldn't happen |
||
| 1723 | 'ip_range_invalid' => [ 'code' => 'invalidrange', 'info' => 'Invalid IP range' ], |
||
| 1724 | 'range_block_disabled' => [ |
||
| 1725 | 'code' => 'rangedisabled', |
||
| 1726 | 'info' => 'Blocking IP ranges has been disabled' |
||
| 1727 | ], |
||
| 1728 | 'nosuchusershort' => [ |
||
| 1729 | 'code' => 'nosuchuser', |
||
| 1730 | 'info' => "The user you specified doesn't exist" |
||
| 1731 | ], |
||
| 1732 | 'badipaddress' => [ 'code' => 'invalidip', 'info' => 'Invalid IP address specified' ], |
||
| 1733 | 'ipb_expiry_invalid' => [ 'code' => 'invalidexpiry', 'info' => 'Invalid expiry time' ], |
||
| 1734 | 'ipb_already_blocked' => [ |
||
| 1735 | 'code' => 'alreadyblocked', |
||
| 1736 | 'info' => 'The user you tried to block was already blocked' |
||
| 1737 | ], |
||
| 1738 | 'ipb_blocked_as_range' => [ |
||
| 1739 | 'code' => 'blockedasrange', |
||
| 1740 | '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." |
||
| 1741 | ], |
||
| 1742 | 'ipb_cant_unblock' => [ |
||
| 1743 | 'code' => 'cantunblock', |
||
| 1744 | 'info' => 'The block you specified was not found. It may have been unblocked already' |
||
| 1745 | ], |
||
| 1746 | 'mailnologin' => [ |
||
| 1747 | 'code' => 'cantsend', |
||
| 1748 | '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' |
||
| 1749 | ], |
||
| 1750 | 'ipbblocked' => [ |
||
| 1751 | 'code' => 'ipbblocked', |
||
| 1752 | 'info' => 'You cannot block or unblock users while you are yourself blocked' |
||
| 1753 | ], |
||
| 1754 | 'ipbnounblockself' => [ |
||
| 1755 | 'code' => 'ipbnounblockself', |
||
| 1756 | 'info' => 'You are not allowed to unblock yourself' |
||
| 1757 | ], |
||
| 1758 | 'usermaildisabled' => [ |
||
| 1759 | 'code' => 'usermaildisabled', |
||
| 1760 | 'info' => 'User email has been disabled' |
||
| 1761 | ], |
||
| 1762 | 'blockedemailuser' => [ |
||
| 1763 | 'code' => 'blockedfrommail', |
||
| 1764 | 'info' => 'You have been blocked from sending email' |
||
| 1765 | ], |
||
| 1766 | 'notarget' => [ |
||
| 1767 | 'code' => 'notarget', |
||
| 1768 | 'info' => 'You have not specified a valid target for this action' |
||
| 1769 | ], |
||
| 1770 | 'noemail' => [ |
||
| 1771 | 'code' => 'noemail', |
||
| 1772 | 'info' => 'The user has not specified a valid email address, or has chosen not to receive email from other users' |
||
| 1773 | ], |
||
| 1774 | 'rcpatroldisabled' => [ |
||
| 1775 | 'code' => 'patroldisabled', |
||
| 1776 | 'info' => 'Patrolling is disabled on this wiki' |
||
| 1777 | ], |
||
| 1778 | 'markedaspatrollederror-noautopatrol' => [ |
||
| 1779 | 'code' => 'noautopatrol', |
||
| 1780 | 'info' => "You don't have permission to patrol your own changes" |
||
| 1781 | ], |
||
| 1782 | 'delete-toobig' => [ |
||
| 1783 | 'code' => 'bigdelete', |
||
| 1784 | 'info' => "You can't delete this page because it has more than \$1 revisions" |
||
| 1785 | ], |
||
| 1786 | 'movenotallowedfile' => [ |
||
| 1787 | 'code' => 'cantmovefile', |
||
| 1788 | 'info' => "You don't have permission to move files" |
||
| 1789 | ], |
||
| 1790 | 'userrights-no-interwiki' => [ |
||
| 1791 | 'code' => 'nointerwikiuserrights', |
||
| 1792 | 'info' => "You don't have permission to change user rights on other wikis" |
||
| 1793 | ], |
||
| 1794 | 'userrights-nodatabase' => [ |
||
| 1795 | 'code' => 'nosuchdatabase', |
||
| 1796 | 'info' => "Database \"\$1\" does not exist or is not local" |
||
| 1797 | ], |
||
| 1798 | 'nouserspecified' => [ 'code' => 'invaliduser', 'info' => "Invalid username \"\$1\"" ], |
||
| 1799 | 'noname' => [ 'code' => 'invaliduser', 'info' => "Invalid username \"\$1\"" ], |
||
| 1800 | 'summaryrequired' => [ 'code' => 'summaryrequired', 'info' => 'Summary required' ], |
||
| 1801 | 'import-rootpage-invalid' => [ |
||
| 1802 | 'code' => 'import-rootpage-invalid', |
||
| 1803 | 'info' => 'Root page is an invalid title' |
||
| 1804 | ], |
||
| 1805 | 'import-rootpage-nosubpage' => [ |
||
| 1806 | 'code' => 'import-rootpage-nosubpage', |
||
| 1807 | 'info' => 'Namespace "$1" of the root page does not allow subpages' |
||
| 1808 | ], |
||
| 1809 | |||
| 1810 | // API-specific messages |
||
| 1811 | 'readrequired' => [ |
||
| 1812 | 'code' => 'readapidenied', |
||
| 1813 | 'info' => 'You need read permission to use this module' |
||
| 1814 | ], |
||
| 1815 | 'writedisabled' => [ |
||
| 1816 | 'code' => 'noapiwrite', |
||
| 1817 | '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" |
||
| 1818 | ], |
||
| 1819 | 'writerequired' => [ |
||
| 1820 | 'code' => 'writeapidenied', |
||
| 1821 | 'info' => "You're not allowed to edit this wiki through the API" |
||
| 1822 | ], |
||
| 1823 | 'missingparam' => [ 'code' => 'no$1', 'info' => "The \$1 parameter must be set" ], |
||
| 1824 | 'invalidtitle' => [ 'code' => 'invalidtitle', 'info' => "Bad title \"\$1\"" ], |
||
| 1825 | 'nosuchpageid' => [ 'code' => 'nosuchpageid', 'info' => "There is no page with ID \$1" ], |
||
| 1826 | 'nosuchrevid' => [ 'code' => 'nosuchrevid', 'info' => "There is no revision with ID \$1" ], |
||
| 1827 | 'nosuchuser' => [ 'code' => 'nosuchuser', 'info' => "User \"\$1\" doesn't exist" ], |
||
| 1828 | 'invaliduser' => [ 'code' => 'invaliduser', 'info' => "Invalid username \"\$1\"" ], |
||
| 1829 | 'invalidexpiry' => [ 'code' => 'invalidexpiry', 'info' => "Invalid expiry time \"\$1\"" ], |
||
| 1830 | 'pastexpiry' => [ 'code' => 'pastexpiry', 'info' => "Expiry time \"\$1\" is in the past" ], |
||
| 1831 | 'create-titleexists' => [ |
||
| 1832 | 'code' => 'create-titleexists', |
||
| 1833 | 'info' => "Existing titles can't be protected with 'create'" |
||
| 1834 | ], |
||
| 1835 | 'missingtitle-createonly' => [ |
||
| 1836 | 'code' => 'missingtitle-createonly', |
||
| 1837 | 'info' => "Missing titles can only be protected with 'create'" |
||
| 1838 | ], |
||
| 1839 | 'cantblock' => [ 'code' => 'cantblock', |
||
| 1840 | 'info' => "You don't have permission to block users" |
||
| 1841 | ], |
||
| 1842 | 'canthide' => [ |
||
| 1843 | 'code' => 'canthide', |
||
| 1844 | 'info' => "You don't have permission to hide user names from the block log" |
||
| 1845 | ], |
||
| 1846 | 'cantblock-email' => [ |
||
| 1847 | 'code' => 'cantblock-email', |
||
| 1848 | 'info' => "You don't have permission to block users from sending email through the wiki" |
||
| 1849 | ], |
||
| 1850 | 'unblock-notarget' => [ |
||
| 1851 | 'code' => 'notarget', |
||
| 1852 | 'info' => 'Either the id or the user parameter must be set' |
||
| 1853 | ], |
||
| 1854 | 'unblock-idanduser' => [ |
||
| 1855 | 'code' => 'idanduser', |
||
| 1856 | 'info' => "The id and user parameters can't be used together" |
||
| 1857 | ], |
||
| 1858 | 'cantunblock' => [ |
||
| 1859 | 'code' => 'permissiondenied', |
||
| 1860 | 'info' => "You don't have permission to unblock users" |
||
| 1861 | ], |
||
| 1862 | 'cannotundelete' => [ |
||
| 1863 | 'code' => 'cantundelete', |
||
| 1864 | 'info' => "Couldn't undelete: the requested revisions may not exist, or may have been undeleted already" |
||
| 1865 | ], |
||
| 1866 | 'permdenied-undelete' => [ |
||
| 1867 | 'code' => 'permissiondenied', |
||
| 1868 | 'info' => "You don't have permission to restore deleted revisions" |
||
| 1869 | ], |
||
| 1870 | 'createonly-exists' => [ |
||
| 1871 | 'code' => 'articleexists', |
||
| 1872 | 'info' => 'The article you tried to create has been created already' |
||
| 1873 | ], |
||
| 1874 | 'nocreate-missing' => [ |
||
| 1875 | 'code' => 'missingtitle', |
||
| 1876 | 'info' => "The article you tried to edit doesn't exist" |
||
| 1877 | ], |
||
| 1878 | 'cantchangecontentmodel' => [ |
||
| 1879 | 'code' => 'cantchangecontentmodel', |
||
| 1880 | 'info' => "You don't have permission to change the content model of a page" |
||
| 1881 | ], |
||
| 1882 | 'nosuchrcid' => [ |
||
| 1883 | 'code' => 'nosuchrcid', |
||
| 1884 | 'info' => "There is no change with rcid \"\$1\"" |
||
| 1885 | ], |
||
| 1886 | 'nosuchlogid' => [ |
||
| 1887 | 'code' => 'nosuchlogid', |
||
| 1888 | 'info' => "There is no log entry with ID \"\$1\"" |
||
| 1889 | ], |
||
| 1890 | 'protect-invalidaction' => [ |
||
| 1891 | 'code' => 'protect-invalidaction', |
||
| 1892 | 'info' => "Invalid protection type \"\$1\"" |
||
| 1893 | ], |
||
| 1894 | 'protect-invalidlevel' => [ |
||
| 1895 | 'code' => 'protect-invalidlevel', |
||
| 1896 | 'info' => "Invalid protection level \"\$1\"" |
||
| 1897 | ], |
||
| 1898 | 'toofewexpiries' => [ |
||
| 1899 | 'code' => 'toofewexpiries', |
||
| 1900 | 'info' => "\$1 expiry timestamps were provided where \$2 were needed" |
||
| 1901 | ], |
||
| 1902 | 'cantimport' => [ |
||
| 1903 | 'code' => 'cantimport', |
||
| 1904 | 'info' => "You don't have permission to import pages" |
||
| 1905 | ], |
||
| 1906 | 'cantimport-upload' => [ |
||
| 1907 | 'code' => 'cantimport-upload', |
||
| 1908 | 'info' => "You don't have permission to import uploaded pages" |
||
| 1909 | ], |
||
| 1910 | 'importnofile' => [ 'code' => 'nofile', 'info' => "You didn't upload a file" ], |
||
| 1911 | 'importuploaderrorsize' => [ |
||
| 1912 | 'code' => 'filetoobig', |
||
| 1913 | 'info' => 'The file you uploaded is bigger than the maximum upload size' |
||
| 1914 | ], |
||
| 1915 | 'importuploaderrorpartial' => [ |
||
| 1916 | 'code' => 'partialupload', |
||
| 1917 | 'info' => 'The file was only partially uploaded' |
||
| 1918 | ], |
||
| 1919 | 'importuploaderrortemp' => [ |
||
| 1920 | 'code' => 'notempdir', |
||
| 1921 | 'info' => 'The temporary upload directory is missing' |
||
| 1922 | ], |
||
| 1923 | 'importcantopen' => [ |
||
| 1924 | 'code' => 'cantopenfile', |
||
| 1925 | 'info' => "Couldn't open the uploaded file" |
||
| 1926 | ], |
||
| 1927 | 'import-noarticle' => [ |
||
| 1928 | 'code' => 'badinterwiki', |
||
| 1929 | 'info' => 'Invalid interwiki title specified' |
||
| 1930 | ], |
||
| 1931 | 'importbadinterwiki' => [ |
||
| 1932 | 'code' => 'badinterwiki', |
||
| 1933 | 'info' => 'Invalid interwiki title specified' |
||
| 1934 | ], |
||
| 1935 | 'import-unknownerror' => [ |
||
| 1936 | 'code' => 'import-unknownerror', |
||
| 1937 | 'info' => "Unknown error on import: \"\$1\"" |
||
| 1938 | ], |
||
| 1939 | 'cantoverwrite-sharedfile' => [ |
||
| 1940 | 'code' => 'cantoverwrite-sharedfile', |
||
| 1941 | 'info' => 'The target file exists on a shared repository and you do not have permission to override it' |
||
| 1942 | ], |
||
| 1943 | 'sharedfile-exists' => [ |
||
| 1944 | 'code' => 'fileexists-sharedrepo-perm', |
||
| 1945 | 'info' => 'The target file exists on a shared repository. Use the ignorewarnings parameter to override it.' |
||
| 1946 | ], |
||
| 1947 | 'mustbeposted' => [ |
||
| 1948 | 'code' => 'mustbeposted', |
||
| 1949 | 'info' => "The \$1 module requires a POST request" |
||
| 1950 | ], |
||
| 1951 | 'show' => [ |
||
| 1952 | 'code' => 'show', |
||
| 1953 | 'info' => 'Incorrect parameter - mutually exclusive values may not be supplied' |
||
| 1954 | ], |
||
| 1955 | 'specialpage-cantexecute' => [ |
||
| 1956 | 'code' => 'specialpage-cantexecute', |
||
| 1957 | 'info' => "You don't have permission to view the results of this special page" |
||
| 1958 | ], |
||
| 1959 | 'invalidoldimage' => [ |
||
| 1960 | 'code' => 'invalidoldimage', |
||
| 1961 | 'info' => 'The oldimage parameter has invalid format' |
||
| 1962 | ], |
||
| 1963 | 'nodeleteablefile' => [ |
||
| 1964 | 'code' => 'nodeleteablefile', |
||
| 1965 | 'info' => 'No such old version of the file' |
||
| 1966 | ], |
||
| 1967 | 'fileexists-forbidden' => [ |
||
| 1968 | 'code' => 'fileexists-forbidden', |
||
| 1969 | 'info' => 'A file with name "$1" already exists, and cannot be overwritten.' |
||
| 1970 | ], |
||
| 1971 | 'fileexists-shared-forbidden' => [ |
||
| 1972 | 'code' => 'fileexists-shared-forbidden', |
||
| 1973 | 'info' => 'A file with name "$1" already exists in the shared file repository, and cannot be overwritten.' |
||
| 1974 | ], |
||
| 1975 | 'filerevert-badversion' => [ |
||
| 1976 | 'code' => 'filerevert-badversion', |
||
| 1977 | 'info' => 'There is no previous local version of this file with the provided timestamp.' |
||
| 1978 | ], |
||
| 1979 | |||
| 1980 | // ApiEditPage messages |
||
| 1981 | 'noimageredirect-anon' => [ |
||
| 1982 | 'code' => 'noimageredirect-anon', |
||
| 1983 | 'info' => "Anonymous users can't create image redirects" |
||
| 1984 | ], |
||
| 1985 | 'noimageredirect-logged' => [ |
||
| 1986 | 'code' => 'noimageredirect', |
||
| 1987 | 'info' => "You don't have permission to create image redirects" |
||
| 1988 | ], |
||
| 1989 | 'spamdetected' => [ |
||
| 1990 | 'code' => 'spamdetected', |
||
| 1991 | 'info' => "Your edit was refused because it contained a spam fragment: \"\$1\"" |
||
| 1992 | ], |
||
| 1993 | 'contenttoobig' => [ |
||
| 1994 | 'code' => 'contenttoobig', |
||
| 1995 | 'info' => "The content you supplied exceeds the article size limit of \$1 kilobytes" |
||
| 1996 | ], |
||
| 1997 | 'noedit-anon' => [ 'code' => 'noedit-anon', 'info' => "Anonymous users can't edit pages" ], |
||
| 1998 | 'noedit' => [ 'code' => 'noedit', 'info' => "You don't have permission to edit pages" ], |
||
| 1999 | 'wasdeleted' => [ |
||
| 2000 | 'code' => 'pagedeleted', |
||
| 2001 | 'info' => 'The page has been deleted since you fetched its timestamp' |
||
| 2002 | ], |
||
| 2003 | 'blankpage' => [ |
||
| 2004 | 'code' => 'emptypage', |
||
| 2005 | 'info' => 'Creating new, empty pages is not allowed' |
||
| 2006 | ], |
||
| 2007 | 'editconflict' => [ 'code' => 'editconflict', 'info' => 'Edit conflict detected' ], |
||
| 2008 | 'hashcheckfailed' => [ 'code' => 'badmd5', 'info' => 'The supplied MD5 hash was incorrect' ], |
||
| 2009 | 'missingtext' => [ |
||
| 2010 | 'code' => 'notext', |
||
| 2011 | 'info' => 'One of the text, appendtext, prependtext and undo parameters must be set' |
||
| 2012 | ], |
||
| 2013 | 'emptynewsection' => [ |
||
| 2014 | 'code' => 'emptynewsection', |
||
| 2015 | 'info' => 'Creating empty new sections is not possible.' |
||
| 2016 | ], |
||
| 2017 | 'revwrongpage' => [ |
||
| 2018 | 'code' => 'revwrongpage', |
||
| 2019 | 'info' => "r\$1 is not a revision of \"\$2\"" |
||
| 2020 | ], |
||
| 2021 | 'undo-failure' => [ |
||
| 2022 | 'code' => 'undofailure', |
||
| 2023 | 'info' => 'Undo failed due to conflicting intermediate edits' |
||
| 2024 | ], |
||
| 2025 | 'content-not-allowed-here' => [ |
||
| 2026 | 'code' => 'contentnotallowedhere', |
||
| 2027 | 'info' => 'Content model "$1" is not allowed at title "$2"' |
||
| 2028 | ], |
||
| 2029 | |||
| 2030 | // Messages from WikiPage::doEit(] |
||
| 2031 | 'edit-hook-aborted' => [ |
||
| 2032 | 'code' => 'edit-hook-aborted', |
||
| 2033 | 'info' => 'Your edit was aborted by an ArticleSave hook' |
||
| 2034 | ], |
||
| 2035 | 'edit-gone-missing' => [ |
||
| 2036 | 'code' => 'edit-gone-missing', |
||
| 2037 | 'info' => "The page you tried to edit doesn't seem to exist anymore" |
||
| 2038 | ], |
||
| 2039 | 'edit-conflict' => [ 'code' => 'editconflict', 'info' => 'Edit conflict detected' ], |
||
| 2040 | 'edit-already-exists' => [ |
||
| 2041 | 'code' => 'edit-already-exists', |
||
| 2042 | 'info' => 'It seems the page you tried to create already exist' |
||
| 2043 | ], |
||
| 2044 | |||
| 2045 | // uploadMsgs |
||
| 2046 | 'invalid-file-key' => [ 'code' => 'invalid-file-key', 'info' => 'Not a valid file key' ], |
||
| 2047 | 'nouploadmodule' => [ 'code' => 'nouploadmodule', 'info' => 'No upload module set' ], |
||
| 2048 | 'uploaddisabled' => [ |
||
| 2049 | 'code' => 'uploaddisabled', |
||
| 2050 | 'info' => 'Uploads are not enabled. Make sure $wgEnableUploads is set to true in LocalSettings.php and the PHP ini setting file_uploads is true' |
||
| 2051 | ], |
||
| 2052 | 'copyuploaddisabled' => [ |
||
| 2053 | 'code' => 'copyuploaddisabled', |
||
| 2054 | 'info' => 'Uploads by URL is not enabled. Make sure $wgAllowCopyUploads is set to true in LocalSettings.php.' |
||
| 2055 | ], |
||
| 2056 | 'copyuploadbaddomain' => [ |
||
| 2057 | 'code' => 'copyuploadbaddomain', |
||
| 2058 | 'info' => 'Uploads by URL are not allowed from this domain.' |
||
| 2059 | ], |
||
| 2060 | 'copyuploadbadurl' => [ |
||
| 2061 | 'code' => 'copyuploadbadurl', |
||
| 2062 | 'info' => 'Upload not allowed from this URL.' |
||
| 2063 | ], |
||
| 2064 | |||
| 2065 | 'filename-tooshort' => [ |
||
| 2066 | 'code' => 'filename-tooshort', |
||
| 2067 | 'info' => 'The filename is too short' |
||
| 2068 | ], |
||
| 2069 | 'filename-toolong' => [ 'code' => 'filename-toolong', 'info' => 'The filename is too long' ], |
||
| 2070 | 'illegal-filename' => [ |
||
| 2071 | 'code' => 'illegal-filename', |
||
| 2072 | 'info' => 'The filename is not allowed' |
||
| 2073 | ], |
||
| 2074 | 'filetype-missing' => [ |
||
| 2075 | 'code' => 'filetype-missing', |
||
| 2076 | 'info' => 'The file is missing an extension' |
||
| 2077 | ], |
||
| 2078 | |||
| 2079 | 'mustbeloggedin' => [ 'code' => 'mustbeloggedin', 'info' => 'You must be logged in to $1.' ] |
||
| 2080 | ]; |
||
| 2081 | // @codingStandardsIgnoreEnd |
||
| 2082 | |||
| 2083 | /** |
||
| 2084 | * Helper function for readonly errors |
||
| 2085 | * |
||
| 2086 | * @throws UsageException always |
||
| 2087 | */ |
||
| 2088 | public function dieReadOnly() { |
||
| 2093 | |||
| 2094 | /** |
||
| 2095 | * Output the error message related to a certain array |
||
| 2096 | * @param array|string $error Element of a getUserPermissionsErrors()-style array |
||
| 2097 | * @throws UsageException always |
||
| 2098 | */ |
||
| 2099 | public function dieUsageMsg( $error ) { |
||
| 2109 | |||
| 2110 | /** |
||
| 2111 | * Will only set a warning instead of failing if the global $wgDebugAPI |
||
| 2112 | * is set to true. Otherwise behaves exactly as dieUsageMsg(). |
||
| 2113 | * @param array|string $error Element of a getUserPermissionsErrors()-style array |
||
| 2114 | * @throws UsageException |
||
| 2115 | * @since 1.21 |
||
| 2116 | */ |
||
| 2117 | public function dieUsageMsgOrDebug( $error ) { |
||
| 2128 | |||
| 2129 | /** |
||
| 2130 | * Die with the $prefix.'badcontinue' error. This call is common enough to |
||
| 2131 | * make it into the base method. |
||
| 2132 | * @param bool $condition Will only die if this value is true |
||
| 2133 | * @throws UsageException |
||
| 2134 | * @since 1.21 |
||
| 2135 | */ |
||
| 2136 | protected function dieContinueUsageIf( $condition ) { |
||
| 2143 | |||
| 2144 | /** |
||
| 2145 | * Return the error message related to a certain array |
||
| 2146 | * @param array $error Element of a getUserPermissionsErrors()-style array |
||
| 2147 | * @return array('code' => code, 'info' => info) |
||
| 2148 | */ |
||
| 2149 | public function parseMsg( $error ) { |
||
| 2178 | |||
| 2179 | /** |
||
| 2180 | * Internal code errors should be reported with this method |
||
| 2181 | * @param string $method Method or function name |
||
| 2182 | * @param string $message Error message |
||
| 2183 | * @throws MWException always |
||
| 2184 | */ |
||
| 2185 | protected static function dieDebug( $method, $message ) { |
||
| 2188 | |||
| 2189 | /** |
||
| 2190 | * Write logging information for API features to a debug log, for usage |
||
| 2191 | * analysis. |
||
| 2192 | * @param string $feature Feature being used. |
||
| 2193 | */ |
||
| 2194 | protected function logFeatureUsage( $feature ) { |
||
| 2203 | |||
| 2204 | /**@}*/ |
||
| 2205 | |||
| 2206 | /************************************************************************//** |
||
| 2207 | * @name Help message generation |
||
| 2208 | * @{ |
||
| 2209 | */ |
||
| 2210 | |||
| 2211 | /** |
||
| 2212 | * Return the description message. |
||
| 2213 | * |
||
| 2214 | * @return string|array|Message |
||
| 2215 | */ |
||
| 2216 | protected function getDescriptionMessage() { |
||
| 2219 | |||
| 2220 | /** |
||
| 2221 | * Get final module description, after hooks have had a chance to tweak it as |
||
| 2222 | * needed. |
||
| 2223 | * |
||
| 2224 | * @since 1.25, returns Message[] rather than string[] |
||
| 2225 | * @return Message[] |
||
| 2226 | */ |
||
| 2227 | public function getFinalDescription() { |
||
| 2251 | |||
| 2252 | /** |
||
| 2253 | * Get final list of parameters, after hooks have had a chance to |
||
| 2254 | * tweak it as needed. |
||
| 2255 | * |
||
| 2256 | * @param int $flags Zero or more flags like GET_VALUES_FOR_HELP |
||
| 2257 | * @return array|bool False on no parameters |
||
| 2258 | * @since 1.21 $flags param added |
||
| 2259 | */ |
||
| 2260 | public function getFinalParams( $flags = 0 ) { |
||
| 2281 | |||
| 2282 | /** |
||
| 2283 | * Get final parameter descriptions, after hooks have had a chance to tweak it as |
||
| 2284 | * needed. |
||
| 2285 | * |
||
| 2286 | * @since 1.25, returns array of Message[] rather than array of string[] |
||
| 2287 | * @return array Keys are parameter names, values are arrays of Message objects |
||
| 2288 | */ |
||
| 2289 | public function getFinalParamDescription() { |
||
| 2393 | |||
| 2394 | /** |
||
| 2395 | * Generates the list of flags for the help screen and for action=paraminfo |
||
| 2396 | * |
||
| 2397 | * Corresponding messages: api-help-flag-deprecated, |
||
| 2398 | * api-help-flag-internal, api-help-flag-readrights, |
||
| 2399 | * api-help-flag-writerights, api-help-flag-mustbeposted |
||
| 2400 | * |
||
| 2401 | * @return string[] |
||
| 2402 | */ |
||
| 2403 | protected function getHelpFlags() { |
||
| 2424 | |||
| 2425 | /** |
||
| 2426 | * Returns information about the source of this module, if known |
||
| 2427 | * |
||
| 2428 | * Returned array is an array with the following keys: |
||
| 2429 | * - path: Install path |
||
| 2430 | * - name: Extension name, or "MediaWiki" for core |
||
| 2431 | * - namemsg: (optional) i18n message key for a display name |
||
| 2432 | * - license-name: (optional) Name of license |
||
| 2433 | * |
||
| 2434 | * @return array|null |
||
| 2435 | */ |
||
| 2436 | protected function getModuleSourceInfo() { |
||
| 2511 | |||
| 2512 | /** |
||
| 2513 | * Called from ApiHelp before the pieces are joined together and returned. |
||
| 2514 | * |
||
| 2515 | * This exists mainly for ApiMain to add the Permissions and Credits |
||
| 2516 | * sections. Other modules probably don't need it. |
||
| 2517 | * |
||
| 2518 | * @param string[] &$help Array of help data |
||
| 2519 | * @param array $options Options passed to ApiHelp::getHelp |
||
| 2520 | * @param array &$tocData If a TOC is being generated, this array has keys |
||
| 2521 | * as anchors in the page and values as for Linker::generateTOC(). |
||
| 2522 | */ |
||
| 2523 | public function modifyHelp( array &$help, array $options, array &$tocData ) { |
||
| 2525 | |||
| 2526 | /**@}*/ |
||
| 2527 | |||
| 2528 | /************************************************************************//** |
||
| 2529 | * @name Deprecated |
||
| 2530 | * @{ |
||
| 2531 | */ |
||
| 2532 | |||
| 2533 | /** |
||
| 2534 | * Returns the description string for this module |
||
| 2535 | * |
||
| 2536 | * Ignored if an i18n message exists for |
||
| 2537 | * "apihelp-{$this->getModulePath()}-description". |
||
| 2538 | * |
||
| 2539 | * @deprecated since 1.25 |
||
| 2540 | * @return Message|string|array |
||
| 2541 | */ |
||
| 2542 | protected function getDescription() { |
||
| 2545 | |||
| 2546 | /** |
||
| 2547 | * Returns an array of parameter descriptions. |
||
| 2548 | * |
||
| 2549 | * For each parameter, ignored if an i18n message exists for the parameter. |
||
| 2550 | * By default that message is |
||
| 2551 | * "apihelp-{$this->getModulePath()}-param-{$param}", but it may be |
||
| 2552 | * overridden using ApiBase::PARAM_HELP_MSG in the data returned by |
||
| 2553 | * self::getFinalParams(). |
||
| 2554 | * |
||
| 2555 | * @deprecated since 1.25 |
||
| 2556 | * @return array|bool False on no parameter descriptions |
||
| 2557 | */ |
||
| 2558 | protected function getParamDescription() { |
||
| 2561 | |||
| 2562 | /** |
||
| 2563 | * Returns usage examples for this module. |
||
| 2564 | * |
||
| 2565 | * Return value as an array is either: |
||
| 2566 | * - numeric keys with partial URLs ("api.php?" plus a query string) as |
||
| 2567 | * values |
||
| 2568 | * - sequential numeric keys with even-numbered keys being display-text |
||
| 2569 | * and odd-numbered keys being partial urls |
||
| 2570 | * - partial URLs as keys with display-text (string or array-to-be-joined) |
||
| 2571 | * as values |
||
| 2572 | * Return value as a string is the same as an array with a numeric key and |
||
| 2573 | * that value, and boolean false means "no examples". |
||
| 2574 | * |
||
| 2575 | * @deprecated since 1.25, use getExamplesMessages() instead |
||
| 2576 | * @return bool|string|array |
||
| 2577 | */ |
||
| 2578 | protected function getExamples() { |
||
| 2581 | |||
| 2582 | /** |
||
| 2583 | * Generates help message for this module, or false if there is no description |
||
| 2584 | * @deprecated since 1.25 |
||
| 2585 | * @return string|bool |
||
| 2586 | */ |
||
| 2587 | public function makeHelpMsg() { |
||
| 2651 | |||
| 2652 | /** |
||
| 2653 | * @deprecated since 1.25 |
||
| 2654 | * @param string $item |
||
| 2655 | * @return string |
||
| 2656 | */ |
||
| 2657 | private function indentExampleText( $item ) { |
||
| 2660 | |||
| 2661 | /** |
||
| 2662 | * @deprecated since 1.25 |
||
| 2663 | * @param string $prefix Text to split output items |
||
| 2664 | * @param string $title What is being output |
||
| 2665 | * @param string|array $input |
||
| 2666 | * @return string |
||
| 2667 | */ |
||
| 2668 | protected function makeHelpArrayToString( $prefix, $title, $input ) { |
||
| 2690 | |||
| 2691 | /** |
||
| 2692 | * Generates the parameter descriptions for this module, to be displayed in the |
||
| 2693 | * module's help. |
||
| 2694 | * @deprecated since 1.25 |
||
| 2695 | * @return string|bool |
||
| 2696 | */ |
||
| 2697 | public function makeHelpMsgParameters() { |
||
| 2850 | |||
| 2851 | /** |
||
| 2852 | * @deprecated since 1.25, always returns empty string |
||
| 2853 | * @param IDatabase|bool $db |
||
| 2854 | * @return string |
||
| 2855 | */ |
||
| 2856 | public function getModuleProfileName( $db = false ) { |
||
| 2860 | |||
| 2861 | /** |
||
| 2862 | * @deprecated since 1.25 |
||
| 2863 | */ |
||
| 2864 | public function profileIn() { |
||
| 2868 | |||
| 2869 | /** |
||
| 2870 | * @deprecated since 1.25 |
||
| 2871 | */ |
||
| 2872 | public function profileOut() { |
||
| 2876 | |||
| 2877 | /** |
||
| 2878 | * @deprecated since 1.25 |
||
| 2879 | */ |
||
| 2880 | public function safeProfileOut() { |
||
| 2883 | |||
| 2884 | /** |
||
| 2885 | * @deprecated since 1.25, always returns 0 |
||
| 2886 | * @return float |
||
| 2887 | */ |
||
| 2888 | public function getProfileTime() { |
||
| 2892 | |||
| 2893 | /** |
||
| 2894 | * @deprecated since 1.25 |
||
| 2895 | */ |
||
| 2896 | public function profileDBIn() { |
||
| 2899 | |||
| 2900 | /** |
||
| 2901 | * @deprecated since 1.25 |
||
| 2902 | */ |
||
| 2903 | public function profileDBOut() { |
||
| 2906 | |||
| 2907 | /** |
||
| 2908 | * @deprecated since 1.25, always returns 0 |
||
| 2909 | * @return float |
||
| 2910 | */ |
||
| 2911 | public function getProfileDBTime() { |
||
| 2915 | |||
| 2916 | /** |
||
| 2917 | * Get the result data array (read-only) |
||
| 2918 | * @deprecated since 1.25, use $this->getResult() methods instead |
||
| 2919 | * @return array |
||
| 2920 | */ |
||
| 2921 | public function getResultData() { |
||
| 2925 | |||
| 2926 | /** |
||
| 2927 | * Call wfTransactionalTimeLimit() if this request was POSTed |
||
| 2928 | * @since 1.26 |
||
| 2929 | */ |
||
| 2930 | protected function useTransactionalTimeLimit() { |
||
| 2935 | |||
| 2936 | /**@}*/ |
||
| 2937 | } |
||
| 2938 | |||
| 2943 |
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.