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 |
||
| 33 | class Title implements LinkTarget { |
||
| 34 | /** @var HashBagOStuff */ |
||
| 35 | static private $titleCache = null; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Title::newFromText maintains a cache to avoid expensive re-normalization of |
||
| 39 | * commonly used titles. On a batch operation this can become a memory leak |
||
| 40 | * if not bounded. After hitting this many titles reset the cache. |
||
| 41 | */ |
||
| 42 | const CACHE_MAX = 1000; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and friends |
||
| 46 | * to use the master DB |
||
| 47 | */ |
||
| 48 | const GAID_FOR_UPDATE = 1; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @name Private member variables |
||
| 52 | * Please use the accessor functions instead. |
||
| 53 | * @private |
||
| 54 | */ |
||
| 55 | // @{ |
||
| 56 | |||
| 57 | /** @var string Text form (spaces not underscores) of the main part */ |
||
| 58 | public $mTextform = ''; |
||
| 59 | |||
| 60 | /** @var string URL-encoded form of the main part */ |
||
| 61 | public $mUrlform = ''; |
||
| 62 | |||
| 63 | /** @var string Main part with underscores */ |
||
| 64 | public $mDbkeyform = ''; |
||
| 65 | |||
| 66 | /** @var string Database key with the initial letter in the case specified by the user */ |
||
| 67 | protected $mUserCaseDBKey; |
||
| 68 | |||
| 69 | /** @var int Namespace index, i.e. one of the NS_xxxx constants */ |
||
| 70 | public $mNamespace = NS_MAIN; |
||
| 71 | |||
| 72 | /** @var string Interwiki prefix */ |
||
| 73 | public $mInterwiki = ''; |
||
| 74 | |||
| 75 | /** @var bool Was this Title created from a string with a local interwiki prefix? */ |
||
| 76 | private $mLocalInterwiki = false; |
||
| 77 | |||
| 78 | /** @var string Title fragment (i.e. the bit after the #) */ |
||
| 79 | public $mFragment = ''; |
||
| 80 | |||
| 81 | /** @var int Article ID, fetched from the link cache on demand */ |
||
| 82 | public $mArticleID = -1; |
||
| 83 | |||
| 84 | /** @var bool|int ID of most recent revision */ |
||
| 85 | protected $mLatestID = false; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var bool|string ID of the page's content model, i.e. one of the |
||
| 89 | * CONTENT_MODEL_XXX constants |
||
| 90 | */ |
||
| 91 | public $mContentModel = false; |
||
| 92 | |||
| 93 | /** @var int Estimated number of revisions; null of not loaded */ |
||
| 94 | private $mEstimateRevisions; |
||
| 95 | |||
| 96 | /** @var array Array of groups allowed to edit this article */ |
||
| 97 | public $mRestrictions = []; |
||
| 98 | |||
| 99 | /** @var string|bool */ |
||
| 100 | protected $mOldRestrictions = false; |
||
| 101 | |||
| 102 | /** @var bool Cascade restrictions on this page to included templates and images? */ |
||
| 103 | public $mCascadeRestriction; |
||
| 104 | |||
| 105 | /** Caching the results of getCascadeProtectionSources */ |
||
| 106 | public $mCascadingRestrictions; |
||
| 107 | |||
| 108 | /** @var array When do the restrictions on this page expire? */ |
||
| 109 | protected $mRestrictionsExpiry = []; |
||
| 110 | |||
| 111 | /** @var bool Are cascading restrictions in effect on this page? */ |
||
| 112 | protected $mHasCascadingRestrictions; |
||
| 113 | |||
| 114 | /** @var array Where are the cascading restrictions coming from on this page? */ |
||
| 115 | public $mCascadeSources; |
||
| 116 | |||
| 117 | /** @var bool Boolean for initialisation on demand */ |
||
| 118 | public $mRestrictionsLoaded = false; |
||
| 119 | |||
| 120 | /** @var string Text form including namespace/interwiki, initialised on demand */ |
||
| 121 | protected $mPrefixedText = null; |
||
| 122 | |||
| 123 | /** @var mixed Cached value for getTitleProtection (create protection) */ |
||
| 124 | public $mTitleProtection; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var int Namespace index when there is no namespace. Don't change the |
||
| 128 | * following default, NS_MAIN is hardcoded in several places. See bug 696. |
||
| 129 | * Zero except in {{transclusion}} tags. |
||
| 130 | */ |
||
| 131 | public $mDefaultNamespace = NS_MAIN; |
||
| 132 | |||
| 133 | /** @var int The page length, 0 for special pages */ |
||
| 134 | protected $mLength = -1; |
||
| 135 | |||
| 136 | /** @var null Is the article at this title a redirect? */ |
||
| 137 | public $mRedirect = null; |
||
| 138 | |||
| 139 | /** @var array Associative array of user ID -> timestamp/false */ |
||
| 140 | private $mNotificationTimestamp = []; |
||
| 141 | |||
| 142 | /** @var bool Whether a page has any subpages */ |
||
| 143 | private $mHasSubpages; |
||
| 144 | |||
| 145 | /** @var bool The (string) language code of the page's language and content code. */ |
||
| 146 | private $mPageLanguage = false; |
||
| 147 | |||
| 148 | /** @var string|bool|null The page language code from the database, null if not saved in |
||
| 149 | * the database or false if not loaded, yet. */ |
||
| 150 | private $mDbPageLanguage = false; |
||
| 151 | |||
| 152 | /** @var TitleValue A corresponding TitleValue object */ |
||
| 153 | private $mTitleValue = null; |
||
| 154 | |||
| 155 | /** @var bool Would deleting this page be a big deletion? */ |
||
| 156 | private $mIsBigDeletion = null; |
||
| 157 | // @} |
||
| 158 | |||
| 159 | /** |
||
| 160 | * B/C kludge: provide a TitleParser for use by Title. |
||
| 161 | * Ideally, Title would have no methods that need this. |
||
| 162 | * Avoid usage of this singleton by using TitleValue |
||
| 163 | * and the associated services when possible. |
||
| 164 | * |
||
| 165 | * @return MediaWikiTitleCodec |
||
| 166 | */ |
||
| 167 | private static function getMediaWikiTitleCodec() { |
||
| 194 | |||
| 195 | /** |
||
| 196 | * B/C kludge: provide a TitleParser for use by Title. |
||
| 197 | * Ideally, Title would have no methods that need this. |
||
| 198 | * Avoid usage of this singleton by using TitleValue |
||
| 199 | * and the associated services when possible. |
||
| 200 | * |
||
| 201 | * @return TitleFormatter |
||
| 202 | */ |
||
| 203 | private static function getTitleFormatter() { |
||
| 208 | |||
| 209 | function __construct() { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Create a new Title from a prefixed DB key |
||
| 214 | * |
||
| 215 | * @param string $key The database key, which has underscores |
||
| 216 | * instead of spaces, possibly including namespace and |
||
| 217 | * interwiki prefixes |
||
| 218 | * @return Title|null Title, or null on an error |
||
| 219 | */ |
||
| 220 | public static function newFromDBkey( $key ) { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Create a new Title from a TitleValue |
||
| 234 | * |
||
| 235 | * @param TitleValue $titleValue Assumed to be safe. |
||
| 236 | * |
||
| 237 | * @return Title |
||
| 238 | */ |
||
| 239 | public static function newFromTitleValue( TitleValue $titleValue ) { |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Create a new Title from a LinkTarget |
||
| 245 | * |
||
| 246 | * @param LinkTarget $linkTarget Assumed to be safe. |
||
| 247 | * |
||
| 248 | * @return Title |
||
| 249 | */ |
||
| 250 | public static function newFromLinkTarget( LinkTarget $linkTarget ) { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Create a new Title from text, such as what one would find in a link. De- |
||
| 259 | * codes any HTML entities in the text. |
||
| 260 | * |
||
| 261 | * @param string|int|null $text The link text; spaces, prefixes, and an |
||
| 262 | * initial ':' indicating the main namespace are accepted. |
||
| 263 | * @param int $defaultNamespace The namespace to use if none is specified |
||
| 264 | * by a prefix. If you want to force a specific namespace even if |
||
| 265 | * $text might begin with a namespace prefix, use makeTitle() or |
||
| 266 | * makeTitleSafe(). |
||
| 267 | * @throws InvalidArgumentException |
||
| 268 | * @return Title|null Title or null on an error. |
||
| 269 | */ |
||
| 270 | public static function newFromText( $text, $defaultNamespace = NS_MAIN ) { |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Like Title::newFromText(), but throws MalformedTitleException when the title is invalid, |
||
| 292 | * rather than returning null. |
||
| 293 | * |
||
| 294 | * The exception subclasses encode detailed information about why the title is invalid. |
||
| 295 | * |
||
| 296 | * @see Title::newFromText |
||
| 297 | * |
||
| 298 | * @since 1.25 |
||
| 299 | * @param string $text Title text to check |
||
| 300 | * @param int $defaultNamespace |
||
| 301 | * @throws MalformedTitleException If the title is invalid |
||
| 302 | * @return Title |
||
| 303 | */ |
||
| 304 | public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) { |
||
| 335 | |||
| 336 | /** |
||
| 337 | * THIS IS NOT THE FUNCTION YOU WANT. Use Title::newFromText(). |
||
| 338 | * |
||
| 339 | * Example of wrong and broken code: |
||
| 340 | * $title = Title::newFromURL( $wgRequest->getVal( 'title' ) ); |
||
| 341 | * |
||
| 342 | * Example of right code: |
||
| 343 | * $title = Title::newFromText( $wgRequest->getVal( 'title' ) ); |
||
| 344 | * |
||
| 345 | * Create a new Title from URL-encoded text. Ensures that |
||
| 346 | * the given title's length does not exceed the maximum. |
||
| 347 | * |
||
| 348 | * @param string $url The title, as might be taken from a URL |
||
| 349 | * @return Title|null The new object, or null on an error |
||
| 350 | */ |
||
| 351 | public static function newFromURL( $url ) { |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @return HashBagOStuff |
||
| 373 | */ |
||
| 374 | private static function getTitleCache() { |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Returns a list of fields that are to be selected for initializing Title |
||
| 383 | * objects or LinkCache entries. Uses $wgContentHandlerUseDB to determine |
||
| 384 | * whether to include page_content_model. |
||
| 385 | * |
||
| 386 | * @return array |
||
| 387 | */ |
||
| 388 | protected static function getSelectFields() { |
||
| 389 | global $wgContentHandlerUseDB, $wgPageLanguageUseDB; |
||
| 390 | |||
| 391 | $fields = [ |
||
| 392 | 'page_namespace', 'page_title', 'page_id', |
||
| 393 | 'page_len', 'page_is_redirect', 'page_latest', |
||
| 394 | ]; |
||
| 395 | |||
| 396 | if ( $wgContentHandlerUseDB ) { |
||
| 397 | $fields[] = 'page_content_model'; |
||
| 398 | } |
||
| 399 | |||
| 400 | if ( $wgPageLanguageUseDB ) { |
||
| 401 | $fields[] = 'page_lang'; |
||
| 402 | } |
||
| 403 | |||
| 404 | return $fields; |
||
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Create a new Title from an article ID |
||
| 409 | * |
||
| 410 | * @param int $id The page_id corresponding to the Title to create |
||
| 411 | * @param int $flags Use Title::GAID_FOR_UPDATE to use master |
||
| 412 | * @return Title|null The new object, or null on an error |
||
| 413 | */ |
||
| 414 | public static function newFromID( $id, $flags = 0 ) { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Make an array of titles from an array of IDs |
||
| 432 | * |
||
| 433 | * @param int[] $ids Array of IDs |
||
| 434 | * @return Title[] Array of Titles |
||
| 435 | */ |
||
| 436 | public static function newFromIDs( $ids ) { |
||
| 437 | if ( !count( $ids ) ) { |
||
| 438 | return []; |
||
| 439 | } |
||
| 440 | $dbr = wfGetDB( DB_SLAVE ); |
||
| 441 | |||
| 442 | $res = $dbr->select( |
||
| 443 | 'page', |
||
| 444 | self::getSelectFields(), |
||
| 445 | [ 'page_id' => $ids ], |
||
| 446 | __METHOD__ |
||
| 447 | ); |
||
| 448 | |||
| 449 | $titles = []; |
||
| 450 | foreach ( $res as $row ) { |
||
| 451 | $titles[] = Title::newFromRow( $row ); |
||
| 452 | } |
||
| 453 | return $titles; |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Make a Title object from a DB row |
||
| 458 | * |
||
| 459 | * @param stdClass $row Object database row (needs at least page_title,page_namespace) |
||
| 460 | * @return Title Corresponding Title |
||
| 461 | */ |
||
| 462 | public static function newFromRow( $row ) { |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Load Title object fields from a DB row. |
||
| 470 | * If false is given, the title will be treated as non-existing. |
||
| 471 | * |
||
| 472 | * @param stdClass|bool $row Database row |
||
| 473 | */ |
||
| 474 | public function loadFromRow( $row ) { |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Create a new Title from a namespace index and a DB key. |
||
| 510 | * It's assumed that $ns and $title are *valid*, for instance when |
||
| 511 | * they came directly from the database or a special page name. |
||
| 512 | * For convenience, spaces are converted to underscores so that |
||
| 513 | * eg user_text fields can be used directly. |
||
| 514 | * |
||
| 515 | * @param int $ns The namespace of the article |
||
| 516 | * @param string $title The unprefixed database key form |
||
| 517 | * @param string $fragment The link fragment (after the "#") |
||
| 518 | * @param string $interwiki The interwiki prefix |
||
| 519 | * @return Title The new object |
||
| 520 | */ |
||
| 521 | public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) { |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Create a new Title from a namespace index and a DB key. |
||
| 536 | * The parameters will be checked for validity, which is a bit slower |
||
| 537 | * than makeTitle() but safer for user-provided data. |
||
| 538 | * |
||
| 539 | * @param int $ns The namespace of the article |
||
| 540 | * @param string $title Database key form |
||
| 541 | * @param string $fragment The link fragment (after the "#") |
||
| 542 | * @param string $interwiki Interwiki prefix |
||
| 543 | * @return Title|null The new object, or null on an error |
||
| 544 | */ |
||
| 545 | public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) { |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Create a new Title for the Main Page |
||
| 563 | * |
||
| 564 | * @return Title The new object |
||
| 565 | */ |
||
| 566 | public static function newMainPage() { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Extract a redirect destination from a string and return the |
||
| 577 | * Title, or null if the text doesn't contain a valid redirect |
||
| 578 | * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit |
||
| 579 | * in order to provide (hopefully) the Title of the final destination instead of another redirect |
||
| 580 | * |
||
| 581 | * @param string $text Text with possible redirect |
||
| 582 | * @return Title |
||
| 583 | * @deprecated since 1.21, use Content::getUltimateRedirectTarget instead. |
||
| 584 | */ |
||
| 585 | public static function newFromRedirectRecurse( $text ) { |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Get the prefixed DB key associated with an ID |
||
| 594 | * |
||
| 595 | * @param int $id The page_id of the article |
||
| 596 | * @return Title|null An object representing the article, or null if no such article was found |
||
| 597 | */ |
||
| 598 | public static function nameOf( $id ) { |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Get a regex character class describing the legal characters in a link |
||
| 617 | * |
||
| 618 | * @return string The list of characters, not delimited |
||
| 619 | */ |
||
| 620 | public static function legalChars() { |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Returns a simple regex that will match on characters and sequences invalid in titles. |
||
| 627 | * Note that this doesn't pick up many things that could be wrong with titles, but that |
||
| 628 | * replacing this regex with something valid will make many titles valid. |
||
| 629 | * |
||
| 630 | * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead |
||
| 631 | * |
||
| 632 | * @return string Regex string |
||
| 633 | */ |
||
| 634 | static function getTitleInvalidRegex() { |
||
| 638 | |||
| 639 | /** |
||
| 640 | * Utility method for converting a character sequence from bytes to Unicode. |
||
| 641 | * |
||
| 642 | * Primary usecase being converting $wgLegalTitleChars to a sequence usable in |
||
| 643 | * javascript, as PHP uses UTF-8 bytes where javascript uses Unicode code units. |
||
| 644 | * |
||
| 645 | * @param string $byteClass |
||
| 646 | * @return string |
||
| 647 | */ |
||
| 648 | public static function convertByteClassToUnicodeClass( $byteClass ) { |
||
| 740 | |||
| 741 | /** |
||
| 742 | * Make a prefixed DB key from a DB key and a namespace index |
||
| 743 | * |
||
| 744 | * @param int $ns Numerical representation of the namespace |
||
| 745 | * @param string $title The DB key form the title |
||
| 746 | * @param string $fragment The link fragment (after the "#") |
||
| 747 | * @param string $interwiki The interwiki prefix |
||
| 748 | * @param bool $canonicalNamespace If true, use the canonical name for |
||
| 749 | * $ns instead of the localized version. |
||
| 750 | * @return string The prefixed form of the title |
||
| 751 | */ |
||
| 752 | public static function makeName( $ns, $title, $fragment = '', $interwiki = '', |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Escape a text fragment, say from a link, for a URL |
||
| 774 | * |
||
| 775 | * @param string $fragment Containing a URL or link fragment (after the "#") |
||
| 776 | * @return string Escaped string |
||
| 777 | */ |
||
| 778 | static function escapeFragmentForURL( $fragment ) { |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Callback for usort() to do title sorts by (namespace, title) |
||
| 788 | * |
||
| 789 | * @param Title $a |
||
| 790 | * @param Title $b |
||
| 791 | * |
||
| 792 | * @return int Result of string comparison, or namespace comparison |
||
| 793 | */ |
||
| 794 | public static function compare( $a, $b ) { |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Determine whether the object refers to a page within |
||
| 804 | * this project (either this wiki or a wiki with a local |
||
| 805 | * interwiki, see https://www.mediawiki.org/wiki/Manual:Interwiki_table#iw_local ) |
||
| 806 | * |
||
| 807 | * @return bool True if this is an in-project interwiki link or a wikilink, false otherwise |
||
| 808 | */ |
||
| 809 | public function isLocal() { |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Is this Title interwiki? |
||
| 821 | * |
||
| 822 | * @return bool |
||
| 823 | */ |
||
| 824 | public function isExternal() { |
||
| 827 | |||
| 828 | /** |
||
| 829 | * Get the interwiki prefix |
||
| 830 | * |
||
| 831 | * Use Title::isExternal to check if a interwiki is set |
||
| 832 | * |
||
| 833 | * @return string Interwiki prefix |
||
| 834 | */ |
||
| 835 | public function getInterwiki() { |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Was this a local interwiki link? |
||
| 841 | * |
||
| 842 | * @return bool |
||
| 843 | */ |
||
| 844 | public function wasLocalInterwiki() { |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Determine whether the object refers to a page within |
||
| 850 | * this project and is transcludable. |
||
| 851 | * |
||
| 852 | * @return bool True if this is transcludable |
||
| 853 | */ |
||
| 854 | public function isTrans() { |
||
| 861 | |||
| 862 | /** |
||
| 863 | * Returns the DB name of the distant wiki which owns the object. |
||
| 864 | * |
||
| 865 | * @return string The DB name |
||
| 866 | */ |
||
| 867 | public function getTransWikiID() { |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Get a TitleValue object representing this Title. |
||
| 877 | * |
||
| 878 | * @note Not all valid Titles have a corresponding valid TitleValue |
||
| 879 | * (e.g. TitleValues cannot represent page-local links that have a |
||
| 880 | * fragment but no title text). |
||
| 881 | * |
||
| 882 | * @return TitleValue|null |
||
| 883 | */ |
||
| 884 | public function getTitleValue() { |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Get the text form (spaces not underscores) of the main part |
||
| 902 | * |
||
| 903 | * @return string Main part of the title |
||
| 904 | */ |
||
| 905 | public function getText() { |
||
| 908 | |||
| 909 | /** |
||
| 910 | * Get the URL-encoded form of the main part |
||
| 911 | * |
||
| 912 | * @return string Main part of the title, URL-encoded |
||
| 913 | */ |
||
| 914 | public function getPartialURL() { |
||
| 917 | |||
| 918 | /** |
||
| 919 | * Get the main part with underscores |
||
| 920 | * |
||
| 921 | * @return string Main part of the title, with underscores |
||
| 922 | */ |
||
| 923 | public function getDBkey() { |
||
| 926 | |||
| 927 | /** |
||
| 928 | * Get the DB key with the initial letter case as specified by the user |
||
| 929 | * |
||
| 930 | * @return string DB key |
||
| 931 | */ |
||
| 932 | function getUserCaseDBKey() { |
||
| 940 | |||
| 941 | /** |
||
| 942 | * Get the namespace index, i.e. one of the NS_xxxx constants. |
||
| 943 | * |
||
| 944 | * @return int Namespace index |
||
| 945 | */ |
||
| 946 | public function getNamespace() { |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Get the page's content model id, see the CONTENT_MODEL_XXX constants. |
||
| 952 | * |
||
| 953 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 954 | * @return string Content model id |
||
| 955 | */ |
||
| 956 | public function getContentModel( $flags = 0 ) { |
||
| 969 | |||
| 970 | /** |
||
| 971 | * Convenience method for checking a title's content model name |
||
| 972 | * |
||
| 973 | * @param string $id The content model ID (use the CONTENT_MODEL_XXX constants). |
||
| 974 | * @return bool True if $this->getContentModel() == $id |
||
| 975 | */ |
||
| 976 | public function hasContentModel( $id ) { |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Get the namespace text |
||
| 982 | * |
||
| 983 | * @return string Namespace text |
||
| 984 | */ |
||
| 985 | public function getNsText() { |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Get the namespace text of the subject (rather than talk) page |
||
| 1007 | * |
||
| 1008 | * @return string Namespace text |
||
| 1009 | */ |
||
| 1010 | public function getSubjectNsText() { |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Get the namespace text of the talk page |
||
| 1017 | * |
||
| 1018 | * @return string Namespace text |
||
| 1019 | */ |
||
| 1020 | public function getTalkNsText() { |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Could this title have a corresponding talk page? |
||
| 1027 | * |
||
| 1028 | * @return bool |
||
| 1029 | */ |
||
| 1030 | public function canTalk() { |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * Is this in a namespace that allows actual pages? |
||
| 1036 | * |
||
| 1037 | * @return bool |
||
| 1038 | */ |
||
| 1039 | public function canExist() { |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Can this title be added to a user's watchlist? |
||
| 1045 | * |
||
| 1046 | * @return bool |
||
| 1047 | */ |
||
| 1048 | public function isWatchable() { |
||
| 1051 | |||
| 1052 | /** |
||
| 1053 | * Returns true if this is a special page. |
||
| 1054 | * |
||
| 1055 | * @return bool |
||
| 1056 | */ |
||
| 1057 | public function isSpecialPage() { |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Returns true if this title resolves to the named special page |
||
| 1063 | * |
||
| 1064 | * @param string $name The special page name |
||
| 1065 | * @return bool |
||
| 1066 | */ |
||
| 1067 | public function isSpecial( $name ) { |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * If the Title refers to a special page alias which is not the local default, resolve |
||
| 1079 | * the alias, and localise the name as necessary. Otherwise, return $this |
||
| 1080 | * |
||
| 1081 | * @return Title |
||
| 1082 | */ |
||
| 1083 | public function fixSpecialName() { |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Returns true if the title is inside the specified namespace. |
||
| 1098 | * |
||
| 1099 | * Please make use of this instead of comparing to getNamespace() |
||
| 1100 | * This function is much more resistant to changes we may make |
||
| 1101 | * to namespaces than code that makes direct comparisons. |
||
| 1102 | * @param int $ns The namespace |
||
| 1103 | * @return bool |
||
| 1104 | * @since 1.19 |
||
| 1105 | */ |
||
| 1106 | public function inNamespace( $ns ) { |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Returns true if the title is inside one of the specified namespaces. |
||
| 1112 | * |
||
| 1113 | * @param int $namespaces,... The namespaces to check for |
||
| 1114 | * @return bool |
||
| 1115 | * @since 1.19 |
||
| 1116 | */ |
||
| 1117 | public function inNamespaces( /* ... */ ) { |
||
| 1131 | |||
| 1132 | /** |
||
| 1133 | * Returns true if the title has the same subject namespace as the |
||
| 1134 | * namespace specified. |
||
| 1135 | * For example this method will take NS_USER and return true if namespace |
||
| 1136 | * is either NS_USER or NS_USER_TALK since both of them have NS_USER |
||
| 1137 | * as their subject namespace. |
||
| 1138 | * |
||
| 1139 | * This is MUCH simpler than individually testing for equivalence |
||
| 1140 | * against both NS_USER and NS_USER_TALK, and is also forward compatible. |
||
| 1141 | * @since 1.19 |
||
| 1142 | * @param int $ns |
||
| 1143 | * @return bool |
||
| 1144 | */ |
||
| 1145 | public function hasSubjectNamespace( $ns ) { |
||
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Is this Title in a namespace which contains content? |
||
| 1151 | * In other words, is this a content page, for the purposes of calculating |
||
| 1152 | * statistics, etc? |
||
| 1153 | * |
||
| 1154 | * @return bool |
||
| 1155 | */ |
||
| 1156 | public function isContentPage() { |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Would anybody with sufficient privileges be able to move this page? |
||
| 1162 | * Some pages just aren't movable. |
||
| 1163 | * |
||
| 1164 | * @return bool |
||
| 1165 | */ |
||
| 1166 | public function isMovable() { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Is this the mainpage? |
||
| 1179 | * @note Title::newFromText seems to be sufficiently optimized by the title |
||
| 1180 | * cache that we don't need to over-optimize by doing direct comparisons and |
||
| 1181 | * accidentally creating new bugs where $title->equals( Title::newFromText() ) |
||
| 1182 | * ends up reporting something differently than $title->isMainPage(); |
||
| 1183 | * |
||
| 1184 | * @since 1.18 |
||
| 1185 | * @return bool |
||
| 1186 | */ |
||
| 1187 | public function isMainPage() { |
||
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Is this a subpage? |
||
| 1193 | * |
||
| 1194 | * @return bool |
||
| 1195 | */ |
||
| 1196 | public function isSubpage() { |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Is this a conversion table for the LanguageConverter? |
||
| 1204 | * |
||
| 1205 | * @return bool |
||
| 1206 | */ |
||
| 1207 | public function isConversionTable() { |
||
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Does that page contain wikitext, or it is JS, CSS or whatever? |
||
| 1216 | * |
||
| 1217 | * @return bool |
||
| 1218 | */ |
||
| 1219 | public function isWikitextPage() { |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * Could this page contain custom CSS or JavaScript for the global UI. |
||
| 1225 | * This is generally true for pages in the MediaWiki namespace having CONTENT_MODEL_CSS |
||
| 1226 | * or CONTENT_MODEL_JAVASCRIPT. |
||
| 1227 | * |
||
| 1228 | * This method does *not* return true for per-user JS/CSS. Use isCssJsSubpage() |
||
| 1229 | * for that! |
||
| 1230 | * |
||
| 1231 | * Note that this method should not return true for pages that contain and |
||
| 1232 | * show "inactive" CSS or JS. |
||
| 1233 | * |
||
| 1234 | * @return bool |
||
| 1235 | * @todo FIXME: Rename to isSiteConfigPage() and remove deprecated hook |
||
| 1236 | */ |
||
| 1237 | public function isCssOrJsPage() { |
||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Is this a .css or .js subpage of a user page? |
||
| 1253 | * @return bool |
||
| 1254 | * @todo FIXME: Rename to isUserConfigPage() |
||
| 1255 | */ |
||
| 1256 | public function isCssJsSubpage() { |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Trim down a .css or .js subpage title to get the corresponding skin name |
||
| 1264 | * |
||
| 1265 | * @return string Containing skin name from .css or .js subpage title |
||
| 1266 | */ |
||
| 1267 | public function getSkinFromCssJsSubpage() { |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Is this a .css subpage of a user page? |
||
| 1279 | * |
||
| 1280 | * @return bool |
||
| 1281 | */ |
||
| 1282 | public function isCssSubpage() { |
||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Is this a .js subpage of a user page? |
||
| 1289 | * |
||
| 1290 | * @return bool |
||
| 1291 | */ |
||
| 1292 | public function isJsSubpage() { |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Is this a talk page of some sort? |
||
| 1299 | * |
||
| 1300 | * @return bool |
||
| 1301 | */ |
||
| 1302 | public function isTalkPage() { |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Get a Title object associated with the talk page of this article |
||
| 1308 | * |
||
| 1309 | * @return Title The object for the talk page |
||
| 1310 | */ |
||
| 1311 | public function getTalkPage() { |
||
| 1314 | |||
| 1315 | /** |
||
| 1316 | * Get a title object associated with the subject page of this |
||
| 1317 | * talk page |
||
| 1318 | * |
||
| 1319 | * @return Title The object for the subject page |
||
| 1320 | */ |
||
| 1321 | public function getSubjectPage() { |
||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Get the other title for this page, if this is a subject page |
||
| 1332 | * get the talk page, if it is a subject page get the talk page |
||
| 1333 | * |
||
| 1334 | * @since 1.25 |
||
| 1335 | * @throws MWException |
||
| 1336 | * @return Title |
||
| 1337 | */ |
||
| 1338 | public function getOtherPage() { |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Get the default namespace index, for when there is no namespace |
||
| 1351 | * |
||
| 1352 | * @return int Default namespace index |
||
| 1353 | */ |
||
| 1354 | public function getDefaultNamespace() { |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Get the Title fragment (i.e.\ the bit after the #) in text form |
||
| 1360 | * |
||
| 1361 | * Use Title::hasFragment to check for a fragment |
||
| 1362 | * |
||
| 1363 | * @return string Title fragment |
||
| 1364 | */ |
||
| 1365 | public function getFragment() { |
||
| 1368 | |||
| 1369 | /** |
||
| 1370 | * Check if a Title fragment is set |
||
| 1371 | * |
||
| 1372 | * @return bool |
||
| 1373 | * @since 1.23 |
||
| 1374 | */ |
||
| 1375 | public function hasFragment() { |
||
| 1378 | |||
| 1379 | /** |
||
| 1380 | * Get the fragment in URL form, including the "#" character if there is one |
||
| 1381 | * @return string Fragment in URL form |
||
| 1382 | */ |
||
| 1383 | public function getFragmentForURL() { |
||
| 1390 | |||
| 1391 | /** |
||
| 1392 | * Set the fragment for this title. Removes the first character from the |
||
| 1393 | * specified fragment before setting, so it assumes you're passing it with |
||
| 1394 | * an initial "#". |
||
| 1395 | * |
||
| 1396 | * Deprecated for public use, use Title::makeTitle() with fragment parameter. |
||
| 1397 | * Still in active use privately. |
||
| 1398 | * |
||
| 1399 | * @private |
||
| 1400 | * @param string $fragment Text |
||
| 1401 | */ |
||
| 1402 | public function setFragment( $fragment ) { |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Prefix some arbitrary text with the namespace or interwiki prefix |
||
| 1408 | * of this object |
||
| 1409 | * |
||
| 1410 | * @param string $name The text |
||
| 1411 | * @return string The prefixed text |
||
| 1412 | */ |
||
| 1413 | private function prefix( $name ) { |
||
| 1424 | |||
| 1425 | /** |
||
| 1426 | * Get the prefixed database key form |
||
| 1427 | * |
||
| 1428 | * @return string The prefixed title, with underscores and |
||
| 1429 | * any interwiki and namespace prefixes |
||
| 1430 | */ |
||
| 1431 | public function getPrefixedDBkey() { |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Get the prefixed title with spaces. |
||
| 1439 | * This is the form usually used for display |
||
| 1440 | * |
||
| 1441 | * @return string The prefixed title, with spaces |
||
| 1442 | */ |
||
| 1443 | public function getPrefixedText() { |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Return a string representation of this title |
||
| 1454 | * |
||
| 1455 | * @return string Representation of this title |
||
| 1456 | */ |
||
| 1457 | public function __toString() { |
||
| 1460 | |||
| 1461 | /** |
||
| 1462 | * Get the prefixed title with spaces, plus any fragment |
||
| 1463 | * (part beginning with '#') |
||
| 1464 | * |
||
| 1465 | * @return string The prefixed title, with spaces and the fragment, including '#' |
||
| 1466 | */ |
||
| 1467 | public function getFullText() { |
||
| 1474 | |||
| 1475 | /** |
||
| 1476 | * Get the root page name text without a namespace, i.e. the leftmost part before any slashes |
||
| 1477 | * |
||
| 1478 | * @par Example: |
||
| 1479 | * @code |
||
| 1480 | * Title::newFromText('User:Foo/Bar/Baz')->getRootText(); |
||
| 1481 | * # returns: 'Foo' |
||
| 1482 | * @endcode |
||
| 1483 | * |
||
| 1484 | * @return string Root name |
||
| 1485 | * @since 1.20 |
||
| 1486 | */ |
||
| 1487 | public function getRootText() { |
||
| 1494 | |||
| 1495 | /** |
||
| 1496 | * Get the root page name title, i.e. the leftmost part before any slashes |
||
| 1497 | * |
||
| 1498 | * @par Example: |
||
| 1499 | * @code |
||
| 1500 | * Title::newFromText('User:Foo/Bar/Baz')->getRootTitle(); |
||
| 1501 | * # returns: Title{User:Foo} |
||
| 1502 | * @endcode |
||
| 1503 | * |
||
| 1504 | * @return Title Root title |
||
| 1505 | * @since 1.20 |
||
| 1506 | */ |
||
| 1507 | public function getRootTitle() { |
||
| 1510 | |||
| 1511 | /** |
||
| 1512 | * Get the base page name without a namespace, i.e. the part before the subpage name |
||
| 1513 | * |
||
| 1514 | * @par Example: |
||
| 1515 | * @code |
||
| 1516 | * Title::newFromText('User:Foo/Bar/Baz')->getBaseText(); |
||
| 1517 | * # returns: 'Foo/Bar' |
||
| 1518 | * @endcode |
||
| 1519 | * |
||
| 1520 | * @return string Base name |
||
| 1521 | */ |
||
| 1522 | public function getBaseText() { |
||
| 1534 | |||
| 1535 | /** |
||
| 1536 | * Get the base page name title, i.e. the part before the subpage name |
||
| 1537 | * |
||
| 1538 | * @par Example: |
||
| 1539 | * @code |
||
| 1540 | * Title::newFromText('User:Foo/Bar/Baz')->getBaseTitle(); |
||
| 1541 | * # returns: Title{User:Foo/Bar} |
||
| 1542 | * @endcode |
||
| 1543 | * |
||
| 1544 | * @return Title Base title |
||
| 1545 | * @since 1.20 |
||
| 1546 | */ |
||
| 1547 | public function getBaseTitle() { |
||
| 1550 | |||
| 1551 | /** |
||
| 1552 | * Get the lowest-level subpage name, i.e. the rightmost part after any slashes |
||
| 1553 | * |
||
| 1554 | * @par Example: |
||
| 1555 | * @code |
||
| 1556 | * Title::newFromText('User:Foo/Bar/Baz')->getSubpageText(); |
||
| 1557 | * # returns: "Baz" |
||
| 1558 | * @endcode |
||
| 1559 | * |
||
| 1560 | * @return string Subpage name |
||
| 1561 | */ |
||
| 1562 | public function getSubpageText() { |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Get the title for a subpage of the current page |
||
| 1572 | * |
||
| 1573 | * @par Example: |
||
| 1574 | * @code |
||
| 1575 | * Title::newFromText('User:Foo/Bar/Baz')->getSubpage("Asdf"); |
||
| 1576 | * # returns: Title{User:Foo/Bar/Baz/Asdf} |
||
| 1577 | * @endcode |
||
| 1578 | * |
||
| 1579 | * @param string $text The subpage name to add to the title |
||
| 1580 | * @return Title Subpage title |
||
| 1581 | * @since 1.20 |
||
| 1582 | */ |
||
| 1583 | public function getSubpage( $text ) { |
||
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Get a URL-encoded form of the subpage text |
||
| 1589 | * |
||
| 1590 | * @return string URL-encoded subpage name |
||
| 1591 | */ |
||
| 1592 | public function getSubpageUrlForm() { |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Get a URL-encoded title (not an actual URL) including interwiki |
||
| 1600 | * |
||
| 1601 | * @return string The URL-encoded form |
||
| 1602 | */ |
||
| 1603 | public function getPrefixedURL() { |
||
| 1608 | |||
| 1609 | /** |
||
| 1610 | * Helper to fix up the get{Canonical,Full,Link,Local,Internal}URL args |
||
| 1611 | * get{Canonical,Full,Link,Local,Internal}URL methods accepted an optional |
||
| 1612 | * second argument named variant. This was deprecated in favor |
||
| 1613 | * of passing an array of option with a "variant" key |
||
| 1614 | * Once $query2 is removed for good, this helper can be dropped |
||
| 1615 | * and the wfArrayToCgi moved to getLocalURL(); |
||
| 1616 | * |
||
| 1617 | * @since 1.19 (r105919) |
||
| 1618 | * @param array|string $query |
||
| 1619 | * @param bool $query2 |
||
| 1620 | * @return string |
||
| 1621 | */ |
||
| 1622 | private static function fixUrlQueryArgs( $query, $query2 = false ) { |
||
| 1648 | |||
| 1649 | /** |
||
| 1650 | * Get a real URL referring to this title, with interwiki link and |
||
| 1651 | * fragment |
||
| 1652 | * |
||
| 1653 | * @see self::getLocalURL for the arguments. |
||
| 1654 | * @see wfExpandUrl |
||
| 1655 | * @param array|string $query |
||
| 1656 | * @param bool $query2 |
||
| 1657 | * @param string $proto Protocol type to use in URL |
||
| 1658 | * @return string The URL |
||
| 1659 | */ |
||
| 1660 | public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) { |
||
| 1677 | |||
| 1678 | /** |
||
| 1679 | * Get a URL with no fragment or server name (relative URL) from a Title object. |
||
| 1680 | * If this page is generated with action=render, however, |
||
| 1681 | * $wgServer is prepended to make an absolute URL. |
||
| 1682 | * |
||
| 1683 | * @see self::getFullURL to always get an absolute URL. |
||
| 1684 | * @see self::getLinkURL to always get a URL that's the simplest URL that will be |
||
| 1685 | * valid to link, locally, to the current Title. |
||
| 1686 | * @see self::newFromText to produce a Title object. |
||
| 1687 | * |
||
| 1688 | * @param string|array $query An optional query string, |
||
| 1689 | * not used for interwiki links. Can be specified as an associative array as well, |
||
| 1690 | * e.g., array( 'action' => 'edit' ) (keys and values will be URL-escaped). |
||
| 1691 | * Some query patterns will trigger various shorturl path replacements. |
||
| 1692 | * @param array $query2 An optional secondary query array. This one MUST |
||
| 1693 | * be an array. If a string is passed it will be interpreted as a deprecated |
||
| 1694 | * variant argument and urlencoded into a variant= argument. |
||
| 1695 | * This second query argument will be added to the $query |
||
| 1696 | * The second parameter is deprecated since 1.19. Pass it as a key,value |
||
| 1697 | * pair in the first parameter array instead. |
||
| 1698 | * |
||
| 1699 | * @return string String of the URL. |
||
| 1700 | */ |
||
| 1701 | public function getLocalURL( $query = '', $query2 = false ) { |
||
| 1776 | |||
| 1777 | /** |
||
| 1778 | * Get a URL that's the simplest URL that will be valid to link, locally, |
||
| 1779 | * to the current Title. It includes the fragment, but does not include |
||
| 1780 | * the server unless action=render is used (or the link is external). If |
||
| 1781 | * there's a fragment but the prefixed text is empty, we just return a link |
||
| 1782 | * to the fragment. |
||
| 1783 | * |
||
| 1784 | * The result obviously should not be URL-escaped, but does need to be |
||
| 1785 | * HTML-escaped if it's being output in HTML. |
||
| 1786 | * |
||
| 1787 | * @param array $query |
||
| 1788 | * @param bool $query2 |
||
| 1789 | * @param string $proto Protocol to use; setting this will cause a full URL to be used |
||
| 1790 | * @see self::getLocalURL for the arguments. |
||
| 1791 | * @return string The URL |
||
| 1792 | */ |
||
| 1793 | public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) { |
||
| 1803 | |||
| 1804 | /** |
||
| 1805 | * Get the URL form for an internal link. |
||
| 1806 | * - Used in various CDN-related code, in case we have a different |
||
| 1807 | * internal hostname for the server from the exposed one. |
||
| 1808 | * |
||
| 1809 | * This uses $wgInternalServer to qualify the path, or $wgServer |
||
| 1810 | * if $wgInternalServer is not set. If the server variable used is |
||
| 1811 | * protocol-relative, the URL will be expanded to http:// |
||
| 1812 | * |
||
| 1813 | * @see self::getLocalURL for the arguments. |
||
| 1814 | * @return string The URL |
||
| 1815 | */ |
||
| 1816 | public function getInternalURL( $query = '', $query2 = false ) { |
||
| 1824 | |||
| 1825 | /** |
||
| 1826 | * Get the URL for a canonical link, for use in things like IRC and |
||
| 1827 | * e-mail notifications. Uses $wgCanonicalServer and the |
||
| 1828 | * GetCanonicalURL hook. |
||
| 1829 | * |
||
| 1830 | * NOTE: Unlike getInternalURL(), the canonical URL includes the fragment |
||
| 1831 | * |
||
| 1832 | * @see self::getLocalURL for the arguments. |
||
| 1833 | * @return string The URL |
||
| 1834 | * @since 1.18 |
||
| 1835 | */ |
||
| 1836 | public function getCanonicalURL( $query = '', $query2 = false ) { |
||
| 1842 | |||
| 1843 | /** |
||
| 1844 | * Get the edit URL for this Title |
||
| 1845 | * |
||
| 1846 | * @return string The URL, or a null string if this is an interwiki link |
||
| 1847 | */ |
||
| 1848 | public function getEditURL() { |
||
| 1856 | |||
| 1857 | /** |
||
| 1858 | * Can $user perform $action on this page? |
||
| 1859 | * This skips potentially expensive cascading permission checks |
||
| 1860 | * as well as avoids expensive error formatting |
||
| 1861 | * |
||
| 1862 | * Suitable for use for nonessential UI controls in common cases, but |
||
| 1863 | * _not_ for functional access control. |
||
| 1864 | * |
||
| 1865 | * May provide false positives, but should never provide a false negative. |
||
| 1866 | * |
||
| 1867 | * @param string $action Action that permission needs to be checked for |
||
| 1868 | * @param User $user User to check (since 1.19); $wgUser will be used if not provided. |
||
| 1869 | * @return bool |
||
| 1870 | */ |
||
| 1871 | public function quickUserCan( $action, $user = null ) { |
||
| 1874 | |||
| 1875 | /** |
||
| 1876 | * Can $user perform $action on this page? |
||
| 1877 | * |
||
| 1878 | * @param string $action Action that permission needs to be checked for |
||
| 1879 | * @param User $user User to check (since 1.19); $wgUser will be used if not |
||
| 1880 | * provided. |
||
| 1881 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 1882 | * @return bool |
||
| 1883 | */ |
||
| 1884 | public function userCan( $action, $user = null, $rigor = 'secure' ) { |
||
| 1892 | |||
| 1893 | /** |
||
| 1894 | * Can $user perform $action on this page? |
||
| 1895 | * |
||
| 1896 | * @todo FIXME: This *does not* check throttles (User::pingLimiter()). |
||
| 1897 | * |
||
| 1898 | * @param string $action Action that permission needs to be checked for |
||
| 1899 | * @param User $user User to check |
||
| 1900 | * @param string $rigor One of (quick,full,secure) |
||
| 1901 | * - quick : does cheap permission checks from slaves (usable for GUI creation) |
||
| 1902 | * - full : does cheap and expensive checks possibly from a slave |
||
| 1903 | * - secure : does cheap and expensive checks, using the master as needed |
||
| 1904 | * @param array $ignoreErrors Array of Strings Set this to a list of message keys |
||
| 1905 | * whose corresponding errors may be ignored. |
||
| 1906 | * @return array Array of arrays of the arguments to wfMessage to explain permissions problems. |
||
| 1907 | */ |
||
| 1908 | public function getUserPermissionsErrors( |
||
| 1927 | |||
| 1928 | /** |
||
| 1929 | * Permissions checks that fail most often, and which are easiest to test. |
||
| 1930 | * |
||
| 1931 | * @param string $action The action to check |
||
| 1932 | * @param User $user User to check |
||
| 1933 | * @param array $errors List of current errors |
||
| 1934 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 1935 | * @param bool $short Short circuit on first error |
||
| 1936 | * |
||
| 1937 | * @return array List of errors |
||
| 1938 | */ |
||
| 1939 | private function checkQuickPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2000 | |||
| 2001 | /** |
||
| 2002 | * Add the resulting error code to the errors array |
||
| 2003 | * |
||
| 2004 | * @param array $errors List of current errors |
||
| 2005 | * @param array $result Result of errors |
||
| 2006 | * |
||
| 2007 | * @return array List of errors |
||
| 2008 | */ |
||
| 2009 | private function resultToError( $errors, $result ) { |
||
| 2028 | |||
| 2029 | /** |
||
| 2030 | * Check various permission hooks |
||
| 2031 | * |
||
| 2032 | * @param string $action The action to check |
||
| 2033 | * @param User $user User to check |
||
| 2034 | * @param array $errors List of current errors |
||
| 2035 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2036 | * @param bool $short Short circuit on first error |
||
| 2037 | * |
||
| 2038 | * @return array List of errors |
||
| 2039 | */ |
||
| 2040 | private function checkPermissionHooks( $action, $user, $errors, $rigor, $short ) { |
||
| 2061 | |||
| 2062 | /** |
||
| 2063 | * Check permissions on special pages & namespaces |
||
| 2064 | * |
||
| 2065 | * @param string $action The action to check |
||
| 2066 | * @param User $user User to check |
||
| 2067 | * @param array $errors List of current errors |
||
| 2068 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2069 | * @param bool $short Short circuit on first error |
||
| 2070 | * |
||
| 2071 | * @return array List of errors |
||
| 2072 | */ |
||
| 2073 | private function checkSpecialsAndNSPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2090 | |||
| 2091 | /** |
||
| 2092 | * Check CSS/JS sub-page permissions |
||
| 2093 | * |
||
| 2094 | * @param string $action The action to check |
||
| 2095 | * @param User $user User to check |
||
| 2096 | * @param array $errors List of current errors |
||
| 2097 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2098 | * @param bool $short Short circuit on first error |
||
| 2099 | * |
||
| 2100 | * @return array List of errors |
||
| 2101 | */ |
||
| 2102 | private function checkCSSandJSPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2124 | |||
| 2125 | /** |
||
| 2126 | * Check against page_restrictions table requirements on this |
||
| 2127 | * page. The user must possess all required rights for this |
||
| 2128 | * action. |
||
| 2129 | * |
||
| 2130 | * @param string $action The action to check |
||
| 2131 | * @param User $user User to check |
||
| 2132 | * @param array $errors List of current errors |
||
| 2133 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2134 | * @param bool $short Short circuit on first error |
||
| 2135 | * |
||
| 2136 | * @return array List of errors |
||
| 2137 | */ |
||
| 2138 | private function checkPageRestrictions( $action, $user, $errors, $rigor, $short ) { |
||
| 2160 | |||
| 2161 | /** |
||
| 2162 | * Check restrictions on cascading pages. |
||
| 2163 | * |
||
| 2164 | * @param string $action The action to check |
||
| 2165 | * @param User $user User to check |
||
| 2166 | * @param array $errors List of current errors |
||
| 2167 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2168 | * @param bool $short Short circuit on first error |
||
| 2169 | * |
||
| 2170 | * @return array List of errors |
||
| 2171 | */ |
||
| 2172 | private function checkCascadingSourcesRestrictions( $action, $user, $errors, $rigor, $short ) { |
||
| 2207 | |||
| 2208 | /** |
||
| 2209 | * Check action permissions not already checked in checkQuickPermissions |
||
| 2210 | * |
||
| 2211 | * @param string $action The action to check |
||
| 2212 | * @param User $user User to check |
||
| 2213 | * @param array $errors List of current errors |
||
| 2214 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2215 | * @param bool $short Short circuit on first error |
||
| 2216 | * |
||
| 2217 | * @return array List of errors |
||
| 2218 | */ |
||
| 2219 | private function checkActionPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2273 | |||
| 2274 | /** |
||
| 2275 | * Check that the user isn't blocked from editing. |
||
| 2276 | * |
||
| 2277 | * @param string $action The action to check |
||
| 2278 | * @param User $user User to check |
||
| 2279 | * @param array $errors List of current errors |
||
| 2280 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2281 | * @param bool $short Short circuit on first error |
||
| 2282 | * |
||
| 2283 | * @return array List of errors |
||
| 2284 | */ |
||
| 2285 | private function checkUserBlock( $action, $user, $errors, $rigor, $short ) { |
||
| 2311 | |||
| 2312 | /** |
||
| 2313 | * Check that the user is allowed to read this page. |
||
| 2314 | * |
||
| 2315 | * @param string $action The action to check |
||
| 2316 | * @param User $user User to check |
||
| 2317 | * @param array $errors List of current errors |
||
| 2318 | * @param string $rigor Same format as Title::getUserPermissionsErrors() |
||
| 2319 | * @param bool $short Short circuit on first error |
||
| 2320 | * |
||
| 2321 | * @return array List of errors |
||
| 2322 | */ |
||
| 2323 | private function checkReadPermissions( $action, $user, $errors, $rigor, $short ) { |
||
| 2389 | |||
| 2390 | /** |
||
| 2391 | * Get a description array when the user doesn't have the right to perform |
||
| 2392 | * $action (i.e. when User::isAllowed() returns false) |
||
| 2393 | * |
||
| 2394 | * @param string $action The action to check |
||
| 2395 | * @param bool $short Short circuit on first error |
||
| 2396 | * @return array List of errors |
||
| 2397 | */ |
||
| 2398 | private function missingPermissionError( $action, $short ) { |
||
| 2418 | |||
| 2419 | /** |
||
| 2420 | * Can $user perform $action on this page? This is an internal function, |
||
| 2421 | * with multiple levels of checks depending on performance needs; see $rigor below. |
||
| 2422 | * It does not check wfReadOnly(). |
||
| 2423 | * |
||
| 2424 | * @param string $action Action that permission needs to be checked for |
||
| 2425 | * @param User $user User to check |
||
| 2426 | * @param string $rigor One of (quick,full,secure) |
||
| 2427 | * - quick : does cheap permission checks from slaves (usable for GUI creation) |
||
| 2428 | * - full : does cheap and expensive checks possibly from a slave |
||
| 2429 | * - secure : does cheap and expensive checks, using the master as needed |
||
| 2430 | * @param bool $short Set this to true to stop after the first permission error. |
||
| 2431 | * @return array Array of arrays of the arguments to wfMessage to explain permissions problems. |
||
| 2432 | */ |
||
| 2433 | protected function getUserPermissionsErrorsInternal( |
||
| 2485 | |||
| 2486 | /** |
||
| 2487 | * Get a filtered list of all restriction types supported by this wiki. |
||
| 2488 | * @param bool $exists True to get all restriction types that apply to |
||
| 2489 | * titles that do exist, False for all restriction types that apply to |
||
| 2490 | * titles that do not exist |
||
| 2491 | * @return array |
||
| 2492 | */ |
||
| 2493 | public static function getFilteredRestrictionTypes( $exists = true ) { |
||
| 2505 | |||
| 2506 | /** |
||
| 2507 | * Returns restriction types for the current Title |
||
| 2508 | * |
||
| 2509 | * @return array Applicable restriction types |
||
| 2510 | */ |
||
| 2511 | public function getRestrictionTypes() { |
||
| 2530 | |||
| 2531 | /** |
||
| 2532 | * Is this title subject to title protection? |
||
| 2533 | * Title protection is the one applied against creation of such title. |
||
| 2534 | * |
||
| 2535 | * @return array|bool An associative array representing any existent title |
||
| 2536 | * protection, or false if there's none. |
||
| 2537 | */ |
||
| 2538 | public function getTitleProtection() { |
||
| 2578 | |||
| 2579 | /** |
||
| 2580 | * Remove any title protection due to page existing |
||
| 2581 | */ |
||
| 2582 | public function deleteTitleProtection() { |
||
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Is this page "semi-protected" - the *only* protection levels are listed |
||
| 2595 | * in $wgSemiprotectedRestrictionLevels? |
||
| 2596 | * |
||
| 2597 | * @param string $action Action to check (default: edit) |
||
| 2598 | * @return bool |
||
| 2599 | */ |
||
| 2600 | public function isSemiProtected( $action = 'edit' ) { |
||
| 2620 | |||
| 2621 | /** |
||
| 2622 | * Does the title correspond to a protected article? |
||
| 2623 | * |
||
| 2624 | * @param string $action The action the page is protected from, |
||
| 2625 | * by default checks all actions. |
||
| 2626 | * @return bool |
||
| 2627 | */ |
||
| 2628 | public function isProtected( $action = '' ) { |
||
| 2652 | |||
| 2653 | /** |
||
| 2654 | * Determines if $user is unable to edit this page because it has been protected |
||
| 2655 | * by $wgNamespaceProtection. |
||
| 2656 | * |
||
| 2657 | * @param User $user User object to check permissions |
||
| 2658 | * @return bool |
||
| 2659 | */ |
||
| 2660 | public function isNamespaceProtected( User $user ) { |
||
| 2672 | |||
| 2673 | /** |
||
| 2674 | * Cascading protection: Return true if cascading restrictions apply to this page, false if not. |
||
| 2675 | * |
||
| 2676 | * @return bool If the page is subject to cascading restrictions. |
||
| 2677 | */ |
||
| 2678 | public function isCascadeProtected() { |
||
| 2682 | |||
| 2683 | /** |
||
| 2684 | * Determines whether cascading protection sources have already been loaded from |
||
| 2685 | * the database. |
||
| 2686 | * |
||
| 2687 | * @param bool $getPages True to check if the pages are loaded, or false to check |
||
| 2688 | * if the status is loaded. |
||
| 2689 | * @return bool Whether or not the specified information has been loaded |
||
| 2690 | * @since 1.23 |
||
| 2691 | */ |
||
| 2692 | public function areCascadeProtectionSourcesLoaded( $getPages = true ) { |
||
| 2695 | |||
| 2696 | /** |
||
| 2697 | * Cascading protection: Get the source of any cascading restrictions on this page. |
||
| 2698 | * |
||
| 2699 | * @param bool $getPages Whether or not to retrieve the actual pages |
||
| 2700 | * that the restrictions have come from and the actual restrictions |
||
| 2701 | * themselves. |
||
| 2702 | * @return array Two elements: First is an array of Title objects of the |
||
| 2703 | * pages from which cascading restrictions have come, false for |
||
| 2704 | * none, or true if such restrictions exist but $getPages was not |
||
| 2705 | * set. Second is an array like that returned by |
||
| 2706 | * Title::getAllRestrictions(), or an empty array if $getPages is |
||
| 2707 | * false. |
||
| 2708 | */ |
||
| 2709 | public function getCascadeProtectionSources( $getPages = true ) { |
||
| 2787 | |||
| 2788 | /** |
||
| 2789 | * Accessor for mRestrictionsLoaded |
||
| 2790 | * |
||
| 2791 | * @return bool Whether or not the page's restrictions have already been |
||
| 2792 | * loaded from the database |
||
| 2793 | * @since 1.23 |
||
| 2794 | */ |
||
| 2795 | public function areRestrictionsLoaded() { |
||
| 2798 | |||
| 2799 | /** |
||
| 2800 | * Accessor/initialisation for mRestrictions |
||
| 2801 | * |
||
| 2802 | * @param string $action Action that permission needs to be checked for |
||
| 2803 | * @return array Restriction levels needed to take the action. All levels are |
||
| 2804 | * required. Note that restriction levels are normally user rights, but 'sysop' |
||
| 2805 | * and 'autoconfirmed' are also allowed for backwards compatibility. These should |
||
| 2806 | * be mapped to 'editprotected' and 'editsemiprotected' respectively. |
||
| 2807 | */ |
||
| 2808 | public function getRestrictions( $action ) { |
||
| 2816 | |||
| 2817 | /** |
||
| 2818 | * Accessor/initialisation for mRestrictions |
||
| 2819 | * |
||
| 2820 | * @return array Keys are actions, values are arrays as returned by |
||
| 2821 | * Title::getRestrictions() |
||
| 2822 | * @since 1.23 |
||
| 2823 | */ |
||
| 2824 | public function getAllRestrictions() { |
||
| 2830 | |||
| 2831 | /** |
||
| 2832 | * Get the expiry time for the restriction against a given action |
||
| 2833 | * |
||
| 2834 | * @param string $action |
||
| 2835 | * @return string|bool 14-char timestamp, or 'infinity' if the page is protected forever |
||
| 2836 | * or not protected at all, or false if the action is not recognised. |
||
| 2837 | */ |
||
| 2838 | public function getRestrictionExpiry( $action ) { |
||
| 2844 | |||
| 2845 | /** |
||
| 2846 | * Returns cascading restrictions for the current article |
||
| 2847 | * |
||
| 2848 | * @return bool |
||
| 2849 | */ |
||
| 2850 | function areRestrictionsCascading() { |
||
| 2857 | |||
| 2858 | /** |
||
| 2859 | * Loads a string into mRestrictions array |
||
| 2860 | * |
||
| 2861 | * @param ResultWrapper $res Resource restrictions as an SQL result. |
||
| 2862 | * @param string $oldFashionedRestrictions Comma-separated list of page |
||
| 2863 | * restrictions from page table (pre 1.10) |
||
| 2864 | */ |
||
| 2865 | private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) { |
||
| 2874 | |||
| 2875 | /** |
||
| 2876 | * Compiles list of active page restrictions from both page table (pre 1.10) |
||
| 2877 | * and page_restrictions table for this existing page. |
||
| 2878 | * Public for usage by LiquidThreads. |
||
| 2879 | * |
||
| 2880 | * @param array $rows Array of db result objects |
||
| 2881 | * @param string $oldFashionedRestrictions Comma-separated list of page |
||
| 2882 | * restrictions from page table (pre 1.10) |
||
| 2883 | */ |
||
| 2884 | public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { |
||
| 2950 | |||
| 2951 | /** |
||
| 2952 | * Load restrictions from the page_restrictions table |
||
| 2953 | * |
||
| 2954 | * @param string $oldFashionedRestrictions Comma-separated list of page |
||
| 2955 | * restrictions from page table (pre 1.10) |
||
| 2956 | */ |
||
| 2957 | public function loadRestrictions( $oldFashionedRestrictions = null ) { |
||
| 2990 | |||
| 2991 | /** |
||
| 2992 | * Flush the protection cache in this object and force reload from the database. |
||
| 2993 | * This is used when updating protection from WikiPage::doUpdateRestrictions(). |
||
| 2994 | */ |
||
| 2995 | public function flushRestrictions() { |
||
| 2999 | |||
| 3000 | /** |
||
| 3001 | * Purge expired restrictions from the page_restrictions table |
||
| 3002 | */ |
||
| 3003 | static function purgeExpiredRestrictions() { |
||
| 3025 | |||
| 3026 | /** |
||
| 3027 | * Does this have subpages? (Warning, usually requires an extra DB query.) |
||
| 3028 | * |
||
| 3029 | * @return bool |
||
| 3030 | */ |
||
| 3031 | public function hasSubpages() { |
||
| 3051 | |||
| 3052 | /** |
||
| 3053 | * Get all subpages of this page. |
||
| 3054 | * |
||
| 3055 | * @param int $limit Maximum number of subpages to fetch; -1 for no limit |
||
| 3056 | * @return TitleArray|array TitleArray, or empty array if this page's namespace |
||
| 3057 | * doesn't allow subpages |
||
| 3058 | */ |
||
| 3059 | public function getSubpages( $limit = -1 ) { |
||
| 3081 | |||
| 3082 | /** |
||
| 3083 | * Is there a version of this page in the deletion archive? |
||
| 3084 | * |
||
| 3085 | * @return int The number of archived revisions |
||
| 3086 | */ |
||
| 3087 | public function isDeleted() { |
||
| 3106 | |||
| 3107 | /** |
||
| 3108 | * Is there a version of this page in the deletion archive? |
||
| 3109 | * |
||
| 3110 | * @return bool |
||
| 3111 | */ |
||
| 3112 | public function isDeletedQuick() { |
||
| 3129 | |||
| 3130 | /** |
||
| 3131 | * Get the article ID for this Title from the link cache, |
||
| 3132 | * adding it if necessary |
||
| 3133 | * |
||
| 3134 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select |
||
| 3135 | * for update |
||
| 3136 | * @return int The ID |
||
| 3137 | */ |
||
| 3138 | public function getArticleID( $flags = 0 ) { |
||
| 3156 | |||
| 3157 | /** |
||
| 3158 | * Is this an article that is a redirect page? |
||
| 3159 | * Uses link cache, adding it if necessary |
||
| 3160 | * |
||
| 3161 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 3162 | * @return bool |
||
| 3163 | */ |
||
| 3164 | public function isRedirect( $flags = 0 ) { |
||
| 3191 | |||
| 3192 | /** |
||
| 3193 | * What is the length of this page? |
||
| 3194 | * Uses link cache, adding it if necessary |
||
| 3195 | * |
||
| 3196 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 3197 | * @return int |
||
| 3198 | */ |
||
| 3199 | public function getLength( $flags = 0 ) { |
||
| 3220 | |||
| 3221 | /** |
||
| 3222 | * What is the page_latest field for this page? |
||
| 3223 | * |
||
| 3224 | * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update |
||
| 3225 | * @return int Int or 0 if the page doesn't exist |
||
| 3226 | */ |
||
| 3227 | public function getLatestRevID( $flags = 0 ) { |
||
| 3248 | |||
| 3249 | /** |
||
| 3250 | * This clears some fields in this object, and clears any associated |
||
| 3251 | * keys in the "bad links" section of the link cache. |
||
| 3252 | * |
||
| 3253 | * - This is called from WikiPage::doEdit() and WikiPage::insertOn() to allow |
||
| 3254 | * loading of the new page_id. It's also called from |
||
| 3255 | * WikiPage::doDeleteArticleReal() |
||
| 3256 | * |
||
| 3257 | * @param int $newid The new Article ID |
||
| 3258 | */ |
||
| 3259 | public function resetArticleID( $newid ) { |
||
| 3280 | |||
| 3281 | public static function clearCaches() { |
||
| 3288 | |||
| 3289 | /** |
||
| 3290 | * Capitalize a text string for a title if it belongs to a namespace that capitalizes |
||
| 3291 | * |
||
| 3292 | * @param string $text Containing title to capitalize |
||
| 3293 | * @param int $ns Namespace index, defaults to NS_MAIN |
||
| 3294 | * @return string Containing capitalized title |
||
| 3295 | */ |
||
| 3296 | public static function capitalize( $text, $ns = NS_MAIN ) { |
||
| 3305 | |||
| 3306 | /** |
||
| 3307 | * Secure and split - main initialisation function for this object |
||
| 3308 | * |
||
| 3309 | * Assumes that mDbkeyform has been set, and is urldecoded |
||
| 3310 | * and uses underscores, but not otherwise munged. This function |
||
| 3311 | * removes illegal characters, splits off the interwiki and |
||
| 3312 | * namespace prefixes, sets the other forms, and canonicalizes |
||
| 3313 | * everything. |
||
| 3314 | * |
||
| 3315 | * @throws MalformedTitleException On invalid titles |
||
| 3316 | * @return bool True on success |
||
| 3317 | */ |
||
| 3318 | private function secureAndSplit() { |
||
| 3351 | |||
| 3352 | /** |
||
| 3353 | * Get an array of Title objects linking to this Title |
||
| 3354 | * Also stores the IDs in the link cache. |
||
| 3355 | * |
||
| 3356 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3357 | * On heavily-used templates it will max out the memory. |
||
| 3358 | * |
||
| 3359 | * @param array $options May be FOR UPDATE |
||
| 3360 | * @param string $table Table name |
||
| 3361 | * @param string $prefix Fields prefix |
||
| 3362 | * @return Title[] Array of Title objects linking here |
||
| 3363 | */ |
||
| 3364 | public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) { |
||
| 3395 | |||
| 3396 | /** |
||
| 3397 | * Get an array of Title objects using this Title as a template |
||
| 3398 | * Also stores the IDs in the link cache. |
||
| 3399 | * |
||
| 3400 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3401 | * On heavily-used templates it will max out the memory. |
||
| 3402 | * |
||
| 3403 | * @param array $options Query option to Database::select() |
||
| 3404 | * @return Title[] Array of Title the Title objects linking here |
||
| 3405 | */ |
||
| 3406 | public function getTemplateLinksTo( $options = [] ) { |
||
| 3409 | |||
| 3410 | /** |
||
| 3411 | * Get an array of Title objects linked from this Title |
||
| 3412 | * Also stores the IDs in the link cache. |
||
| 3413 | * |
||
| 3414 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3415 | * On heavily-used templates it will max out the memory. |
||
| 3416 | * |
||
| 3417 | * @param array $options Query option to Database::select() |
||
| 3418 | * @param string $table Table name |
||
| 3419 | * @param string $prefix Fields prefix |
||
| 3420 | * @return array Array of Title objects linking here |
||
| 3421 | */ |
||
| 3422 | public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) { |
||
| 3464 | |||
| 3465 | /** |
||
| 3466 | * Get an array of Title objects used on this Title as a template |
||
| 3467 | * Also stores the IDs in the link cache. |
||
| 3468 | * |
||
| 3469 | * WARNING: do not use this function on arbitrary user-supplied titles! |
||
| 3470 | * On heavily-used templates it will max out the memory. |
||
| 3471 | * |
||
| 3472 | * @param array $options May be FOR UPDATE |
||
| 3473 | * @return Title[] Array of Title the Title objects used here |
||
| 3474 | */ |
||
| 3475 | public function getTemplateLinksFrom( $options = [] ) { |
||
| 3478 | |||
| 3479 | /** |
||
| 3480 | * Get an array of Title objects referring to non-existent articles linked |
||
| 3481 | * from this page. |
||
| 3482 | * |
||
| 3483 | * @todo check if needed (used only in SpecialBrokenRedirects.php, and |
||
| 3484 | * should use redirect table in this case). |
||
| 3485 | * @return Title[] Array of Title the Title objects |
||
| 3486 | */ |
||
| 3487 | public function getBrokenLinksFrom() { |
||
| 3516 | |||
| 3517 | /** |
||
| 3518 | * Get a list of URLs to purge from the CDN cache when this |
||
| 3519 | * page changes |
||
| 3520 | * |
||
| 3521 | * @return string[] Array of String the URLs |
||
| 3522 | */ |
||
| 3523 | public function getCdnUrls() { |
||
| 3547 | |||
| 3548 | /** |
||
| 3549 | * @deprecated since 1.27 use getCdnUrls() |
||
| 3550 | */ |
||
| 3551 | public function getSquidURLs() { |
||
| 3554 | |||
| 3555 | /** |
||
| 3556 | * Purge all applicable CDN URLs |
||
| 3557 | */ |
||
| 3558 | public function purgeSquid() { |
||
| 3564 | |||
| 3565 | /** |
||
| 3566 | * Move this page without authentication |
||
| 3567 | * |
||
| 3568 | * @deprecated since 1.25 use MovePage class instead |
||
| 3569 | * @param Title $nt The new page Title |
||
| 3570 | * @return array|bool True on success, getUserPermissionsErrors()-like array on failure |
||
| 3571 | */ |
||
| 3572 | public function moveNoAuth( &$nt ) { |
||
| 3576 | |||
| 3577 | /** |
||
| 3578 | * Check whether a given move operation would be valid. |
||
| 3579 | * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise |
||
| 3580 | * |
||
| 3581 | * @deprecated since 1.25, use MovePage's methods instead |
||
| 3582 | * @param Title $nt The new title |
||
| 3583 | * @param bool $auth Whether to check user permissions (uses $wgUser) |
||
| 3584 | * @param string $reason Is the log summary of the move, used for spam checking |
||
| 3585 | * @return array|bool True on success, getUserPermissionsErrors()-like array on failure |
||
| 3586 | */ |
||
| 3587 | public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) { |
||
| 3607 | |||
| 3608 | /** |
||
| 3609 | * Check if the requested move target is a valid file move target |
||
| 3610 | * @todo move this to MovePage |
||
| 3611 | * @param Title $nt Target title |
||
| 3612 | * @return array List of errors |
||
| 3613 | */ |
||
| 3614 | protected function validateFileMoveOperation( $nt ) { |
||
| 3629 | |||
| 3630 | /** |
||
| 3631 | * Move a title to a new location |
||
| 3632 | * |
||
| 3633 | * @deprecated since 1.25, use the MovePage class instead |
||
| 3634 | * @param Title $nt The new title |
||
| 3635 | * @param bool $auth Indicates whether $wgUser's permissions |
||
| 3636 | * should be checked |
||
| 3637 | * @param string $reason The reason for the move |
||
| 3638 | * @param bool $createRedirect Whether to create a redirect from the old title to the new title. |
||
| 3639 | * Ignored if the user doesn't have the suppressredirect right. |
||
| 3640 | * @return array|bool True on success, getUserPermissionsErrors()-like array on failure |
||
| 3641 | */ |
||
| 3642 | public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) { |
||
| 3663 | |||
| 3664 | /** |
||
| 3665 | * Move this page's subpages to be subpages of $nt |
||
| 3666 | * |
||
| 3667 | * @param Title $nt Move target |
||
| 3668 | * @param bool $auth Whether $wgUser's permissions should be checked |
||
| 3669 | * @param string $reason The reason for the move |
||
| 3670 | * @param bool $createRedirect Whether to create redirects from the old subpages to |
||
| 3671 | * the new ones Ignored if the user doesn't have the 'suppressredirect' right |
||
| 3672 | * @return array Array with old page titles as keys, and strings (new page titles) or |
||
| 3673 | * arrays (errors) as values, or an error array with numeric indices if no pages |
||
| 3674 | * were moved |
||
| 3675 | */ |
||
| 3676 | public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) { |
||
| 3736 | |||
| 3737 | /** |
||
| 3738 | * Checks if this page is just a one-rev redirect. |
||
| 3739 | * Adds lock, so don't use just for light purposes. |
||
| 3740 | * |
||
| 3741 | * @return bool |
||
| 3742 | */ |
||
| 3743 | public function isSingleRevRedirect() { |
||
| 3785 | |||
| 3786 | /** |
||
| 3787 | * Checks if $this can be moved to a given Title |
||
| 3788 | * - Selects for update, so don't call it unless you mean business |
||
| 3789 | * |
||
| 3790 | * @deprecated since 1.25, use MovePage's methods instead |
||
| 3791 | * @param Title $nt The new title to check |
||
| 3792 | * @return bool |
||
| 3793 | */ |
||
| 3794 | public function isValidMoveTarget( $nt ) { |
||
| 3834 | |||
| 3835 | /** |
||
| 3836 | * Get categories to which this Title belongs and return an array of |
||
| 3837 | * categories' names. |
||
| 3838 | * |
||
| 3839 | * @return array Array of parents in the form: |
||
| 3840 | * $parent => $currentarticle |
||
| 3841 | */ |
||
| 3842 | public function getParentCategories() { |
||
| 3870 | |||
| 3871 | /** |
||
| 3872 | * Get a tree of parent categories |
||
| 3873 | * |
||
| 3874 | * @param array $children Array with the children in the keys, to check for circular refs |
||
| 3875 | * @return array Tree of parent categories |
||
| 3876 | */ |
||
| 3877 | public function getParentCategoryTree( $children = [] ) { |
||
| 3897 | |||
| 3898 | /** |
||
| 3899 | * Get an associative array for selecting this title from |
||
| 3900 | * the "page" table |
||
| 3901 | * |
||
| 3902 | * @return array Array suitable for the $where parameter of DB::select() |
||
| 3903 | */ |
||
| 3904 | public function pageCond() { |
||
| 3912 | |||
| 3913 | /** |
||
| 3914 | * Get the revision ID of the previous revision |
||
| 3915 | * |
||
| 3916 | * @param int $revId Revision ID. Get the revision that was before this one. |
||
| 3917 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3918 | * @return int|bool Old revision ID, or false if none exists |
||
| 3919 | */ |
||
| 3920 | View Code Duplication | public function getPreviousRevisionID( $revId, $flags = 0 ) { |
|
| 3937 | |||
| 3938 | /** |
||
| 3939 | * Get the revision ID of the next revision |
||
| 3940 | * |
||
| 3941 | * @param int $revId Revision ID. Get the revision that was after this one. |
||
| 3942 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3943 | * @return int|bool Next revision ID, or false if none exists |
||
| 3944 | */ |
||
| 3945 | View Code Duplication | public function getNextRevisionID( $revId, $flags = 0 ) { |
|
| 3962 | |||
| 3963 | /** |
||
| 3964 | * Get the first revision of the page |
||
| 3965 | * |
||
| 3966 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3967 | * @return Revision|null If page doesn't exist |
||
| 3968 | */ |
||
| 3969 | public function getFirstRevision( $flags = 0 ) { |
||
| 3984 | |||
| 3985 | /** |
||
| 3986 | * Get the oldest revision timestamp of this page |
||
| 3987 | * |
||
| 3988 | * @param int $flags Title::GAID_FOR_UPDATE |
||
| 3989 | * @return string MW timestamp |
||
| 3990 | */ |
||
| 3991 | public function getEarliestRevTime( $flags = 0 ) { |
||
| 3995 | |||
| 3996 | /** |
||
| 3997 | * Check if this is a new page |
||
| 3998 | * |
||
| 3999 | * @return bool |
||
| 4000 | */ |
||
| 4001 | public function isNewPage() { |
||
| 4005 | |||
| 4006 | /** |
||
| 4007 | * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit |
||
| 4008 | * |
||
| 4009 | * @return bool |
||
| 4010 | */ |
||
| 4011 | public function isBigDeletion() { |
||
| 4034 | |||
| 4035 | /** |
||
| 4036 | * Get the approximate revision count of this page. |
||
| 4037 | * |
||
| 4038 | * @return int |
||
| 4039 | */ |
||
| 4040 | public function estimateRevisionCount() { |
||
| 4053 | |||
| 4054 | /** |
||
| 4055 | * Get the number of revisions between the given revision. |
||
| 4056 | * Used for diffs and other things that really need it. |
||
| 4057 | * |
||
| 4058 | * @param int|Revision $old Old revision or rev ID (first before range) |
||
| 4059 | * @param int|Revision $new New revision or rev ID (first after range) |
||
| 4060 | * @param int|null $max Limit of Revisions to count, will be incremented to detect truncations |
||
| 4061 | * @return int Number of revisions between these revisions. |
||
| 4062 | */ |
||
| 4063 | public function countRevisionsBetween( $old, $new, $max = null ) { |
||
| 4089 | |||
| 4090 | /** |
||
| 4091 | * Get the authors between the given revisions or revision IDs. |
||
| 4092 | * Used for diffs and other things that really need it. |
||
| 4093 | * |
||
| 4094 | * @since 1.23 |
||
| 4095 | * |
||
| 4096 | * @param int|Revision $old Old revision or rev ID (first before range by default) |
||
| 4097 | * @param int|Revision $new New revision or rev ID (first after range by default) |
||
| 4098 | * @param int $limit Maximum number of authors |
||
| 4099 | * @param string|array $options (Optional): Single option, or an array of options: |
||
| 4100 | * 'include_old' Include $old in the range; $new is excluded. |
||
| 4101 | * 'include_new' Include $new in the range; $old is excluded. |
||
| 4102 | * 'include_both' Include both $old and $new in the range. |
||
| 4103 | * Unknown option values are ignored. |
||
| 4104 | * @return array|null Names of revision authors in the range; null if not both revisions exist |
||
| 4105 | */ |
||
| 4106 | public function getAuthorsBetween( $old, $new, $limit, $options = [] ) { |
||
| 4165 | |||
| 4166 | /** |
||
| 4167 | * Get the number of authors between the given revisions or revision IDs. |
||
| 4168 | * Used for diffs and other things that really need it. |
||
| 4169 | * |
||
| 4170 | * @param int|Revision $old Old revision or rev ID (first before range by default) |
||
| 4171 | * @param int|Revision $new New revision or rev ID (first after range by default) |
||
| 4172 | * @param int $limit Maximum number of authors |
||
| 4173 | * @param string|array $options (Optional): Single option, or an array of options: |
||
| 4174 | * 'include_old' Include $old in the range; $new is excluded. |
||
| 4175 | * 'include_new' Include $new in the range; $old is excluded. |
||
| 4176 | * 'include_both' Include both $old and $new in the range. |
||
| 4177 | * Unknown option values are ignored. |
||
| 4178 | * @return int Number of revision authors in the range; zero if not both revisions exist |
||
| 4179 | */ |
||
| 4180 | public function countAuthorsBetween( $old, $new, $limit, $options = [] ) { |
||
| 4184 | |||
| 4185 | /** |
||
| 4186 | * Compare with another title. |
||
| 4187 | * |
||
| 4188 | * @param Title $title |
||
| 4189 | * @return bool |
||
| 4190 | */ |
||
| 4191 | public function equals( Title $title ) { |
||
| 4197 | |||
| 4198 | /** |
||
| 4199 | * Check if this title is a subpage of another title |
||
| 4200 | * |
||
| 4201 | * @param Title $title |
||
| 4202 | * @return bool |
||
| 4203 | */ |
||
| 4204 | public function isSubpageOf( Title $title ) { |
||
| 4209 | |||
| 4210 | /** |
||
| 4211 | * Check if page exists. For historical reasons, this function simply |
||
| 4212 | * checks for the existence of the title in the page table, and will |
||
| 4213 | * thus return false for interwiki links, special pages and the like. |
||
| 4214 | * If you want to know if a title can be meaningfully viewed, you should |
||
| 4215 | * probably call the isKnown() method instead. |
||
| 4216 | * |
||
| 4217 | * @param int $flags An optional bit field; may be Title::GAID_FOR_UPDATE to check |
||
| 4218 | * from master/for update |
||
| 4219 | * @return bool |
||
| 4220 | */ |
||
| 4221 | public function exists( $flags = 0 ) { |
||
| 4226 | |||
| 4227 | /** |
||
| 4228 | * Should links to this title be shown as potentially viewable (i.e. as |
||
| 4229 | * "bluelinks"), even if there's no record by this title in the page |
||
| 4230 | * table? |
||
| 4231 | * |
||
| 4232 | * This function is semi-deprecated for public use, as well as somewhat |
||
| 4233 | * misleadingly named. You probably just want to call isKnown(), which |
||
| 4234 | * calls this function internally. |
||
| 4235 | * |
||
| 4236 | * (ISSUE: Most of these checks are cheap, but the file existence check |
||
| 4237 | * can potentially be quite expensive. Including it here fixes a lot of |
||
| 4238 | * existing code, but we might want to add an optional parameter to skip |
||
| 4239 | * it and any other expensive checks.) |
||
| 4240 | * |
||
| 4241 | * @return bool |
||
| 4242 | */ |
||
| 4243 | public function isAlwaysKnown() { |
||
| 4284 | |||
| 4285 | /** |
||
| 4286 | * Does this title refer to a page that can (or might) be meaningfully |
||
| 4287 | * viewed? In particular, this function may be used to determine if |
||
| 4288 | * links to the title should be rendered as "bluelinks" (as opposed to |
||
| 4289 | * "redlinks" to non-existent pages). |
||
| 4290 | * Adding something else to this function will cause inconsistency |
||
| 4291 | * since LinkHolderArray calls isAlwaysKnown() and does its own |
||
| 4292 | * page existence check. |
||
| 4293 | * |
||
| 4294 | * @return bool |
||
| 4295 | */ |
||
| 4296 | public function isKnown() { |
||
| 4299 | |||
| 4300 | /** |
||
| 4301 | * Does this page have source text? |
||
| 4302 | * |
||
| 4303 | * @return bool |
||
| 4304 | */ |
||
| 4305 | public function hasSourceText() { |
||
| 4325 | |||
| 4326 | /** |
||
| 4327 | * Get the default message text or false if the message doesn't exist |
||
| 4328 | * |
||
| 4329 | * @return string|bool |
||
| 4330 | */ |
||
| 4331 | public function getDefaultMessageText() { |
||
| 4349 | |||
| 4350 | /** |
||
| 4351 | * Updates page_touched for this page; called from LinksUpdate.php |
||
| 4352 | * |
||
| 4353 | * @param string $purgeTime [optional] TS_MW timestamp |
||
| 4354 | * @return bool True if the update succeeded |
||
| 4355 | */ |
||
| 4356 | public function invalidateCache( $purgeTime = null ) { |
||
| 4381 | |||
| 4382 | /** |
||
| 4383 | * Update page_touched timestamps and send CDN purge messages for |
||
| 4384 | * pages linking to this title. May be sent to the job queue depending |
||
| 4385 | * on the number of links. Typically called on create and delete. |
||
| 4386 | */ |
||
| 4387 | public function touchLinks() { |
||
| 4393 | |||
| 4394 | /** |
||
| 4395 | * Get the last touched timestamp |
||
| 4396 | * |
||
| 4397 | * @param IDatabase $db Optional db |
||
| 4398 | * @return string Last-touched timestamp |
||
| 4399 | */ |
||
| 4400 | public function getTouched( $db = null ) { |
||
| 4407 | |||
| 4408 | /** |
||
| 4409 | * Get the timestamp when this page was updated since the user last saw it. |
||
| 4410 | * |
||
| 4411 | * @param User $user |
||
| 4412 | * @return string|null |
||
| 4413 | */ |
||
| 4414 | public function getNotificationTimestamp( $user = null ) { |
||
| 4444 | |||
| 4445 | /** |
||
| 4446 | * Generate strings used for xml 'id' names in monobook tabs |
||
| 4447 | * |
||
| 4448 | * @param string $prepend Defaults to 'nstab-' |
||
| 4449 | * @return string XML 'id' name |
||
| 4450 | */ |
||
| 4451 | public function getNamespaceKey( $prepend = 'nstab-' ) { |
||
| 4475 | |||
| 4476 | /** |
||
| 4477 | * Get all extant redirects to this Title |
||
| 4478 | * |
||
| 4479 | * @param int|null $ns Single namespace to consider; null to consider all namespaces |
||
| 4480 | * @return Title[] Array of Title redirects to this title |
||
| 4481 | */ |
||
| 4482 | public function getRedirectsHere( $ns = null ) { |
||
| 4512 | |||
| 4513 | /** |
||
| 4514 | * Check if this Title is a valid redirect target |
||
| 4515 | * |
||
| 4516 | * @return bool |
||
| 4517 | */ |
||
| 4518 | public function isValidRedirectTarget() { |
||
| 4536 | |||
| 4537 | /** |
||
| 4538 | * Get a backlink cache object |
||
| 4539 | * |
||
| 4540 | * @return BacklinkCache |
||
| 4541 | */ |
||
| 4542 | public function getBacklinkCache() { |
||
| 4545 | |||
| 4546 | /** |
||
| 4547 | * Whether the magic words __INDEX__ and __NOINDEX__ function for this page. |
||
| 4548 | * |
||
| 4549 | * @return bool |
||
| 4550 | */ |
||
| 4551 | public function canUseNoindex() { |
||
| 4561 | |||
| 4562 | /** |
||
| 4563 | * Returns the raw sort key to be used for categories, with the specified |
||
| 4564 | * prefix. This will be fed to Collation::getSortKey() to get a |
||
| 4565 | * binary sortkey that can be used for actual sorting. |
||
| 4566 | * |
||
| 4567 | * @param string $prefix The prefix to be used, specified using |
||
| 4568 | * {{defaultsort:}} or like [[Category:Foo|prefix]]. Empty for no |
||
| 4569 | * prefix. |
||
| 4570 | * @return string |
||
| 4571 | */ |
||
| 4572 | public function getCategorySortkey( $prefix = '' ) { |
||
| 4590 | |||
| 4591 | /** |
||
| 4592 | * Returns the page language code saved in the database, if $wgPageLanguageUseDB is set |
||
| 4593 | * to true in LocalSettings.php, otherwise returns false. If there is no language saved in |
||
| 4594 | * the db, it will return NULL. |
||
| 4595 | * |
||
| 4596 | * @return string|null|bool |
||
| 4597 | */ |
||
| 4598 | private function getDbPageLanguageCode() { |
||
| 4611 | |||
| 4612 | /** |
||
| 4613 | * Get the language in which the content of this page is written in |
||
| 4614 | * wikitext. Defaults to $wgContLang, but in certain cases it can be |
||
| 4615 | * e.g. $wgLang (such as special pages, which are in the user language). |
||
| 4616 | * |
||
| 4617 | * @since 1.18 |
||
| 4618 | * @return Language |
||
| 4619 | */ |
||
| 4620 | public function getPageLanguage() { |
||
| 4649 | |||
| 4650 | /** |
||
| 4651 | * Get the language in which the content of this page is written when |
||
| 4652 | * viewed by user. Defaults to $wgContLang, but in certain cases it can be |
||
| 4653 | * e.g. $wgLang (such as special pages, which are in the user language). |
||
| 4654 | * |
||
| 4655 | * @since 1.20 |
||
| 4656 | * @return Language |
||
| 4657 | */ |
||
| 4658 | public function getPageViewLanguage() { |
||
| 4691 | |||
| 4692 | /** |
||
| 4693 | * Get a list of rendered edit notices for this page. |
||
| 4694 | * |
||
| 4695 | * Array is keyed by the original message key, and values are rendered using parseAsBlock, so |
||
| 4696 | * they will already be wrapped in paragraphs. |
||
| 4697 | * |
||
| 4698 | * @since 1.21 |
||
| 4699 | * @param int $oldid Revision ID that's being edited |
||
| 4700 | * @return array |
||
| 4701 | */ |
||
| 4702 | public function getEditNotices( $oldid = 0 ) { |
||
| 4769 | |||
| 4770 | /** |
||
| 4771 | * @return array |
||
| 4772 | */ |
||
| 4773 | public function __sleep() { |
||
| 4784 | |||
| 4785 | public function __wakeup() { |
||
| 4790 | |||
| 4791 | } |
||
| 4792 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: