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 Title 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 Title, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class Title implements LinkTarget { |
||
| 36 | /** @var HashBagOStuff */ |
||
| 37 | static private $titleCache = null; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Title::newFromText maintains a cache to avoid expensive re-normalization of |
||
| 41 | * commonly used titles. On a batch operation this can become a memory leak |
||
| 42 | * if not bounded. After hitting this many titles reset the cache. |
||
| 43 | */ |
||
| 44 | const CACHE_MAX = 1000; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and friends |
||
| 48 | * to use the master DB |
||
| 49 | */ |
||
| 50 | const GAID_FOR_UPDATE = 1; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @name Private member variables |
||
| 54 | * Please use the accessor functions instead. |
||
| 55 | * @private |
||
| 56 | */ |
||
| 57 | // @{ |
||
| 58 | |||
| 59 | /** @var string Text form (spaces not underscores) of the main part */ |
||
| 60 | public $mTextform = ''; |
||
| 61 | |||
| 62 | /** @var string URL-encoded form of the main part */ |
||
| 63 | public $mUrlform = ''; |
||
| 64 | |||
| 65 | /** @var string Main part with underscores */ |
||
| 66 | public $mDbkeyform = ''; |
||
| 67 | |||
| 68 | /** @var string Database key with the initial letter in the case specified by the user */ |
||
| 69 | protected $mUserCaseDBKey; |
||
| 70 | |||
| 71 | /** @var int Namespace index, i.e. one of the NS_xxxx constants */ |
||
| 72 | public $mNamespace = NS_MAIN; |
||
| 73 | |||
| 74 | /** @var string Interwiki prefix */ |
||
| 75 | public $mInterwiki = ''; |
||
| 76 | |||
| 77 | /** @var bool Was this Title created from a string with a local interwiki prefix? */ |
||
| 78 | private $mLocalInterwiki = false; |
||
| 79 | |||
| 80 | /** @var string Title fragment (i.e. the bit after the #) */ |
||
| 81 | public $mFragment = ''; |
||
| 82 | |||
| 83 | /** @var int Article ID, fetched from the link cache on demand */ |
||
| 84 | public $mArticleID = -1; |
||
| 85 | |||
| 86 | /** @var bool|int ID of most recent revision */ |
||
| 87 | protected $mLatestID = false; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var bool|string ID of the page's content model, i.e. one of the |
||
| 91 | * CONTENT_MODEL_XXX constants |
||
| 92 | */ |
||
| 93 | public $mContentModel = false; |
||
| 94 | |||
| 95 | /** @var int Estimated number of revisions; null of not loaded */ |
||
| 96 | private $mEstimateRevisions; |
||
| 97 | |||
| 98 | /** @var array Array of groups allowed to edit this article */ |
||
| 99 | public $mRestrictions = []; |
||
| 100 | |||
| 101 | /** @var string|bool */ |
||
| 102 | protected $mOldRestrictions = false; |
||
| 103 | |||
| 104 | /** @var bool Cascade restrictions on this page to included templates and images? */ |
||
| 105 | public $mCascadeRestriction; |
||
| 106 | |||
| 107 | /** Caching the results of getCascadeProtectionSources */ |
||
| 108 | public $mCascadingRestrictions; |
||
| 109 | |||
| 110 | /** @var array When do the restrictions on this page expire? */ |
||
| 111 | protected $mRestrictionsExpiry = []; |
||
| 112 | |||
| 113 | /** @var bool Are cascading restrictions in effect on this page? */ |
||
| 114 | protected $mHasCascadingRestrictions; |
||
| 115 | |||
| 116 | /** @var array Where are the cascading restrictions coming from on this page? */ |
||
| 117 | public $mCascadeSources; |
||
| 118 | |||
| 119 | /** @var bool Boolean for initialisation on demand */ |
||
| 120 | public $mRestrictionsLoaded = false; |
||
| 121 | |||
| 122 | /** @var string Text form including namespace/interwiki, initialised on demand */ |
||
| 123 | protected $mPrefixedText = null; |
||
| 124 | |||
| 125 | /** @var mixed Cached value for getTitleProtection (create protection) */ |
||
| 126 | public $mTitleProtection; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var int Namespace index when there is no namespace. Don't change the |
||
| 130 | * following default, NS_MAIN is hardcoded in several places. See bug 696. |
||
| 131 | * Zero except in {{transclusion}} tags. |
||
| 132 | */ |
||
| 133 | public $mDefaultNamespace = NS_MAIN; |
||
| 134 | |||
| 135 | /** @var int The page length, 0 for special pages */ |
||
| 136 | protected $mLength = -1; |
||
| 137 | |||
| 138 | /** @var null Is the article at this title a redirect? */ |
||
| 139 | public $mRedirect = null; |
||
| 140 | |||
| 141 | /** @var array Associative array of user ID -> timestamp/false */ |
||
| 142 | private $mNotificationTimestamp = []; |
||
| 143 | |||
| 144 | /** @var bool Whether a page has any subpages */ |
||
| 145 | private $mHasSubpages; |
||
| 146 | |||
| 147 | /** @var bool The (string) language code of the page's language and content code. */ |
||
| 148 | private $mPageLanguage = false; |
||
| 149 | |||
| 150 | /** @var string|bool|null The page language code from the database, null if not saved in |
||
| 151 | * the database or false if not loaded, yet. */ |
||
| 152 | private $mDbPageLanguage = false; |
||
| 153 | |||
| 154 | /** @var TitleValue A corresponding TitleValue object */ |
||
| 155 | private $mTitleValue = null; |
||
| 156 | |||
| 157 | /** @var bool Would deleting this page be a big deletion? */ |
||
| 158 | private $mIsBigDeletion = null; |
||
| 159 | // @} |
||
| 160 | |||
| 161 | /** |
||
| 162 | * B/C kludge: provide a TitleParser for use by Title. |
||
| 163 | * Ideally, Title would have no methods that need this. |
||
| 164 | * Avoid usage of this singleton by using TitleValue |
||
| 165 | * and the associated services when possible. |
||
| 166 | * |
||
| 167 | * @return TitleFormatter |
||
| 168 | */ |
||
| 169 | private static function getTitleFormatter() { |
||
| 170 | return MediaWikiServices::getInstance()->getTitleFormatter(); |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @access protected |
||
| 175 | */ |
||
| 176 | function __construct() { |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Create a new Title from a prefixed DB key |
||
| 181 | * |
||
| 182 | * @param string $key The database key, which has underscores |
||
| 183 | * instead of spaces, possibly including namespace and |
||
| 184 | * interwiki prefixes |
||
| 185 | * @return Title|null Title, or null on an error |
||
| 186 | */ |
||
| 187 | public static function newFromDBkey( $key ) { |
||
| 188 | $t = new Title(); |
||
| 189 | $t->mDbkeyform = $key; |
||
| 190 | |||
| 191 | try { |
||
| 192 | $t->secureAndSplit(); |
||
| 193 | return $t; |
||
| 194 | } catch ( MalformedTitleException $ex ) { |
||
| 195 | return null; |
||
| 196 | } |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Create a new Title from a TitleValue |
||
| 201 | * |
||
| 202 | * @param TitleValue $titleValue Assumed to be safe. |
||
| 203 | * |
||
| 204 | * @return Title |
||
| 205 | */ |
||
| 206 | public static function newFromTitleValue( TitleValue $titleValue ) { |
||
| 207 | return self::newFromLinkTarget( $titleValue ); |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Create a new Title from a LinkTarget |
||
| 212 | * |
||
| 213 | * @param LinkTarget $linkTarget Assumed to be safe. |
||
| 214 | * |
||
| 215 | * @return Title |
||
| 216 | */ |
||
| 217 | public static function newFromLinkTarget( LinkTarget $linkTarget ) { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Create a new Title from text, such as what one would find in a link. De- |
||
| 232 | * codes any HTML entities in the text. |
||
| 233 | * |
||
| 234 | * @param string|int|null $text The link text; spaces, prefixes, and an |
||
| 235 | * initial ':' indicating the main namespace are accepted. |
||
| 236 | * @param int $defaultNamespace The namespace to use if none is specified |
||
| 237 | * by a prefix. If you want to force a specific namespace even if |
||
| 238 | * $text might begin with a namespace prefix, use makeTitle() or |
||
| 239 | * makeTitleSafe(). |
||
| 240 | * @throws InvalidArgumentException |
||
| 241 | * @return Title|null Title or null on an error. |
||
| 242 | */ |
||
| 243 | public static function newFromText( $text, $defaultNamespace = NS_MAIN ) { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Like Title::newFromText(), but throws MalformedTitleException when the title is invalid, |
||
| 261 | * rather than returning null. |
||
| 262 | * |
||
| 263 | * The exception subclasses encode detailed information about why the title is invalid. |
||
| 264 | * |
||
| 265 | * @see Title::newFromText |
||
| 266 | * |
||
| 267 | * @since 1.25 |
||
| 268 | * @param string $text Title text to check |
||
| 269 | * @param int $defaultNamespace |
||
| 270 | * @throws MalformedTitleException If the title is invalid |
||
| 271 | * @return Title |
||
| 272 | */ |
||
| 273 | public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) { |
||
| 304 | |||
| 305 | /** |
||
| 306 | * THIS IS NOT THE FUNCTION YOU WANT. Use Title::newFromText(). |
||
| 307 | * |
||
| 308 | * Example of wrong and broken code: |
||
| 309 | * $title = Title::newFromURL( $wgRequest->getVal( 'title' ) ); |
||
| 310 | * |
||
| 311 | * Example of right code: |
||
| 312 | * $title = Title::newFromText( $wgRequest->getVal( 'title' ) ); |
||
| 313 | * |
||
| 314 | * Create a new Title from URL-encoded text. Ensures that |
||
| 315 | * the given title's length does not exceed the maximum. |
||
| 316 | * |
||
| 317 | * @param string $url The title, as might be taken from a URL |
||
| 318 | * @return Title|null The new object, or null on an error |
||
| 319 | */ |
||
| 320 | public static function newFromURL( $url ) { |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @return HashBagOStuff |
||
| 342 | */ |
||
| 343 | private static function getTitleCache() { |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Returns a list of fields that are to be selected for initializing Title |
||
| 352 | * objects or LinkCache entries. Uses $wgContentHandlerUseDB to determine |
||
| 353 | * whether to include page_content_model. |
||
| 354 | * |
||
| 355 | * @return array |
||
| 356 | */ |
||
| 357 | View Code Duplication | protected static function getSelectFields() { |
|
| 358 | global $wgContentHandlerUseDB, $wgPageLanguageUseDB; |
||
| 359 | |||
| 360 | $fields = [ |
||
| 361 | 'page_namespace', 'page_title', 'page_id', |
||
| 362 | 'page_len', 'page_is_redirect', 'page_latest', |
||
| 363 | ]; |
||
| 364 | |||
| 365 | if ( $wgContentHandlerUseDB ) { |
||
| 366 | $fields[] = 'page_content_model'; |
||
| 367 | } |
||
| 368 | |||
| 369 | if ( $wgPageLanguageUseDB ) { |
||
| 370 | $fields[] = 'page_lang'; |
||
| 371 | } |
||
| 372 | |||
| 373 | return $fields; |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Create a new Title from an article ID |
||
| 378 | * |
||
| 379 | * @param int $id The page_id corresponding to the Title to create |
||
| 380 | * @param int $flags Use Title::GAID_FOR_UPDATE to use master |
||
| 381 | * @return Title|null The new object, or null on an error |
||
| 382 | */ |
||
| 383 | public static function newFromID( $id, $flags = 0 ) { |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Make an array of titles from an array of IDs |
||
| 401 | * |
||
| 402 | * @param int[] $ids Array of IDs |
||
| 403 | * @return Title[] Array of Titles |
||
| 404 | */ |
||
| 405 | public static function newFromIDs( $ids ) { |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Make a Title object from a DB row |
||
| 427 | * |
||
| 428 | * @param stdClass $row Object database row (needs at least page_title,page_namespace) |
||
| 429 | * @return Title Corresponding Title |
||
| 430 | */ |
||
| 431 | public static function newFromRow( $row ) { |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Load Title object fields from a DB row. |
||
| 439 | * If false is given, the title will be treated as non-existing. |
||
| 440 | * |
||
| 441 | * @param stdClass|bool $row Database row |
||
| 442 | */ |
||
| 443 | public function loadFromRow( $row ) { |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Create a new Title from a namespace index and a DB key. |
||
| 479 | * It's assumed that $ns and $title are *valid*, for instance when |
||
| 480 | * they came directly from the database or a special page name. |
||
| 481 | * For convenience, spaces are converted to underscores so that |
||
| 482 | * eg user_text fields can be used directly. |
||
| 483 | * |
||
| 484 | * @param int $ns The namespace of the article |
||
| 485 | * @param string $title The unprefixed database key form |
||
| 486 | * @param string $fragment The link fragment (after the "#") |
||
| 487 | * @param string $interwiki The interwiki prefix |
||
| 488 | * @return Title The new object |
||
| 489 | */ |
||
| 490 | public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) { |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Create a new Title from a namespace index and a DB key. |
||
| 505 | * The parameters will be checked for validity, which is a bit slower |
||
| 506 | * than makeTitle() but safer for user-provided data. |
||
| 507 | * |
||
| 508 | * @param int $ns The namespace of the article |
||
| 509 | * @param string $title Database key form |
||
| 510 | * @param string $fragment The link fragment (after the "#") |
||
| 511 | * @param string $interwiki Interwiki prefix |
||
| 512 | * @return Title|null The new object, or null on an error |
||
| 513 | */ |
||
| 514 | public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) { |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Create a new Title for the Main Page |
||
| 532 | * |
||
| 533 | * @return Title The new object |
||
| 534 | */ |
||
| 535 | public static function newMainPage() { |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Get the prefixed DB key associated with an ID |
||
| 546 | * |
||
| 547 | * @param int $id The page_id of the article |
||
| 548 | * @return Title|null An object representing the article, or null if no such article was found |
||
| 549 | */ |
||
| 550 | public static function nameOf( $id ) { |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Get a regex character class describing the legal characters in a link |
||
| 569 | * |
||
| 570 | * @return string The list of characters, not delimited |
||
| 571 | */ |
||
| 572 | public static function legalChars() { |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Returns a simple regex that will match on characters and sequences invalid in titles. |
||
| 579 | * Note that this doesn't pick up many things that could be wrong with titles, but that |
||
| 580 | * replacing this regex with something valid will make many titles valid. |
||
| 581 | * |
||
| 582 | * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead |
||
| 583 | * |
||
| 584 | * @return string Regex string |
||
| 585 | */ |
||
| 586 | static function getTitleInvalidRegex() { |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Utility method for converting a character sequence from bytes to Unicode. |
||
| 593 | * |
||
| 594 | * Primary usecase being converting $wgLegalTitleChars to a sequence usable in |
||
| 595 | * javascript, as PHP uses UTF-8 bytes where javascript uses Unicode code units. |
||
| 596 | * |
||
| 597 | * @param string $byteClass |
||
| 598 | * @return string |
||
| 599 | */ |
||
| 600 | public static function convertByteClassToUnicodeClass( $byteClass ) { |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Make a prefixed DB key from a DB key and a namespace index |
||
| 695 | * |
||
| 696 | * @param int $ns Numerical representation of the namespace |
||
| 697 | * @param string $title The DB key form the title |
||
| 698 | * @param string $fragment The link fragment (after the "#") |
||
| 699 | * @param string $interwiki The interwiki prefix |
||
| 700 | * @param bool $canonicalNamespace If true, use the canonical name for |
||
| 701 | * $ns instead of the localized version. |
||
| 702 | * @return string The prefixed form of the title |
||
| 703 | */ |
||
| 704 | public static function makeName( $ns, $title, $fragment = '', $interwiki = '', |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Escape a text fragment, say from a link, for a URL |
||
| 726 | * |
||
| 727 | * @param string $fragment Containing a URL or link fragment (after the "#") |
||
| 728 | * @return string Escaped string |
||
| 729 | */ |
||
| 730 | static function escapeFragmentForURL( $fragment ) { |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Callback for usort() to do title sorts by (namespace, title) |
||
| 740 | * |
||
| 741 | * @param Title $a |
||
| 742 | * @param Title $b |
||
| 743 | * |
||
| 744 | * @return int Result of string comparison, or namespace comparison |
||
| 745 | */ |
||
| 746 | public static function compare( $a, $b ) { |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Determine whether the object refers to a page within |
||
| 756 | * this project (either this wiki or a wiki with a local |
||
| 757 | * interwiki, see https://www.mediawiki.org/wiki/Manual:Interwiki_table#iw_local ) |
||
| 758 | * |
||
| 759 | * @return bool True if this is an in-project interwiki link or a wikilink, false otherwise |
||
| 760 | */ |
||
| 761 | public function isLocal() { |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Is this Title interwiki? |
||
| 773 | * |
||
| 774 | * @return bool |
||
| 775 | */ |
||
| 776 | public function isExternal() { |
||
| 779 | |||
| 780 | /** |
||
| 781 | * Get the interwiki prefix |
||
| 782 | * |
||
| 783 | * Use Title::isExternal to check if a interwiki is set |
||
| 784 | * |
||
| 785 | * @return string Interwiki prefix |
||
| 786 | */ |
||
| 787 | public function getInterwiki() { |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Was this a local interwiki link? |
||
| 793 | * |
||
| 794 | * @return bool |
||
| 795 | */ |
||
| 796 | public function wasLocalInterwiki() { |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Determine whether the object refers to a page within |
||
| 802 | * this project and is transcludable. |
||
| 803 | * |
||
| 804 | * @return bool True if this is transcludable |
||
| 805 | */ |
||
| 806 | public function isTrans() { |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Returns the DB name of the distant wiki which owns the object. |
||
| 816 | * |
||
| 817 | * @return string The DB name |
||
| 818 | */ |
||
| 819 | public function getTransWikiID() { |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Get a TitleValue object representing this Title. |
||
| 829 | * |
||
| 830 | * @note Not all valid Titles have a corresponding valid TitleValue |
||
| 831 | * (e.g. TitleValues cannot represent page-local links that have a |
||
| 832 | * fragment but no title text). |
||
| 833 | * |
||
| 834 | * @return TitleValue|null |
||
| 835 | */ |
||
| 836 | public function getTitleValue() { |
||
| 853 | |||
| 854 | /** |
||
| 855 | * Get the text form (spaces not underscores) of the main part |
||
| 856 | * |
||
| 857 | * @return string Main part of the title |
||
| 858 | */ |
||
| 859 | public function getText() { |
||
| 862 | |||
| 863 | /** |
||
| 864 | * Get the URL-encoded form of the main part |
||
| 865 | * |
||
| 866 | * @return string Main part of the title, URL-encoded |
||
| 867 | */ |
||
| 868 | public function getPartialURL() { |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Get the main part with underscores |
||
| 874 | * |
||
| 875 | * @return string Main part of the title, with underscores |
||
| 876 | */ |
||
| 877 | public function getDBkey() { |
||
| 880 | |||
| 881 | /** |
||
| 882 | * Get the DB key with the initial letter case as specified by the user |
||
| 883 | * |
||
| 884 | * @return string DB key |
||
| 885 | */ |
||
| 886 | function getUserCaseDBKey() { |
||
| 894 | |||
| 895 | /** |
||
| 896 | * Get the namespace index, i.e. one of the NS_xxxx constants. |
||
| 897 | * |
||
| 898 | * @return int Namespace index |
||
| 899 | */ |
||
| 900 | public function getNamespace() { |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Get the page's content model id, see the CONTENT_MODEL_XXX constants. |
||
| 906 | * |
||
| 907 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 908 | * @return string Content model id |
||
| 909 | */ |
||
| 910 | public function getContentModel( $flags = 0 ) { |
||
| 925 | |||
| 926 | /** |
||
| 927 | * Convenience method for checking a title's content model name |
||
| 928 | * |
||
| 929 | * @param string $id The content model ID (use the CONTENT_MODEL_XXX constants). |
||
| 930 | * @return bool True if $this->getContentModel() == $id |
||
| 931 | */ |
||
| 932 | public function hasContentModel( $id ) { |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Get the namespace text |
||
| 938 | * |
||
| 939 | * @return string Namespace text |
||
| 940 | */ |
||
| 941 | public function getNsText() { |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Get the namespace text of the subject (rather than talk) page |
||
| 963 | * |
||
| 964 | * @return string Namespace text |
||
| 965 | */ |
||
| 966 | public function getSubjectNsText() { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Get the namespace text of the talk page |
||
| 973 | * |
||
| 974 | * @return string Namespace text |
||
| 975 | */ |
||
| 976 | public function getTalkNsText() { |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Could this title have a corresponding talk page? |
||
| 983 | * |
||
| 984 | * @return bool |
||
| 985 | */ |
||
| 986 | public function canTalk() { |
||
| 989 | |||
| 990 | /** |
||
| 991 | * Is this in a namespace that allows actual pages? |
||
| 992 | * |
||
| 993 | * @return bool |
||
| 994 | */ |
||
| 995 | public function canExist() { |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Can this title be added to a user's watchlist? |
||
| 1001 | * |
||
| 1002 | * @return bool |
||
| 1003 | */ |
||
| 1004 | public function isWatchable() { |
||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Returns true if this is a special page. |
||
| 1010 | * |
||
| 1011 | * @return bool |
||
| 1012 | */ |
||
| 1013 | public function isSpecialPage() { |
||
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Returns true if this title resolves to the named special page |
||
| 1019 | * |
||
| 1020 | * @param string $name The special page name |
||
| 1021 | * @return bool |
||
| 1022 | */ |
||
| 1023 | public function isSpecial( $name ) { |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * If the Title refers to a special page alias which is not the local default, resolve |
||
| 1035 | * the alias, and localise the name as necessary. Otherwise, return $this |
||
| 1036 | * |
||
| 1037 | * @return Title |
||
| 1038 | */ |
||
| 1039 | public function fixSpecialName() { |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * Returns true if the title is inside the specified namespace. |
||
| 1054 | * |
||
| 1055 | * Please make use of this instead of comparing to getNamespace() |
||
| 1056 | * This function is much more resistant to changes we may make |
||
| 1057 | * to namespaces than code that makes direct comparisons. |
||
| 1058 | * @param int $ns The namespace |
||
| 1059 | * @return bool |
||
| 1060 | * @since 1.19 |
||
| 1061 | */ |
||
| 1062 | public function inNamespace( $ns ) { |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Returns true if the title is inside one of the specified namespaces. |
||
| 1068 | * |
||
| 1069 | * @param int $namespaces,... The namespaces to check for |
||
| 1070 | * @return bool |
||
| 1071 | * @since 1.19 |
||
| 1072 | */ |
||
| 1073 | public function inNamespaces( /* ... */ ) { |
||
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Returns true if the title has the same subject namespace as the |
||
| 1090 | * namespace specified. |
||
| 1091 | * For example this method will take NS_USER and return true if namespace |
||
| 1092 | * is either NS_USER or NS_USER_TALK since both of them have NS_USER |
||
| 1093 | * as their subject namespace. |
||
| 1094 | * |
||
| 1095 | * This is MUCH simpler than individually testing for equivalence |
||
| 1096 | * against both NS_USER and NS_USER_TALK, and is also forward compatible. |
||
| 1097 | * @since 1.19 |
||
| 1098 | * @param int $ns |
||
| 1099 | * @return bool |
||
| 1100 | */ |
||
| 1101 | public function hasSubjectNamespace( $ns ) { |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Is this Title in a namespace which contains content? |
||
| 1107 | * In other words, is this a content page, for the purposes of calculating |
||
| 1108 | * statistics, etc? |
||
| 1109 | * |
||
| 1110 | * @return bool |
||
| 1111 | */ |
||
| 1112 | public function isContentPage() { |
||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Would anybody with sufficient privileges be able to move this page? |
||
| 1118 | * Some pages just aren't movable. |
||
| 1119 | * |
||
| 1120 | * @return bool |
||
| 1121 | */ |
||
| 1122 | public function isMovable() { |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Is this the mainpage? |
||
| 1135 | * @note Title::newFromText seems to be sufficiently optimized by the title |
||
| 1136 | * cache that we don't need to over-optimize by doing direct comparisons and |
||
| 1137 | * accidentally creating new bugs where $title->equals( Title::newFromText() ) |
||
| 1138 | * ends up reporting something differently than $title->isMainPage(); |
||
| 1139 | * |
||
| 1140 | * @since 1.18 |
||
| 1141 | * @return bool |
||
| 1142 | */ |
||
| 1143 | public function isMainPage() { |
||
| 1146 | |||
| 1147 | /** |
||
| 1148 | * Is this a subpage? |
||
| 1149 | * |
||
| 1150 | * @return bool |
||
| 1151 | */ |
||
| 1152 | public function isSubpage() { |
||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Is this a conversion table for the LanguageConverter? |
||
| 1160 | * |
||
| 1161 | * @return bool |
||
| 1162 | */ |
||
| 1163 | public function isConversionTable() { |
||
| 1169 | |||
| 1170 | /** |
||
| 1171 | * Does that page contain wikitext, or it is JS, CSS or whatever? |
||
| 1172 | * |
||
| 1173 | * @return bool |
||
| 1174 | */ |
||
| 1175 | public function isWikitextPage() { |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Could this page contain custom CSS or JavaScript for the global UI. |
||
| 1181 | * This is generally true for pages in the MediaWiki namespace having CONTENT_MODEL_CSS |
||
| 1182 | * or CONTENT_MODEL_JAVASCRIPT. |
||
| 1183 | * |
||
| 1184 | * This method does *not* return true for per-user JS/CSS. Use isCssJsSubpage() |
||
| 1185 | * for that! |
||
| 1186 | * |
||
| 1187 | * Note that this method should not return true for pages that contain and |
||
| 1188 | * show "inactive" CSS or JS. |
||
| 1189 | * |
||
| 1190 | * @return bool |
||
| 1191 | * @todo FIXME: Rename to isSiteConfigPage() and remove deprecated hook |
||
| 1192 | */ |
||
| 1193 | public function isCssOrJsPage() { |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Is this a .css or .js subpage of a user page? |
||
| 1209 | * @return bool |
||
| 1210 | * @todo FIXME: Rename to isUserConfigPage() |
||
| 1211 | */ |
||
| 1212 | public function isCssJsSubpage() { |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Trim down a .css or .js subpage title to get the corresponding skin name |
||
| 1220 | * |
||
| 1221 | * @return string Containing skin name from .css or .js subpage title |
||
| 1222 | */ |
||
| 1223 | public function getSkinFromCssJsSubpage() { |
||
| 1232 | |||
| 1233 | /** |
||
| 1234 | * Is this a .css subpage of a user page? |
||
| 1235 | * |
||
| 1236 | * @return bool |
||
| 1237 | */ |
||
| 1238 | public function isCssSubpage() { |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Is this a .js subpage of a user page? |
||
| 1245 | * |
||
| 1246 | * @return bool |
||
| 1247 | */ |
||
| 1248 | public function isJsSubpage() { |
||
| 1252 | |||
| 1253 | /** |
||
| 1254 | * Is this a talk page of some sort? |
||
| 1255 | * |
||
| 1256 | * @return bool |
||
| 1257 | */ |
||
| 1258 | public function isTalkPage() { |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Get a Title object associated with the talk page of this article |
||
| 1264 | * |
||
| 1265 | * @return Title The object for the talk page |
||
| 1266 | */ |
||
| 1267 | public function getTalkPage() { |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Get a title object associated with the subject page of this |
||
| 1273 | * talk page |
||
| 1274 | * |
||
| 1275 | * @return Title The object for the subject page |
||
| 1276 | */ |
||
| 1277 | public function getSubjectPage() { |
||
| 1285 | |||
| 1286 | /** |
||
| 1287 | * Get the other title for this page, if this is a subject page |
||
| 1288 | * get the talk page, if it is a subject page get the talk page |
||
| 1289 | * |
||
| 1290 | * @since 1.25 |
||
| 1291 | * @throws MWException |
||
| 1292 | * @return Title |
||
| 1293 | */ |
||
| 1294 | public function getOtherPage() { |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * Get the default namespace index, for when there is no namespace |
||
| 1307 | * |
||
| 1308 | * @return int Default namespace index |
||
| 1309 | */ |
||
| 1310 | public function getDefaultNamespace() { |
||
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Get the Title fragment (i.e.\ the bit after the #) in text form |
||
| 1316 | * |
||
| 1317 | * Use Title::hasFragment to check for a fragment |
||
| 1318 | * |
||
| 1319 | * @return string Title fragment |
||
| 1320 | */ |
||
| 1321 | public function getFragment() { |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Check if a Title fragment is set |
||
| 1327 | * |
||
| 1328 | * @return bool |
||
| 1329 | * @since 1.23 |
||
| 1330 | */ |
||
| 1331 | public function hasFragment() { |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * Get the fragment in URL form, including the "#" character if there is one |
||
| 1337 | * @return string Fragment in URL form |
||
| 1338 | */ |
||
| 1339 | public function getFragmentForURL() { |
||
| 1346 | |||
| 1347 | /** |
||
| 1348 | * Set the fragment for this title. Removes the first character from the |
||
| 1349 | * specified fragment before setting, so it assumes you're passing it with |
||
| 1350 | * an initial "#". |
||
| 1351 | * |
||
| 1352 | * Deprecated for public use, use Title::makeTitle() with fragment parameter, |
||
| 1353 | * or Title::createFragmentTarget(). |
||
| 1354 | * Still in active use privately. |
||
| 1355 | * |
||
| 1356 | * @private |
||
| 1357 | * @param string $fragment Text |
||
| 1358 | */ |
||
| 1359 | public function setFragment( $fragment ) { |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * Creates a new Title for a different fragment of the same page. |
||
| 1365 | * |
||
| 1366 | * @since 1.27 |
||
| 1367 | * @param string $fragment |
||
| 1368 | * @return Title |
||
| 1369 | */ |
||
| 1370 | public function createFragmentTarget( $fragment ) { |
||
| 1379 | |||
| 1380 | /** |
||
| 1381 | * Prefix some arbitrary text with the namespace or interwiki prefix |
||
| 1382 | * of this object |
||
| 1383 | * |
||
| 1384 | * @param string $name The text |
||
| 1385 | * @return string The prefixed text |
||
| 1386 | */ |
||
| 1387 | private function prefix( $name ) { |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Get the prefixed database key form |
||
| 1401 | * |
||
| 1402 | * @return string The prefixed title, with underscores and |
||
| 1403 | * any interwiki and namespace prefixes |
||
| 1404 | */ |
||
| 1405 | public function getPrefixedDBkey() { |
||
| 1410 | |||
| 1411 | /** |
||
| 1412 | * Get the prefixed title with spaces. |
||
| 1413 | * This is the form usually used for display |
||
| 1414 | * |
||
| 1415 | * @return string The prefixed title, with spaces |
||
| 1416 | */ |
||
| 1417 | public function getPrefixedText() { |
||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * Return a string representation of this title |
||
| 1428 | * |
||
| 1429 | * @return string Representation of this title |
||
| 1430 | */ |
||
| 1431 | public function __toString() { |
||
| 1434 | |||
| 1435 | /** |
||
| 1436 | * Get the prefixed title with spaces, plus any fragment |
||
| 1437 | * (part beginning with '#') |
||
| 1438 | * |
||
| 1439 | * @return string The prefixed title, with spaces and the fragment, including '#' |
||
| 1440 | */ |
||
| 1441 | public function getFullText() { |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Get the root page name text without a namespace, i.e. the leftmost part before any slashes |
||
| 1451 | * |
||
| 1452 | * @par Example: |
||
| 1453 | * @code |
||
| 1454 | * Title::newFromText('User:Foo/Bar/Baz')->getRootText(); |
||
| 1455 | * # returns: 'Foo' |
||
| 1456 | * @endcode |
||
| 1457 | * |
||
| 1458 | * @return string Root name |
||
| 1459 | * @since 1.20 |
||
| 1460 | */ |
||
| 1461 | public function getRootText() { |
||
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Get the root page name title, i.e. the leftmost part before any slashes |
||
| 1471 | * |
||
| 1472 | * @par Example: |
||
| 1473 | * @code |
||
| 1474 | * Title::newFromText('User:Foo/Bar/Baz')->getRootTitle(); |
||
| 1475 | * # returns: Title{User:Foo} |
||
| 1476 | * @endcode |
||
| 1477 | * |
||
| 1478 | * @return Title Root title |
||
| 1479 | * @since 1.20 |
||
| 1480 | */ |
||
| 1481 | public function getRootTitle() { |
||
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Get the base page name without a namespace, i.e. the part before the subpage name |
||
| 1487 | * |
||
| 1488 | * @par Example: |
||
| 1489 | * @code |
||
| 1490 | * Title::newFromText('User:Foo/Bar/Baz')->getBaseText(); |
||
| 1491 | * # returns: 'Foo/Bar' |
||
| 1492 | * @endcode |
||
| 1493 | * |
||
| 1494 | * @return string Base name |
||
| 1495 | */ |
||
| 1496 | public function getBaseText() { |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * Get the base page name title, i.e. the part before the subpage name |
||
| 1511 | * |
||
| 1512 | * @par Example: |
||
| 1513 | * @code |
||
| 1514 | * Title::newFromText('User:Foo/Bar/Baz')->getBaseTitle(); |
||
| 1515 | * # returns: Title{User:Foo/Bar} |
||
| 1516 | * @endcode |
||
| 1517 | * |
||
| 1518 | * @return Title Base title |
||
| 1519 | * @since 1.20 |
||
| 1520 | */ |
||
| 1521 | public function getBaseTitle() { |
||
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Get the lowest-level subpage name, i.e. the rightmost part after any slashes |
||
| 1527 | * |
||
| 1528 | * @par Example: |
||
| 1529 | * @code |
||
| 1530 | * Title::newFromText('User:Foo/Bar/Baz')->getSubpageText(); |
||
| 1531 | * # returns: "Baz" |
||
| 1532 | * @endcode |
||
| 1533 | * |
||
| 1534 | * @return string Subpage name |
||
| 1535 | */ |
||
| 1536 | public function getSubpageText() { |
||
| 1543 | |||
| 1544 | /** |
||
| 1545 | * Get the title for a subpage of the current page |
||
| 1546 | * |
||
| 1547 | * @par Example: |
||
| 1548 | * @code |
||
| 1549 | * Title::newFromText('User:Foo/Bar/Baz')->getSubpage("Asdf"); |
||
| 1550 | * # returns: Title{User:Foo/Bar/Baz/Asdf} |
||
| 1551 | * @endcode |
||
| 1552 | * |
||
| 1553 | * @param string $text The subpage name to add to the title |
||
| 1554 | * @return Title Subpage title |
||
| 1555 | * @since 1.20 |
||
| 1556 | */ |
||
| 1557 | public function getSubpage( $text ) { |
||
| 1560 | |||
| 1561 | /** |
||
| 1562 | * Get a URL-encoded form of the subpage text |
||
| 1563 | * |
||
| 1564 | * @return string URL-encoded subpage name |
||
| 1565 | */ |
||
| 1566 | public function getSubpageUrlForm() { |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Get a URL-encoded title (not an actual URL) including interwiki |
||
| 1574 | * |
||
| 1575 | * @return string The URL-encoded form |
||
| 1576 | */ |
||
| 1577 | public function getPrefixedURL() { |
||
| 1582 | |||
| 1583 | /** |
||
| 1584 | * Helper to fix up the get{Canonical,Full,Link,Local,Internal}URL args |
||
| 1585 | * get{Canonical,Full,Link,Local,Internal}URL methods accepted an optional |
||
| 1586 | * second argument named variant. This was deprecated in favor |
||
| 1587 | * of passing an array of option with a "variant" key |
||
| 1588 | * Once $query2 is removed for good, this helper can be dropped |
||
| 1589 | * and the wfArrayToCgi moved to getLocalURL(); |
||
| 1590 | * |
||
| 1591 | * @since 1.19 (r105919) |
||
| 1592 | * @param array|string $query |
||
| 1593 | * @param bool $query2 |
||
| 1594 | * @return string |
||
| 1595 | */ |
||
| 1596 | private static function fixUrlQueryArgs( $query, $query2 = false ) { |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * Get a real URL referring to this title, with interwiki link and |
||
| 1625 | * fragment |
||
| 1626 | * |
||
| 1627 | * @see self::getLocalURL for the arguments. |
||
| 1628 | * @see wfExpandUrl |
||
| 1629 | * @param array|string $query |
||
| 1630 | * @param bool $query2 |
||
| 1631 | * @param string $proto Protocol type to use in URL |
||
| 1632 | * @return string The URL |
||
| 1633 | */ |
||
| 1634 | public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) { |
||
| 1651 | |||
| 1652 | /** |
||
| 1653 | * Get a URL with no fragment or server name (relative URL) from a Title object. |
||
| 1654 | * If this page is generated with action=render, however, |
||
| 1655 | * $wgServer is prepended to make an absolute URL. |
||
| 1656 | * |
||
| 1657 | * @see self::getFullURL to always get an absolute URL. |
||
| 1658 | * @see self::getLinkURL to always get a URL that's the simplest URL that will be |
||
| 1659 | * valid to link, locally, to the current Title. |
||
| 1660 | * @see self::newFromText to produce a Title object. |
||
| 1661 | * |
||
| 1662 | * @param string|array $query An optional query string, |
||
| 1663 | * not used for interwiki links. Can be specified as an associative array as well, |
||
| 1664 | * e.g., array( 'action' => 'edit' ) (keys and values will be URL-escaped). |
||
| 1665 | * Some query patterns will trigger various shorturl path replacements. |
||
| 1666 | * @param array $query2 An optional secondary query array. This one MUST |
||
| 1667 | * be an array. If a string is passed it will be interpreted as a deprecated |
||
| 1668 | * variant argument and urlencoded into a variant= argument. |
||
| 1669 | * This second query argument will be added to the $query |
||
| 1670 | * The second parameter is deprecated since 1.19. Pass it as a key,value |
||
| 1671 | * pair in the first parameter array instead. |
||
| 1672 | * |
||
| 1673 | * @return string String of the URL. |
||
| 1674 | */ |
||
| 1675 | public function getLocalURL( $query = '', $query2 = false ) { |
||
| 1750 | |||
| 1751 | /** |
||
| 1752 | * Get a URL that's the simplest URL that will be valid to link, locally, |
||
| 1753 | * to the current Title. It includes the fragment, but does not include |
||
| 1754 | * the server unless action=render is used (or the link is external). If |
||
| 1755 | * there's a fragment but the prefixed text is empty, we just return a link |
||
| 1756 | * to the fragment. |
||
| 1757 | * |
||
| 1758 | * The result obviously should not be URL-escaped, but does need to be |
||
| 1759 | * HTML-escaped if it's being output in HTML. |
||
| 1760 | * |
||
| 1761 | * @param array $query |
||
| 1762 | * @param bool $query2 |
||
| 1763 | * @param string $proto Protocol to use; setting this will cause a full URL to be used |
||
| 1764 | * @see self::getLocalURL for the arguments. |
||
| 1765 | * @return string The URL |
||
| 1766 | */ |
||
| 1767 | public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) { |
||
| 1777 | |||
| 1778 | /** |
||
| 1779 | * Get the URL form for an internal link. |
||
| 1780 | * - Used in various CDN-related code, in case we have a different |
||
| 1781 | * internal hostname for the server from the exposed one. |
||
| 1782 | * |
||
| 1783 | * This uses $wgInternalServer to qualify the path, or $wgServer |
||
| 1784 | * if $wgInternalServer is not set. If the server variable used is |
||
| 1785 | * protocol-relative, the URL will be expanded to http:// |
||
| 1786 | * |
||
| 1787 | * @see self::getLocalURL for the arguments. |
||
| 1788 | * @return string The URL |
||
| 1789 | */ |
||
| 1790 | public function getInternalURL( $query = '', $query2 = false ) { |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * Get the URL for a canonical link, for use in things like IRC and |
||
| 1801 | * e-mail notifications. Uses $wgCanonicalServer and the |
||
| 1802 | * GetCanonicalURL hook. |
||
| 1803 | * |
||
| 1804 | * NOTE: Unlike getInternalURL(), the canonical URL includes the fragment |
||
| 1805 | * |
||
| 1806 | * @see self::getLocalURL for the arguments. |
||
| 1807 | * @return string The URL |
||
| 1808 | * @since 1.18 |
||
| 1809 | */ |
||
| 1810 | public function getCanonicalURL( $query = '', $query2 = false ) { |
||
| 1816 | |||
| 1817 | /** |
||
| 1818 | * Get the edit URL for this Title |
||
| 1819 | * |
||
| 1820 | * @return string The URL, or a null string if this is an interwiki link |
||
| 1821 | */ |
||
| 1822 | public function getEditURL() { |
||
| 1830 | |||
| 1831 | /** |
||
| 1832 | * Can $user perform $action on this page? |
||
| 1833 | * This skips potentially expensive cascading permission checks |
||
| 1834 | * as well as avoids expensive error formatting |
||
| 1835 | * |
||
| 1836 | * Suitable for use for nonessential UI controls in common cases, but |
||
| 1837 | * _not_ for functional access control. |
||
| 1838 | * |
||
| 1839 | * May provide false positives, but should never provide a false negative. |
||
| 1840 | * |
||
| 1841 | * @param string $action Action that permission needs to be checked for |
||
| 1842 | * @param User $user User to check (since 1.19); $wgUser will be used if not provided. |
||
| 1843 | * @return bool |
||
| 1844 | */ |
||
| 1845 | public function quickUserCan( $action, $user = null ) { |
||
| 1848 | |||
| 1849 | /** |
||
| 1850 | * Can $user perform $action on this page? |
||
| 1851 | * |
||
| 1852 | * @param string $action Action that permission needs to be checked for |
||
| 1853 | * @param User $user User to check (since 1.19); $wgUser will be used if not |
||
| 1854 | * provided. |
||
| 1855 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 1856 | * @return bool |
||
| 1857 | */ |
||
| 1858 | public function userCan( $action, $user = null, $rigor = 'secure' ) { |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Can $user perform $action on this page? |
||
| 1869 | * |
||
| 1870 | * @todo FIXME: This *does not* check throttles (User::pingLimiter()). |
||
| 1871 | * |
||
| 1872 | * @param string $action Action that permission needs to be checked for |
||
| 1873 | * @param User $user User to check |
||
| 1874 | * @param string $rigor One of (quick,full,secure) |
||
| 1875 | * - quick : does cheap permission checks from slaves (usable for GUI creation) |
||
| 1876 | * - full : does cheap and expensive checks possibly from a slave |
||
| 1877 | * - secure : does cheap and expensive checks, using the master as needed |
||
| 1878 | * @param array $ignoreErrors Array of Strings Set this to a list of message keys |
||
| 1879 | * whose corresponding errors may be ignored. |
||
| 1880 | * @return array Array of arrays of the arguments to wfMessage to explain permissions problems. |
||
| 1881 | */ |
||
| 1882 | public function getUserPermissionsErrors( |
||
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Permissions checks that fail most often, and which are easiest to test. |
||
| 1904 | * |
||
| 1905 | * @param string $action The action to check |
||
| 1906 | * @param User $user User to check |
||
| 1907 | * @param array $errors List of current errors |
||
| 1908 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 1909 | * @param bool $short Short circuit on first error |
||
| 1910 | * |
||
| 1911 | * @return array List of errors |
||
| 1912 | */ |
||
| 1913 | private function checkQuickPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Add the resulting error code to the errors array |
||
| 1977 | * |
||
| 1978 | * @param array $errors List of current errors |
||
| 1979 | * @param array $result Result of errors |
||
| 1980 | * |
||
| 1981 | * @return array List of errors |
||
| 1982 | */ |
||
| 1983 | private function resultToError( $errors, $result ) { |
||
| 2002 | |||
| 2003 | /** |
||
| 2004 | * Check various permission hooks |
||
| 2005 | * |
||
| 2006 | * @param string $action The action to check |
||
| 2007 | * @param User $user User to check |
||
| 2008 | * @param array $errors List of current errors |
||
| 2009 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2010 | * @param bool $short Short circuit on first error |
||
| 2011 | * |
||
| 2012 | * @return array List of errors |
||
| 2013 | */ |
||
| 2014 | private function checkPermissionHooks( $action, $user, $errors, $rigor, $short ) { |
||
| 2035 | |||
| 2036 | /** |
||
| 2037 | * Check permissions on special pages & namespaces |
||
| 2038 | * |
||
| 2039 | * @param string $action The action to check |
||
| 2040 | * @param User $user User to check |
||
| 2041 | * @param array $errors List of current errors |
||
| 2042 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2043 | * @param bool $short Short circuit on first error |
||
| 2044 | * |
||
| 2045 | * @return array List of errors |
||
| 2046 | */ |
||
| 2047 | private function checkSpecialsAndNSPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2064 | |||
| 2065 | /** |
||
| 2066 | * Check CSS/JS sub-page permissions |
||
| 2067 | * |
||
| 2068 | * @param string $action The action to check |
||
| 2069 | * @param User $user User to check |
||
| 2070 | * @param array $errors List of current errors |
||
| 2071 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2072 | * @param bool $short Short circuit on first error |
||
| 2073 | * |
||
| 2074 | * @return array List of errors |
||
| 2075 | */ |
||
| 2076 | private function checkCSSandJSPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2098 | |||
| 2099 | /** |
||
| 2100 | * Check against page_restrictions table requirements on this |
||
| 2101 | * page. The user must possess all required rights for this |
||
| 2102 | * action. |
||
| 2103 | * |
||
| 2104 | * @param string $action The action to check |
||
| 2105 | * @param User $user User to check |
||
| 2106 | * @param array $errors List of current errors |
||
| 2107 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2108 | * @param bool $short Short circuit on first error |
||
| 2109 | * |
||
| 2110 | * @return array List of errors |
||
| 2111 | */ |
||
| 2112 | private function checkPageRestrictions( $action, $user, $errors, $rigor, $short ) { |
||
| 2134 | |||
| 2135 | /** |
||
| 2136 | * Check restrictions on cascading pages. |
||
| 2137 | * |
||
| 2138 | * @param string $action The action to check |
||
| 2139 | * @param User $user User to check |
||
| 2140 | * @param array $errors List of current errors |
||
| 2141 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2142 | * @param bool $short Short circuit on first error |
||
| 2143 | * |
||
| 2144 | * @return array List of errors |
||
| 2145 | */ |
||
| 2146 | private function checkCascadingSourcesRestrictions( $action, $user, $errors, $rigor, $short ) { |
||
| 2181 | |||
| 2182 | /** |
||
| 2183 | * Check action permissions not already checked in checkQuickPermissions |
||
| 2184 | * |
||
| 2185 | * @param string $action The action to check |
||
| 2186 | * @param User $user User to check |
||
| 2187 | * @param array $errors List of current errors |
||
| 2188 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2189 | * @param bool $short Short circuit on first error |
||
| 2190 | * |
||
| 2191 | * @return array List of errors |
||
| 2192 | */ |
||
| 2193 | private function checkActionPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2247 | |||
| 2248 | /** |
||
| 2249 | * Check that the user isn't blocked from editing. |
||
| 2250 | * |
||
| 2251 | * @param string $action The action to check |
||
| 2252 | * @param User $user User to check |
||
| 2253 | * @param array $errors List of current errors |
||
| 2254 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2255 | * @param bool $short Short circuit on first error |
||
| 2256 | * |
||
| 2257 | * @return array List of errors |
||
| 2258 | */ |
||
| 2259 | private function checkUserBlock( $action, $user, $errors, $rigor, $short ) { |
||
| 2285 | |||
| 2286 | /** |
||
| 2287 | * Check that the user is allowed to read this page. |
||
| 2288 | * |
||
| 2289 | * @param string $action The action to check |
||
| 2290 | * @param User $user User to check |
||
| 2291 | * @param array $errors List of current errors |
||
| 2292 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2293 | * @param bool $short Short circuit on first error |
||
| 2294 | * |
||
| 2295 | * @return array List of errors |
||
| 2296 | */ |
||
| 2297 | private function checkReadPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2363 | |||
| 2364 | /** |
||
| 2365 | * Get a description array when the user doesn't have the right to perform |
||
| 2366 | * $action (i.e. when User::isAllowed() returns false) |
||
| 2367 | * |
||
| 2368 | * @param string $action The action to check |
||
| 2369 | * @param bool $short Short circuit on first error |
||
| 2370 | * @return array List of errors |
||
| 2371 | */ |
||
| 2372 | private function missingPermissionError( $action, $short ) { |
||
| 2392 | |||
| 2393 | /** |
||
| 2394 | * Can $user perform $action on this page? This is an internal function, |
||
| 2395 | * with multiple levels of checks depending on performance needs; see $rigor below. |
||
| 2396 | * It does not check wfReadOnly(). |
||
| 2397 | * |
||
| 2398 | * @param string $action Action that permission needs to be checked for |
||
| 2399 | * @param User $user User to check |
||
| 2400 | * @param string $rigor One of (quick,full,secure) |
||
| 2401 | * - quick : does cheap permission checks from slaves (usable for GUI creation) |
||
| 2402 | * - full : does cheap and expensive checks possibly from a slave |
||
| 2403 | * - secure : does cheap and expensive checks, using the master as needed |
||
| 2404 | * @param bool $short Set this to true to stop after the first permission error. |
||
| 2405 | * @return array Array of arrays of the arguments to wfMessage to explain permissions problems. |
||
| 2406 | */ |
||
| 2407 | protected function getUserPermissionsErrorsInternal( |
||
| 2459 | |||
| 2460 | /** |
||
| 2461 | * Get a filtered list of all restriction types supported by this wiki. |
||
| 2462 | * @param bool $exists True to get all restriction types that apply to |
||
| 2463 | * titles that do exist, False for all restriction types that apply to |
||
| 2464 | * titles that do not exist |
||
| 2465 | * @return array |
||
| 2466 | */ |
||
| 2467 | public static function getFilteredRestrictionTypes( $exists = true ) { |
||
| 2479 | |||
| 2480 | /** |
||
| 2481 | * Returns restriction types for the current Title |
||
| 2482 | * |
||
| 2483 | * @return array Applicable restriction types |
||
| 2484 | */ |
||
| 2485 | public function getRestrictionTypes() { |
||
| 2504 | |||
| 2505 | /** |
||
| 2506 | * Is this title subject to title protection? |
||
| 2507 | * Title protection is the one applied against creation of such title. |
||
| 2508 | * |
||
| 2509 | * @return array|bool An associative array representing any existent title |
||
| 2510 | * protection, or false if there's none. |
||
| 2511 | */ |
||
| 2512 | public function getTitleProtection() { |
||
| 2552 | |||
| 2553 | /** |
||
| 2554 | * Remove any title protection due to page existing |
||
| 2555 | */ |
||
| 2556 | public function deleteTitleProtection() { |
||
| 2566 | |||
| 2567 | /** |
||
| 2568 | * Is this page "semi-protected" - the *only* protection levels are listed |
||
| 2569 | * in $wgSemiprotectedRestrictionLevels? |
||
| 2570 | * |
||
| 2571 | * @param string $action Action to check (default: edit) |
||
| 2572 | * @return bool |
||
| 2573 | */ |
||
| 2574 | public function isSemiProtected( $action = 'edit' ) { |
||
| 2594 | |||
| 2595 | /** |
||
| 2596 | * Does the title correspond to a protected article? |
||
| 2597 | * |
||
| 2598 | * @param string $action The action the page is protected from, |
||
| 2599 | * by default checks all actions. |
||
| 2600 | * @return bool |
||
| 2601 | */ |
||
| 2602 | public function isProtected( $action = '' ) { |
||
| 2626 | |||
| 2627 | /** |
||
| 2628 | * Determines if $user is unable to edit this page because it has been protected |
||
| 2629 | * by $wgNamespaceProtection. |
||
| 2630 | * |
||
| 2631 | * @param User $user User object to check permissions |
||
| 2632 | * @return bool |
||
| 2633 | */ |
||
| 2634 | public function isNamespaceProtected( User $user ) { |
||
| 2646 | |||
| 2647 | /** |
||
| 2648 | * Cascading protection: Return true if cascading restrictions apply to this page, false if not. |
||
| 2649 | * |
||
| 2650 | * @return bool If the page is subject to cascading restrictions. |
||
| 2651 | */ |
||
| 2652 | public function isCascadeProtected() { |
||
| 2656 | |||
| 2657 | /** |
||
| 2658 | * Determines whether cascading protection sources have already been loaded from |
||
| 2659 | * the database. |
||
| 2660 | * |
||
| 2661 | * @param bool $getPages True to check if the pages are loaded, or false to check |
||
| 2662 | * if the status is loaded. |
||
| 2663 | * @return bool Whether or not the specified information has been loaded |
||
| 2664 | * @since 1.23 |
||
| 2665 | */ |
||
| 2666 | public function areCascadeProtectionSourcesLoaded( $getPages = true ) { |
||
| 2669 | |||
| 2670 | /** |
||
| 2671 | * Cascading protection: Get the source of any cascading restrictions on this page. |
||
| 2672 | * |
||
| 2673 | * @param bool $getPages Whether or not to retrieve the actual pages |
||
| 2674 | * that the restrictions have come from and the actual restrictions |
||
| 2675 | * themselves. |
||
| 2676 | * @return array Two elements: First is an array of Title objects of the |
||
| 2677 | * pages from which cascading restrictions have come, false for |
||
| 2678 | * none, or true if such restrictions exist but $getPages was not |
||
| 2679 | * set. Second is an array like that returned by |
||
| 2680 | * Title::getAllRestrictions(), or an empty array if $getPages is |
||
| 2681 | * false. |
||
| 2682 | */ |
||
| 2683 | public function getCascadeProtectionSources( $getPages = true ) { |
||
| 2761 | |||
| 2762 | /** |
||
| 2763 | * Accessor for mRestrictionsLoaded |
||
| 2764 | * |
||
| 2765 | * @return bool Whether or not the page's restrictions have already been |
||
| 2766 | * loaded from the database |
||
| 2767 | * @since 1.23 |
||
| 2768 | */ |
||
| 2769 | public function areRestrictionsLoaded() { |
||
| 2772 | |||
| 2773 | /** |
||
| 2774 | * Accessor/initialisation for mRestrictions |
||
| 2775 | * |
||
| 2776 | * @param string $action Action that permission needs to be checked for |
||
| 2777 | * @return array Restriction levels needed to take the action. All levels are |
||
| 2778 | * required. Note that restriction levels are normally user rights, but 'sysop' |
||
| 2779 | * and 'autoconfirmed' are also allowed for backwards compatibility. These should |
||
| 2780 | * be mapped to 'editprotected' and 'editsemiprotected' respectively. |
||
| 2781 | */ |
||
| 2782 | public function getRestrictions( $action ) { |
||
| 2790 | |||
| 2791 | /** |
||
| 2792 | * Accessor/initialisation for mRestrictions |
||
| 2793 | * |
||
| 2794 | * @return array Keys are actions, values are arrays as returned by |
||
| 2795 | * Title::getRestrictions() |
||
| 2796 | * @since 1.23 |
||
| 2797 | */ |
||
| 2798 | public function getAllRestrictions() { |
||
| 2804 | |||
| 2805 | /** |
||
| 2806 | * Get the expiry time for the restriction against a given action |
||
| 2807 | * |
||
| 2808 | * @param string $action |
||
| 2809 | * @return string|bool 14-char timestamp, or 'infinity' if the page is protected forever |
||
| 2810 | * or not protected at all, or false if the action is not recognised. |
||
| 2811 | */ |
||
| 2812 | public function getRestrictionExpiry( $action ) { |
||
| 2818 | |||
| 2819 | /** |
||
| 2820 | * Returns cascading restrictions for the current article |
||
| 2821 | * |
||
| 2822 | * @return bool |
||
| 2823 | */ |
||
| 2824 | function areRestrictionsCascading() { |
||
| 2831 | |||
| 2832 | /** |
||
| 2833 | * Loads a string into mRestrictions array |
||
| 2834 | * |
||
| 2835 | * @param ResultWrapper $res Resource restrictions as an SQL result. |
||
| 2836 | * @param string $oldFashionedRestrictions Comma-separated list of page |
||
| 2837 | * restrictions from page table (pre 1.10) |
||
| 2838 | */ |
||
| 2839 | private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) { |
||
| 2848 | |||
| 2849 | /** |
||
| 2850 | * Compiles list of active page restrictions from both page table (pre 1.10) |
||
| 2851 | * and page_restrictions table for this existing page. |
||
| 2852 | * Public for usage by LiquidThreads. |
||
| 2853 | * |
||
| 2854 | * @param array $rows Array of db result objects |
||
| 2855 | * @param string $oldFashionedRestrictions Comma-separated list of page |
||
| 2856 | * restrictions from page table (pre 1.10) |
||
| 2857 | */ |
||
| 2858 | public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { |
||
| 2924 | |||
| 2925 | /** |
||
| 2926 | * Load restrictions from the page_restrictions table |
||
| 2927 | * |
||
| 2928 | * @param string $oldFashionedRestrictions Comma-separated list of page |
||
| 2929 | * restrictions from page table (pre 1.10) |
||
| 2930 | */ |
||
| 2931 | public function loadRestrictions( $oldFashionedRestrictions = null ) { |
||
| 2964 | |||
| 2965 | /** |
||
| 2966 | * Flush the protection cache in this object and force reload from the database. |
||
| 2967 | * This is used when updating protection from WikiPage::doUpdateRestrictions(). |
||
| 2968 | */ |
||
| 2969 | public function flushRestrictions() { |
||
| 2973 | |||
| 2974 | /** |
||
| 2975 | * Purge expired restrictions from the page_restrictions table |
||
| 2976 | * |
||
| 2977 | * This will purge no more than $wgUpdateRowsPerQuery page_restrictions rows |
||
| 2978 | */ |
||
| 2979 | static function purgeExpiredRestrictions() { |
||
| 3014 | |||
| 3015 | /** |
||
| 3016 | * Does this have subpages? (Warning, usually requires an extra DB query.) |
||
| 3017 | * |
||
| 3018 | * @return bool |
||
| 3019 | */ |
||
| 3020 | public function hasSubpages() { |
||
| 3040 | |||
| 3041 | /** |
||
| 3042 | * Get all subpages of this page. |
||
| 3043 | * |
||
| 3044 | * @param int $limit Maximum number of subpages to fetch; -1 for no limit |
||
| 3045 | * @return TitleArray|array TitleArray, or empty array if this page's namespace |
||
| 3046 | * doesn't allow subpages |
||
| 3047 | */ |
||
| 3048 | public function getSubpages( $limit = -1 ) { |
||
| 3070 | |||
| 3071 | /** |
||
| 3072 | * Is there a version of this page in the deletion archive? |
||
| 3073 | * |
||
| 3074 | * @return int The number of archived revisions |
||
| 3075 | */ |
||
| 3076 | public function isDeleted() { |
||
| 3095 | |||
| 3096 | /** |
||
| 3097 | * Is there a version of this page in the deletion archive? |
||
| 3098 | * |
||
| 3099 | * @return bool |
||
| 3100 | */ |
||
| 3101 | public function isDeletedQuick() { |
||
| 3118 | |||
| 3119 | /** |
||
| 3120 | * Get the article ID for this Title from the link cache, |
||
| 3121 | * adding it if necessary |
||
| 3122 | * |
||
| 3123 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select |
||
| 3124 | * for update |
||
| 3125 | * @return int The ID |
||
| 3126 | */ |
||
| 3127 | public function getArticleID( $flags = 0 ) { |
||
| 3145 | |||
| 3146 | /** |
||
| 3147 | * Is this an article that is a redirect page? |
||
| 3148 | * Uses link cache, adding it if necessary |
||
| 3149 | * |
||
| 3150 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 3151 | * @return bool |
||
| 3152 | */ |
||
| 3153 | public function isRedirect( $flags = 0 ) { |
||
| 3180 | |||
| 3181 | /** |
||
| 3182 | * What is the length of this page? |
||
| 3183 | * Uses link cache, adding it if necessary |
||
| 3184 | * |
||
| 3185 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 3186 | * @return int |
||
| 3187 | */ |
||
| 3188 | public function getLength( $flags = 0 ) { |
||
| 3209 | |||
| 3210 | /** |
||
| 3211 | * What is the page_latest field for this page? |
||
| 3212 | * |
||
| 3213 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 3214 | * @return int Int or 0 if the page doesn't exist |
||
| 3215 | */ |
||
| 3216 | public function getLatestRevID( $flags = 0 ) { |
||
| 3237 | |||
| 3238 | /** |
||
| 3239 | * This clears some fields in this object, and clears any associated |
||
| 3240 | * keys in the "bad links" section of the link cache. |
||
| 3241 | * |
||
| 3242 | * - This is called from WikiPage::doEdit() and WikiPage::insertOn() to allow |
||
| 3243 | * loading of the new page_id. It's also called from |
||
| 3244 | * WikiPage::doDeleteArticleReal() |
||
| 3245 | * |
||
| 3246 | * @param int $newid The new Article ID |
||
| 3247 | */ |
||
| 3248 | public function resetArticleID( $newid ) { |
||
| 3269 | |||
| 3270 | public static function clearCaches() { |
||
| 3277 | |||
| 3278 | /** |
||
| 3279 | * Capitalize a text string for a title if it belongs to a namespace that capitalizes |
||
| 3280 | * |
||
| 3281 | * @param string $text Containing title to capitalize |
||
| 3282 | * @param int $ns Namespace index, defaults to NS_MAIN |
||
| 3283 | * @return string Containing capitalized title |
||
| 3284 | */ |
||
| 3285 | public static function capitalize( $text, $ns = NS_MAIN ) { |
||
| 3294 | |||
| 3295 | /** |
||
| 3296 | * Secure and split - main initialisation function for this object |
||
| 3297 | * |
||
| 3298 | * Assumes that mDbkeyform has been set, and is urldecoded |
||
| 3299 | * and uses underscores, but not otherwise munged. This function |
||
| 3300 | * removes illegal characters, splits off the interwiki and |
||
| 3301 | * namespace prefixes, sets the other forms, and canonicalizes |
||
| 3302 | * everything. |
||
| 3303 | * |
||
| 3304 | * @throws MalformedTitleException On invalid titles |
||
| 3305 | * @return bool True on success |
||
| 3306 | */ |
||
| 3307 | private function secureAndSplit() { |
||
| 3342 | |||
| 3343 | /** |
||
| 3344 | * Get an array of Title objects linking to this Title |
||
| 3345 | * Also stores the IDs in the link cache. |
||
| 3346 | * |
||
| 3347 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3348 | * On heavily-used templates it will max out the memory. |
||
| 3349 | * |
||
| 3350 | * @param array $options May be FOR UPDATE |
||
| 3351 | * @param string $table Table name |
||
| 3352 | * @param string $prefix Fields prefix |
||
| 3353 | * @return Title[] Array of Title objects linking here |
||
| 3354 | */ |
||
| 3355 | public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) { |
||
| 3386 | |||
| 3387 | /** |
||
| 3388 | * Get an array of Title objects using this Title as a template |
||
| 3389 | * Also stores the IDs in the link cache. |
||
| 3390 | * |
||
| 3391 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3392 | * On heavily-used templates it will max out the memory. |
||
| 3393 | * |
||
| 3394 | * @param array $options Query option to Database::select() |
||
| 3395 | * @return Title[] Array of Title the Title objects linking here |
||
| 3396 | */ |
||
| 3397 | public function getTemplateLinksTo( $options = [] ) { |
||
| 3400 | |||
| 3401 | /** |
||
| 3402 | * Get an array of Title objects linked from this Title |
||
| 3403 | * Also stores the IDs in the link cache. |
||
| 3404 | * |
||
| 3405 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3406 | * On heavily-used templates it will max out the memory. |
||
| 3407 | * |
||
| 3408 | * @param array $options Query option to Database::select() |
||
| 3409 | * @param string $table Table name |
||
| 3410 | * @param string $prefix Fields prefix |
||
| 3411 | * @return array Array of Title objects linking here |
||
| 3412 | */ |
||
| 3413 | public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) { |
||
| 3455 | |||
| 3456 | /** |
||
| 3457 | * Get an array of Title objects used on this Title as a template |
||
| 3458 | * Also stores the IDs in the link cache. |
||
| 3459 | * |
||
| 3460 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3461 | * On heavily-used templates it will max out the memory. |
||
| 3462 | * |
||
| 3463 | * @param array $options May be FOR UPDATE |
||
| 3464 | * @return Title[] Array of Title the Title objects used here |
||
| 3465 | */ |
||
| 3466 | public function getTemplateLinksFrom( $options = [] ) { |
||
| 3469 | |||
| 3470 | /** |
||
| 3471 | * Get an array of Title objects referring to non-existent articles linked |
||
| 3472 | * from this page. |
||
| 3473 | * |
||
| 3474 | * @todo check if needed (used only in SpecialBrokenRedirects.php, and |
||
| 3475 | * should use redirect table in this case). |
||
| 3476 | * @return Title[] Array of Title the Title objects |
||
| 3477 | */ |
||
| 3478 | public function getBrokenLinksFrom() { |
||
| 3507 | |||
| 3508 | /** |
||
| 3509 | * Get a list of URLs to purge from the CDN cache when this |
||
| 3510 | * page changes |
||
| 3511 | * |
||
| 3512 | * @return string[] Array of String the URLs |
||
| 3513 | */ |
||
| 3514 | public function getCdnUrls() { |
||
| 3538 | |||
| 3539 | /** |
||
| 3540 | * @deprecated since 1.27 use getCdnUrls() |
||
| 3541 | */ |
||
| 3542 | public function getSquidURLs() { |
||
| 3545 | |||
| 3546 | /** |
||
| 3547 | * Purge all applicable CDN URLs |
||
| 3548 | */ |
||
| 3549 | public function purgeSquid() { |
||
| 3555 | |||
| 3556 | /** |
||
| 3557 | * Move this page without authentication |
||
| 3558 | * |
||
| 3559 | * @deprecated since 1.25 use MovePage class instead |
||
| 3560 | * @param Title $nt The new page Title |
||
| 3561 | * @return array|bool True on success, getUserPermissionsErrors()-like array on failure |
||
| 3562 | */ |
||
| 3563 | public function moveNoAuth( &$nt ) { |
||
| 3567 | |||
| 3568 | /** |
||
| 3569 | * Check whether a given move operation would be valid. |
||
| 3570 | * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise |
||
| 3571 | * |
||
| 3572 | * @deprecated since 1.25, use MovePage's methods instead |
||
| 3573 | * @param Title $nt The new title |
||
| 3574 | * @param bool $auth Whether to check user permissions (uses $wgUser) |
||
| 3575 | * @param string $reason Is the log summary of the move, used for spam checking |
||
| 3576 | * @return array|bool True on success, getUserPermissionsErrors()-like array on failure |
||
| 3577 | */ |
||
| 3578 | public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) { |
||
| 3598 | |||
| 3599 | /** |
||
| 3600 | * Check if the requested move target is a valid file move target |
||
| 3601 | * @todo move this to MovePage |
||
| 3602 | * @param Title $nt Target title |
||
| 3603 | * @return array List of errors |
||
| 3604 | */ |
||
| 3605 | protected function validateFileMoveOperation( $nt ) { |
||
| 3620 | |||
| 3621 | /** |
||
| 3622 | * Move a title to a new location |
||
| 3623 | * |
||
| 3624 | * @deprecated since 1.25, use the MovePage class instead |
||
| 3625 | * @param Title $nt The new title |
||
| 3626 | * @param bool $auth Indicates whether $wgUser's permissions |
||
| 3627 | * should be checked |
||
| 3628 | * @param string $reason The reason for the move |
||
| 3629 | * @param bool $createRedirect Whether to create a redirect from the old title to the new title. |
||
| 3630 | * Ignored if the user doesn't have the suppressredirect right. |
||
| 3631 | * @return array|bool True on success, getUserPermissionsErrors()-like array on failure |
||
| 3632 | */ |
||
| 3633 | public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) { |
||
| 3654 | |||
| 3655 | /** |
||
| 3656 | * Move this page's subpages to be subpages of $nt |
||
| 3657 | * |
||
| 3658 | * @param Title $nt Move target |
||
| 3659 | * @param bool $auth Whether $wgUser's permissions should be checked |
||
| 3660 | * @param string $reason The reason for the move |
||
| 3661 | * @param bool $createRedirect Whether to create redirects from the old subpages to |
||
| 3662 | * the new ones Ignored if the user doesn't have the 'suppressredirect' right |
||
| 3663 | * @return array Array with old page titles as keys, and strings (new page titles) or |
||
| 3664 | * arrays (errors) as values, or an error array with numeric indices if no pages |
||
| 3665 | * were moved |
||
| 3666 | */ |
||
| 3667 | public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) { |
||
| 3727 | |||
| 3728 | /** |
||
| 3729 | * Checks if this page is just a one-rev redirect. |
||
| 3730 | * Adds lock, so don't use just for light purposes. |
||
| 3731 | * |
||
| 3732 | * @return bool |
||
| 3733 | */ |
||
| 3734 | public function isSingleRevRedirect() { |
||
| 3776 | |||
| 3777 | /** |
||
| 3778 | * Checks if $this can be moved to a given Title |
||
| 3779 | * - Selects for update, so don't call it unless you mean business |
||
| 3780 | * |
||
| 3781 | * @deprecated since 1.25, use MovePage's methods instead |
||
| 3782 | * @param Title $nt The new title to check |
||
| 3783 | * @return bool |
||
| 3784 | */ |
||
| 3785 | public function isValidMoveTarget( $nt ) { |
||
| 3825 | |||
| 3826 | /** |
||
| 3827 | * Get categories to which this Title belongs and return an array of |
||
| 3828 | * categories' names. |
||
| 3829 | * |
||
| 3830 | * @return array Array of parents in the form: |
||
| 3831 | * $parent => $currentarticle |
||
| 3832 | */ |
||
| 3833 | public function getParentCategories() { |
||
| 3861 | |||
| 3862 | /** |
||
| 3863 | * Get a tree of parent categories |
||
| 3864 | * |
||
| 3865 | * @param array $children Array with the children in the keys, to check for circular refs |
||
| 3866 | * @return array Tree of parent categories |
||
| 3867 | */ |
||
| 3868 | public function getParentCategoryTree( $children = [] ) { |
||
| 3888 | |||
| 3889 | /** |
||
| 3890 | * Get an associative array for selecting this title from |
||
| 3891 | * the "page" table |
||
| 3892 | * |
||
| 3893 | * @return array Array suitable for the $where parameter of DB::select() |
||
| 3894 | */ |
||
| 3895 | public function pageCond() { |
||
| 3903 | |||
| 3904 | /** |
||
| 3905 | * Get the revision ID of the previous revision |
||
| 3906 | * |
||
| 3907 | * @param int $revId Revision ID. Get the revision that was before this one. |
||
| 3908 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3909 | * @return int|bool Old revision ID, or false if none exists |
||
| 3910 | */ |
||
| 3911 | View Code Duplication | public function getPreviousRevisionID( $revId, $flags = 0 ) { |
|
| 3928 | |||
| 3929 | /** |
||
| 3930 | * Get the revision ID of the next revision |
||
| 3931 | * |
||
| 3932 | * @param int $revId Revision ID. Get the revision that was after this one. |
||
| 3933 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3934 | * @return int|bool Next revision ID, or false if none exists |
||
| 3935 | */ |
||
| 3936 | View Code Duplication | public function getNextRevisionID( $revId, $flags = 0 ) { |
|
| 3953 | |||
| 3954 | /** |
||
| 3955 | * Get the first revision of the page |
||
| 3956 | * |
||
| 3957 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3958 | * @return Revision|null If page doesn't exist |
||
| 3959 | */ |
||
| 3960 | public function getFirstRevision( $flags = 0 ) { |
||
| 3975 | |||
| 3976 | /** |
||
| 3977 | * Get the oldest revision timestamp of this page |
||
| 3978 | * |
||
| 3979 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3980 | * @return string MW timestamp |
||
| 3981 | */ |
||
| 3982 | public function getEarliestRevTime( $flags = 0 ) { |
||
| 3986 | |||
| 3987 | /** |
||
| 3988 | * Check if this is a new page |
||
| 3989 | * |
||
| 3990 | * @return bool |
||
| 3991 | */ |
||
| 3992 | public function isNewPage() { |
||
| 3996 | |||
| 3997 | /** |
||
| 3998 | * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit |
||
| 3999 | * |
||
| 4000 | * @return bool |
||
| 4001 | */ |
||
| 4002 | public function isBigDeletion() { |
||
| 4025 | |||
| 4026 | /** |
||
| 4027 | * Get the approximate revision count of this page. |
||
| 4028 | * |
||
| 4029 | * @return int |
||
| 4030 | */ |
||
| 4031 | public function estimateRevisionCount() { |
||
| 4044 | |||
| 4045 | /** |
||
| 4046 | * Get the number of revisions between the given revision. |
||
| 4047 | * Used for diffs and other things that really need it. |
||
| 4048 | * |
||
| 4049 | * @param int|Revision $old Old revision or rev ID (first before range) |
||
| 4050 | * @param int|Revision $new New revision or rev ID (first after range) |
||
| 4051 | * @param int|null $max Limit of Revisions to count, will be incremented to detect truncations |
||
| 4052 | * @return int Number of revisions between these revisions. |
||
| 4053 | */ |
||
| 4054 | public function countRevisionsBetween( $old, $new, $max = null ) { |
||
| 4080 | |||
| 4081 | /** |
||
| 4082 | * Get the authors between the given revisions or revision IDs. |
||
| 4083 | * Used for diffs and other things that really need it. |
||
| 4084 | * |
||
| 4085 | * @since 1.23 |
||
| 4086 | * |
||
| 4087 | * @param int|Revision $old Old revision or rev ID (first before range by default) |
||
| 4088 | * @param int|Revision $new New revision or rev ID (first after range by default) |
||
| 4089 | * @param int $limit Maximum number of authors |
||
| 4090 | * @param string|array $options (Optional): Single option, or an array of options: |
||
| 4091 | * 'include_old' Include $old in the range; $new is excluded. |
||
| 4092 | * 'include_new' Include $new in the range; $old is excluded. |
||
| 4093 | * 'include_both' Include both $old and $new in the range. |
||
| 4094 | * Unknown option values are ignored. |
||
| 4095 | * @return array|null Names of revision authors in the range; null if not both revisions exist |
||
| 4096 | */ |
||
| 4097 | public function getAuthorsBetween( $old, $new, $limit, $options = [] ) { |
||
| 4156 | |||
| 4157 | /** |
||
| 4158 | * Get the number of authors between the given revisions or revision IDs. |
||
| 4159 | * Used for diffs and other things that really need it. |
||
| 4160 | * |
||
| 4161 | * @param int|Revision $old Old revision or rev ID (first before range by default) |
||
| 4162 | * @param int|Revision $new New revision or rev ID (first after range by default) |
||
| 4163 | * @param int $limit Maximum number of authors |
||
| 4164 | * @param string|array $options (Optional): Single option, or an array of options: |
||
| 4165 | * 'include_old' Include $old in the range; $new is excluded. |
||
| 4166 | * 'include_new' Include $new in the range; $old is excluded. |
||
| 4167 | * 'include_both' Include both $old and $new in the range. |
||
| 4168 | * Unknown option values are ignored. |
||
| 4169 | * @return int Number of revision authors in the range; zero if not both revisions exist |
||
| 4170 | */ |
||
| 4171 | public function countAuthorsBetween( $old, $new, $limit, $options = [] ) { |
||
| 4175 | |||
| 4176 | /** |
||
| 4177 | * Compare with another title. |
||
| 4178 | * |
||
| 4179 | * @param Title $title |
||
| 4180 | * @return bool |
||
| 4181 | */ |
||
| 4182 | public function equals( Title $title ) { |
||
| 4188 | |||
| 4189 | /** |
||
| 4190 | * Check if this title is a subpage of another title |
||
| 4191 | * |
||
| 4192 | * @param Title $title |
||
| 4193 | * @return bool |
||
| 4194 | */ |
||
| 4195 | public function isSubpageOf( Title $title ) { |
||
| 4200 | |||
| 4201 | /** |
||
| 4202 | * Check if page exists. For historical reasons, this function simply |
||
| 4203 | * checks for the existence of the title in the page table, and will |
||
| 4204 | * thus return false for interwiki links, special pages and the like. |
||
| 4205 | * If you want to know if a title can be meaningfully viewed, you should |
||
| 4206 | * probably call the isKnown() method instead. |
||
| 4207 | * |
||
| 4208 | * @param int $flags An optional bit field; may be Title::GAID_FOR_UPDATE to check |
||
| 4209 | * from master/for update |
||
| 4210 | * @return bool |
||
| 4211 | */ |
||
| 4212 | public function exists( $flags = 0 ) { |
||
| 4217 | |||
| 4218 | /** |
||
| 4219 | * Should links to this title be shown as potentially viewable (i.e. as |
||
| 4220 | * "bluelinks"), even if there's no record by this title in the page |
||
| 4221 | * table? |
||
| 4222 | * |
||
| 4223 | * This function is semi-deprecated for public use, as well as somewhat |
||
| 4224 | * misleadingly named. You probably just want to call isKnown(), which |
||
| 4225 | * calls this function internally. |
||
| 4226 | * |
||
| 4227 | * (ISSUE: Most of these checks are cheap, but the file existence check |
||
| 4228 | * can potentially be quite expensive. Including it here fixes a lot of |
||
| 4229 | * existing code, but we might want to add an optional parameter to skip |
||
| 4230 | * it and any other expensive checks.) |
||
| 4231 | * |
||
| 4232 | * @return bool |
||
| 4233 | */ |
||
| 4234 | public function isAlwaysKnown() { |
||
| 4275 | |||
| 4276 | /** |
||
| 4277 | * Does this title refer to a page that can (or might) be meaningfully |
||
| 4278 | * viewed? In particular, this function may be used to determine if |
||
| 4279 | * links to the title should be rendered as "bluelinks" (as opposed to |
||
| 4280 | * "redlinks" to non-existent pages). |
||
| 4281 | * Adding something else to this function will cause inconsistency |
||
| 4282 | * since LinkHolderArray calls isAlwaysKnown() and does its own |
||
| 4283 | * page existence check. |
||
| 4284 | * |
||
| 4285 | * @return bool |
||
| 4286 | */ |
||
| 4287 | public function isKnown() { |
||
| 4290 | |||
| 4291 | /** |
||
| 4292 | * Does this page have source text? |
||
| 4293 | * |
||
| 4294 | * @return bool |
||
| 4295 | */ |
||
| 4296 | public function hasSourceText() { |
||
| 4316 | |||
| 4317 | /** |
||
| 4318 | * Get the default message text or false if the message doesn't exist |
||
| 4319 | * |
||
| 4320 | * @return string|bool |
||
| 4321 | */ |
||
| 4322 | public function getDefaultMessageText() { |
||
| 4340 | |||
| 4341 | /** |
||
| 4342 | * Updates page_touched for this page; called from LinksUpdate.php |
||
| 4343 | * |
||
| 4344 | * @param string $purgeTime [optional] TS_MW timestamp |
||
| 4345 | * @return bool True if the update succeeded |
||
| 4346 | */ |
||
| 4347 | public function invalidateCache( $purgeTime = null ) { |
||
| 4372 | |||
| 4373 | /** |
||
| 4374 | * Update page_touched timestamps and send CDN purge messages for |
||
| 4375 | * pages linking to this title. May be sent to the job queue depending |
||
| 4376 | * on the number of links. Typically called on create and delete. |
||
| 4377 | */ |
||
| 4378 | public function touchLinks() { |
||
| 4384 | |||
| 4385 | /** |
||
| 4386 | * Get the last touched timestamp |
||
| 4387 | * |
||
| 4388 | * @param IDatabase $db Optional db |
||
| 4389 | * @return string Last-touched timestamp |
||
| 4390 | */ |
||
| 4391 | public function getTouched( $db = null ) { |
||
| 4398 | |||
| 4399 | /** |
||
| 4400 | * Get the timestamp when this page was updated since the user last saw it. |
||
| 4401 | * |
||
| 4402 | * @param User $user |
||
| 4403 | * @return string|null |
||
| 4404 | */ |
||
| 4405 | public function getNotificationTimestamp( $user = null ) { |
||
| 4436 | |||
| 4437 | /** |
||
| 4438 | * Generate strings used for xml 'id' names in monobook tabs |
||
| 4439 | * |
||
| 4440 | * @param string $prepend Defaults to 'nstab-' |
||
| 4441 | * @return string XML 'id' name |
||
| 4442 | */ |
||
| 4443 | public function getNamespaceKey( $prepend = 'nstab-' ) { |
||
| 4467 | |||
| 4468 | /** |
||
| 4469 | * Get all extant redirects to this Title |
||
| 4470 | * |
||
| 4471 | * @param int|null $ns Single namespace to consider; null to consider all namespaces |
||
| 4472 | * @return Title[] Array of Title redirects to this title |
||
| 4473 | */ |
||
| 4474 | public function getRedirectsHere( $ns = null ) { |
||
| 4504 | |||
| 4505 | /** |
||
| 4506 | * Check if this Title is a valid redirect target |
||
| 4507 | * |
||
| 4508 | * @return bool |
||
| 4509 | */ |
||
| 4510 | public function isValidRedirectTarget() { |
||
| 4528 | |||
| 4529 | /** |
||
| 4530 | * Get a backlink cache object |
||
| 4531 | * |
||
| 4532 | * @return BacklinkCache |
||
| 4533 | */ |
||
| 4534 | public function getBacklinkCache() { |
||
| 4537 | |||
| 4538 | /** |
||
| 4539 | * Whether the magic words __INDEX__ and __NOINDEX__ function for this page. |
||
| 4540 | * |
||
| 4541 | * @return bool |
||
| 4542 | */ |
||
| 4543 | public function canUseNoindex() { |
||
| 4553 | |||
| 4554 | /** |
||
| 4555 | * Returns the raw sort key to be used for categories, with the specified |
||
| 4556 | * prefix. This will be fed to Collation::getSortKey() to get a |
||
| 4557 | * binary sortkey that can be used for actual sorting. |
||
| 4558 | * |
||
| 4559 | * @param string $prefix The prefix to be used, specified using |
||
| 4560 | * {{defaultsort:}} or like [[Category:Foo|prefix]]. Empty for no |
||
| 4561 | * prefix. |
||
| 4562 | * @return string |
||
| 4563 | */ |
||
| 4564 | public function getCategorySortkey( $prefix = '' ) { |
||
| 4582 | |||
| 4583 | /** |
||
| 4584 | * Returns the page language code saved in the database, if $wgPageLanguageUseDB is set |
||
| 4585 | * to true in LocalSettings.php, otherwise returns false. If there is no language saved in |
||
| 4586 | * the db, it will return NULL. |
||
| 4587 | * |
||
| 4588 | * @return string|null|bool |
||
| 4589 | */ |
||
| 4590 | private function getDbPageLanguageCode() { |
||
| 4603 | |||
| 4604 | /** |
||
| 4605 | * Get the language in which the content of this page is written in |
||
| 4606 | * wikitext. Defaults to $wgContLang, but in certain cases it can be |
||
| 4607 | * e.g. $wgLang (such as special pages, which are in the user language). |
||
| 4608 | * |
||
| 4609 | * @since 1.18 |
||
| 4610 | * @return Language |
||
| 4611 | */ |
||
| 4612 | public function getPageLanguage() { |
||
| 4641 | |||
| 4642 | /** |
||
| 4643 | * Get the language in which the content of this page is written when |
||
| 4644 | * viewed by user. Defaults to $wgContLang, but in certain cases it can be |
||
| 4645 | * e.g. $wgLang (such as special pages, which are in the user language). |
||
| 4646 | * |
||
| 4647 | * @since 1.20 |
||
| 4648 | * @return Language |
||
| 4649 | */ |
||
| 4650 | public function getPageViewLanguage() { |
||
| 4683 | |||
| 4684 | /** |
||
| 4685 | * Get a list of rendered edit notices for this page. |
||
| 4686 | * |
||
| 4687 | * Array is keyed by the original message key, and values are rendered using parseAsBlock, so |
||
| 4688 | * they will already be wrapped in paragraphs. |
||
| 4689 | * |
||
| 4690 | * @since 1.21 |
||
| 4691 | * @param int $oldid Revision ID that's being edited |
||
| 4692 | * @return array |
||
| 4693 | */ |
||
| 4694 | public function getEditNotices( $oldid = 0 ) { |
||
| 4761 | |||
| 4762 | /** |
||
| 4763 | * @return array |
||
| 4764 | */ |
||
| 4765 | public function __sleep() { |
||
| 4776 | |||
| 4777 | public function __wakeup() { |
||
| 4782 | |||
| 4783 | } |
||
| 4784 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.