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 Message 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 Message, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 159 | class Message implements MessageSpecifier, Serializable { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * In which language to get this message. True, which is the default, |
||
| 163 | * means the current user language, false content language. |
||
| 164 | * |
||
| 165 | * @var bool |
||
| 166 | */ |
||
| 167 | protected $interface = true; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * In which language to get this message. Overrides the $interface setting. |
||
| 171 | * |
||
| 172 | * @var Language|bool Explicit language object, or false for user language |
||
| 173 | */ |
||
| 174 | protected $language = false; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @var string The message key. If $keysToTry has more than one element, |
||
| 178 | * this may change to one of the keys to try when fetching the message text. |
||
| 179 | */ |
||
| 180 | protected $key; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @var string[] List of keys to try when fetching the message. |
||
| 184 | */ |
||
| 185 | protected $keysToTry; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @var array List of parameters which will be substituted into the message. |
||
| 189 | */ |
||
| 190 | protected $parameters = []; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Format for the message. |
||
| 194 | * Supported formats are: |
||
| 195 | * * text (transform) |
||
| 196 | * * escaped (transform+htmlspecialchars) |
||
| 197 | * * block-parse |
||
| 198 | * * parse (default) |
||
| 199 | * * plain |
||
| 200 | * |
||
| 201 | * @var string |
||
| 202 | */ |
||
| 203 | protected $format = 'parse'; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @var bool Whether database can be used. |
||
| 207 | */ |
||
| 208 | protected $useDatabase = true; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @var Title Title object to use as context. |
||
| 212 | */ |
||
| 213 | protected $title = null; |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @var Content Content object representing the message. |
||
| 217 | */ |
||
| 218 | protected $content = null; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @var string |
||
| 222 | */ |
||
| 223 | protected $message; |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @since 1.17 |
||
| 227 | * @param string|string[]|MessageSpecifier $key Message key, or array of |
||
| 228 | * message keys to try and use the first non-empty message for, or a |
||
| 229 | * MessageSpecifier to copy from. |
||
| 230 | * @param array $params Message parameters. |
||
| 231 | * @param Language $language [optional] Language to use (defaults to current user language). |
||
| 232 | * @throws InvalidArgumentException |
||
| 233 | */ |
||
| 234 | public function __construct( $key, $params = [], Language $language = null ) { |
||
| 235 | if ( $key instanceof MessageSpecifier ) { |
||
| 236 | if ( $params ) { |
||
|
|
|||
| 237 | throw new InvalidArgumentException( |
||
| 238 | '$params must be empty if $key is a MessageSpecifier' |
||
| 239 | ); |
||
| 240 | } |
||
| 241 | $params = $key->getParams(); |
||
| 242 | $key = $key->getKey(); |
||
| 243 | } |
||
| 244 | |||
| 245 | if ( !is_string( $key ) && !is_array( $key ) ) { |
||
| 246 | throw new InvalidArgumentException( '$key must be a string or an array' ); |
||
| 247 | } |
||
| 248 | |||
| 249 | $this->keysToTry = (array)$key; |
||
| 250 | |||
| 251 | if ( empty( $this->keysToTry ) ) { |
||
| 252 | throw new InvalidArgumentException( '$key must not be an empty list' ); |
||
| 253 | } |
||
| 254 | |||
| 255 | $this->key = reset( $this->keysToTry ); |
||
| 256 | |||
| 257 | $this->parameters = array_values( $params ); |
||
| 258 | // User language is only resolved in getLanguage(). This helps preserve the |
||
| 259 | // semantic intent of "user language" across serialize() and unserialize(). |
||
| 260 | $this->language = $language ?: false; |
||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @see Serializable::serialize() |
||
| 265 | * @since 1.26 |
||
| 266 | * @return string |
||
| 267 | */ |
||
| 268 | public function serialize() { |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @see Serializable::unserialize() |
||
| 283 | * @since 1.26 |
||
| 284 | * @param string $serialized |
||
| 285 | */ |
||
| 286 | public function unserialize( $serialized ) { |
||
| 287 | $data = unserialize( $serialized ); |
||
| 288 | $this->interface = $data['interface']; |
||
| 289 | $this->key = $data['key']; |
||
| 290 | $this->keysToTry = $data['keysToTry']; |
||
| 291 | $this->parameters = $data['parameters']; |
||
| 292 | $this->format = $data['format']; |
||
| 293 | $this->useDatabase = $data['useDatabase']; |
||
| 294 | $this->language = $data['language'] ? Language::factory( $data['language'] ) : false; |
||
| 295 | $this->title = $data['title']; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @since 1.24 |
||
| 300 | * |
||
| 301 | * @return bool True if this is a multi-key message, that is, if the key provided to the |
||
| 302 | * constructor was a fallback list of keys to try. |
||
| 303 | */ |
||
| 304 | public function isMultiKey() { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @since 1.24 |
||
| 310 | * |
||
| 311 | * @return string[] The list of keys to try when fetching the message text, |
||
| 312 | * in order of preference. |
||
| 313 | */ |
||
| 314 | public function getKeysToTry() { |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Returns the message key. |
||
| 320 | * |
||
| 321 | * If a list of multiple possible keys was supplied to the constructor, this method may |
||
| 322 | * return any of these keys. After the message has been fetched, this method will return |
||
| 323 | * the key that was actually used to fetch the message. |
||
| 324 | * |
||
| 325 | * @since 1.21 |
||
| 326 | * |
||
| 327 | * @return string |
||
| 328 | */ |
||
| 329 | public function getKey() { |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Returns the message parameters. |
||
| 335 | * |
||
| 336 | * @since 1.21 |
||
| 337 | * |
||
| 338 | * @return array |
||
| 339 | */ |
||
| 340 | public function getParams() { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Returns the message format. |
||
| 346 | * |
||
| 347 | * @since 1.21 |
||
| 348 | * |
||
| 349 | * @return string |
||
| 350 | */ |
||
| 351 | public function getFormat() { |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Returns the Language of the Message. |
||
| 357 | * |
||
| 358 | * @since 1.23 |
||
| 359 | * |
||
| 360 | * @return Language |
||
| 361 | */ |
||
| 362 | public function getLanguage() { |
||
| 363 | // Defaults to false which means current user language |
||
| 364 | return $this->language ?: RequestContext::getMain()->getLanguage(); |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Factory function that is just wrapper for the real constructor. It is |
||
| 369 | * intended to be used instead of the real constructor, because it allows |
||
| 370 | * chaining method calls, while new objects don't. |
||
| 371 | * |
||
| 372 | * @since 1.17 |
||
| 373 | * |
||
| 374 | * @param string|string[]|MessageSpecifier $key |
||
| 375 | * @param mixed $param,... Parameters as strings. |
||
| 376 | * |
||
| 377 | * @return Message |
||
| 378 | */ |
||
| 379 | public static function newFromKey( $key /*...*/ ) { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Transform a MessageSpecifier or a primitive value used interchangeably with |
||
| 387 | * specifiers (a message key string, or a key + params array) into a proper Message |
||
| 388 | * @param string|array|MessageSpecifier $value |
||
| 389 | * @return Message |
||
| 390 | * @throws InvalidArgumentException |
||
| 391 | */ |
||
| 392 | public static function newFromSpecifier( $value ) { |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Factory function accepting multiple message keys and returning a message instance |
||
| 412 | * for the first message which is non-empty. If all messages are empty then an |
||
| 413 | * instance of the first message key is returned. |
||
| 414 | * |
||
| 415 | * @since 1.18 |
||
| 416 | * |
||
| 417 | * @param string|string[] $keys,... Message keys, or first argument as an array of all the |
||
| 418 | * message keys. |
||
| 419 | * |
||
| 420 | * @return Message |
||
| 421 | */ |
||
| 422 | public static function newFallbackSequence( /*...*/ ) { |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Get a title object for a mediawiki message, where it can be found in the mediawiki namespace. |
||
| 438 | * The title will be for the current language, if the message key is in |
||
| 439 | * $wgForceUIMsgAsContentMsg it will be append with the language code (except content |
||
| 440 | * language), because Message::inContentLanguage will also return in user language. |
||
| 441 | * |
||
| 442 | * @see $wgForceUIMsgAsContentMsg |
||
| 443 | * @return Title |
||
| 444 | * @since 1.26 |
||
| 445 | */ |
||
| 446 | public function getTitle() { |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Adds parameters to the parameter list of this message. |
||
| 463 | * |
||
| 464 | * @since 1.17 |
||
| 465 | * |
||
| 466 | * @param mixed ... Parameters as strings, or a single argument that is |
||
| 467 | * an array of strings. |
||
| 468 | * |
||
| 469 | * @return Message $this |
||
| 470 | */ |
||
| 471 | public function params( /*...*/ ) { |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Add parameters that are substituted after parsing or escaping. |
||
| 483 | * In other words the parsing process cannot access the contents |
||
| 484 | * of this type of parameter, and you need to make sure it is |
||
| 485 | * sanitized beforehand. The parser will see "$n", instead. |
||
| 486 | * |
||
| 487 | * @since 1.17 |
||
| 488 | * |
||
| 489 | * @param mixed $params,... Raw parameters as strings, or a single argument that is |
||
| 490 | * an array of raw parameters. |
||
| 491 | * |
||
| 492 | * @return Message $this |
||
| 493 | */ |
||
| 494 | View Code Duplication | public function rawParams( /*...*/ ) { |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Add parameters that are numeric and will be passed through |
||
| 507 | * Language::formatNum before substitution |
||
| 508 | * |
||
| 509 | * @since 1.18 |
||
| 510 | * |
||
| 511 | * @param mixed $param,... Numeric parameters, or a single argument that is |
||
| 512 | * an array of numeric parameters. |
||
| 513 | * |
||
| 514 | * @return Message $this |
||
| 515 | */ |
||
| 516 | View Code Duplication | public function numParams( /*...*/ ) { |
|
| 526 | |||
| 527 | /** |
||
| 528 | * Add parameters that are durations of time and will be passed through |
||
| 529 | * Language::formatDuration before substitution |
||
| 530 | * |
||
| 531 | * @since 1.22 |
||
| 532 | * |
||
| 533 | * @param int|int[] $param,... Duration parameters, or a single argument that is |
||
| 534 | * an array of duration parameters. |
||
| 535 | * |
||
| 536 | * @return Message $this |
||
| 537 | */ |
||
| 538 | View Code Duplication | public function durationParams( /*...*/ ) { |
|
| 548 | |||
| 549 | /** |
||
| 550 | * Add parameters that are expiration times and will be passed through |
||
| 551 | * Language::formatExpiry before substitution |
||
| 552 | * |
||
| 553 | * @since 1.22 |
||
| 554 | * |
||
| 555 | * @param string|string[] $param,... Expiry parameters, or a single argument that is |
||
| 556 | * an array of expiry parameters. |
||
| 557 | * |
||
| 558 | * @return Message $this |
||
| 559 | */ |
||
| 560 | View Code Duplication | public function expiryParams( /*...*/ ) { |
|
| 570 | |||
| 571 | /** |
||
| 572 | * Add parameters that are time periods and will be passed through |
||
| 573 | * Language::formatTimePeriod before substitution |
||
| 574 | * |
||
| 575 | * @since 1.22 |
||
| 576 | * |
||
| 577 | * @param int|int[] $param,... Time period parameters, or a single argument that is |
||
| 578 | * an array of time period parameters. |
||
| 579 | * |
||
| 580 | * @return Message $this |
||
| 581 | */ |
||
| 582 | View Code Duplication | public function timeperiodParams( /*...*/ ) { |
|
| 592 | |||
| 593 | /** |
||
| 594 | * Add parameters that are file sizes and will be passed through |
||
| 595 | * Language::formatSize before substitution |
||
| 596 | * |
||
| 597 | * @since 1.22 |
||
| 598 | * |
||
| 599 | * @param int|int[] $param,... Size parameters, or a single argument that is |
||
| 600 | * an array of size parameters. |
||
| 601 | * |
||
| 602 | * @return Message $this |
||
| 603 | */ |
||
| 604 | View Code Duplication | public function sizeParams( /*...*/ ) { |
|
| 614 | |||
| 615 | /** |
||
| 616 | * Add parameters that are bitrates and will be passed through |
||
| 617 | * Language::formatBitrate before substitution |
||
| 618 | * |
||
| 619 | * @since 1.22 |
||
| 620 | * |
||
| 621 | * @param int|int[] $param,... Bit rate parameters, or a single argument that is |
||
| 622 | * an array of bit rate parameters. |
||
| 623 | * |
||
| 624 | * @return Message $this |
||
| 625 | */ |
||
| 626 | View Code Duplication | public function bitrateParams( /*...*/ ) { |
|
| 636 | |||
| 637 | /** |
||
| 638 | * Add parameters that are plaintext and will be passed through without |
||
| 639 | * the content being evaluated. Plaintext parameters are not valid as |
||
| 640 | * arguments to parser functions. This differs from self::rawParams in |
||
| 641 | * that the Message class handles escaping to match the output format. |
||
| 642 | * |
||
| 643 | * @since 1.25 |
||
| 644 | * |
||
| 645 | * @param string|string[] $param,... plaintext parameters, or a single argument that is |
||
| 646 | * an array of plaintext parameters. |
||
| 647 | * |
||
| 648 | * @return Message $this |
||
| 649 | */ |
||
| 650 | View Code Duplication | public function plaintextParams( /*...*/ ) { |
|
| 660 | |||
| 661 | /** |
||
| 662 | * Set the language and the title from a context object |
||
| 663 | * |
||
| 664 | * @since 1.19 |
||
| 665 | * |
||
| 666 | * @param IContextSource $context |
||
| 667 | * |
||
| 668 | * @return Message $this |
||
| 669 | */ |
||
| 670 | public function setContext( IContextSource $context ) { |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Request the message in any language that is supported. |
||
| 680 | * |
||
| 681 | * As a side effect interface message status is unconditionally |
||
| 682 | * turned off. |
||
| 683 | * |
||
| 684 | * @since 1.17 |
||
| 685 | * @param Language|string $lang Language code or Language object. |
||
| 686 | * @return Message $this |
||
| 687 | * @throws MWException |
||
| 688 | */ |
||
| 689 | public function inLanguage( $lang ) { |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Request the message in the wiki's content language, |
||
| 711 | * unless it is disabled for this message. |
||
| 712 | * |
||
| 713 | * @since 1.17 |
||
| 714 | * @see $wgForceUIMsgAsContentMsg |
||
| 715 | * |
||
| 716 | * @return Message $this |
||
| 717 | */ |
||
| 718 | public function inContentLanguage() { |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Allows manipulating the interface message flag directly. |
||
| 731 | * Can be used to restore the flag after setting a language. |
||
| 732 | * |
||
| 733 | * @since 1.20 |
||
| 734 | * |
||
| 735 | * @param bool $interface |
||
| 736 | * |
||
| 737 | * @return Message $this |
||
| 738 | */ |
||
| 739 | public function setInterfaceMessageFlag( $interface ) { |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Enable or disable database use. |
||
| 746 | * |
||
| 747 | * @since 1.17 |
||
| 748 | * |
||
| 749 | * @param bool $useDatabase |
||
| 750 | * |
||
| 751 | * @return Message $this |
||
| 752 | */ |
||
| 753 | public function useDatabase( $useDatabase ) { |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Set the Title object to use as context when transforming the message |
||
| 760 | * |
||
| 761 | * @since 1.18 |
||
| 762 | * |
||
| 763 | * @param Title $title |
||
| 764 | * |
||
| 765 | * @return Message $this |
||
| 766 | */ |
||
| 767 | public function title( $title ) { |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Returns the message as a Content object. |
||
| 774 | * |
||
| 775 | * @return Content |
||
| 776 | */ |
||
| 777 | public function content() { |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Returns the message parsed from wikitext to HTML. |
||
| 787 | * |
||
| 788 | * @since 1.17 |
||
| 789 | * |
||
| 790 | * @return string HTML |
||
| 791 | */ |
||
| 792 | public function toString() { |
||
| 832 | |||
| 833 | /** |
||
| 834 | * Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg: |
||
| 835 | * $foo = new Message( $key ); |
||
| 836 | * $string = "<abbr>$foo</abbr>"; |
||
| 837 | * |
||
| 838 | * @since 1.18 |
||
| 839 | * |
||
| 840 | * @return string |
||
| 841 | */ |
||
| 842 | public function __toString() { |
||
| 862 | |||
| 863 | /** |
||
| 864 | * Fully parse the text from wikitext to HTML. |
||
| 865 | * |
||
| 866 | * @since 1.17 |
||
| 867 | * |
||
| 868 | * @return string Parsed HTML. |
||
| 869 | */ |
||
| 870 | public function parse() { |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Returns the message text. {{-transformation is done. |
||
| 877 | * |
||
| 878 | * @since 1.17 |
||
| 879 | * |
||
| 880 | * @return string Unescaped message text. |
||
| 881 | */ |
||
| 882 | public function text() { |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Returns the message text as-is, only parameters are substituted. |
||
| 889 | * |
||
| 890 | * @since 1.17 |
||
| 891 | * |
||
| 892 | * @return string Unescaped untransformed message text. |
||
| 893 | */ |
||
| 894 | public function plain() { |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Returns the parsed message text which is always surrounded by a block element. |
||
| 901 | * |
||
| 902 | * @since 1.17 |
||
| 903 | * |
||
| 904 | * @return string HTML |
||
| 905 | */ |
||
| 906 | public function parseAsBlock() { |
||
| 910 | |||
| 911 | /** |
||
| 912 | * Returns the message text. {{-transformation is done and the result |
||
| 913 | * is escaped excluding any raw parameters. |
||
| 914 | * |
||
| 915 | * @since 1.17 |
||
| 916 | * |
||
| 917 | * @return string Escaped message text. |
||
| 918 | */ |
||
| 919 | public function escaped() { |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Check whether a message key has been defined currently. |
||
| 926 | * |
||
| 927 | * @since 1.17 |
||
| 928 | * |
||
| 929 | * @return bool |
||
| 930 | */ |
||
| 931 | public function exists() { |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Check whether a message does not exist, or is an empty string |
||
| 937 | * |
||
| 938 | * @since 1.18 |
||
| 939 | * @todo FIXME: Merge with isDisabled()? |
||
| 940 | * |
||
| 941 | * @return bool |
||
| 942 | */ |
||
| 943 | public function isBlank() { |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Check whether a message does not exist, is an empty string, or is "-". |
||
| 950 | * |
||
| 951 | * @since 1.18 |
||
| 952 | * |
||
| 953 | * @return bool |
||
| 954 | */ |
||
| 955 | public function isDisabled() { |
||
| 959 | |||
| 960 | /** |
||
| 961 | * @since 1.17 |
||
| 962 | * |
||
| 963 | * @param mixed $raw |
||
| 964 | * |
||
| 965 | * @return array Array with a single "raw" key. |
||
| 966 | */ |
||
| 967 | public static function rawParam( $raw ) { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * @since 1.18 |
||
| 973 | * |
||
| 974 | * @param mixed $num |
||
| 975 | * |
||
| 976 | * @return array Array with a single "num" key. |
||
| 977 | */ |
||
| 978 | public static function numParam( $num ) { |
||
| 981 | |||
| 982 | /** |
||
| 983 | * @since 1.22 |
||
| 984 | * |
||
| 985 | * @param int $duration |
||
| 986 | * |
||
| 987 | * @return int[] Array with a single "duration" key. |
||
| 988 | */ |
||
| 989 | public static function durationParam( $duration ) { |
||
| 992 | |||
| 993 | /** |
||
| 994 | * @since 1.22 |
||
| 995 | * |
||
| 996 | * @param string $expiry |
||
| 997 | * |
||
| 998 | * @return string[] Array with a single "expiry" key. |
||
| 999 | */ |
||
| 1000 | public static function expiryParam( $expiry ) { |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * @since 1.22 |
||
| 1006 | * |
||
| 1007 | * @param number $period |
||
| 1008 | * |
||
| 1009 | * @return number[] Array with a single "period" key. |
||
| 1010 | */ |
||
| 1011 | public static function timeperiodParam( $period ) { |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * @since 1.22 |
||
| 1017 | * |
||
| 1018 | * @param int $size |
||
| 1019 | * |
||
| 1020 | * @return int[] Array with a single "size" key. |
||
| 1021 | */ |
||
| 1022 | public static function sizeParam( $size ) { |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * @since 1.22 |
||
| 1028 | * |
||
| 1029 | * @param int $bitrate |
||
| 1030 | * |
||
| 1031 | * @return int[] Array with a single "bitrate" key. |
||
| 1032 | */ |
||
| 1033 | public static function bitrateParam( $bitrate ) { |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * @since 1.25 |
||
| 1039 | * |
||
| 1040 | * @param string $plaintext |
||
| 1041 | * |
||
| 1042 | * @return string[] Array with a single "plaintext" key. |
||
| 1043 | */ |
||
| 1044 | public static function plaintextParam( $plaintext ) { |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Substitutes any parameters into the message text. |
||
| 1050 | * |
||
| 1051 | * @since 1.17 |
||
| 1052 | * |
||
| 1053 | * @param string $message The message text. |
||
| 1054 | * @param string $type Either "before" or "after". |
||
| 1055 | * |
||
| 1056 | * @return string |
||
| 1057 | */ |
||
| 1058 | protected function replaceParameters( $message, $type = 'before' ) { |
||
| 1069 | |||
| 1070 | /** |
||
| 1071 | * Extracts the parameter type and preprocessed the value if needed. |
||
| 1072 | * |
||
| 1073 | * @since 1.18 |
||
| 1074 | * |
||
| 1075 | * @param mixed $param Parameter as defined in this class. |
||
| 1076 | * |
||
| 1077 | * @return array Array with the parameter type (either "before" or "after") and the value. |
||
| 1078 | */ |
||
| 1079 | protected function extractParam( $param ) { |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Wrapper for what ever method we use to parse wikitext. |
||
| 1120 | * |
||
| 1121 | * @since 1.17 |
||
| 1122 | * |
||
| 1123 | * @param string $string Wikitext message contents. |
||
| 1124 | * |
||
| 1125 | * @return string Wikitext parsed into HTML. |
||
| 1126 | */ |
||
| 1127 | protected function parseText( $string ) { |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Wrapper for what ever method we use to {{-transform wikitext. |
||
| 1141 | * |
||
| 1142 | * @since 1.17 |
||
| 1143 | * |
||
| 1144 | * @param string $string Wikitext message contents. |
||
| 1145 | * |
||
| 1146 | * @return string Wikitext with {{-constructs replaced with their values. |
||
| 1147 | */ |
||
| 1148 | protected function transformText( $string ) { |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Wrapper for what ever method we use to get message contents. |
||
| 1159 | * |
||
| 1160 | * @since 1.17 |
||
| 1161 | * |
||
| 1162 | * @return string |
||
| 1163 | * @throws MWException If message key array is empty. |
||
| 1164 | */ |
||
| 1165 | protected function fetchMessage() { |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * Formats a message parameter wrapped with 'plaintext'. Ensures that |
||
| 1186 | * the entire string is displayed unchanged when displayed in the output |
||
| 1187 | * format. |
||
| 1188 | * |
||
| 1189 | * @since 1.25 |
||
| 1190 | * |
||
| 1191 | * @param string $plaintext String to ensure plaintext output of |
||
| 1192 | * |
||
| 1193 | * @return string Input plaintext encoded for output to $this->format |
||
| 1194 | */ |
||
| 1195 | protected function formatPlaintext( $plaintext ) { |
||
| 1209 | } |
||
| 1210 | |||
| 1263 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.