X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=866f0415d8934114b6081861ca7f799f4f043eda;hb=94022121b5415796e4ee0c89d41ddcd73c3fd3da;hp=12ab5325587bc572c2bff2c08e29c22af6e09b9f;hpb=821505367e41597e23d3547ca70c2485f1d9da26;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 12ab532558..866f0415d8 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -246,6 +246,8 @@ class Title implements LinkTarget, IDBAccessObject { * unless $forceClone is "clone". If $forceClone is "clone" and the given TitleValue * is already a Title instance, that instance is copied using the clone operator. * + * @deprecated since 1.34, use newFromLinkTarget or castFromLinkTarget + * * @param TitleValue $titleValue Assumed to be safe. * @param string $forceClone set to NEW_CLONE to ensure a fresh instance is returned. * @@ -283,6 +285,17 @@ class Title implements LinkTarget, IDBAccessObject { ); } + /** + * Same as newFromLinkTarget, but if passed null, returns null. + * + * @param LinkTarget|null $linkTarget Assumed to be safe (if not null). + * + * @return Title|null + */ + public static function castFromLinkTarget( $linkTarget ) { + return $linkTarget ? self::newFromLinkTarget( $linkTarget ) : null; + } + /** * Create a new Title from text, such as what one would find in a link. De- * codes any HTML entities in the text. @@ -605,7 +618,7 @@ class Title implements LinkTarget, IDBAccessObject { // NOTE: ideally, this would just call makeTitle() and then isValid(), // but presently, that means more overhead on a potential performance hotspot. - if ( !MWNamespace::exists( $ns ) ) { + if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) { return null; } @@ -807,7 +820,8 @@ class Title implements LinkTarget, IDBAccessObject { $canonicalNamespace = false ) { if ( $canonicalNamespace ) { - $namespace = MWNamespace::getCanonicalName( $ns ); + $namespace = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $ns ); } else { $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns ); } @@ -849,13 +863,13 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isValid() { - if ( !MWNamespace::exists( $this->mNamespace ) ) { + $services = MediaWikiServices::getInstance(); + if ( !$services->getNamespaceInfo()->exists( $this->mNamespace ) ) { return false; } try { - $parser = MediaWikiServices::getInstance()->getTitleParser(); - $parser->parseTitle( $this->mDbkeyform, $this->mNamespace ); + $services->getTitleParser()->parseTitle( $this->mDbkeyform, $this->mNamespace ); return true; } catch ( MalformedTitleException $ex ) { return false; @@ -1073,7 +1087,8 @@ class Title implements LinkTarget, IDBAccessObject { if ( $this->isExternal() ) { // This probably shouldn't even happen, except for interwiki transclusion. // If possible, use the canonical name for the foreign namespace. - $nsText = MWNamespace::getCanonicalName( $this->mNamespace ); + $nsText = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalName( $this->mNamespace ); if ( $nsText !== false ) { return $nsText; } @@ -1094,8 +1109,9 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Namespace text */ public function getSubjectNsText() { - return MediaWikiServices::getInstance()->getContentLanguage()-> - getNsText( MWNamespace::getSubject( $this->mNamespace ) ); + $services = MediaWikiServices::getInstance(); + return $services->getContentLanguage()-> + getNsText( $services->getNamespaceInfo()->getSubject( $this->mNamespace ) ); } /** @@ -1104,20 +1120,22 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Namespace text */ public function getTalkNsText() { - return MediaWikiServices::getInstance()->getContentLanguage()-> - getNsText( MWNamespace::getTalk( $this->mNamespace ) ); + $services = MediaWikiServices::getInstance(); + return $services->getContentLanguage()-> + getNsText( $services->getNamespaceInfo()->getTalk( $this->mNamespace ) ); } /** * Can this title have a corresponding talk page? * - * @see MWNamespace::hasTalkNamespace + * @see NamespaceInfo::hasTalkNamespace * @since 1.30 * * @return bool True if this title either is a talk page or can have a talk page associated. */ public function canHaveTalkPage() { - return MWNamespace::hasTalkNamespace( $this->mNamespace ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasTalkNamespace( $this->mNamespace ); } /** @@ -1135,7 +1153,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isWatchable() { - return !$this->isExternal() && MWNamespace::isWatchable( $this->mNamespace ); + return !$this->isExternal() && MediaWikiServices::getInstance()->getNamespaceInfo()-> + isWatchable( $this->mNamespace ); } /** @@ -1196,7 +1215,8 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.19 */ public function inNamespace( $ns ) { - return MWNamespace::equals( $this->mNamespace, $ns ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + equals( $this->mNamespace, $ns ); } /** @@ -1235,7 +1255,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function hasSubjectNamespace( $ns ) { - return MWNamespace::subjectEquals( $this->mNamespace, $ns ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + subjectEquals( $this->mNamespace, $ns ); } /** @@ -1246,7 +1267,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isContentPage() { - return MWNamespace::isContent( $this->mNamespace ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + isContent( $this->mNamespace ); } /** @@ -1256,7 +1278,10 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isMovable() { - if ( !MWNamespace::isMovable( $this->mNamespace ) || $this->isExternal() ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + isMovable( $this->mNamespace ) || $this->isExternal() + ) { // Interwiki title or immovable namespace. Hooks don't get to override here return false; } @@ -1286,7 +1311,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isSubpage() { - return MWNamespace::hasSubpages( $this->mNamespace ) + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) ? strpos( $this->getText(), '/' ) !== false : false; } @@ -1482,16 +1508,19 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isTalkPage() { - return MWNamespace::isTalk( $this->mNamespace ); + return MediaWikiServices::getInstance()->getNamespaceInfo()-> + isTalk( $this->mNamespace ); } /** * Get a Title object associated with the talk page of this article * + * @deprecated since 1.34, use NamespaceInfo::getTalkPage * @return Title The object for the talk page */ public function getTalkPage() { - return self::makeTitle( MWNamespace::getTalk( $this->mNamespace ), $this->mDbkeyform ); + return self::castFromLinkTarget( + MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) ); } /** @@ -1515,37 +1544,26 @@ class Title implements LinkTarget, IDBAccessObject { * Get a title object associated with the subject page of this * talk page * + * @deprecated since 1.34, use NamespaceInfo::getSubjectPage * @return Title The object for the subject page */ public function getSubjectPage() { - // Is this the same title? - $subjectNS = MWNamespace::getSubject( $this->mNamespace ); - if ( $this->mNamespace == $subjectNS ) { - return $this; - } - return self::makeTitle( $subjectNS, $this->mDbkeyform ); + return self::castFromLinkTarget( + MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) ); } /** * Get the other title for this page, if this is a subject page * get the talk page, if it is a subject page get the talk page * + * @deprecated since 1.34, use NamespaceInfo::getAssociatedPage * @since 1.25 * @throws MWException If the page doesn't have an other page * @return Title */ public function getOtherPage() { - if ( $this->isSpecialPage() ) { - throw new MWException( 'Special pages cannot have other pages' ); - } - if ( $this->isTalkPage() ) { - return $this->getSubjectPage(); - } else { - if ( !$this->canHaveTalkPage() ) { - throw new MWException( "{$this->getPrefixedText()} does not have an other page" ); - } - return $this->getTalkPage(); - } + return self::castFromLinkTarget( + MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) ); } /** @@ -1720,7 +1738,10 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.20 */ public function getRootText() { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return $this->getText(); } @@ -1756,7 +1777,10 @@ class Title implements LinkTarget, IDBAccessObject { */ public function getBaseText() { $text = $this->getText(); - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return $text; } @@ -1797,7 +1821,10 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Subpage name */ public function getSubpageText() { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return $this->mTextform; } $parts = explode( '/', $this->mTextform ); @@ -2864,7 +2891,10 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function hasSubpages() { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { # Duh return false; } @@ -2892,7 +2922,10 @@ class Title implements LinkTarget, IDBAccessObject { * doesn't allow subpages */ public function getSubpages( $limit = -1 ) { - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + !MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { return []; } @@ -3126,7 +3159,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Containing capitalized title */ public static function capitalize( $text, $ns = NS_MAIN ) { - if ( MWNamespace::isCapitalized( $ns ) ) { + $services = MediaWikiServices::getInstance(); + if ( $services->getNamespaceInfo()->isCapitalized( $ns ) ) { return MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $text ); } else { return $text; @@ -3432,19 +3466,10 @@ class Title implements LinkTarget, IDBAccessObject { array $changeTags = [] ) { global $wgUser; - $err = $this->isValidMoveOperation( $nt, $auth, $reason ); - if ( is_array( $err ) ) { - // Auto-block user's IP if the account was "hard" blocked - $wgUser->spreadAnyEditBlock(); - return $err; - } - // Check suppressredirect permission - if ( $auth && !$wgUser->isAllowed( 'suppressredirect' ) ) { - $createRedirect = true; - } $mp = new MovePage( $this, $nt ); - $status = $mp->move( $wgUser, $reason, $createRedirect, $changeTags ); + $method = $auth ? 'moveIfAllowed' : 'move'; + $status = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags ); if ( $status->isOK() ) { return true; } else { @@ -3477,14 +3502,15 @@ class Title implements LinkTarget, IDBAccessObject { ]; } // Do the source and target namespaces support subpages? - if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + if ( !$nsInfo->hasSubpages( $this->mNamespace ) ) { return [ - [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $this->mNamespace ) ], + [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $this->mNamespace ) ], ]; } - if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) { + if ( !$nsInfo->hasSubpages( $nt->getNamespace() ) ) { return [ - [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $nt->getNamespace() ) ], + [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $nt->getNamespace() ) ], ]; } @@ -3717,57 +3743,25 @@ class Title implements LinkTarget, IDBAccessObject { * @return int|bool New revision ID, or false if none exists */ private function getRelativeRevisionID( $revId, $flags, $dir ) { - $revId = (int)$revId; - if ( $dir === 'next' ) { - $op = '>'; - $sort = 'ASC'; - } elseif ( $dir === 'prev' ) { - $op = '<'; - $sort = 'DESC'; - } else { - throw new InvalidArgumentException( '$dir must be "next" or "prev"' ); - } - - if ( $flags & self::GAID_FOR_UPDATE ) { - $db = wfGetDB( DB_MASTER ); - } else { - $db = wfGetDB( DB_REPLICA, 'contributions' ); - } - - // Intentionally not caring if the specified revision belongs to this - // page. We only care about the timestamp. - $ts = $db->selectField( 'revision', 'rev_timestamp', [ 'rev_id' => $revId ], __METHOD__ ); - if ( $ts === false ) { - $ts = $db->selectField( 'archive', 'ar_timestamp', [ 'ar_rev_id' => $revId ], __METHOD__ ); - if ( $ts === false ) { - // Or should this throw an InvalidArgumentException or something? - return false; - } + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); + $rlFlags = $flags === self::GAID_FOR_UPDATE ? IDBAccessObject::READ_LATEST : 0; + $rev = $rl->getRevisionById( $revId, $rlFlags ); + if ( !$rev ) { + return false; } - $ts = $db->addQuotes( $ts ); - - $revId = $db->selectField( 'revision', 'rev_id', - [ - 'rev_page' => $this->getArticleID( $flags ), - "rev_timestamp $op $ts OR (rev_timestamp = $ts AND rev_id $op $revId)" - ], - __METHOD__, - [ - 'ORDER BY' => "rev_timestamp $sort, rev_id $sort", - 'IGNORE INDEX' => 'rev_timestamp', // Probably needed for T159319 - ] - ); - - if ( $revId === false ) { + $oldRev = $dir === 'next' + ? $rl->getNextRevision( $rev, $rlFlags ) + : $rl->getPreviousRevision( $rev, $rlFlags ); + if ( !$oldRev ) { return false; - } else { - return intval( $revId ); } + return $oldRev->getId(); } /** * Get the revision ID of the previous revision * + * @deprecated since 1.34, use RevisionLookup::getPreviousRevision * @param int $revId Revision ID. Get the revision that was before this one. * @param int $flags Title::GAID_FOR_UPDATE * @return int|bool Old revision ID, or false if none exists @@ -3779,6 +3773,7 @@ class Title implements LinkTarget, IDBAccessObject { /** * Get the revision ID of the next revision * + * @deprecated since 1.34, use RevisionLookup::getNextRevision * @param int $revId Revision ID. Get the revision that was after this one. * @param int $flags Title::GAID_FOR_UPDATE * @return int|bool Next revision ID, or false if none exists @@ -4018,14 +4013,14 @@ class Title implements LinkTarget, IDBAccessObject { /** * Compare with another title. * - * @param Title $title + * @param LinkTarget $title * @return bool */ - public function equals( Title $title ) { + public function equals( LinkTarget $title ) { // Note: === is necessary for proper matching of number-like titles. - return $this->mInterwiki === $title->mInterwiki - && $this->mNamespace == $title->mNamespace - && $this->mDbkeyform === $title->mDbkeyform; + return $this->mInterwiki === $title->getInterwiki() + && $this->mNamespace == $title->getNamespace() + && $this->mDbkeyform === $title->getDBkey(); } /** @@ -4329,9 +4324,10 @@ class Title implements LinkTarget, IDBAccessObject { */ public function getNamespaceKey( $prepend = 'nstab-' ) { // Gets the subject namespace of this title - $subjectNS = MWNamespace::getSubject( $this->mNamespace ); + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + $subjectNS = $nsInfo->getSubject( $this->mNamespace ); // Prefer canonical namespace name for HTML IDs - $namespaceKey = MWNamespace::getCanonicalName( $subjectNS ); + $namespaceKey = $nsInfo->getCanonicalName( $subjectNS ); if ( $namespaceKey === false ) { // Fallback to localised text $namespaceKey = $this->getSubjectNsText(); @@ -4427,7 +4423,8 @@ class Title implements LinkTarget, IDBAccessObject { public function canUseNoindex() { global $wgExemptFromUserRobotsControl; - $bannedNamespaces = $wgExemptFromUserRobotsControl ?? MWNamespace::getContentNamespaces(); + $bannedNamespaces = $wgExemptFromUserRobotsControl ?? + MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces(); return !in_array( $this->mNamespace, $bannedNamespaces ); } @@ -4594,7 +4591,10 @@ class Title implements LinkTarget, IDBAccessObject { } } - if ( MWNamespace::hasSubpages( $this->mNamespace ) ) { + if ( + MediaWikiServices::getInstance()->getNamespaceInfo()-> + hasSubpages( $this->mNamespace ) + ) { // Optional notice for page itself and any parent page $editnotice_base = $editnotice_ns; foreach ( explode( '/', $this->mDbkeyform ) as $part ) {