if ( $t->isRedirect() ) {
# Page is a redirect
$colour = 'mw-redirect';
- } elseif ( $threshold > 0 &&
+ } elseif ( $threshold > 0 &&
$t->exists() && $t->getLength() < $threshold &&
MWNamespace::isContent( $t->getNamespace() ) ) {
# Page is a stub
return $this->link( $target, $text, $customAttribs, $query, $options );
}
+ /**
+ * Returns the Url used to link to a Title
+ */
private function linkUrl( $target, $query, $options ) {
wfProfileIn( __METHOD__ );
# We don't want to include fragments for broken links, because they
return $ret;
}
+ /**
+ * Returns the array of attributes used when linking to the Title $target
+ */
private function linkAttribs( $target, $attribs, $options ) {
wfProfileIn( __METHOD__ );
global $wgUser;
return $ret;
}
+ /**
+ * Default text of the links to the Title $target
+ */
private function linkText( $target ) {
# We might be passed a non-Title by make*LinkObj(). Fail gracefully.
if( !$target instanceof Title ) {
* despite $query not being used.
*/
function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
- if ( '' == $text ) {
+ if ( $text == '' ) {
$text = htmlspecialchars( $nt->getPrefixedText() );
}
list( $inside, $trail ) = Linker::splitTrail( $trail );
}
}
- /** @todo document */
+ /**
+ * Returns the filename part of an url.
+ * Used as alternative text for external images.
+ */
function fnamePart( $url ) {
$basename = strrchr( $url, '/' );
if ( false === $basename ) {
return $basename;
}
- /** @todo document */
+ /**
+ * Return the code for images which were added via external links,
+ * via Parser::maybeMakeExternalImage().
+ */
function makeExternalImage( $url, $alt = '' ) {
- if ( '' == $alt ) {
+ if ( $alt == '' ) {
$alt = $this->fnamePart( $url );
}
$img = '';
if ( $file && !isset( $hp['width'] ) ) {
$hp['width'] = $file->getWidth( $page );
- if( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
+ if( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) ) {
$wopt = $wgUser->getOption( 'thumbsize' );
if( !isset( $wgThumbLimits[$wopt] ) ) {
round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
$wgThumbLimits[$wopt];
if ( $hp['width'] <= 0 || $prefWidth < $hp['width'] ) {
- $hp['width'] = $prefWidth;
+ if( !isset( $hp['height'] ) ) {
+ $hp['width'] = $prefWidth;
+ }
}
}
}
}
if ( !$thumb ) {
- $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
+ $s = $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
} else {
$params = array(
'alt' => $fp['alt'],
$s = $thumb->toHtml( $params );
}
- if ( '' != $fp['align'] ) {
+ if ( $fp['align'] != '' ) {
$s = "<div class=\"float{$fp['align']}\">{$s}</div>";
}
return str_replace("\n", ' ',$prefix.$s.$postfix);
# 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 bug 14771
$url = $title->getLocalURL( $query );
- if( $page ) {
+ if( $page ) {
$url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
}
$s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
if( !$exists ) {
- $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
+ $s .= $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
$zoomicon = '';
} elseif ( !$thumb ) {
$s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
* @return string
*/
public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
- global $wgEnableUploads;
+ global $wgEnableUploads, $wgUploadNavigationUrl;
if( $title instanceof Title ) {
wfProfileIn( __METHOD__ );
$currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
- if( $wgEnableUploads && !$currentExists ) {
- $upload = SpecialPage::getTitleFor( 'Upload' );
+ if( ( $wgUploadNavigationUrl || $wgEnableUploads ) && !$currentExists ) {
if( $text == '' )
$text = htmlspecialchars( $title->getPrefixedText() );
+
$redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
if( $redir ) {
+ wfProfileOut( __METHOD__ );
return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
}
- $q = 'wpDestFile=' . $title->getPartialUrl();
- if( $query != '' )
- $q .= '&' . $query;
+
+ $href = $this->getUploadUrl( $title, $query );
+
+
list( $inside, $trail ) = self::splitTrail( $trail );
- $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
+
wfProfileOut( __METHOD__ );
- return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
- . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
+ return Html::element( 'a', array(
+ 'href' => $href,
+ 'class' => 'new',
+ 'title' => $title->getPrefixedText()
+ ), $prefix . $text . $inside ) . $trail;
} else {
wfProfileOut( __METHOD__ );
return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
}
}
+
+ /**
+ * Get the URL to upload a certain file
+ *
+ * @param $destFile Title Title of the file to upload
+ * @param $query string Urlencoded query string to prepend
+ * @return string Urlencoded URL
+ */
+ protected function getUploadUrl( $destFile, $query = '' ) {
+ global $wgUploadNavigationUrl;
+ $q = 'wpDestFile=' . $destFile->getPartialUrl();
+ if( $query != '' )
+ $q .= '&' . $query;
+
+ if( $wgUploadNavigationUrl ) {
+ return wfAppendQuery( $wgUploadNavigationUrl, $q );
+ } else {
+ $upload = SpecialPage::getTitleFor( 'Upload' );
+ return $upload->getLocalUrl( $q );
+ }
+ }
/**
* Create a direct link to a given uploaded file.
$url = $img->getURL();
$class = 'internal';
} else {
- $upload = SpecialPage::getTitleFor( 'Upload' );
- $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
+ $url = $this->getUploadUrl( $title );
$class = 'new';
}
$alt = htmlspecialchars( $title->getText() );
}
}
- /** @todo document */
+ /**
+ * Make a link to a special page given its name and, optionally,
+ * a message key from the link text.
+ * Usage example: $skin->specialLink( 'recentchanges' )
+ */
function specialLink( $name, $key = '' ) {
global $wgContLang;
- if ( '' == $key ) { $key = strtolower( $name ); }
+ if ( $key == '' ) { $key = strtolower( $name ); }
$pn = $wgContLang->ucfirst( $name );
return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
wfMsg( $key ) );
* @param boolean $escape Do we escape the link text?
* @param String $linktype Type of external link. Gets added to the classes
* @param array $attribs Array of extra attributes to <a>
- *
- * @TODO! @FIXME! This is a really crappy implementation. $linktype and
+ *
+ * @todo FIXME: This is a really crappy implementation. $linktype and
* 'external' are mashed into the class attrib for the link (which is made
- * into a string). Then, if we've got additional params in $attribs, we
+ * into a string). Then, if we've got additional params in $attribs, we
* add to it. People using this might want to change the classes (or other
- * default link attributes), but passing $attribsText is just messy. Would
- * make a lot more sense to make put the classes into $attribs, let the
- * hook play with them, *then* expand it all at once.
+ * default link attributes), but passing $attribsText is just messy. Would
+ * make a lot more sense to make put the classes into $attribs, let the
+ * hook play with them, *then* expand it all at once.
*/
function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
- $attribsText = $this->getExternalLinkAttributes( 'external ' . $linktype );
+ if ( isset( $attribs[ 'class' ] ) ) $class = $attribs[ 'class' ]; # yet another hack :(
+ else $class = 'external ' . $linktype;
+
+ $attribsText = $this->getExternalLinkAttributes( $class );
$url = htmlspecialchars( $url );
if( $escape ) {
$text = htmlspecialchars( $text );
if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
$link = wfMsgHtml( 'rev-deleted-user' );
} else if( $rev->userCan( Revision::DELETED_USER ) ) {
- $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ),
+ $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ),
$rev->getUserText( Revision::FOR_THIS_USER ) );
} else {
$link = wfMsgHtml( 'rev-deleted-user' );
$link = wfMsgHtml( 'rev-deleted-user' );
} else if( $rev->userCan( Revision::DELETED_USER ) ) {
$userId = $rev->getUser( Revision::FOR_THIS_USER );
- $userText = $rev->getUserText( Revision::FOR_THIS_USER );
+ $userText = $rev->getUserText( Revision::FOR_THIS_USER );
$link = $this->userLink( $userId, $userText ) .
' ' . $this->userToolLinks( $userId, $userText );
} else {
* @param mixed $title Title object (to generate link to the section in autocomment) or null
* @param bool $local Whether section links should refer to local page
*/
- function formatComment($comment, $title = NULL, $local = false) {
+ function formatComment($comment, $title = null, $local = false) {
wfProfileIn( __METHOD__ );
# Sanitize text a bit:
$comment = Sanitizer::escapeHtmlAllowEntities( $comment );
# Render autocomments and make links:
- $comment = $this->formatAutoComments( $comment, $title, $local );
+ $comment = $this->formatAutocomments( $comment, $title, $local );
$comment = $this->formatLinksInComment( $comment, $title, $local );
wfProfileOut( __METHOD__ );
unset( $this->autocommentLocal );
return $comment;
}
-
+
private function formatAutocommentsCallback( $match ) {
$title = $this->autocommentTitle;
$local = $this->autocommentLocal;
-
- $pre=$match[1];
- $auto=$match[2];
- $post=$match[3];
- $link='';
- if( $title ) {
+
+ $pre = $match[1];
+ $auto = $match[2];
+ $post = $match[3];
+ $link = '';
+ if ( $title ) {
$section = $auto;
# Generate a valid anchor name from the section title.
if ( $local ) {
$sectionTitle = Title::newFromText( '#' . $section );
} else {
- $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
+ $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
$title->getDBkey(), $section );
}
if ( $sectionTitle ) {
* Formats wiki links and media links in text; all other wiki formatting
* is ignored
*
- * @fixme doesn't handle sub-links as in image thumb texts like the main parser
+ * @todo Fixme: doesn't handle sub-links as in image thumb texts like the main parser
* @param string $comment Text to format links in
* @return string
*/
}
# Handle link renaming [[foo|text]] will show link as "text"
- if( "" != $match[3] ) {
+ if( $match[3] != "" ) {
$text = $match[3];
} else {
$text = $match[1];
if (isset($match[1][0]) && $match[1][0] == ':')
$match[1] = substr($match[1], 1);
list( $inside, $trail ) = Linker::splitTrail( $trail );
-
+
$linkText = $text;
$linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle,
$match[1], $linkText );
-
+
$target = Title::newFromText( $linkTarget );
if( $target ) {
if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) {
return $comment;
}
-
+
static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
# Valid link forms:
# Foobar -- normal
}
$ret = $contextTitle->getPrefixedText(). '/' . trim($noslash) . $suffix;
- if( '' === $text ) {
+ if( $text === '' ) {
$text = $target . $suffix;
} # this might be changed for ugliness reasons
} else {
# / at the end means don't show full path
if( substr( $nodotdot, -1, 1 ) === '/' ) {
$nodotdot = substr( $nodotdot, 0, -1 );
- if( '' === $text ) {
+ if( $text === '' ) {
$text = $nodotdot . $suffix;
}
}
*
* @return string
*/
- function commentBlock( $comment, $title = NULL, $local = false ) {
+ function commentBlock( $comment, $title = null, $local = false ) {
// '*' used to be the comment inserted by the software way back
// in antiquity in case none was provided, here for backwards
// compatability, acc. to brion -ævar
return "<span class=\"history-size\">$stxt</span>";
}
- /** @todo document */
+ /**
+ * Add another level to the Table of Contents
+ */
function tocIndent() {
return "\n<ul>";
}
- /** @todo document */
+ /**
+ * Finish one or more sublevels on the Table of Contents
+ */
function tocUnindent($level) {
return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
}
$tocline . '</span></a>';
}
- /** @todo document */
+ /**
+ * End a Table Of Contents line.
+ * tocUnindent() will be used instead if we're ending a line below
+ * the new level.
+ */
function tocLineEnd() {
return "</li>\n";
}
- /** @todo document */
+ /**
+ * Wraps the TOC in a table and provides the hide/collapse javascript.
+ * @param string $toc html of the Table Of Contents
+ * @return string Full html of the TOC
+ */
function tocList($toc) {
$title = wfMsgHtml('toc') ;
return
. ' } ' )
. "\n";
}
-
+
/**
* Generate a table of contents from a section tree
+ * Currently unused.
* @param $tree Return value of ParserOutput::getSections()
* @return string HTML
*/
$lastLevel - $section['toclevel'] );
else
$toc .= $this->tocLineEnd();
-
+
$toc .= $this->tocLine( $section['anchor'],
$section['line'], $section['number'],
$section['toclevel'], $section['index'] );
* @return string HTML to use for edit link
*/
public function doEditSectionLink( Title $nt, $section, $tooltip = null ) {
+ // HTML generated here should probably have userlangattributes
+ // added to it for LTR text on RTL pages
$attribs = array();
if( !is_null( $tooltip ) ) {
$attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
$regex = $wgContLang->linkTrail();
}
$inside = '';
- if ( '' != $trail ) {
+ if ( $trail != '' ) {
$m = array();
if ( preg_match( $regex, $trail, $m ) ) {
$inside = $m[1];
# Construct the HTML
$outText = '<div class="mw-templatesUsedExplanation">';
if ( $preview ) {
- $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
+ $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) );
} elseif ( $section ) {
- $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
+ $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) );
} else {
- $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
+ $outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) );
}
$outText .= "</div><ul>\n";
wfProfileOut( __METHOD__ );
return false;
}
-
+
/**
* Creates a (show/hide) link for deleting revisions/log entries
*
* @param array $query Query parameters to be passed to link()
* @param bool $restricted Set to true to use a <strong> instead of a <span>
+ * @param bool $delete Set to true to use (show/hide) rather than (show)
*
* @return string HTML <a> link to Special:Revisiondelete, wrapped in a
* span to allow for customization of appearance with CSS
*/
- public function revDeleteLink( $query = array(), $restricted = false ) {
+ public function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
$sp = SpecialPage::getTitleFor( 'Revisiondelete' );
- $text = wfMsgHtml( 'rev-delundel' );
+ $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
$tag = $restricted ? 'strong' : 'span';
$link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
}
+ /**
+ * Creates a dead (show/hide) link for deleting revisions/log entries
+ *
+ * @param bool $delete Set to true to use (show/hide) rather than (show)
+ *
+ * @return string HTML text wrapped in a span to allow for customization
+ * of appearance with CSS
+ */
+ public function revDeleteLinkDisabled( $delete = true ) {
+ $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
+ return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" );
+ }
+
/* Deprecated methods */
/**
}
/**
- * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey()
+ * Returns the attributes for the tooltip and access key
*/
- public function tooltipAndAccesskey( $name ) {
+ public function tooltipAndAccesskeyAttribs( $name ) {
global $wgEnableTooltipsAndAccesskeys;
- if (!$wgEnableTooltipsAndAccesskeys)
+ if ( !$wgEnableTooltipsAndAccesskeys )
return array();
# FIXME: If Sanitizer::expandAttributes() treated "false" as "output
# no attribute" instead of "output '' as value for attribute", this
if ( $attribs['accesskey'] === false ) {
unset( $attribs['accesskey'] );
}
- return Xml::expandAttributes( $attribs );
+ return $attribs;
}
+ /**
+ * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey()
+ */
+ public function tooltipAndAccesskey( $name ) {
+ return Xml::expandAttributes( $this->tooltipAndAccesskeyAttribs( $name ) );
+ }
+
/** @deprecated Returns raw bits of HTML, use titleAttrib() */
public function tooltip( $name, $options = null ) {
global $wgEnableTooltipsAndAccesskeys;
- if ($wgEnableTooltipsAndAccesskeys)
- return array();
+ if ( !$wgEnableTooltipsAndAccesskeys )
+ return '';
# FIXME: If Sanitizer::expandAttributes() treated "false" as "output
# no attribute" instead of "output '' as value for attribute", this
# would be two lines.