* @return Title
*/
public static function newFromLinkTarget( LinkTarget $linkTarget ) {
+ if ( $linkTarget instanceof Title ) {
+ // Special case if it's already a Title object
+ return $linkTarget;
+ }
return self::makeTitle(
$linkTarget->getNamespace(),
$linkTarget->getText(),
* specified fragment before setting, so it assumes you're passing it with
* an initial "#".
*
- * Deprecated for public use, use Title::makeTitle() with fragment parameter.
+ * Deprecated for public use, use Title::makeTitle() with fragment parameter,
+ * or Title::createFragmentTarget().
* Still in active use privately.
*
* @private
$this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
}
+ /**
+ * Creates a new Title for a different fragment of the same page.
+ *
+ * @since 1.27
+ * @param string $fragment
+ * @return Title
+ */
+ public function createFragmentTarget( $fragment ) {
+ return self::makeTitle(
+ $this->getNamespace(),
+ $this->getText(),
+ $fragment,
+ $this->getInterwiki()
+ );
+
+ }
+
/**
* Prefix some arbitrary text with the namespace or interwiki prefix
* of this object