* 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.
*
);
}
+ /**
+ * 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.
$this->assertTrue( $clone->equals( $title ) );
}
+ public function provideCastFromLinkTarget() {
+ return array_merge( [ [ null ] ], self::provideNewFromTitleValue() );
+ }
+
+ /**
+ * @covers Title::castFromLinkTarget
+ * @dataProvider provideCastFromLinkTarget
+ */
+ public function testCastFromLinkTarget( $value ) {
+ $title = Title::castFromLinkTarget( $value );
+
+ if ( $value === null ) {
+ $this->assertNull( $title );
+ } else {
+ $dbkey = str_replace( ' ', '_', $value->getText() );
+ $this->assertSame( $dbkey, $title->getDBkey() );
+ $this->assertSame( $value->getNamespace(), $title->getNamespace() );
+ $this->assertSame( $value->getFragment(), $title->getFragment() );
+ }
+ }
+
public static function provideGetTitleValue() {
return [
[ 'Foo' ],