X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FTitle.php;h=60adb570fe15cdf2397115c05e622d5703e4a619;hp=1e93c44250d6afa6b22c3fe452b1cf100374d676;hb=326d52f9613c5227d75f97361be6ec6ef78b214e;hpb=93d9da40d3153ee8f63ffbd7bc72f08d62e11efd diff --git a/includes/Title.php b/includes/Title.php index 1e93c44250..60adb570fe 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -23,7 +23,7 @@ */ use MediaWiki\Permissions\PermissionManager; -use MediaWiki\Storage\RevisionRecord; +use MediaWiki\Revision\RevisionRecord; use Wikimedia\Assert\Assert; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; @@ -1059,7 +1059,7 @@ class Title implements LinkTarget, IDBAccessObject { $this->lazyFillContentModel( $this->loadFieldFromDB( 'page_content_model', $flags ) ); } elseif ( ( !$this->mContentModel || $flags & self::GAID_FOR_UPDATE ) && - $this->getArticleId( $flags ) + $this->getArticleID( $flags ) ) { $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addLinkObj( $this ); # in case we already had an article ID @@ -1266,13 +1266,11 @@ class Title implements LinkTarget, IDBAccessObject { /** * Returns true if the title is inside one of the specified namespaces. * - * @param int|int[] $namespaces,... The namespaces to check for + * @param int|int[] ...$namespaces The namespaces to check for * @return bool * @since 1.19 - * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ - public function inNamespaces( /* ... */ ) { - $namespaces = func_get_args(); + public function inNamespaces( ...$namespaces ) { if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) { $namespaces = $namespaces[0]; } @@ -1561,14 +1559,32 @@ class Title implements LinkTarget, IDBAccessObject { * Get a Title object associated with the talk page of this article * * @deprecated since 1.34, use getTalkPageIfDefined() or NamespaceInfo::getTalkPage() - * with NamespaceInfo::canHaveTalkPage(). + * with NamespaceInfo::canHaveTalkPage(). Note that the new method will + * throw if asked for the talk page of a section-only link, or of an interwiki + * link. * @return Title The object for the talk page * @throws MWException if $target doesn't have talk pages, e.g. because it's in NS_SPECIAL * or because it's a relative link, or an interwiki link. */ public function getTalkPage() { - return self::castFromLinkTarget( - MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) ); + // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles. + // Instead of failing on invalid titles, let's just log the issue for now. + // See the discussion on T227817. + + // Is this the same title? + $talkNS = MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $this->mNamespace ); + if ( $this->mNamespace == $talkNS ) { + return $this; + } + + $title = self::makeTitle( $talkNS, $this->mDbkeyform ); + + $this->warnIfPageCannotExist( $title, __METHOD__ ); + + return $title; + // TODO: replace the above with the code below: + // return self::castFromLinkTarget( + // MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkPage( $this ) ); } /** @@ -1596,8 +1612,51 @@ class Title implements LinkTarget, IDBAccessObject { * @return Title The object for the subject page */ public function getSubjectPage() { - return self::castFromLinkTarget( - MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) ); + // Is this the same title? + $subjectNS = MediaWikiServices::getInstance()->getNamespaceInfo() + ->getSubject( $this->mNamespace ); + if ( $this->mNamespace == $subjectNS ) { + return $this; + } + // NOTE: The equivalent code in NamespaceInfo is less lenient about producing invalid titles. + // Instead of failing on invalid titles, let's just log the issue for now. + // See the discussion on T227817. + $title = self::makeTitle( $subjectNS, $this->mDbkeyform ); + + $this->warnIfPageCannotExist( $title, __METHOD__ ); + + return $title; + // TODO: replace the above with the code below: + // return self::castFromLinkTarget( + // MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectPage( $this ) ); + } + + /** + * @param Title $title + * @param string $method + * + * @return bool whether a warning was issued + */ + private function warnIfPageCannotExist( Title $title, $method ) { + if ( $this->getText() == '' ) { + wfLogWarning( + $method . ': called on empty title ' . $this->getFullText() . ', returning ' + . $title->getFullText() + ); + + return true; + } + + if ( $this->getInterwiki() !== '' ) { + wfLogWarning( + $method . ': called on interwiki title ' . $this->getFullText() . ', returning ' + . $title->getFullText() + ); + + return true; + } + + return false; } /** @@ -1610,8 +1669,23 @@ class Title implements LinkTarget, IDBAccessObject { * @return Title */ public function getOtherPage() { - return self::castFromLinkTarget( - MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) ); + // NOTE: Depend on the methods in this class instead of their equivalent in NamespaceInfo, + // until their semantics has become exactly the same. + // See the discussion on T227817. + 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(); + } + // TODO: replace the above with the code below: + // return self::castFromLinkTarget( + // MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociatedPage( $this ) ); } /** @@ -1986,7 +2060,7 @@ class Title implements LinkTarget, IDBAccessObject { * * @see self::getLocalURL for the arguments. * @see wfExpandUrl - * @param string|string[] $query + * @param string|array $query * @param string|string[]|bool $query2 * @param string|int|null $proto Protocol type to use in URL * @return string The URL @@ -2047,7 +2121,7 @@ class Title implements LinkTarget, IDBAccessObject { * valid to link, locally, to the current Title. * @see self::newFromText to produce a Title object. * - * @param string|string[] $query An optional query string, + * @param string|array $query An optional query string, * not used for interwiki links. Can be specified as an associative array as well, * e.g., [ 'action' => 'edit' ] (keys and values will be URL-escaped). * Some query patterns will trigger various shorturl path replacements. @@ -2061,7 +2135,7 @@ class Title implements LinkTarget, IDBAccessObject { * @return string String of the URL. */ public function getLocalURL( $query = '', $query2 = false ) { - global $wgArticlePath, $wgScript, $wgServer, $wgRequest; + global $wgArticlePath, $wgScript, $wgServer, $wgRequest, $wgMainPageIsDomainRoot; $query = self::fixUrlQueryArgs( $query, $query2 ); @@ -2138,6 +2212,11 @@ class Title implements LinkTarget, IDBAccessObject { $url = $wgServer . $url; } } + + if ( $wgMainPageIsDomainRoot && $this->isMainPage() && $query === '' ) { + return '/'; + } + // Avoid PHP 7.1 warning from passing $this by reference $titleRef = $this; Hooks::run( 'GetLocalURL', [ &$titleRef, &$url, $query ] ); @@ -2182,7 +2261,7 @@ class Title implements LinkTarget, IDBAccessObject { * protocol-relative, the URL will be expanded to http:// * * @see self::getLocalURL for the arguments. - * @param string|string[] $query + * @param string|array $query * @param string|bool $query2 Deprecated * @return string The URL */ @@ -2205,7 +2284,7 @@ class Title implements LinkTarget, IDBAccessObject { * NOTE: Unlike getInternalURL(), the canonical URL includes the fragment * * @see self::getLocalURL for the arguments. - * @param string|string[] $query + * @param string|array $query * @param string|bool $query2 Deprecated * @return string The URL * @since 1.18 @@ -4270,12 +4349,21 @@ class Title implements LinkTarget, IDBAccessObject { * on the number of links. Typically called on create and delete. */ public function touchLinks() { - DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks', 'page-touch' ) ); + $jobs = []; + $jobs[] = HTMLCacheUpdateJob::newForBacklinks( + $this, + 'pagelinks', + [ 'causeAction' => 'page-touch' ] + ); if ( $this->mNamespace == NS_CATEGORY ) { - DeferredUpdates::addUpdate( - new HTMLCacheUpdate( $this, 'categorylinks', 'category-touch' ) + $jobs[] = HTMLCacheUpdateJob::newForBacklinks( + $this, + 'categorylinks', + [ 'causeAction' => 'category-touch' ] ); } + + JobQueueGroup::singleton()->lazyPush( $jobs ); } /**