X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=55c7179276392ec7acb3d8717bb2313af086baf8;hb=9a05babfa5d53ff7264b0a615f202c6d2e1bf5ba;hp=5b86ed6f68edaa9ecdc7126c87ec4ad6fd8546ad;hpb=e024b4e93cbfb0f78e88ae9441d58e68dbfb27a9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 5b86ed6f68..55c7179276 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -30,7 +30,7 @@ * @note Consider using a TitleValue object instead. TitleValue is more lightweight * and does not rely on global state or the database. */ -class Title { +class Title implements LinkTarget { /** @var HashBagOStuff */ static private $titleCache = null; @@ -236,17 +236,28 @@ class Title { * @return Title */ public static function newFromTitleValue( TitleValue $titleValue ) { + return self::newFromLinkTarget( $titleValue ); + } + + /** + * Create a new Title from a LinkTarget + * + * @param LinkTarget $linkTarget Assumed to be safe. + * + * @return Title + */ + public static function newFromLinkTarget( LinkTarget $linkTarget ) { return self::makeTitle( - $titleValue->getNamespace(), - $titleValue->getText(), - $titleValue->getFragment() ); + $linkTarget->getNamespace(), + $linkTarget->getText(), + $linkTarget->getFragment() ); } /** * Create a new Title from text, such as what one would find in a link. De- * codes any HTML entities in the text. * - * @param string|null $text The link text; spaces, prefixes, and an + * @param string|int|null $text The link text; spaces, prefixes, and an * initial ':' indicating the main namespace are accepted. * @param int $defaultNamespace The namespace to use if none is specified * by a prefix. If you want to force a specific namespace even if @@ -259,7 +270,8 @@ class Title { if ( is_object( $text ) ) { throw new InvalidArgumentException( '$text must be a string.' ); } - if ( $text !== null && !is_string( $text ) ) { + // DWIM: Integers can be passed in here when page titles are used as array keys. + if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) { wfDebugLog( 'T76305', wfGetAllCallers( 5 ) ); return null; } @@ -268,7 +280,7 @@ class Title { } try { - return Title::newFromTextThrow( $text, $defaultNamespace ); + return Title::newFromTextThrow( strval( $text ), $defaultNamespace ); } catch ( MalformedTitleException $ex ) { return null; } @@ -4631,7 +4643,7 @@ class Title { // Checking $wgLanguageCode hasn't changed for the benefit of unit // tests. $contentHandler = ContentHandler::getForTitle( $this ); - $langObj = wfGetLangObj( $contentHandler->getPageLanguage( $this ) ); + $langObj = $contentHandler->getPageLanguage( $this ); $this->mPageLanguage = array( $langObj->getCode(), $wgLanguageCode ); } else { $langObj = wfGetLangObj( $this->mPageLanguage[0] );