/**
* This function returns an HTML link to the given target. It serves a few
* purposes:
- * 1) If $target is a Title, the correct URL to link to will be figured
+ * 1) If $target is a LinkTarget, the correct URL to link to will be figured
* out automatically.
* 2) It automatically adds the usual classes for various types of link
* targets: "new" for red links, "stub" for short articles, etc.
* 3) It escapes all attribute values safely so there's no risk of XSS.
- * 4) It provides a default tooltip if the target is a Title (the page
+ * 4) It provides a default tooltip if the target is a LinkTarget (the page
* name of the target).
* link() replaces the old functions in the makeLink() family.
*
* change to support Images, literal URLs, etc.
* @param string $html The HTML contents of the <a> element, i.e.,
* the link text. This is raw HTML and will not be escaped. If null,
- * defaults to the prefixed text of the Title; or if the Title is just a
+ * defaults to the prefixed text of the LinkTarget; or if the LinkTarget is just a
* fragment, the contents of the fragment.
* @param array $customAttribs A key => value array of extra HTML attributes,
* such as title and class. (href is ignored.) Classes will be
* @since 1.16.3
* @deprecated since 1.28, use MediaWiki\Linker\LinkRenderer instead
* @see Linker::link
- * @param Title $target
+ * @param LinkTarget $target
* @param string $html
* @param array $customAttribs
* @param array $query
* make*LinkObj static functions, but $query is not used.
*
* @since 1.16.3
- * @param Title $nt
+ * @param LinkTarget $nt
* @param string $html [optional]
* @param string $query [optional]
* @param string $trail [optional]
* @return string
*/
public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
+ $nt = Title::newFromLinkTarget( $nt );
$ret = "<a class=\"mw-selflink selflink\">{$prefix}{$html}</a>{$trail}";
if ( !Hooks::run( 'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) {
return $ret;
* HTML that that syntax inserts in the page.
*
* @param Parser $parser
- * @param Title $title Title object of the file (not the currently viewed page)
+ * @param LinkTarget $title LinkTarget object of the file (not the currently viewed page)
* @param File $file File object, or false if it doesn't exist
* @param array $frameParams Associative array of parameters external to the media handler.
* Boolean parameters are indicated by presence or absence, the value is arbitrary and
* class HTML for image classes. Plain text.
* caption HTML for image caption.
* link-url URL to link to
- * link-title Title object to link to
+ * link-title LinkTarget object to link to
* link-target Value for the target attribute, only with link-url
* no-link Boolean, suppress description link
* targetlang (optional) Target language code, see Parser::getTargetLanguage()
* @since 1.20
* @return string HTML for an image, with links, wrappers, etc.
*/
- public static function makeImageLink( Parser $parser, Title $title,
+ public static function makeImageLink( Parser $parser, LinkTarget $title,
$file, $frameParams = [], $handlerParams = [], $time = false,
$query = "", $widthOption = null
) {
+ $title = Title::newFromLinkTarget( $title );
$res = null;
$dummy = new DummyLinker;
if ( !Hooks::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title,
/**
* Make HTML for a thumbnail including image, border and caption
- * @param Title $title
+ * @param LinkTarget $title
* @param File|bool $file File object or false if it doesn't exist
* @param string $label
* @param string $alt
* @param string $manualthumb
* @return string
*/
- public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt = '',
+ public static function makeThumbLinkObj( LinkTarget $title, $file, $label = '', $alt = '',
$align = 'right', $params = [], $framed = false, $manualthumb = ""
) {
$frameParams = [
}
/**
- * @param Title $title
+ * @param LinkTarget $title
* @param File $file
* @param array $frameParams
* @param array $handlerParams
* @param string $query
* @return string
*/
- public static function makeThumbLink2( Title $title, $file, $frameParams = [],
+ public static function makeThumbLink2( LinkTarget $title, $file, $frameParams = [],
$handlerParams = [], $time = false, $query = ""
) {
$exists = $file && $file->exists();
# ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
# So we don't need to pass it here in $query. However, the URL for the
# zoom icon still needs it, so we make a unique query for it. See T16771
- $url = $title->getLocalURL( $query );
+ $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
if ( $page ) {
$url = wfAppendQuery( $url, [ 'page' => $page ] );
}
* Make a "broken" link to an image
*
* @since 1.16.3
- * @param Title $title
+ * @param LinkTarget $title
* @param string $label Link label (plain text)
* @param string $query Query string
* @param string $unused1 Unused parameter kept for b/c
public static function makeBrokenImageLinkObj( $title, $label = '',
$query = '', $unused1 = '', $unused2 = '', $time = false
) {
- if ( !$title instanceof Title ) {
- wfWarn( __METHOD__ . ': Requires $title to be a Title object.' );
+ if ( !$title instanceof LinkTarget ) {
+ wfWarn( __METHOD__ . ': Requires $title to be a LinkTarget object.' );
return "<!-- ERROR -->" . htmlspecialchars( $label );
}
+ $title = Title::castFromLinkTarget( $title );
+
global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
if ( $label == '' ) {
$label = $title->getPrefixedText();
* Get the URL to upload a certain file
*
* @since 1.16.3
- * @param Title $destFile Title object of the file to upload
+ * @param LinkTarget $destFile LinkTarget object of the file to upload
* @param string $query Urlencoded query string to prepend
* @return string Urlencoded URL
*/
protected static function getUploadUrl( $destFile, $query = '' ) {
global $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
- $q = 'wpDestFile=' . $destFile->getPartialURL();
+ $q = 'wpDestFile=' . Title::castFromLinkTarget( $destFile )->getPartialURL();
if ( $query != '' ) {
$q .= '&' . $query;
}
* Create a direct link to a given uploaded file.
*
* @since 1.16.3
- * @param Title $title
+ * @param LinkTarget $title
* @param string $html Pre-sanitized HTML
* @param string $time MW timestamp of file creation time
* @return string HTML
* This will make a broken link if $file is false.
*
* @since 1.16.3
- * @param Title $title
+ * @param LinkTarget $title
* @param File|bool $file File object or false
* @param string $html Pre-sanitized HTML
* @return string HTML
*
* @todo Handle invalid or missing images better.
*/
- public static function makeMediaLinkFile( Title $title, $file, $html = '' ) {
+ public static function makeMediaLinkFile( LinkTarget $title, $file, $html = '' ) {
if ( $file && $file->exists() ) {
$url = $file->getUrl();
$class = 'internal';
];
if ( !Hooks::run( 'LinkerMakeMediaLinkFile',
- [ $title, $file, &$html, &$attribs, &$ret ] ) ) {
+ [ Title::castFromLinkTarget( $title ), $file, &$html, &$attribs, &$ret ] ) ) {
wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
. "with url {$url} and text {$html} to {$ret}\n", true );
return $ret;
* @param-taint $linktype escapes_html
* @param array $attribs Array of extra attributes to <a>
* @param-taint $attribs escapes_html
- * @param Title|null $title Title object used for title specific link attributes
+ * @param LinkTarget|null $title LinkTarget object used for title specific link attributes
* @param-taint $title none
* @return string
*/
}
$classes .= ' mw-anonuserlink'; // Separate link class for anons (T45179)
} else {
- $page = Title::makeTitle( NS_USER, $userName );
+ $page = new TitleValue( NS_USER, strtr( $userName, ' ', '_' ) );
}
// Wrap the output with <bdi> tags for directionality isolation
* @return string HTML fragment with user talk link
*/
public static function userTalkLink( $userId, $userText ) {
- $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
+ $userTalkPage = new TitleValue( NS_USER_TALK, strtr( $userText, ' ', '_' ) );
$moreLinkAttribs['class'] = 'mw-usertoollinks-talk';
return self::link( $userTalkPage,
* @since 1.16.3. $wikiId added in 1.26
*
* @param string $comment
- * @param Title|null $title Title object (to generate link to the section in autocomment)
- * or null
+ * @param LinkTarget|null $title LinkTarget object (to generate link to the section in
+ * autocomment) or null
* @param bool $local Whether section links should refer to local page
* @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
* For use with external changes.
* Called by Linker::formatComment.
*
* @param string $comment Comment text
- * @param Title|null $title An optional title object used to links to sections
+ * @param LinkTarget|null $title An optional LinkTarget object used to links to sections
* @param bool $local Whether section links should refer to local page
* @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
* as used by WikiMap.
Hooks::run(
'FormatAutocomments',
- [ &$comment, $pre, $auto, $post, $title, $local, $wikiId ]
+ [ &$comment, $pre, $auto, $post, Title::castFromLinkTarget( $title ), $local,
+ $wikiId ]
);
if ( $comment === null ) {
$section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
if ( $local ) {
- $sectionTitle = Title::makeTitleSafe( NS_MAIN, '', $section );
+ $sectionTitle = new TitleValue( NS_MAIN, '', $section );
} else {
- $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
- $title->getDBkey(), $section );
+ $sectionTitle = $title->createFragmentTarget( $section );
}
if ( $sectionTitle ) {
$auto = Linker::makeCommentLink(
* function is html, $comment must be sanitized for use as html. You probably want
* to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
* this function.
- * @param Title|null $title An optional title object used to links to sections
+ * @param LinkTarget|null $title An optional LinkTarget object used to links to sections
* @param bool $local Whether section links should refer to local page
* @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
* as used by WikiMap.
$linkText = $text;
$linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText );
- $target = Title::newFromText( $linkTarget );
- if ( $target ) {
+ Title::newFromText( $linkTarget );
+ try {
+ $target = MediaWikiServices::getInstance()->getTitleParser()->
+ parseTitle( $linkTarget );
+
if ( $target->getText() == '' && !$target->isExternal()
&& !$local && $title
) {
}
$thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
+ } catch ( MalformedTitleException $e ) {
+ // Fall through
}
}
}
}
/**
- * Generates a link to the given Title
+ * Generates a link to the given LinkTarget
*
* @note This is only public for technical reasons. It's not intended for use outside Linker.
*
}
/**
- * @param Title $contextTitle
+ * @param LinkTarget $contextTitle
* @param string $target
* @param string &$text
* @return string
}
# T9425
$target = trim( $target );
+ $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
+ getPrefixedText( $contextTitle );
# Look at the first character
if ( $target != '' && $target[0] === '/' ) {
# / at end means we don't want the slash to be shown
$noslash = substr( $target, 1 );
}
- $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
+ $ret = $contextPrefixedText . '/' . trim( $noslash ) . $suffix;
if ( $text === '' ) {
$text = $target . $suffix;
} # this might be changed for ugliness reasons
$nodotdot = substr( $nodotdot, 3 );
}
if ( $dotdotcount > 0 ) {
- $exploded = explode( '/', $contextTitle->getPrefixedText() );
+ $exploded = explode( '/', $contextPrefixedText );
if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
$ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
# / at the end means don't show full path
*
* @since 1.16.3. $wikiId added in 1.26
* @param string $comment
- * @param Title|null $title Title object (to generate link to section in autocomment) or null
+ * @param LinkTarget|null $title LinkTarget object (to generate link to section in autocomment)
+ * or null
* @param bool $local Whether section links should refer to local page
* @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
* For use with external changes.
*
* @param User $user
* @param Revision $rev
- * @param Title $title
+ * @param LinkTarget $title
* @return string HTML fragment
*/
- public static function getRevDeleteLink( User $user, Revision $rev, Title $title ) {
+ public static function getRevDeleteLink( User $user, Revision $rev, LinkTarget $title ) {
$canHide = $user->isAllowed( 'deleterevision' );
if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
return '';
if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
return self::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
}
+ $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
+ getPrefixedDBkey( $title );
if ( $rev->getId() ) {
// RevDelete links using revision ID are stable across
// page deletion and undeletion; use when possible.
$query = [
'type' => 'revision',
- 'target' => $title->getPrefixedDBkey(),
+ 'target' => $prefixedDbKey,
'ids' => $rev->getId()
];
} else {
// We have to refer to these by timestamp, ick!
$query = [
'type' => 'archive',
- 'target' => $title->getPrefixedDBkey(),
+ 'target' => $prefixedDbKey,
'ids' => $rev->getTimestamp()
];
}