2004-12-18 06:29:23 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2011-04-03 11:44:11 +00:00
|
|
|
* Some internal bits split of from Skin.php. These functions are used
|
2008-07-01 00:40:53 +00:00
|
|
|
* for primarily page content: links, embedded images, table of contents. Links
|
2011-04-03 11:44:11 +00:00
|
|
|
* are also used in the skin.
|
2004-12-18 06:29:23 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Skins
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
|
|
|
|
class Linker {
|
2007-08-06 07:09:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Flags for userToolLinks()
|
|
|
|
|
*/
|
|
|
|
|
const TOOL_LINKS_NOBLOCK = 1;
|
2011-09-07 12:12:24 +00:00
|
|
|
const TOOL_LINKS_EMAIL = 2;
|
2007-08-06 07:09:59 +00:00
|
|
|
|
2008-07-01 00:57:39 +00:00
|
|
|
/**
|
|
|
|
|
* Get the appropriate HTML attributes to add to the "a" element of an ex-
|
|
|
|
|
* ternal link, as created by [wikisyntax].
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $class String: the contents of the class attribute; if an empty
|
2008-07-01 00:57:39 +00:00
|
|
|
* string is passed, which is the default value, defaults to 'external'.
|
2011-05-06 20:59:58 +00:00
|
|
|
* @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes
|
2008-07-01 00:57:39 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function getExternalLinkAttributes( $class = 'external' ) {
|
2011-02-05 23:06:36 +00:00
|
|
|
wfDeprecated( __METHOD__ );
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::getLinkAttributesInternal( '', $class );
|
2006-03-17 01:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-01 00:57:39 +00:00
|
|
|
/**
|
|
|
|
|
* Get the appropriate HTML attributes to add to the "a" element of an in-
|
|
|
|
|
* terwiki link.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title String: the title text for the link, URL-encoded (???) but
|
2008-07-01 00:57:39 +00:00
|
|
|
* not HTML-escaped
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $unused String: unused
|
|
|
|
|
* @param $class String: the contents of the class attribute; if an empty
|
2008-07-01 00:57:39 +00:00
|
|
|
* string is passed, which is the default value, defaults to 'external'.
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
|
2006-03-17 01:02:14 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
2011-05-17 22:03:20 +00:00
|
|
|
# @todo FIXME: We have a whole bunch of handling here that doesn't happen in
|
2008-07-01 00:57:39 +00:00
|
|
|
# getExternalLinkAttributes, why?
|
|
|
|
|
$title = urldecode( $title );
|
|
|
|
|
$title = $wgContLang->checkTitleEncoding( $title );
|
|
|
|
|
$title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::getLinkAttributesInternal( $title, $class );
|
2008-07-01 01:17:39 +00:00
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2008-07-01 01:17:39 +00:00
|
|
|
/**
|
|
|
|
|
* Get the appropriate HTML attributes to add to the "a" element of an in-
|
|
|
|
|
* ternal link.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title String: the title text for the link, URL-encoded (???) but
|
2008-07-01 01:17:39 +00:00
|
|
|
* not HTML-escaped
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $unused String: unused
|
|
|
|
|
* @param $class String: the contents of the class attribute, default none
|
2008-07-01 01:17:39 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
|
2008-07-01 01:17:39 +00:00
|
|
|
$title = urldecode( $title );
|
|
|
|
|
$title = str_replace( '_', ' ', $title );
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::getLinkAttributesInternal( $title, $class );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-01 01:17:39 +00:00
|
|
|
/**
|
|
|
|
|
* Get the appropriate HTML attributes to add to the "a" element of an in-
|
|
|
|
|
* ternal link, given the Title object for the page we want to link to.
|
|
|
|
|
*
|
2011-03-02 10:57:55 +00:00
|
|
|
* @param $nt Title
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $unused String: unused
|
|
|
|
|
* @param $class String: the contents of the class attribute, default none
|
|
|
|
|
* @param $title Mixed: optional (unescaped) string to use in the title
|
2008-07-01 01:17:39 +00:00
|
|
|
* attribute; if false, default to the name of the page we're linking to
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $title === false ) {
|
2008-07-01 01:17:39 +00:00
|
|
|
$title = $nt->getPrefixedText();
|
|
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::getLinkAttributesInternal( $title, $class );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-01 01:17:39 +00:00
|
|
|
* Common code for getLinkAttributesX functions
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @param $title string
|
|
|
|
|
* @param $class string
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
private static function getLinkAttributesInternal( $title, $class ) {
|
2008-07-01 01:17:39 +00:00
|
|
|
$title = htmlspecialchars( $title );
|
|
|
|
|
$class = htmlspecialchars( $class );
|
|
|
|
|
$r = '';
|
2009-07-11 04:47:12 +00:00
|
|
|
if ( $class != '' ) {
|
2008-07-01 01:17:39 +00:00
|
|
|
$r .= " class=\"$class\"";
|
2008-02-21 09:32:59 +00:00
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $title != '' ) {
|
2009-07-11 04:47:12 +00:00
|
|
|
$r .= " title=\"$title\"";
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-22 15:54:18 +00:00
|
|
|
/**
|
|
|
|
|
* Return the CSS colour of a known link
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $t Title object
|
|
|
|
|
* @param $threshold Integer: user defined threshold
|
|
|
|
|
* @return String: CSS class
|
2007-11-22 15:54:18 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function getLinkColour( $t, $threshold ) {
|
2008-02-12 18:01:42 +00:00
|
|
|
$colour = '';
|
2008-04-08 20:34:09 +00:00
|
|
|
if ( $t->isRedirect() ) {
|
2008-02-12 18:01:42 +00:00
|
|
|
# Page is a redirect
|
|
|
|
|
$colour = 'mw-redirect';
|
2010-01-07 09:32:09 +00:00
|
|
|
} elseif ( $threshold > 0 &&
|
2008-08-09 02:32:08 +00:00
|
|
|
$t->exists() && $t->getLength() < $threshold &&
|
2010-08-02 15:53:22 +00:00
|
|
|
$t->isContentPage() ) {
|
2008-02-12 18:01:42 +00:00
|
|
|
# Page is a stub
|
|
|
|
|
$colour = 'stub';
|
2007-11-22 15:54:18 +00:00
|
|
|
}
|
|
|
|
|
return $colour;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-30 21:02:28 +00:00
|
|
|
/**
|
2008-07-30 21:11:17 +00:00
|
|
|
* 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
|
|
|
|
|
* out automatically.
|
|
|
|
|
* 2) It automatically adds the usual classes for various types of link
|
|
|
|
|
* targets: "new" for red links, "stub" for short articles, etc.
|
2008-07-30 21:02:28 +00:00
|
|
|
* 3) It escapes all attribute values safely so there's no risk of XSS.
|
2008-07-30 21:11:17 +00:00
|
|
|
* 4) It provides a default tooltip if the target is a Title (the page
|
|
|
|
|
* name of the target).
|
|
|
|
|
* link() replaces the old functions in the makeLink() family.
|
2008-07-30 21:02:28 +00:00
|
|
|
*
|
2008-07-30 21:11:17 +00:00
|
|
|
* @param $target Title Can currently only be a Title, but this may
|
|
|
|
|
* change to support Images, literal URLs, etc.
|
2011-09-03 13:46:56 +00:00
|
|
|
* @param $html string The HTML contents of the <a> element, i.e.,
|
2008-08-01 14:33:14 +00:00
|
|
|
* the link text. This is raw HTML and will not be escaped. If null,
|
2008-08-01 01:37:07 +00:00
|
|
|
* defaults to the prefixed text of the Title; or if the Title is just a
|
|
|
|
|
* fragment, the contents of the fragment.
|
2008-07-30 21:11:17 +00:00
|
|
|
* @param $customAttribs array A key => value array of extra HTML attri-
|
|
|
|
|
* butes, such as title and class. (href is ignored.) Classes will be
|
|
|
|
|
* merged with the default classes, while other attributes will replace
|
|
|
|
|
* default attributes. All passed attribute values will be HTML-escaped.
|
|
|
|
|
* A false attribute value means to suppress that attribute.
|
2008-08-06 11:41:51 +00:00
|
|
|
* @param $query array The query string to append to the URL
|
|
|
|
|
* you're linking to, in key => value array form. Query keys and values
|
|
|
|
|
* will be URL-encoded.
|
2011-05-28 18:59:42 +00:00
|
|
|
* @param $options string|array String or array of strings:
|
2008-07-30 21:02:28 +00:00
|
|
|
* 'known': Page is known to exist, so don't check if it does.
|
|
|
|
|
* 'broken': Page is known not to exist, so don't check if it does.
|
2008-08-01 00:47:26 +00:00
|
|
|
* 'noclasses': Don't add any classes automatically (includes "new",
|
2008-08-01 15:02:46 +00:00
|
|
|
* "stub", "mw-redirect", "extiw"). Only use the class attribute
|
|
|
|
|
* provided, if any, so you get a simple blue link with no funny i-
|
|
|
|
|
* cons.
|
2008-10-02 22:52:42 +00:00
|
|
|
* 'forcearticlepath': Use the article path always, even with a querystring.
|
|
|
|
|
* Has compatibility issues on some setups, so avoid wherever possible.
|
2008-07-30 21:02:28 +00:00
|
|
|
* @return string HTML <a> attribute
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function link(
|
2011-05-08 00:10:31 +00:00
|
|
|
$target, $html = null, $customAttribs = array(), $query = array(), $options = array()
|
2011-03-21 16:15:56 +00:00
|
|
|
) {
|
2008-07-30 21:02:28 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !$target instanceof Title ) {
|
2011-01-11 22:20:56 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2011-05-08 00:10:31 +00:00
|
|
|
return "<!-- ERROR -->$html";
|
2008-09-14 00:49:52 +00:00
|
|
|
}
|
|
|
|
|
$options = (array)$options;
|
|
|
|
|
|
2011-04-03 12:04:04 +00:00
|
|
|
$dummy = new DummyLinker; // dummy linker instance for bc on the hooks
|
2011-04-03 11:44:11 +00:00
|
|
|
|
2008-08-05 17:05:59 +00:00
|
|
|
$ret = null;
|
2011-05-08 00:10:31 +00:00
|
|
|
if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html,
|
2008-08-05 17:05:59 +00:00
|
|
|
&$customAttribs, &$query, &$options, &$ret ) ) ) {
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-30 21:02:28 +00:00
|
|
|
# Normalize the Title if it's a special page
|
2011-04-03 11:44:11 +00:00
|
|
|
$target = self::normaliseSpecialPage( $target );
|
2008-07-30 21:02:28 +00:00
|
|
|
|
|
|
|
|
# If we don't know whether the page exists, let's find out.
|
2008-08-01 15:13:14 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-checkPageExistence' );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
|
|
|
|
|
if ( $target->isKnown() ) {
|
|
|
|
|
$options[] = 'known';
|
2008-07-30 21:02:28 +00:00
|
|
|
} else {
|
2010-08-26 19:40:29 +00:00
|
|
|
$options[] = 'broken';
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-08-01 15:13:14 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-checkPageExistence' );
|
2008-07-30 21:02:28 +00:00
|
|
|
|
2008-10-02 21:04:36 +00:00
|
|
|
$oldquery = array();
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( in_array( "forcearticlepath", $options ) && $query ) {
|
2008-10-02 21:04:36 +00:00
|
|
|
$oldquery = $query;
|
|
|
|
|
$query = array();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-30 21:02:28 +00:00
|
|
|
# Note: we want the href attribute first, for prettiness.
|
2011-04-03 11:44:11 +00:00
|
|
|
$attribs = array( 'href' => self::linkUrl( $target, $query, $options ) );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
|
2008-10-02 21:04:36 +00:00
|
|
|
$attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-30 21:02:28 +00:00
|
|
|
$attribs = array_merge(
|
|
|
|
|
$attribs,
|
2011-04-27 19:13:34 +00:00
|
|
|
self::linkAttribs( $target, $customAttribs, $options )
|
2008-07-30 21:02:28 +00:00
|
|
|
);
|
2011-05-08 00:10:31 +00:00
|
|
|
if ( is_null( $html ) ) {
|
|
|
|
|
$html = self::linkText( $target );
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-05 17:05:59 +00:00
|
|
|
$ret = null;
|
2011-05-08 00:10:31 +00:00
|
|
|
if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
|
|
|
|
|
$ret = Html::rawElement( 'a', $attribs, $html );
|
2008-08-05 17:05:59 +00:00
|
|
|
}
|
2008-07-30 21:02:28 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-29 16:02:16 +00:00
|
|
|
/**
|
|
|
|
|
* Identical to link(), except $options defaults to 'known'.
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function linkKnown(
|
2011-09-03 13:46:56 +00:00
|
|
|
$target, $html = null, $customAttribs = array(),
|
2011-03-21 16:15:56 +00:00
|
|
|
$query = array(), $options = array( 'known', 'noclasses' ) )
|
|
|
|
|
{
|
2011-09-03 13:46:56 +00:00
|
|
|
return self::link( $target, $html, $customAttribs, $query, $options );
|
2009-03-29 16:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-26 14:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the Url used to link to a Title
|
2011-03-02 10:57:55 +00:00
|
|
|
*
|
|
|
|
|
* @param $target Title
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
private static function linkUrl( $target, $query, $options ) {
|
2008-08-01 15:13:14 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-08-05 17:05:59 +00:00
|
|
|
# We don't want to include fragments for broken links, because they
|
|
|
|
|
# generally make no sense.
|
2011-03-02 10:57:55 +00:00
|
|
|
if ( in_array( 'broken', $options ) && $target->mFragment !== '' ) {
|
2008-08-05 17:05:59 +00:00
|
|
|
$target = clone $target;
|
|
|
|
|
$target->mFragment = '';
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-01 15:02:46 +00:00
|
|
|
# If it's a broken link, add the appropriate query pieces, unless
|
2008-08-03 16:52:55 +00:00
|
|
|
# there's already an action specified, or unless 'edit' makes no sense
|
|
|
|
|
# (i.e., for a nonexistent special page).
|
2011-03-02 10:57:55 +00:00
|
|
|
if ( in_array( 'broken', $options ) && empty( $query['action'] )
|
|
|
|
|
&& $target->getNamespace() != NS_SPECIAL ) {
|
2008-07-30 21:02:28 +00:00
|
|
|
$query['action'] = 'edit';
|
|
|
|
|
$query['redlink'] = '1';
|
|
|
|
|
}
|
2008-08-01 15:13:14 +00:00
|
|
|
$ret = $target->getLinkUrl( $query );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-26 14:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the array of attributes used when linking to the Title $target
|
2011-03-02 10:57:55 +00:00
|
|
|
*
|
|
|
|
|
* @param $target Title
|
2011-05-29 14:01:47 +00:00
|
|
|
* @param $attribs
|
|
|
|
|
* @param $options
|
2011-06-17 16:03:52 +00:00
|
|
|
*
|
2011-05-29 14:01:47 +00:00
|
|
|
* @return array
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-27 19:13:34 +00:00
|
|
|
private static function linkAttribs( $target, $attribs, $options ) {
|
2008-08-01 15:13:14 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2008-07-30 21:02:28 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$defaults = array();
|
|
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !in_array( 'noclasses', $options ) ) {
|
2008-08-03 16:52:55 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-getClasses' );
|
2008-08-05 17:05:59 +00:00
|
|
|
# Now build the classes.
|
2008-07-30 21:02:28 +00:00
|
|
|
$classes = array();
|
|
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( in_array( 'broken', $options ) ) {
|
2008-08-01 15:02:46 +00:00
|
|
|
$classes[] = 'new';
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $target->isExternal() ) {
|
2008-08-01 15:02:46 +00:00
|
|
|
$classes[] = 'extiw';
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-02 15:53:22 +00:00
|
|
|
if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
|
2011-04-03 11:44:11 +00:00
|
|
|
$colour = self::getLinkColour( $target, $wgUser->getStubThreshold() );
|
2010-08-02 15:53:22 +00:00
|
|
|
if ( $colour !== '' ) {
|
|
|
|
|
$classes[] = $colour; # mw-redirect or stub
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $classes != array() ) {
|
2008-07-30 21:02:28 +00:00
|
|
|
$defaults['class'] = implode( ' ', $classes );
|
|
|
|
|
}
|
2008-08-03 16:52:55 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-getClasses' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get a default title attribute.
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $target->getPrefixedText() == '' ) {
|
2009-03-31 14:26:40 +00:00
|
|
|
# A link like [[#Foo]]. This used to mean an empty title
|
|
|
|
|
# attribute, but that's silly. Just don't output a title.
|
2011-04-27 19:13:34 +00:00
|
|
|
} elseif ( in_array( 'known', $options ) ) {
|
2008-08-03 16:52:55 +00:00
|
|
|
$defaults['title'] = $target->getPrefixedText();
|
2011-04-27 19:13:34 +00:00
|
|
|
} else {
|
2008-08-03 16:52:55 +00:00
|
|
|
$defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Finally, merge the custom attribs with the default ones, and iterate
|
|
|
|
|
# over that, deleting all "false" attributes.
|
|
|
|
|
$ret = array();
|
2008-07-30 22:02:23 +00:00
|
|
|
$merged = Sanitizer::mergeAttributes( $defaults, $attribs );
|
2010-08-26 19:40:29 +00:00
|
|
|
foreach ( $merged as $key => $val ) {
|
2008-07-30 21:11:17 +00:00
|
|
|
# A false value suppresses the attribute, and we don't want the
|
|
|
|
|
# href attribute to be overridden.
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $key != 'href' and $val !== false ) {
|
2008-07-30 21:02:28 +00:00
|
|
|
$ret[$key] = $val;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-01 15:13:14 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-07-30 21:02:28 +00:00
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 14:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* Default text of the links to the Title $target
|
2011-03-02 10:57:55 +00:00
|
|
|
*
|
|
|
|
|
* @param $target Title
|
2011-05-06 22:53:59 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
private static function linkText( $target ) {
|
2008-09-08 22:53:44 +00:00
|
|
|
# We might be passed a non-Title by make*LinkObj(). Fail gracefully.
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !$target instanceof Title ) {
|
2008-09-08 22:53:44 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:36:51 +00:00
|
|
|
# If the target is just a fragment, with no title, we return the frag-
|
2008-07-30 21:02:28 +00:00
|
|
|
# ment text. Otherwise, we return the title text itself.
|
2011-03-02 10:57:55 +00:00
|
|
|
if ( $target->getPrefixedText() === '' && $target->getFragment() !== '' ) {
|
2008-08-01 14:33:14 +00:00
|
|
|
return htmlspecialchars( $target->getFragment() );
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
2008-08-01 14:33:14 +00:00
|
|
|
return htmlspecialchars( $target->getPrefixedText() );
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
2005-06-01 10:29:34 +00:00
|
|
|
/**
|
|
|
|
|
* Generate either a normal exists-style link or a stub link, depending
|
|
|
|
|
* on the given page size.
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
2010-11-05 19:06:12 +00:00
|
|
|
* @param $size Integer
|
|
|
|
|
* @param $nt Title object.
|
|
|
|
|
* @param $text String
|
|
|
|
|
* @param $query String
|
|
|
|
|
* @param $trail String
|
|
|
|
|
* @param $prefix String
|
|
|
|
|
* @return string HTML of link
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.17
|
2005-06-01 10:29:34 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2005-06-01 10:29:34 +00:00
|
|
|
global $wgUser;
|
2010-08-02 15:53:22 +00:00
|
|
|
wfDeprecated( __METHOD__ );
|
2010-08-26 19:40:29 +00:00
|
|
|
|
2010-08-03 22:32:09 +00:00
|
|
|
$threshold = $wgUser->getStubThreshold();
|
2007-11-22 15:54:18 +00:00
|
|
|
$colour = ( $size < $threshold ) ? 'stub' : '';
|
2011-05-17 22:03:20 +00:00
|
|
|
// @todo FIXME: Replace deprecated makeColouredLinkObj by link()
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
|
2005-06-01 10:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2006-02-01 04:34:47 +00:00
|
|
|
* Make appropriate markup for a link to the current article. This is currently rendered
|
2011-04-03 12:04:04 +00:00
|
|
|
* as the bold link text. The calling sequence is the same as the other make*LinkObj static functions,
|
2006-02-01 04:34:47 +00:00
|
|
|
* despite $query not being used.
|
2011-03-02 10:57:55 +00:00
|
|
|
*
|
2011-03-02 10:59:30 +00:00
|
|
|
* @param $nt Title
|
2011-05-06 22:53:59 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2006-02-01 04:34:47 +00:00
|
|
|
*/
|
2011-09-03 13:46:56 +00:00
|
|
|
static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
|
|
|
|
|
if ( $html == '' ) {
|
|
|
|
|
$html = htmlspecialchars( $nt->getPrefixedText() );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2011-09-03 13:46:56 +00:00
|
|
|
return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-06 22:53:59 +00:00
|
|
|
/**
|
|
|
|
|
* @param $title Title
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function normaliseSpecialPage( Title $title ) {
|
2008-06-17 08:08:59 +00:00
|
|
|
if ( $title->getNamespace() == NS_SPECIAL ) {
|
2011-04-17 11:31:11 +00:00
|
|
|
list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
|
2010-08-19 11:21:14 +00:00
|
|
|
if ( !$name ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
2008-08-01 22:44:11 +00:00
|
|
|
$ret = SpecialPage::getTitleFor( $name, $subpage );
|
|
|
|
|
$ret->mFragment = $title->getFragment();
|
|
|
|
|
return $ret;
|
2008-06-17 08:08:59 +00:00
|
|
|
} else {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 09:32:09 +00:00
|
|
|
/**
|
2009-10-26 14:25:48 +00:00
|
|
|
* Returns the filename part of an url.
|
|
|
|
|
* Used as alternative text for external images.
|
2011-05-06 22:53:59 +00:00
|
|
|
*
|
|
|
|
|
* @param $url string
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function fnamePart( $url ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$basename = strrchr( $url, '/' );
|
|
|
|
|
if ( false === $basename ) {
|
|
|
|
|
$basename = $url;
|
|
|
|
|
} else {
|
|
|
|
|
$basename = substr( $basename, 1 );
|
|
|
|
|
}
|
2008-07-02 01:19:00 +00:00
|
|
|
return $basename;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 09:32:09 +00:00
|
|
|
/**
|
2009-10-26 14:25:48 +00:00
|
|
|
* Return the code for images which were added via external links,
|
|
|
|
|
* via Parser::maybeMakeExternalImage().
|
2011-05-06 22:53:59 +00:00
|
|
|
*
|
|
|
|
|
* @param $url
|
|
|
|
|
* @param $alt
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeExternalImage( $url, $alt = '' ) {
|
2010-01-06 19:59:42 +00:00
|
|
|
if ( $alt == '' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$alt = self::fnamePart( $url );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2008-06-24 14:32:49 +00:00
|
|
|
$img = '';
|
2010-08-26 19:40:29 +00:00
|
|
|
$success = wfRunHooks( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
|
|
|
|
|
if ( !$success ) {
|
|
|
|
|
wfDebug( "Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true );
|
2008-06-24 14:32:49 +00:00
|
|
|
return $img;
|
|
|
|
|
}
|
2009-08-21 20:39:35 +00:00
|
|
|
return Html::element( 'img',
|
2008-07-02 01:19:00 +00:00
|
|
|
array(
|
|
|
|
|
'src' => $url,
|
|
|
|
|
'alt' => $alt ) );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2009-06-08 22:33:37 +00:00
|
|
|
* Given parameters derived from [[Image:Foo|options...]], generate the
|
|
|
|
|
* HTML that that syntax inserts in the page.
|
2008-02-26 17:20:39 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title Title object
|
|
|
|
|
* @param $file File object, or false if it doesn't exist
|
|
|
|
|
* @param $frameParams Array: associative array of parameters external to the media handler.
|
2008-04-14 07:45:50 +00:00
|
|
|
* Boolean parameters are indicated by presence or absence, the value is arbitrary and
|
2008-01-03 19:28:50 +00:00
|
|
|
* will often be false.
|
|
|
|
|
* thumbnail If present, downscale and frame
|
|
|
|
|
* manualthumb Image name to use as a thumbnail, instead of automatic scaling
|
|
|
|
|
* framed Shows image in original size in a frame
|
|
|
|
|
* frameless Downscale but don't frame
|
|
|
|
|
* upright If present, tweak default sizes for portrait orientation
|
|
|
|
|
* upright_factor Fudge factor for "upright" tweak (default 0.75)
|
|
|
|
|
* border If present, show a border around the image
|
|
|
|
|
* align Horizontal alignment (left, right, center, none)
|
2008-04-14 07:45:50 +00:00
|
|
|
* valign Vertical alignment (baseline, sub, super, top, text-top, middle,
|
2008-01-03 19:28:50 +00:00
|
|
|
* bottom, text-bottom)
|
|
|
|
|
* alt Alternate text for image (i.e. alt attribute). Plain text.
|
|
|
|
|
* caption HTML for image caption.
|
2008-10-07 00:31:26 +00:00
|
|
|
* link-url URL to link to
|
|
|
|
|
* link-title Title object to link to
|
2010-11-09 12:25:57 +00:00
|
|
|
* link-target Value for the target attribue, only with link-url
|
2008-10-06 05:55:27 +00:00
|
|
|
* no-link Boolean, suppress description link
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $handlerParams Array: associative array of media handler parameters, to be passed
|
2008-04-14 07:45:50 +00:00
|
|
|
* to transform(). Typical keys are "width" and "page".
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $time String: timestamp of the file, set as false for current
|
|
|
|
|
* @param $query String: query params for desc url
|
2010-10-31 21:53:29 +00:00
|
|
|
* @param $widthOption: Used by the parser to remember the user preference thumbnailsize
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML for an image, with links, wrappers, etc.
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeImageLink2( Title $title, $file, $frameParams = array(),
|
2011-03-21 16:15:56 +00:00
|
|
|
$handlerParams = array(), $time = false, $query = "", $widthOption = null )
|
|
|
|
|
{
|
2008-02-26 17:20:39 +00:00
|
|
|
$res = null;
|
2011-04-03 12:04:04 +00:00
|
|
|
$dummy = new DummyLinker;
|
2011-04-03 11:44:11 +00:00
|
|
|
if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
|
2011-03-02 10:57:55 +00:00
|
|
|
&$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
|
2008-02-26 17:20:39 +00:00
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( $file && !$file->allowInlineDisplay() ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::link( $title );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
// Shortcuts
|
|
|
|
|
$fp =& $frameParams;
|
|
|
|
|
$hp =& $handlerParams;
|
2006-08-13 17:34:48 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
// Clean up parameters
|
|
|
|
|
$page = isset( $hp['page'] ) ? $hp['page'] : false;
|
2011-03-02 10:57:55 +00:00
|
|
|
if ( !isset( $fp['align'] ) ) {
|
|
|
|
|
$fp['align'] = '';
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $fp['alt'] ) ) {
|
|
|
|
|
$fp['alt'] = '';
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $fp['title'] ) ) {
|
|
|
|
|
$fp['title'] = '';
|
|
|
|
|
}
|
2006-01-03 00:51:57 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$prefix = $postfix = '';
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-10-08 16:33:36 +00:00
|
|
|
if ( 'center' == $fp['align'] ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$prefix = '<div class="center">';
|
|
|
|
|
$postfix = '</div>';
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$fp['align'] = 'none';
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( $file && !isset( $hp['width'] ) ) {
|
2011-05-14 23:48:59 +00:00
|
|
|
if ( isset( $hp['height'] ) && $file->isVectorized() ) {
|
|
|
|
|
// If its a vector image, and user only specifies height
|
|
|
|
|
// we don't want it to be limited by its "normal" width.
|
|
|
|
|
global $wgSVGMaxSize;
|
|
|
|
|
$hp['width'] = $wgSVGMaxSize;
|
2011-06-17 16:03:52 +00:00
|
|
|
} else {
|
2011-05-14 23:48:59 +00:00
|
|
|
$hp['width'] = $file->getWidth( $page );
|
|
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
|
2010-10-31 21:53:29 +00:00
|
|
|
global $wgThumbLimits, $wgThumbUpright;
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !isset( $widthOption ) || !isset( $wgThumbLimits[$widthOption] ) ) {
|
2010-10-31 21:53:29 +00:00
|
|
|
$widthOption = User::getDefaultOption( 'thumbsize' );
|
2007-04-20 19:24:53 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
|
2007-05-21 18:56:03 +00:00
|
|
|
// Reduce width for upright images when parameter 'upright' is used
|
2007-08-27 11:24:53 +00:00
|
|
|
if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
|
|
|
|
|
$fp['upright'] = $wgThumbUpright;
|
2007-05-21 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
// For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
|
2008-04-14 07:45:50 +00:00
|
|
|
$prefWidth = isset( $fp['upright'] ) ?
|
2010-08-07 22:35:23 +00:00
|
|
|
round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
|
|
|
|
|
$wgThumbLimits[$widthOption];
|
2010-10-31 21:53:29 +00:00
|
|
|
|
|
|
|
|
// Use width which is smaller: real image width or user preference width
|
|
|
|
|
// Unless image is scalable vector.
|
|
|
|
|
if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
|
|
|
|
|
$prefWidth < $hp['width'] || $file->isVectorized() ) ) {
|
|
|
|
|
$hp['width'] = $prefWidth;
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
2007-04-20 19:24:53 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-01 19:36:29 +00:00
|
|
|
if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
|
2010-10-31 21:53:29 +00:00
|
|
|
global $wgContLang;
|
2004-12-18 06:29:23 +00:00
|
|
|
# Create a thumbnail. Alignment depends on language
|
2006-11-08 07:12:03 +00:00
|
|
|
# writing direction, # right aligned for left-to-right-
|
2004-12-18 06:29:23 +00:00
|
|
|
# languages ("Western languages"), left-aligned
|
|
|
|
|
# for right-to-left-languages ("Semitic languages")
|
|
|
|
|
#
|
2006-11-08 07:12:03 +00:00
|
|
|
# If thumbnail width has not been provided, it is set
|
2005-04-12 00:37:45 +00:00
|
|
|
# to the default user option as specified in Language*.php
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( $fp['align'] == '' ) {
|
2009-08-22 01:24:04 +00:00
|
|
|
$fp['align'] = $wgContLang->alignEnd();
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
|
2005-08-16 13:27:00 +00:00
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2007-11-20 12:11:05 +00:00
|
|
|
if ( $file && isset( $fp['frameless'] ) ) {
|
|
|
|
|
$srcWidth = $file->getWidth( $page );
|
|
|
|
|
# For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
|
|
|
|
|
# This is the same behaviour as the "thumb" option does it already.
|
|
|
|
|
if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
|
|
|
|
|
$hp['width'] = $srcWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 21:53:29 +00:00
|
|
|
if ( $file && isset( $hp['width'] ) ) {
|
2007-04-20 12:31:36 +00:00
|
|
|
# Create a resized image, without the additional thumbnail features
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$thumb = $file->transform( $hp );
|
2005-07-04 19:20:53 +00:00
|
|
|
} else {
|
2007-04-20 12:31:36 +00:00
|
|
|
$thumb = false;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
if ( !$thumb ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$s = self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2008-10-06 05:55:27 +00:00
|
|
|
$params = array(
|
2007-08-31 02:51:23 +00:00
|
|
|
'alt' => $fp['alt'],
|
2008-10-08 16:33:36 +00:00
|
|
|
'title' => $fp['title'],
|
2007-08-31 14:01:27 +00:00
|
|
|
'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
|
2008-10-06 05:55:27 +00:00
|
|
|
'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
|
2011-04-03 11:44:11 +00:00
|
|
|
$params = self::getImageLinkMTOParams( $fp, $query ) + $params;
|
2008-10-06 05:55:27 +00:00
|
|
|
|
|
|
|
|
$s = $thumb->toHtml( $params );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2010-01-06 19:59:42 +00:00
|
|
|
if ( $fp['align'] != '' ) {
|
2008-10-06 04:22:19 +00:00
|
|
|
$s = "<div class=\"float{$fp['align']}\">{$s}</div>";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
return str_replace( "\n", ' ', $prefix . $s . $postfix );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 10:28:00 +00:00
|
|
|
/**
|
2010-08-26 19:40:29 +00:00
|
|
|
* Get the link parameters for MediaTransformOutput::toHtml() from given
|
2010-07-20 10:28:00 +00:00
|
|
|
* frame parameters supplied by the Parser.
|
|
|
|
|
* @param $frameParams The frame parameters
|
|
|
|
|
* @param $query An optional query string to add to description page links
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function getImageLinkMTOParams( $frameParams, $query = '' ) {
|
2010-07-20 10:28:00 +00:00
|
|
|
$mtoParams = array();
|
|
|
|
|
if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
|
|
|
|
|
$mtoParams['custom-url-link'] = $frameParams['link-url'];
|
2010-11-09 12:25:57 +00:00
|
|
|
if ( isset( $frameParams['link-target'] ) ) {
|
|
|
|
|
$mtoParams['custom-target-link'] = $frameParams['link-target'];
|
|
|
|
|
}
|
2010-07-20 10:28:00 +00:00
|
|
|
} elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$mtoParams['custom-title-link'] = self::normaliseSpecialPage( $frameParams['link-title'] );
|
2010-07-20 10:28:00 +00:00
|
|
|
} elseif ( !empty( $frameParams['no-link'] ) ) {
|
|
|
|
|
// No link
|
|
|
|
|
} else {
|
|
|
|
|
$mtoParams['desc-link'] = true;
|
|
|
|
|
$mtoParams['desc-query'] = $query;
|
|
|
|
|
}
|
|
|
|
|
return $mtoParams;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
/**
|
|
|
|
|
* Make HTML for a thumbnail including image, border and caption
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title Title object
|
|
|
|
|
* @param $file File object or false if it doesn't exist
|
|
|
|
|
* @param $label String
|
|
|
|
|
* @param $alt String
|
|
|
|
|
* @param $align String
|
|
|
|
|
* @param $params Array
|
|
|
|
|
* @param $framed Boolean
|
|
|
|
|
* @param $manualthumb String
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
|
2011-03-21 16:15:56 +00:00
|
|
|
$align = 'right', $params = array(), $framed = false , $manualthumb = "" )
|
|
|
|
|
{
|
2008-04-14 07:45:50 +00:00
|
|
|
$frameParams = array(
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
'alt' => $alt,
|
|
|
|
|
'caption' => $label,
|
|
|
|
|
'align' => $align
|
|
|
|
|
);
|
2011-03-02 10:57:55 +00:00
|
|
|
if ( $framed ) {
|
|
|
|
|
$frameParams['framed'] = true;
|
|
|
|
|
}
|
|
|
|
|
if ( $manualthumb ) {
|
|
|
|
|
$frameParams['manualthumb'] = $manualthumb;
|
|
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::makeThumbLink2( $title, $file, $frameParams, $params );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 10:57:55 +00:00
|
|
|
/**
|
|
|
|
|
* @param $title Title
|
|
|
|
|
* @param $file File
|
|
|
|
|
* @param array $frameParams
|
|
|
|
|
* @param array $handlerParams
|
|
|
|
|
* @param bool $time
|
|
|
|
|
* @param string $query
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeThumbLink2( Title $title, $file, $frameParams = array(),
|
2011-03-21 16:15:56 +00:00
|
|
|
$handlerParams = array(), $time = false, $query = "" )
|
|
|
|
|
{
|
2011-04-30 12:04:00 +00:00
|
|
|
global $wgStylePath, $wgContLang;
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$exists = $file && $file->exists();
|
2004-12-18 06:29:23 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
# Shortcuts
|
|
|
|
|
$fp =& $frameParams;
|
|
|
|
|
$hp =& $handlerParams;
|
2007-04-20 12:31:36 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$page = isset( $hp['page'] ) ? $hp['page'] : false;
|
|
|
|
|
if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
|
|
|
|
|
if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
|
2009-07-03 05:13:58 +00:00
|
|
|
if ( !isset( $fp['title'] ) ) $fp['title'] = '';
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
|
|
|
|
|
|
|
|
|
|
if ( empty( $hp['width'] ) ) {
|
2008-04-14 07:45:50 +00:00
|
|
|
// Reduce width for upright images when parameter 'upright' is used
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$hp['width'] = isset( $fp['upright'] ) ? 130 : 180;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
$thumb = false;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
if ( !$exists ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$outerWidth = $hp['width'] + 2;
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( isset( $fp['manualthumb'] ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
# Use manually specified thumbnail
|
2008-12-01 17:14:30 +00:00
|
|
|
$manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $manual_title ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$manual_img = wfFindFile( $manual_title );
|
|
|
|
|
if ( $manual_img ) {
|
2010-05-19 00:40:48 +00:00
|
|
|
$thumb = $manual_img->getUnscaledThumb( $hp );
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
|
|
|
|
$exists = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
} elseif ( isset( $fp['framed'] ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
// Use image dimensions, don't scale
|
2010-05-19 00:40:48 +00:00
|
|
|
$thumb = $file->getUnscaledThumb( $hp );
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
2007-09-18 14:30:40 +00:00
|
|
|
# Do not present an image bigger than the source, for bitmap-style images
|
|
|
|
|
# This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
|
|
|
|
|
$srcWidth = $file->getWidth( $page );
|
|
|
|
|
if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
|
|
|
|
|
$hp['width'] = $srcWidth;
|
|
|
|
|
}
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$thumb = $file->transform( $hp );
|
2007-05-01 21:30:46 +00:00
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $thumb ) {
|
|
|
|
|
$outerWidth = $thumb->getWidth() + 2;
|
|
|
|
|
} else {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$outerWidth = $hp['width'] + 2;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-13 15:02:28 +00:00
|
|
|
# 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 bug 14771
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$url = $title->getLocalURL( $query );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $page ) {
|
2009-03-13 15:02:28 +00:00
|
|
|
$url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !$exists ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$s .= self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
|
2010-07-20 10:28:00 +00:00
|
|
|
$zoomIcon = '';
|
2007-05-30 21:02:32 +00:00
|
|
|
} elseif ( !$thumb ) {
|
|
|
|
|
$s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
|
2010-07-20 10:28:00 +00:00
|
|
|
$zoomIcon = '';
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2010-07-20 10:28:00 +00:00
|
|
|
$params = array(
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
'alt' => $fp['alt'],
|
2008-10-08 16:33:36 +00:00
|
|
|
'title' => $fp['title'],
|
2010-07-20 10:28:00 +00:00
|
|
|
'img-class' => 'thumbimage' );
|
2011-04-03 11:44:11 +00:00
|
|
|
$params = self::getImageLinkMTOParams( $fp, $query ) + $params;
|
2010-07-20 10:28:00 +00:00
|
|
|
$s .= $thumb->toHtml( $params );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( isset( $fp['framed'] ) ) {
|
2010-07-20 10:28:00 +00:00
|
|
|
$zoomIcon = "";
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2011-04-30 12:04:00 +00:00
|
|
|
$zoomIcon = Html::rawElement( 'div', array( 'class' => 'magnify' ),
|
|
|
|
|
Html::rawElement( 'a', array(
|
|
|
|
|
'href' => $url,
|
|
|
|
|
'class' => 'internal',
|
|
|
|
|
'title' => wfMsg( 'thumbnail-more' ) ),
|
|
|
|
|
Html::element( 'img', array(
|
|
|
|
|
'src' => $wgStylePath . '/common/images/magnify-clip' . ( $wgContLang->isRTL() ? '-rtl' : '' ) . '.png',
|
|
|
|
|
'width' => 15,
|
|
|
|
|
'height' => 11,
|
|
|
|
|
'alt' => "" ) ) ) );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-20 10:28:00 +00:00
|
|
|
$s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
|
2010-08-26 19:40:29 +00:00
|
|
|
return str_replace( "\n", ' ', $s );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-04-17 08:30:15 +00:00
|
|
|
/**
|
2007-06-09 16:19:38 +00:00
|
|
|
* Make a "broken" link to an image
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title Title object
|
2011-09-03 13:46:56 +00:00
|
|
|
* @param $html String: link label in htmlescaped text form
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $query String: query string
|
2011-02-26 12:08:59 +00:00
|
|
|
* @param $trail String: link trail (HTML fragment)
|
|
|
|
|
* @param $prefix String: link prefix (HTML fragment)
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $time Boolean: a file of a certain timestamp was requested
|
|
|
|
|
* @return String
|
2005-04-17 08:30:15 +00:00
|
|
|
*/
|
2011-09-03 13:46:56 +00:00
|
|
|
public static function makeBrokenImageLinkObj( $title, $html = '', $query = '', $trail = '', $prefix = '', $time = false ) {
|
2011-07-19 23:09:55 +00:00
|
|
|
global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
|
2011-05-15 12:34:00 +00:00
|
|
|
if ( ! $title instanceof Title ) {
|
2011-09-03 13:46:56 +00:00
|
|
|
return "<!-- ERROR -->{$prefix}{$html}{$trail}";
|
2011-05-15 12:34:00 +00:00
|
|
|
}
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
|
2010-09-04 22:25:59 +00:00
|
|
|
|
2011-05-15 12:34:00 +00:00
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2011-09-03 13:46:56 +00:00
|
|
|
if ( $html == '' )
|
|
|
|
|
$html = htmlspecialchars( $title->getPrefixedText() );
|
2010-08-26 19:40:29 +00:00
|
|
|
|
2011-07-19 23:09:55 +00:00
|
|
|
if ( ( $wgUploadMissingFileUrl || $wgUploadNavigationUrl || $wgEnableUploads ) && !$currentExists ) {
|
2011-05-15 12:34:00 +00:00
|
|
|
$redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
|
2010-01-03 22:45:34 +00:00
|
|
|
|
2011-05-15 12:34:00 +00:00
|
|
|
if ( $redir ) {
|
2007-06-09 16:19:38 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2011-09-03 13:46:56 +00:00
|
|
|
return self::linkKnown( $title, "$prefix$html$inside", array(), $query ) . $trail;
|
2007-06-09 16:19:38 +00:00
|
|
|
}
|
2011-05-15 12:34:00 +00:00
|
|
|
|
|
|
|
|
$href = self::getUploadUrl( $title, $query );
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
|
|
|
|
|
htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
|
2011-09-03 13:46:56 +00:00
|
|
|
"$prefix$html$inside</a>$trail";
|
2007-06-09 16:19:38 +00:00
|
|
|
} else {
|
2011-05-15 12:34:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2011-09-03 13:46:56 +00:00
|
|
|
return self::linkKnown( $title, "$prefix$html$inside", array(), $query ) . $trail;
|
2005-04-17 08:30:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
|
2010-01-12 19:43:03 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL to upload a certain file
|
2010-08-26 19:40:29 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $destFile Title object of the file to upload
|
|
|
|
|
* @param $query String: urlencoded query string to prepend
|
|
|
|
|
* @return String: urlencoded URL
|
2010-01-12 19:43:03 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
protected static function getUploadUrl( $destFile, $query = '' ) {
|
2011-07-19 23:09:55 +00:00
|
|
|
global $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
|
2010-01-12 19:43:03 +00:00
|
|
|
$q = 'wpDestFile=' . $destFile->getPartialUrl();
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $query != '' )
|
2010-01-12 19:43:03 +00:00
|
|
|
$q .= '&' . $query;
|
|
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $wgUploadMissingFileUrl ) {
|
2010-07-27 10:31:30 +00:00
|
|
|
return wfAppendQuery( $wgUploadMissingFileUrl, $q );
|
2011-07-19 23:09:55 +00:00
|
|
|
} elseif( $wgUploadNavigationUrl ) {
|
|
|
|
|
return wfAppendQuery( $wgUploadNavigationUrl, $q );
|
2010-01-12 19:43:03 +00:00
|
|
|
} else {
|
|
|
|
|
$upload = SpecialPage::getTitleFor( 'Upload' );
|
|
|
|
|
return $upload->getLocalUrl( $q );
|
2010-08-26 19:40:29 +00:00
|
|
|
}
|
2010-01-12 19:43:03 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-02-21 01:56:50 +00:00
|
|
|
/**
|
|
|
|
|
* Create a direct link to a given uploaded file.
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
|
|
|
|
* @param $title Title object.
|
2011-09-03 13:46:56 +00:00
|
|
|
* @param $html String: pre-sanitized HTML
|
2011-03-23 03:13:37 +00:00
|
|
|
* @param $time string: MW timestamp of file creation time
|
|
|
|
|
* @return String: HTML
|
|
|
|
|
*/
|
2011-09-03 13:46:56 +00:00
|
|
|
public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
|
2011-03-23 03:13:37 +00:00
|
|
|
$img = wfFindFile( $title, array( 'time' => $time ) );
|
2011-09-03 13:46:56 +00:00
|
|
|
return self::makeMediaLinkFile( $title, $img, $html );
|
2011-03-23 03:13:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a direct link to a given uploaded file.
|
|
|
|
|
* This will make a broken link if $file is false.
|
|
|
|
|
*
|
|
|
|
|
* @param $title Title object.
|
2011-05-29 14:01:47 +00:00
|
|
|
* @param $file File|false mixed File object or false
|
2011-09-03 13:46:56 +00:00
|
|
|
* @param $html String: pre-sanitized HTML
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
2005-02-21 01:56:50 +00:00
|
|
|
* @todo Handle invalid or missing images better.
|
|
|
|
|
*/
|
2011-09-03 13:46:56 +00:00
|
|
|
public static function makeMediaLinkFile( Title $title, $file, $html = '' ) {
|
2011-03-23 03:13:37 +00:00
|
|
|
if ( $file && $file->exists() ) {
|
|
|
|
|
$url = $file->getURL();
|
|
|
|
|
$class = 'internal';
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2011-04-03 11:44:11 +00:00
|
|
|
$url = self::getUploadUrl( $title );
|
2011-03-23 03:13:37 +00:00
|
|
|
$class = 'new';
|
|
|
|
|
}
|
|
|
|
|
$alt = htmlspecialchars( $title->getText(), ENT_QUOTES );
|
2011-09-03 13:46:56 +00:00
|
|
|
if ( $html == '' ) {
|
|
|
|
|
$html = $alt;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2011-03-23 03:13:37 +00:00
|
|
|
$u = htmlspecialchars( $url );
|
2011-09-03 13:46:56 +00:00
|
|
|
return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$html}</a>";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 09:32:09 +00:00
|
|
|
/**
|
2011-05-29 14:01:47 +00:00
|
|
|
* Make a link to a special page given its name and, optionally,
|
2010-01-07 09:32:09 +00:00
|
|
|
* a message key from the link text.
|
2009-10-26 14:25:48 +00:00
|
|
|
* Usage example: $skin->specialLink( 'recentchanges' )
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
2011-07-23 20:58:18 +00:00
|
|
|
* @return string
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function specialLink( $name, $key = '' ) {
|
2011-05-29 14:01:47 +00:00
|
|
|
if ( $key == '' ) {
|
|
|
|
|
$key = strtolower( $name );
|
|
|
|
|
}
|
2010-09-03 21:53:02 +00:00
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMsg( $key ) );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-09 15:53:08 +00:00
|
|
|
/**
|
|
|
|
|
* Make an external link
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $url String: URL to link to
|
|
|
|
|
* @param $text String: text of link
|
|
|
|
|
* @param $escape Boolean: do we escape the link text?
|
|
|
|
|
* @param $linktype String: type of external link. Gets added to the classes
|
|
|
|
|
* @param $attribs Array of extra attributes to <a>
|
2009-03-09 15:53:08 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
|
2011-02-05 23:06:36 +00:00
|
|
|
$class = "external";
|
|
|
|
|
if ( isset($linktype) && $linktype ) {
|
|
|
|
|
$class .= " $linktype";
|
2010-08-26 19:40:29 +00:00
|
|
|
}
|
2011-02-05 23:06:36 +00:00
|
|
|
if ( isset($attribs['class']) && $attribs['class'] ) {
|
|
|
|
|
$class .= " {$attribs['class']}";
|
|
|
|
|
}
|
|
|
|
|
$attribs['class'] = $class;
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $escape ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$text = htmlspecialchars( $text );
|
|
|
|
|
}
|
2008-06-08 21:45:05 +00:00
|
|
|
$link = '';
|
2011-03-21 16:15:56 +00:00
|
|
|
$success = wfRunHooks( 'LinkerMakeExternalLink',
|
|
|
|
|
array( &$url, &$text, &$link, &$attribs, $linktype ) );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( !$success ) {
|
|
|
|
|
wfDebug( "Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true );
|
2008-06-08 21:45:05 +00:00
|
|
|
return $link;
|
|
|
|
|
}
|
2011-02-05 23:06:36 +00:00
|
|
|
$attribs['href'] = $url;
|
|
|
|
|
return Html::rawElement( 'a', $attribs, $text );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-16 19:04:25 +00:00
|
|
|
/**
|
|
|
|
|
* Make user link (or user contributions for unregistered users)
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $userId Integer: user id in database.
|
|
|
|
|
* @param $userText String: user name in database
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML fragment
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2011-09-07 17:00:46 +00:00
|
|
|
public static function userLink( $userId, $userText ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $userId == 0 ) {
|
2008-07-30 21:02:28 +00:00
|
|
|
$page = SpecialPage::getTitleFor( 'Contributions', $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
2008-07-30 21:02:28 +00:00
|
|
|
$page = Title::makeTitle( NS_USER, $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-08-06 07:09:59 +00:00
|
|
|
* Generate standard user tool links (talk, contributions, block link, etc.)
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $userId Integer: user identifier
|
|
|
|
|
* @param $userText String: user name or IP address
|
|
|
|
|
* @param $redContribsWhenNoEdits Boolean: should the contributions link be
|
|
|
|
|
* red if the user has no edits?
|
2011-09-07 12:12:24 +00:00
|
|
|
* @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK and Linker::TOOL_LINKS_EMAIL)
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $edits Integer: user edit count (optional, for performance)
|
|
|
|
|
* @return String: HTML fragment
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function userToolLinks(
|
2011-03-21 16:15:56 +00:00
|
|
|
$userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
|
|
|
|
|
) {
|
2011-03-12 12:13:22 +00:00
|
|
|
global $wgUser, $wgDisableAnonTalk, $wgLang;
|
2006-03-16 19:04:25 +00:00
|
|
|
$talkable = !( $wgDisableAnonTalk && 0 == $userId );
|
2011-09-11 08:14:46 +00:00
|
|
|
$blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
|
|
|
|
|
$addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
|
2006-03-16 19:04:25 +00:00
|
|
|
|
|
|
|
|
$items = array();
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $talkable ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$items[] = self::userTalkLink( $userId, $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $userId ) {
|
2007-01-23 19:56:01 +00:00
|
|
|
// check if the user has an edit
|
2008-07-30 21:02:28 +00:00
|
|
|
$attribs = array();
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $redContribsWhenNoEdits ) {
|
|
|
|
|
$count = !is_null( $edits ) ? $edits : User::edits( $userId );
|
|
|
|
|
if ( $count == 0 ) {
|
2008-07-30 21:02:28 +00:00
|
|
|
$attribs['class'] = 'new';
|
|
|
|
|
}
|
2007-01-23 19:56:01 +00:00
|
|
|
}
|
2006-12-02 08:52:54 +00:00
|
|
|
$contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
|
2007-01-23 19:56:01 +00:00
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
$items[] = self::link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
|
2006-03-16 21:17:32 +00:00
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$items[] = self::blockLink( $userId, $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-07 12:12:24 +00:00
|
|
|
if ( $addEmailLink && $wgUser->canSendEmail() ) {
|
|
|
|
|
$items[] = self::emailLink( $userId, $userText );
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $items ) {
|
2009-02-09 09:13:30 +00:00
|
|
|
return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-23 19:56:01 +00:00
|
|
|
/**
|
|
|
|
|
* Alias for userToolLinks( $userId, $userText, true );
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $userId Integer: user identifier
|
|
|
|
|
* @param $userText String: user name or IP address
|
|
|
|
|
* @param $edits Integer: user edit count (optional, for performance)
|
2007-01-23 19:56:01 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::userToolLinks( $userId, $userText, true, 0, $edits );
|
2007-01-23 19:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-16 19:04:25 +00:00
|
|
|
/**
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $userId Integer: user id in database.
|
|
|
|
|
* @param $userText String: user name in database.
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML fragment with user talk link
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2011-09-07 17:00:46 +00:00
|
|
|
public static function userTalkLink( $userId, $userText ) {
|
2006-03-16 19:04:25 +00:00
|
|
|
$userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
|
2011-04-03 11:44:11 +00:00
|
|
|
$userTalkLink = self::link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
|
2006-03-16 19:04:25 +00:00
|
|
|
return $userTalkLink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $userId Integer: userid
|
|
|
|
|
* @param $userText String: user name in database.
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML fragment with block link
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2011-09-07 17:00:46 +00:00
|
|
|
public static function blockLink( $userId, $userText ) {
|
2011-03-12 23:22:34 +00:00
|
|
|
$blockPage = SpecialPage::getTitleFor( 'Block', $userText );
|
2011-04-03 11:44:11 +00:00
|
|
|
$blockLink = self::link( $blockPage, wfMsgHtml( 'blocklink' ) );
|
2006-03-16 19:04:25 +00:00
|
|
|
return $blockLink;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-09-07 12:12:24 +00:00
|
|
|
/**
|
|
|
|
|
* @param $userId Integer: userid
|
|
|
|
|
* @param $userText String: user name in database.
|
|
|
|
|
* @return String: HTML fragment with e-mail user link
|
|
|
|
|
*/
|
2011-09-07 17:00:46 +00:00
|
|
|
public static function emailLink( $userId, $userText ) {
|
2011-09-07 13:35:01 +00:00
|
|
|
$emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
|
2011-09-07 12:12:24 +00:00
|
|
|
$emailLink = self::link( $emailPage, wfMsgHtml( 'emaillink' ) );
|
|
|
|
|
return $emailLink;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-16 19:04:25 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a user link if the current user is allowed to view it
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $rev Revision object.
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $isPublic Boolean: show only if all users can see it
|
|
|
|
|
* @return String: HTML fragment
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function revUserLink( $rev, $isPublic = false ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
|
2008-03-09 02:25:04 +00:00
|
|
|
$link = wfMsgHtml( 'rev-deleted-user' );
|
2011-06-17 16:03:52 +00:00
|
|
|
} elseif ( $rev->userCan( Revision::DELETED_USER ) ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$link = self::userLink( $rev->getUser( Revision::FOR_THIS_USER ),
|
2008-09-24 09:44:45 +00:00
|
|
|
$rev->getUserText( Revision::FOR_THIS_USER ) );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
|
|
|
|
$link = wfMsgHtml( 'rev-deleted-user' );
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
|
2006-03-16 19:04:25 +00:00
|
|
|
return '<span class="history-deleted">' . $link . '</span>';
|
|
|
|
|
}
|
|
|
|
|
return $link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a user tool link cluster if the current user is allowed to view it
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $rev Revision object.
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $isPublic Boolean: show only if all users can see it
|
2006-03-16 19:04:25 +00:00
|
|
|
* @return string HTML
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function revUserTools( $rev, $isPublic = false ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
|
2008-03-09 02:25:04 +00:00
|
|
|
$link = wfMsgHtml( 'rev-deleted-user' );
|
2011-06-17 16:03:52 +00:00
|
|
|
} elseif ( $rev->userCan( Revision::DELETED_USER ) ) {
|
2008-09-24 09:44:45 +00:00
|
|
|
$userId = $rev->getUser( Revision::FOR_THIS_USER );
|
2010-01-07 09:32:09 +00:00
|
|
|
$userText = $rev->getUserText( Revision::FOR_THIS_USER );
|
2011-04-03 11:44:11 +00:00
|
|
|
$link = self::userLink( $userId, $userText ) .
|
|
|
|
|
' ' . self::userToolLinks( $userId, $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
|
|
|
|
$link = wfMsgHtml( 'rev-deleted-user' );
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
|
2008-03-09 02:25:04 +00:00
|
|
|
return ' <span class="history-deleted">' . $link . '</span>';
|
2007-03-14 15:50:06 +00:00
|
|
|
}
|
|
|
|
|
return $link;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
/**
|
|
|
|
|
* This function is called by all recent changes variants, by the page history,
|
|
|
|
|
* and by the user contributions list. It is responsible for formatting edit
|
|
|
|
|
* comments. It escapes any HTML in the comment, but adds some CSS to format
|
|
|
|
|
* auto-generated comments (from section editing) and formats [[wikilinks]].
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
2004-12-18 06:29:23 +00:00
|
|
|
* @author Erik Moeller <moeller@scireview.de>
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
2004-12-18 06:29:23 +00:00
|
|
|
* Note: there's not always a title to pass to this function.
|
|
|
|
|
* Since you can't set a default parameter for a reference, I've turned it
|
|
|
|
|
* temporarily to a value pass. Should be adjusted further. --brion
|
2006-11-17 03:59:32 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $comment String
|
|
|
|
|
* @param $title Mixed: Title object (to generate link to the section in autocomment) or null
|
|
|
|
|
* @param $local Boolean: whether section links should refer to local page
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function formatComment( $comment, $title = null, $local = false ) {
|
2006-11-17 03:59:32 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-05-09 20:05:08 +00:00
|
|
|
# Sanitize text a bit:
|
2005-04-06 00:00:03 +00:00
|
|
|
$comment = str_replace( "\n", " ", $comment );
|
2008-08-18 18:15:47 +00:00
|
|
|
# Allow HTML entities (for bug 13815)
|
|
|
|
|
$comment = Sanitizer::escapeHtmlAllowEntities( $comment );
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2007-05-09 20:05:08 +00:00
|
|
|
# Render autocomments and make links:
|
2011-04-03 11:44:11 +00:00
|
|
|
$comment = self::formatAutocomments( $comment, $title, $local );
|
|
|
|
|
$comment = self::formatLinksInComment( $comment, $title, $local );
|
2007-05-09 20:05:08 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $comment;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-28 14:52:55 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
2011-04-03 11:44:11 +00:00
|
|
|
static $autocommentTitle;
|
|
|
|
|
static $autocommentLocal;
|
|
|
|
|
|
2007-05-09 20:05:08 +00:00
|
|
|
/**
|
|
|
|
|
* The pattern for autogen comments is / * foo * /, which makes for
|
|
|
|
|
* some nasty regex.
|
|
|
|
|
* We look for all comments, match any text before and after the comment,
|
|
|
|
|
* add a separator where needed and format the comment itself with CSS
|
|
|
|
|
* Called by Linker::formatComment.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $comment String: comment text
|
|
|
|
|
* @param $title An optional title object used to links to sections
|
|
|
|
|
* @param $local Boolean: whether section links should refer to local page
|
|
|
|
|
* @return String: formatted comment
|
2007-05-09 20:05:08 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
private static function formatAutocomments( $comment, $title = null, $local = false ) {
|
2008-08-14 23:33:02 +00:00
|
|
|
// Bah!
|
2011-04-03 11:44:11 +00:00
|
|
|
self::$autocommentTitle = $title;
|
|
|
|
|
self::$autocommentLocal = $local;
|
2008-08-14 23:33:02 +00:00
|
|
|
$comment = preg_replace_callback(
|
2008-08-18 17:22:12 +00:00
|
|
|
'!(.*)/\*\s*(.*?)\s*\*/(.*)!',
|
2011-04-03 11:44:11 +00:00
|
|
|
array( 'Linker', 'formatAutocommentsCallback' ),
|
2008-08-14 23:33:02 +00:00
|
|
|
$comment );
|
2011-04-03 11:44:11 +00:00
|
|
|
self::$autocommentTitle = null;
|
|
|
|
|
self::$autocommentLocal = null;
|
2008-08-14 23:33:02 +00:00
|
|
|
return $comment;
|
|
|
|
|
}
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @param $match
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
private static function formatAutocommentsCallback( $match ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$title = self::$autocommentTitle;
|
|
|
|
|
$local = self::$autocommentLocal;
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2010-02-08 20:05:06 +00:00
|
|
|
$pre = $match[1];
|
|
|
|
|
$auto = $match[2];
|
|
|
|
|
$post = $match[3];
|
|
|
|
|
$link = '';
|
|
|
|
|
if ( $title ) {
|
2008-08-14 23:33:02 +00:00
|
|
|
$section = $auto;
|
|
|
|
|
|
2010-06-21 01:17:36 +00:00
|
|
|
# Remove links that a user may have manually put in the autosummary
|
|
|
|
|
# This could be improved by copying as much of Parser::stripSectionName as desired.
|
2008-08-14 23:33:02 +00:00
|
|
|
$section = str_replace( '[[:', '', $section );
|
|
|
|
|
$section = str_replace( '[[', '', $section );
|
|
|
|
|
$section = str_replace( ']]', '', $section );
|
2010-06-19 13:40:05 +00:00
|
|
|
|
2010-06-21 01:17:36 +00:00
|
|
|
$section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
|
2008-08-14 23:33:02 +00:00
|
|
|
if ( $local ) {
|
|
|
|
|
$sectionTitle = Title::newFromText( '#' . $section );
|
|
|
|
|
} else {
|
2010-01-07 09:32:09 +00:00
|
|
|
$sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
|
2008-09-01 15:05:25 +00:00
|
|
|
$title->getDBkey(), $section );
|
2008-02-06 11:45:38 +00:00
|
|
|
}
|
2008-09-01 15:05:25 +00:00
|
|
|
if ( $sectionTitle ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$link = self::link( $sectionTitle,
|
2009-05-22 09:35:48 +00:00
|
|
|
htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
|
2008-08-28 23:12:57 +00:00
|
|
|
'noclasses' );
|
|
|
|
|
} else {
|
|
|
|
|
$link = '';
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2008-08-28 23:12:57 +00:00
|
|
|
$auto = "$link$auto";
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $pre ) {
|
2008-08-14 23:33:02 +00:00
|
|
|
# written summary $presep autocomment (summary /* section */)
|
|
|
|
|
$auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $post ) {
|
2008-08-14 23:33:02 +00:00
|
|
|
# autocomment $postsep written summary (/* section */ summary)
|
|
|
|
|
$auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
|
|
|
|
|
}
|
|
|
|
|
$auto = '<span class="autocomment">' . $auto . '</span>';
|
|
|
|
|
$comment = $pre . $auto . $post;
|
2007-05-09 20:05:08 +00:00
|
|
|
return $comment;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
2011-04-03 11:44:11 +00:00
|
|
|
static $commentContextTitle;
|
|
|
|
|
static $commentLocal;
|
|
|
|
|
|
2007-05-09 20:05:08 +00:00
|
|
|
/**
|
2007-06-07 22:16:19 +00:00
|
|
|
* Formats wiki links and media links in text; all other wiki formatting
|
|
|
|
|
* is ignored
|
|
|
|
|
*
|
2011-05-17 22:03:20 +00:00
|
|
|
* @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $comment String: text to format links in
|
|
|
|
|
* @param $title An optional title object used to links to sections
|
|
|
|
|
* @param $local Boolean: whether section links should refer to local page
|
|
|
|
|
* @return String
|
2007-05-09 20:05:08 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function formatLinksInComment( $comment, $title = null, $local = false ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
self::$commentContextTitle = $title;
|
|
|
|
|
self::$commentLocal = $local;
|
2009-08-27 22:27:42 +00:00
|
|
|
$html = preg_replace_callback(
|
|
|
|
|
'/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
|
2011-04-03 11:44:11 +00:00
|
|
|
array( 'Linker', 'formatLinksInCommentCallback' ),
|
2009-08-27 22:27:42 +00:00
|
|
|
$comment );
|
2011-04-03 11:44:11 +00:00
|
|
|
self::$commentContextTitle = null;
|
|
|
|
|
self::$commentLocal = null;
|
2009-07-20 02:07:56 +00:00
|
|
|
return $html;
|
2007-10-04 18:59:50 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @param $match
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
protected static function formatLinksInCommentCallback( $match ) {
|
2007-05-09 20:05:08 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
2008-03-21 23:13:34 +00:00
|
|
|
$medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
|
2006-12-03 04:09:48 +00:00
|
|
|
$medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-10-04 18:59:50 +00:00
|
|
|
$comment = $match[0];
|
2007-05-09 20:05:08 +00:00
|
|
|
|
2008-05-22 20:02:03 +00:00
|
|
|
# fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( strpos( $match[1], '%' ) !== false ) {
|
2010-12-24 09:53:08 +00:00
|
|
|
$match[1] = str_replace( array( '<', '>' ), array( '<', '>' ), rawurldecode( $match[1] ) );
|
2008-05-22 20:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-04 18:59:50 +00:00
|
|
|
# Handle link renaming [[foo|text]] will show link as "text"
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $match[3] != "" ) {
|
2007-10-04 18:59:50 +00:00
|
|
|
$text = $match[3];
|
|
|
|
|
} else {
|
|
|
|
|
$text = $match[1];
|
|
|
|
|
}
|
|
|
|
|
$submatch = array();
|
2009-07-21 17:07:56 +00:00
|
|
|
$thelink = null;
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
|
2007-10-04 18:59:50 +00:00
|
|
|
# Media link; trail not supported.
|
2009-08-27 22:27:42 +00:00
|
|
|
$linkRegexp = '/\[\[(.*?)\]\]/';
|
2009-06-13 13:41:48 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
|
2011-04-03 11:44:11 +00:00
|
|
|
$thelink = self::makeMediaLinkObj( $title, $text );
|
2007-10-04 18:59:50 +00:00
|
|
|
} else {
|
|
|
|
|
# Other kind of link
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
|
2007-10-04 18:59:50 +00:00
|
|
|
$trail = $submatch[1];
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2007-10-04 18:59:50 +00:00
|
|
|
$trail = "";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2009-08-27 22:27:42 +00:00
|
|
|
$linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( isset( $match[1][0] ) && $match[1][0] == ':' )
|
|
|
|
|
$match[1] = substr( $match[1], 1 );
|
2011-04-03 11:44:11 +00:00
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2009-07-20 02:07:56 +00:00
|
|
|
$linkText = $text;
|
2011-04-03 11:44:11 +00:00
|
|
|
$linkTarget = self::normalizeSubpageLink( self::$commentContextTitle,
|
2009-07-20 02:07:56 +00:00
|
|
|
$match[1], $linkText );
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2009-07-20 02:26:37 +00:00
|
|
|
$target = Title::newFromText( $linkTarget );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $target ) {
|
|
|
|
|
if ( $target->getText() == '' && $target->getInterwiki() === ''
|
2011-04-03 11:44:11 +00:00
|
|
|
&& !self::$commentLocal && self::$commentContextTitle )
|
2010-04-27 18:09:37 +00:00
|
|
|
{
|
2011-04-03 11:44:11 +00:00
|
|
|
$newTarget = clone ( self::$commentContextTitle );
|
2009-07-20 02:26:37 +00:00
|
|
|
$newTarget->setFragment( '#' . $target->getFragment() );
|
|
|
|
|
$target = $newTarget;
|
|
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
$thelink = self::link(
|
2009-07-20 02:26:37 +00:00
|
|
|
$target,
|
|
|
|
|
$linkText . $inside
|
|
|
|
|
) . $trail;
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $thelink ) {
|
2009-07-21 17:07:56 +00:00
|
|
|
// If the link is still valid, go ahead and replace it in!
|
|
|
|
|
$comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
|
|
|
|
|
}
|
2007-05-09 20:05:08 +00:00
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
return $comment;
|
|
|
|
|
}
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2011-03-02 10:57:55 +00:00
|
|
|
/**
|
|
|
|
|
* @param $contextTitle Title
|
|
|
|
|
* @param $target
|
|
|
|
|
* @param $text
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2009-07-20 02:07:56 +00:00
|
|
|
static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
|
|
|
|
|
# Valid link forms:
|
|
|
|
|
# Foobar -- normal
|
|
|
|
|
# :Foobar -- override special treatment of prefix (images, language links)
|
|
|
|
|
# /Foobar -- convert to CurrentPage/Foobar
|
|
|
|
|
# /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
|
|
|
|
|
# ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
|
|
|
|
|
# ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
|
|
|
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$ret = $target; # default return value is no change
|
|
|
|
|
|
|
|
|
|
# Some namespaces don't allow subpages,
|
|
|
|
|
# so only perform processing if subpages are allowed
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$hash = strpos( $target, '#' );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $hash !== false ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$suffix = substr( $target, $hash );
|
|
|
|
|
$target = substr( $target, 0, $hash );
|
|
|
|
|
} else {
|
|
|
|
|
$suffix = '';
|
|
|
|
|
}
|
|
|
|
|
# bug 7425
|
|
|
|
|
$target = trim( $target );
|
|
|
|
|
# Look at the first character
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $target != '' && $target { 0 } === '/' ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
# / at end means we don't want the slash to be shown
|
|
|
|
|
$m = array();
|
|
|
|
|
$trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $trailingSlashes ) {
|
|
|
|
|
$noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
|
2009-07-20 02:07:56 +00:00
|
|
|
} else {
|
|
|
|
|
$noslash = substr( $target, 1 );
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 19:40:29 +00:00
|
|
|
$ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
|
|
|
|
|
if ( $text === '' ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$text = $target . $suffix;
|
|
|
|
|
} # this might be changed for ugliness reasons
|
|
|
|
|
} else {
|
|
|
|
|
# check for .. subpage backlinks
|
|
|
|
|
$dotdotcount = 0;
|
|
|
|
|
$nodotdot = $target;
|
2010-08-26 19:40:29 +00:00
|
|
|
while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
++$dotdotcount;
|
|
|
|
|
$nodotdot = substr( $nodotdot, 3 );
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $dotdotcount > 0 ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$exploded = explode( '/', $contextTitle->GetPrefixedText() );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
|
2009-07-20 02:07:56 +00:00
|
|
|
$ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
|
|
|
|
|
# / at the end means don't show full path
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( substr( $nodotdot, -1, 1 ) === '/' ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$nodotdot = substr( $nodotdot, 0, -1 );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $text === '' ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$text = $nodotdot . $suffix;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$nodotdot = trim( $nodotdot );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $nodotdot != '' ) {
|
2009-07-20 02:07:56 +00:00
|
|
|
$ret .= '/' . $nodotdot;
|
|
|
|
|
}
|
|
|
|
|
$ret .= $suffix;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-02-21 12:23:52 +00:00
|
|
|
/**
|
|
|
|
|
* Wrap a comment in standard punctuation and formatting if
|
|
|
|
|
* it's non-empty, otherwise return empty string.
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $comment String
|
|
|
|
|
* @param $title Mixed: Title object (to generate link to section in autocomment) or null
|
|
|
|
|
* @param $local Boolean: whether section links should refer to local page
|
2011-06-14 23:50:40 +00:00
|
|
|
*
|
2006-11-08 07:12:03 +00:00
|
|
|
* @return string
|
2005-02-21 12:23:52 +00:00
|
|
|
*/
|
2011-06-14 23:50:40 +00:00
|
|
|
static function commentBlock( $comment, $title = null, $local = false ) {
|
2005-12-08 20:19:33 +00:00
|
|
|
// '*' 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
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $comment == '' || $comment == '*' ) {
|
2005-02-21 12:23:52 +00:00
|
|
|
return '';
|
|
|
|
|
} else {
|
2011-04-03 11:44:11 +00:00
|
|
|
$formatted = self::formatComment( $comment, $title, $local );
|
2011-06-14 23:50:40 +00:00
|
|
|
return " <span class=\"comment\">($formatted)</span>";
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-05-09 20:05:08 +00:00
|
|
|
|
2006-03-16 19:04:25 +00:00
|
|
|
/**
|
|
|
|
|
* Wrap and format the given revision's comment block, if the current
|
|
|
|
|
* user is allowed to view it.
|
2006-11-17 03:59:32 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $rev Revision object
|
|
|
|
|
* @param $local Boolean: whether section links should refer to local page
|
|
|
|
|
* @param $isPublic Boolean: show only if all users can see it
|
|
|
|
|
* @return String: HTML fragment
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function revComment( Revision $rev, $local = false, $isPublic = false ) {
|
2011-03-02 10:57:55 +00:00
|
|
|
if ( $rev->getRawComment() == "" ) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
|
2008-03-09 02:35:09 +00:00
|
|
|
$block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
|
2011-06-17 16:03:52 +00:00
|
|
|
} elseif ( $rev->userCan( Revision::DELETED_COMMENT ) ) {
|
2011-06-14 23:50:40 +00:00
|
|
|
$block = self::commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
|
2008-09-24 09:44:45 +00:00
|
|
|
$rev->getTitle(), $local );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
2008-03-09 02:35:09 +00:00
|
|
|
$block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
|
2006-06-12 05:33:48 +00:00
|
|
|
return " <span class=\"history-deleted\">$block</span>";
|
2005-02-21 12:23:52 +00:00
|
|
|
}
|
2006-03-16 19:04:25 +00:00
|
|
|
return $block;
|
2005-02-21 12:23:52 +00:00
|
|
|
}
|
2005-01-27 19:51:47 +00:00
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @param $size
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function formatRevisionSize( $size ) {
|
2008-07-14 19:10:47 +00:00
|
|
|
if ( $size == 0 ) {
|
|
|
|
|
$stxt = wfMsgExt( 'historyempty', 'parsemag' );
|
|
|
|
|
} else {
|
2008-07-14 19:34:12 +00:00
|
|
|
global $wgLang;
|
2008-07-14 19:10:47 +00:00
|
|
|
$stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
|
|
|
|
|
$stxt = "($stxt)";
|
|
|
|
|
}
|
|
|
|
|
$stxt = htmlspecialchars( $stxt );
|
|
|
|
|
return "<span class=\"history-size\">$stxt</span>";
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 14:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* Add another level to the Table of Contents
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function tocIndent() {
|
2005-01-15 23:21:52 +00:00
|
|
|
return "\n<ul>";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-26 14:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* Finish one or more sublevels on the Table of Contents
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function tocUnindent( $level ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* parameter level defines if we are on an indentation level
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
|
2009-06-20 21:47:10 +00:00
|
|
|
$classes = "toclevel-$level";
|
2011-05-29 14:01:47 +00:00
|
|
|
if ( $sectionIndex !== false ) {
|
2009-06-20 21:47:10 +00:00
|
|
|
$classes .= " tocsection-$sectionIndex";
|
2011-05-29 14:01:47 +00:00
|
|
|
}
|
2009-06-20 21:47:10 +00:00
|
|
|
return "\n<li class=\"$classes\"><a href=\"#" .
|
2005-02-21 01:56:50 +00:00
|
|
|
$anchor . '"><span class="tocnumber">' .
|
|
|
|
|
$tocnumber . '</span> <span class="toctext">' .
|
|
|
|
|
$tocline . '</span></a>';
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-26 14:25:48 +00:00
|
|
|
/**
|
|
|
|
|
* End a Table Of Contents line.
|
2010-01-07 09:32:09 +00:00
|
|
|
* tocUnindent() will be used instead if we're ending a line below
|
2009-10-26 14:25:48 +00:00
|
|
|
* the new level.
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function tocLineEnd() {
|
2005-01-15 23:21:52 +00:00
|
|
|
return "</li>\n";
|
2010-11-05 19:06:12 +00:00
|
|
|
}
|
2005-01-15 23:21:52 +00:00
|
|
|
|
2010-01-07 09:32:09 +00:00
|
|
|
/**
|
2009-10-26 14:25:48 +00:00
|
|
|
* Wraps the TOC in a table and provides the hide/collapse javascript.
|
2010-05-20 20:36:12 +00:00
|
|
|
*
|
|
|
|
|
* @param $toc String: html of the Table Of Contents
|
2011-02-23 20:32:57 +00:00
|
|
|
* @param $lang mixed: Language code for the toc title
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: full html of the TOC
|
2009-10-26 14:25:48 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function tocList( $toc, $lang = false ) {
|
2011-02-23 20:32:57 +00:00
|
|
|
$title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) );
|
2005-12-04 01:12:54 +00:00
|
|
|
return
|
2011-07-28 22:00:09 +00:00
|
|
|
'<table id="toc" class="toc"><tr><td>'
|
2005-12-04 01:12:54 +00:00
|
|
|
. '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
|
|
|
|
|
. $toc
|
2011-07-28 22:00:09 +00:00
|
|
|
. "</ul>\n</td></tr></table>\n";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2009-06-25 11:05:22 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a table of contents from a section tree
|
2009-10-26 14:25:48 +00:00
|
|
|
* Currently unused.
|
2010-05-20 20:36:12 +00:00
|
|
|
*
|
2009-06-25 11:05:22 +00:00
|
|
|
* @param $tree Return value of ParserOutput::getSections()
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML fragment
|
2009-06-25 11:05:22 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function generateTOC( $tree ) {
|
2009-06-25 11:05:22 +00:00
|
|
|
$toc = '';
|
|
|
|
|
$lastLevel = 0;
|
|
|
|
|
foreach ( $tree as $section ) {
|
|
|
|
|
if ( $section['toclevel'] > $lastLevel )
|
2011-04-03 11:44:11 +00:00
|
|
|
$toc .= self::tocIndent();
|
2011-06-17 16:03:52 +00:00
|
|
|
elseif ( $section['toclevel'] < $lastLevel )
|
2011-04-03 11:44:11 +00:00
|
|
|
$toc .= self::tocUnindent(
|
2009-06-25 11:05:22 +00:00
|
|
|
$lastLevel - $section['toclevel'] );
|
|
|
|
|
else
|
2011-04-03 11:44:11 +00:00
|
|
|
$toc .= self::tocLineEnd();
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
$toc .= self::tocLine( $section['anchor'],
|
2009-06-25 11:05:22 +00:00
|
|
|
$section['line'], $section['number'],
|
|
|
|
|
$section['toclevel'], $section['index'] );
|
|
|
|
|
$lastLevel = $section['toclevel'];
|
|
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
$toc .= self::tocLineEnd();
|
|
|
|
|
return self::tocList( $toc );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2005-04-27 07:48:14 +00:00
|
|
|
|
2007-01-08 02:11:45 +00:00
|
|
|
/**
|
|
|
|
|
* Create a headline for content
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $level Integer: the level of the headline (1-6)
|
|
|
|
|
* @param $attribs String: any attributes for the headline, starting with
|
|
|
|
|
* a space and ending with '>'
|
|
|
|
|
* This *must* be at least '>' for no attribs
|
|
|
|
|
* @param $anchor String: the anchor to give the headline (the bit after the #)
|
2011-09-03 13:46:56 +00:00
|
|
|
* @param $html String: html for the text of the header
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $link String: HTML to add for the section edit link
|
|
|
|
|
* @param $legacyAnchor Mixed: a second, optional anchor to give for
|
2009-01-05 15:59:46 +00:00
|
|
|
* backward compatibility (false to omit)
|
2007-01-08 02:11:45 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML headline
|
2007-01-08 02:11:45 +00:00
|
|
|
*/
|
2011-09-03 13:46:56 +00:00
|
|
|
public static function makeHeadline( $level, $attribs, $anchor, $html, $link, $legacyAnchor = false ) {
|
2011-07-27 19:24:43 +00:00
|
|
|
$ret = "<h$level$attribs"
|
|
|
|
|
. $link
|
2011-09-03 13:46:56 +00:00
|
|
|
. " <span class=\"mw-headline\" id=\"$anchor\">$html</span>"
|
2011-07-27 19:24:43 +00:00
|
|
|
. "</h$level>";
|
2009-01-05 15:59:46 +00:00
|
|
|
if ( $legacyAnchor !== false ) {
|
2010-08-17 21:55:21 +00:00
|
|
|
$ret = "<div id=\"$legacyAnchor\"></div>$ret";
|
2009-01-05 15:59:46 +00:00
|
|
|
}
|
|
|
|
|
return $ret;
|
2007-01-08 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-07 13:09:30 +00:00
|
|
|
/**
|
2005-04-27 07:48:14 +00:00
|
|
|
* Split a link trail, return the "inside" portion and the remainder of the trail
|
|
|
|
|
* as a two-element array
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
static function splitTrail( $trail ) {
|
2011-04-06 21:11:49 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$regex = $wgContLang->linkTrail();
|
2005-04-27 07:48:14 +00:00
|
|
|
$inside = '';
|
2010-05-28 14:16:46 +00:00
|
|
|
if ( $trail !== '' ) {
|
2006-11-23 08:25:56 +00:00
|
|
|
$m = array();
|
2005-04-27 07:48:14 +00:00
|
|
|
if ( preg_match( $regex, $trail, $m ) ) {
|
|
|
|
|
$inside = $m[1];
|
|
|
|
|
$trail = $m[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return array( $inside, $trail );
|
|
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
|
2006-11-16 22:53:01 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a rollback link for a given revision. Currently it's the
|
|
|
|
|
* caller's responsibility to ensure that the revision is the top one. If
|
|
|
|
|
* it's not, of course, the user will get an error message.
|
|
|
|
|
*
|
|
|
|
|
* If the calling page is called with the parameter &bot=1, all rollback
|
|
|
|
|
* links also get that parameter. It causes the edit itself and the rollback
|
|
|
|
|
* to be marked as "bot" edits. Bot edits are hidden by default from recent
|
|
|
|
|
* changes, so this allows sysops to combat a busy vandal without bothering
|
|
|
|
|
* other users.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $rev Revision object
|
2006-11-16 22:53:01 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function generateRollback( $rev ) {
|
2007-07-07 00:17:51 +00:00
|
|
|
return '<span class="mw-rollback-link">['
|
2011-04-03 11:44:11 +00:00
|
|
|
. self::buildRollbackLink( $rev )
|
2007-07-07 00:17:51 +00:00
|
|
|
. ']</span>';
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-07-07 00:17:51 +00:00
|
|
|
/**
|
|
|
|
|
* Build a raw rollback link, useful for collections of "tool" links
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $rev Revision object
|
|
|
|
|
* @return String: HTML fragment
|
2007-07-07 00:17:51 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function buildRollbackLink( $rev ) {
|
2009-05-18 18:48:36 +00:00
|
|
|
global $wgRequest, $wgUser;
|
2006-11-16 22:53:01 +00:00
|
|
|
$title = $rev->getTitle();
|
2008-08-01 00:54:08 +00:00
|
|
|
$query = array(
|
|
|
|
|
'action' => 'rollback',
|
2010-12-18 23:07:30 +00:00
|
|
|
'from' => $rev->getUserText(),
|
2010-12-20 19:03:00 +00:00
|
|
|
'token' => $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
|
2008-08-01 00:54:08 +00:00
|
|
|
);
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $wgRequest->getBool( 'bot' ) ) {
|
2008-07-30 21:02:28 +00:00
|
|
|
$query['bot'] = '1';
|
2009-01-03 05:39:13 +00:00
|
|
|
$query['hidediff'] = '1'; // bug 15999
|
2008-07-30 21:02:28 +00:00
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
return self::link(
|
|
|
|
|
$title,
|
2010-12-18 23:07:30 +00:00
|
|
|
wfMsgHtml( 'rollbacklink' ),
|
2009-05-18 18:48:36 +00:00
|
|
|
array( 'title' => wfMsg( 'tooltip-rollback' ) ),
|
2011-05-25 15:39:47 +00:00
|
|
|
$query,
|
|
|
|
|
array( 'known', 'noclasses' )
|
2010-12-18 23:07:30 +00:00
|
|
|
);
|
2006-11-16 22:53:01 +00:00
|
|
|
}
|
2006-11-17 03:42:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns HTML for the "templates used on this page" list.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $templates Array of templates from Article::getUsedTemplate
|
2006-11-17 03:42:23 +00:00
|
|
|
* or similar
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $preview Boolean: whether this is for a preview
|
|
|
|
|
* @param $section Boolean: whether this is for a section edit
|
|
|
|
|
* @return String: HTML output
|
2006-11-17 03:42:23 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function formatTemplates( $templates, $preview = false, $section = false ) {
|
2006-11-17 03:42:23 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$outText = '';
|
|
|
|
|
if ( count( $templates ) > 0 ) {
|
|
|
|
|
# Do a batch existence check
|
|
|
|
|
$batch = new LinkBatch;
|
2010-08-26 19:40:29 +00:00
|
|
|
foreach ( $templates as $title ) {
|
2006-11-17 03:42:23 +00:00
|
|
|
$batch->addObj( $title );
|
|
|
|
|
}
|
|
|
|
|
$batch->execute();
|
|
|
|
|
|
|
|
|
|
# Construct the HTML
|
2006-11-21 03:22:18 +00:00
|
|
|
$outText = '<div class="mw-templatesUsedExplanation">';
|
2006-12-31 01:35:26 +00:00
|
|
|
if ( $preview ) {
|
2009-10-15 19:10:52 +00:00
|
|
|
$outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) );
|
2006-12-31 01:35:26 +00:00
|
|
|
} elseif ( $section ) {
|
2009-10-15 19:10:52 +00:00
|
|
|
$outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) );
|
2006-12-31 01:35:26 +00:00
|
|
|
} else {
|
2009-10-15 19:10:52 +00:00
|
|
|
$outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) );
|
2006-12-31 01:35:26 +00:00
|
|
|
}
|
2008-12-28 16:46:05 +00:00
|
|
|
$outText .= "</div><ul>\n";
|
2006-12-31 01:35:26 +00:00
|
|
|
|
2008-05-08 23:16:36 +00:00
|
|
|
usort( $templates, array( 'Title', 'compare' ) );
|
2006-11-17 03:42:23 +00:00
|
|
|
foreach ( $templates as $titleObj ) {
|
2006-12-31 01:35:26 +00:00
|
|
|
$r = $titleObj->getRestrictions( 'edit' );
|
2008-04-14 07:45:50 +00:00
|
|
|
if ( in_array( 'sysop', $r ) ) {
|
2006-12-31 01:35:26 +00:00
|
|
|
$protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
|
|
|
|
|
} elseif ( in_array( 'autoconfirmed', $r ) ) {
|
|
|
|
|
$protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
|
|
|
|
|
} else {
|
|
|
|
|
$protected = '';
|
|
|
|
|
}
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $titleObj->quickUserCan( 'edit' ) ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$editLink = self::link(
|
2009-06-06 15:45:43 +00:00
|
|
|
$titleObj,
|
|
|
|
|
wfMsg( 'editlink' ),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'action' => 'edit' )
|
|
|
|
|
);
|
2008-10-08 02:29:23 +00:00
|
|
|
} else {
|
2011-04-03 11:44:11 +00:00
|
|
|
$editLink = self::link(
|
2009-06-06 15:45:43 +00:00
|
|
|
$titleObj,
|
|
|
|
|
wfMsg( 'viewsourcelink' ),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'action' => 'edit' )
|
|
|
|
|
);
|
2008-10-08 02:29:23 +00:00
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
$outText .= '<li>' . self::link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
|
2006-11-17 03:42:23 +00:00
|
|
|
}
|
|
|
|
|
$outText .= '</ul>';
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $outText;
|
|
|
|
|
}
|
2008-02-25 13:38:21 +00:00
|
|
|
|
2011-08-24 13:03:03 +00:00
|
|
|
/**
|
|
|
|
|
* Returns HTML for the "templates used on this page" list.
|
|
|
|
|
*
|
|
|
|
|
* @param $templates Array of templates from Article::getUsedTemplate
|
|
|
|
|
* or similar
|
|
|
|
|
* @param $preview Boolean: whether this is for a preview
|
|
|
|
|
* @param $section Boolean: whether this is for a section edit
|
|
|
|
|
* @return String: HTML output
|
|
|
|
|
*/
|
|
|
|
|
public static function formatDistantTemplates( $templates, $preview = false, $section = false ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$outText = '';
|
|
|
|
|
if ( count( $templates ) > 0 ) {
|
|
|
|
|
|
|
|
|
|
# Construct the HTML
|
|
|
|
|
$outText = '<div class="mw-templatesUsedExplanation">';
|
|
|
|
|
if ( $preview ) {
|
|
|
|
|
$outText .= wfMsgExt( 'distanttemplatesusedpreview', array( 'parse' ), count( $templates ) );
|
|
|
|
|
} elseif ( $section ) {
|
|
|
|
|
$outText .= wfMsgExt( 'distanttemplatesusedsection', array( 'parse' ), count( $templates ) );
|
|
|
|
|
} else {
|
|
|
|
|
$outText .= wfMsgExt( 'distanttemplatesused', array( 'parse' ), count( $templates ) );
|
|
|
|
|
}
|
|
|
|
|
$outText .= "</div><ul>\n";
|
|
|
|
|
|
|
|
|
|
usort( $templates, array( 'Title', 'compare' ) );
|
|
|
|
|
foreach ( $templates as $titleObj ) {
|
|
|
|
|
$outText .= '<li>' . self::link( $titleObj ) . '</li>';
|
|
|
|
|
}
|
|
|
|
|
$outText .= '</ul>';
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $outText;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-25 13:38:21 +00:00
|
|
|
/**
|
|
|
|
|
* Returns HTML for the "hidden categories on this page" list.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $hiddencats Array of hidden categories from Article::getHiddenCategories
|
2008-02-25 13:38:21 +00:00
|
|
|
* or similar
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML output
|
2008-02-25 13:38:21 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function formatHiddenCategories( $hiddencats ) {
|
2008-12-28 16:46:05 +00:00
|
|
|
global $wgLang;
|
2008-02-25 13:38:21 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$outText = '';
|
|
|
|
|
if ( count( $hiddencats ) > 0 ) {
|
|
|
|
|
# Construct the HTML
|
|
|
|
|
$outText = '<div class="mw-hiddenCategoriesExplanation">';
|
2008-02-25 20:36:29 +00:00
|
|
|
$outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
|
2008-12-28 16:46:05 +00:00
|
|
|
$outText .= "</div><ul>\n";
|
2008-02-25 13:38:21 +00:00
|
|
|
|
|
|
|
|
foreach ( $hiddencats as $titleObj ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$outText .= '<li>' . self::link( $titleObj, null, array(), array(), 'known' ) . "</li>\n"; # If it's hidden, it must exist - no need to check with a LinkBatch
|
2008-02-25 13:38:21 +00:00
|
|
|
}
|
|
|
|
|
$outText .= '</ul>';
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $outText;
|
|
|
|
|
}
|
2008-02-25 19:09:25 +00:00
|
|
|
|
2006-12-23 13:13:13 +00:00
|
|
|
/**
|
|
|
|
|
* Format a size in bytes for output, using an appropriate
|
|
|
|
|
* unit (B, KB, MB or GB) according to the magnitude in question
|
|
|
|
|
*
|
|
|
|
|
* @param $size Size to format
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String
|
2006-12-23 13:13:13 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function formatSize( $size ) {
|
2006-12-23 13:13:13 +00:00
|
|
|
global $wgLang;
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
return htmlspecialchars( $wgLang->formatSize( $size ) );
|
2006-12-23 13:13:13 +00:00
|
|
|
}
|
2007-01-10 05:18:30 +00:00
|
|
|
|
2007-01-10 06:03:14 +00:00
|
|
|
/**
|
2007-01-11 00:57:30 +00:00
|
|
|
* Given the id of an interface element, constructs the appropriate title
|
|
|
|
|
* attribute from the system messages. (Note, this is usually the id but
|
|
|
|
|
* isn't always, because sometimes the accesskey needs to go on a different
|
|
|
|
|
* element than the id, for reverse-compatibility, etc.)
|
2007-01-10 06:03:14 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $name String: id of the element, minus prefixes.
|
|
|
|
|
* @param $options Mixed: null or the string 'withaccess' to add an access-
|
2008-08-13 15:11:36 +00:00
|
|
|
* key hint
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: contents of the title attribute (which you must HTML-
|
2008-10-27 23:58:00 +00:00
|
|
|
* escape), or false for no title attribute
|
2007-01-10 06:03:14 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function titleAttrib( $name, $options = null ) {
|
2011-06-30 18:21:05 +00:00
|
|
|
global $wgEnableTooltipsAndAccesskeys;
|
|
|
|
|
if ( !$wgEnableTooltipsAndAccesskeys )
|
|
|
|
|
return false;
|
2011-07-18 23:01:08 +00:00
|
|
|
|
2008-08-13 14:52:40 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2007-01-10 06:03:14 +00:00
|
|
|
|
2010-12-25 12:33:17 +00:00
|
|
|
$message = wfMessage( "tooltip-$name" );
|
|
|
|
|
|
|
|
|
|
if ( !$message->exists() ) {
|
2008-10-27 23:58:00 +00:00
|
|
|
$tooltip = false;
|
2010-08-05 16:22:42 +00:00
|
|
|
} else {
|
2010-12-25 12:33:17 +00:00
|
|
|
$tooltip = $message->text();
|
2010-08-05 16:22:42 +00:00
|
|
|
# Compatibility: formerly some tooltips had [alt-.] hardcoded
|
|
|
|
|
$tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
|
|
|
|
|
# Message equal to '-' means suppress it.
|
|
|
|
|
if ( $tooltip == '-' ) {
|
|
|
|
|
$tooltip = false;
|
|
|
|
|
}
|
2008-08-13 15:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
2008-10-27 23:58:00 +00:00
|
|
|
if ( $options == 'withaccess' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$accesskey = self::accesskey( $name );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $accesskey !== false ) {
|
2008-10-27 23:58:00 +00:00
|
|
|
if ( $tooltip === false || $tooltip === '' ) {
|
|
|
|
|
$tooltip = "[$accesskey]";
|
|
|
|
|
} else {
|
|
|
|
|
$tooltip .= " [$accesskey]";
|
|
|
|
|
}
|
2008-08-13 15:11:36 +00:00
|
|
|
}
|
2007-01-10 06:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-13 14:52:40 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-10-27 23:58:00 +00:00
|
|
|
return $tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
static $accesskeycache;
|
|
|
|
|
|
2008-10-27 23:58:00 +00:00
|
|
|
/**
|
|
|
|
|
* Given the id of an interface element, constructs the appropriate
|
|
|
|
|
* accesskey attribute from the system messages. (Note, this is usually
|
|
|
|
|
* the id but isn't always, because sometimes the accesskey needs to go on
|
|
|
|
|
* a different element than the id, for reverse-compatibility, etc.)
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $name String: id of the element, minus prefixes.
|
|
|
|
|
* @return String: contents of the accesskey attribute (which you must HTML-
|
2008-10-27 23:58:00 +00:00
|
|
|
* escape), or false for no accesskey attribute
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function accesskey( $name ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
if ( isset( self::$accesskeycache[$name] ) ) {
|
|
|
|
|
return self::$accesskeycache[$name];
|
2010-12-25 12:24:18 +00:00
|
|
|
}
|
2011-02-10 16:08:44 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2010-12-25 12:24:18 +00:00
|
|
|
|
|
|
|
|
$message = wfMessage( "accesskey-$name" );
|
|
|
|
|
|
|
|
|
|
if ( !$message->exists() ) {
|
2010-08-05 16:22:42 +00:00
|
|
|
$accesskey = false;
|
|
|
|
|
} else {
|
2010-12-25 12:24:18 +00:00
|
|
|
$accesskey = $message->plain();
|
2010-08-05 16:22:42 +00:00
|
|
|
if ( $accesskey === '' || $accesskey === '-' ) {
|
2011-05-17 22:03:20 +00:00
|
|
|
# @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
|
2010-08-05 16:22:42 +00:00
|
|
|
# attribute, but this is broken for accesskey: that might be a useful
|
|
|
|
|
# value.
|
|
|
|
|
$accesskey = false;
|
|
|
|
|
}
|
2008-10-27 23:58:00 +00:00
|
|
|
}
|
2008-10-28 00:23:26 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::$accesskeycache[$name] = $accesskey;
|
2007-01-10 06:03:14 +00:00
|
|
|
}
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2011-08-03 22:37:20 +00:00
|
|
|
/**
|
|
|
|
|
* Get a revision-deletion link, or disabled link, or nothing, depending
|
|
|
|
|
* on user permissions & the settings on the revision.
|
|
|
|
|
*
|
|
|
|
|
* Will use forward-compatible revision ID in the Special:RevDelete link
|
|
|
|
|
* if possible, otherwise the timestamp-based ID which may break after
|
|
|
|
|
* undeletion.
|
|
|
|
|
*
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @param Revision $rev
|
|
|
|
|
* @param Revision $title
|
|
|
|
|
* @return string HTML fragment
|
|
|
|
|
*/
|
|
|
|
|
public static function getRevDeleteLink( User $user, Revision $rev, Title $title ) {
|
|
|
|
|
$canHide = $user->isAllowed( 'deleterevision' );
|
|
|
|
|
if ( $canHide || ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
|
|
|
|
|
if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
|
|
|
|
|
$revdlink = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
|
|
|
|
|
} else {
|
|
|
|
|
if ( $rev->getId() ) {
|
|
|
|
|
// RevDelete links using revision ID are stable across
|
|
|
|
|
// page deletion and undeletion; use when possible.
|
|
|
|
|
$query = array(
|
|
|
|
|
'type' => 'revision',
|
|
|
|
|
'target' => $title->getPrefixedDBkey(),
|
|
|
|
|
'ids' => $rev->getId()
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// Older deleted entries didn't save a revision ID.
|
|
|
|
|
// We have to refer to these by timestamp, ick!
|
|
|
|
|
$query = array(
|
|
|
|
|
'type' => 'archive',
|
|
|
|
|
'target' => $title->getPrefixedDBkey(),
|
|
|
|
|
'ids' => $rev->getTimestamp()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Linker::revDeleteLink( $query,
|
|
|
|
|
$rev->isDeleted( File::DELETED_RESTRICTED ), $canHide );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-18 21:07:09 +00:00
|
|
|
/**
|
|
|
|
|
* Creates a (show/hide) link for deleting revisions/log entries
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $query Array: query parameters to be passed to link()
|
|
|
|
|
* @param $restricted Boolean: set to true to use a <strong> instead of a <span>
|
|
|
|
|
* @param $delete Boolean: set to true to use (show/hide) rather than (show)
|
2009-01-18 21:07:09 +00:00
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @return String: HTML <a> link to Special:Revisiondelete, wrapped in a
|
2009-01-18 21:07:09 +00:00
|
|
|
* span to allow for customization of appearance with CSS
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
|
2009-01-18 21:07:09 +00:00
|
|
|
$sp = SpecialPage::getTitleFor( 'Revisiondelete' );
|
2011-09-03 13:46:56 +00:00
|
|
|
$html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
|
2009-02-22 14:35:29 +00:00
|
|
|
$tag = $restricted ? 'strong' : 'span';
|
2011-09-03 13:46:56 +00:00
|
|
|
$link = self::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) );
|
2009-01-18 21:07:09 +00:00
|
|
|
return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
|
|
|
|
|
}
|
2010-01-07 09:32:09 +00:00
|
|
|
|
2009-10-30 02:14:22 +00:00
|
|
|
/**
|
|
|
|
|
* Creates a dead (show/hide) link for deleting revisions/log entries
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $delete Boolean: set to true to use (show/hide) rather than (show)
|
2009-10-30 02:14:22 +00:00
|
|
|
*
|
|
|
|
|
* @return string HTML text wrapped in a span to allow for customization
|
|
|
|
|
* of appearance with CSS
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function revDeleteLinkDisabled( $delete = true ) {
|
2011-09-03 13:46:56 +00:00
|
|
|
$html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
|
|
|
|
|
return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($html)" );
|
2009-10-30 02:14:22 +00:00
|
|
|
}
|
2009-06-08 22:33:37 +00:00
|
|
|
|
|
|
|
|
/* Deprecated methods */
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.16 Use link()
|
2009-06-08 22:33:37 +00:00
|
|
|
*
|
|
|
|
|
* This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
|
|
|
|
|
* it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title String: The text of the title
|
|
|
|
|
* @param $text String: Link text
|
|
|
|
|
* @param $query String: Optional query part
|
|
|
|
|
* @param $trail String: Optional trail. Alphabetic characters at the start of this string will
|
|
|
|
|
* be included in the link text. Other characters will be appended after
|
|
|
|
|
* the end of the link.
|
2009-06-08 22:33:37 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
|
2009-06-08 22:33:37 +00:00
|
|
|
$nt = Title::newFromText( $title );
|
|
|
|
|
if ( $nt instanceof Title ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::makeBrokenLinkObj( $nt, $text, $query, $trail );
|
2009-06-08 22:33:37 +00:00
|
|
|
} else {
|
2011-04-03 11:44:11 +00:00
|
|
|
wfDebug( 'Invalid title passed to self::makeBrokenLink(): "' . $title . "\"\n" );
|
2009-06-08 22:33:37 +00:00
|
|
|
return $text == '' ? $title : $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.16 Use link()
|
2009-06-08 22:33:37 +00:00
|
|
|
*
|
|
|
|
|
* Make a link for a title which may or may not be in the database. If you need to
|
|
|
|
|
* call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
|
|
|
|
|
* call to this will result in a DB query.
|
|
|
|
|
*
|
|
|
|
|
* @param $nt Title: the title object to make the link from, e.g. from
|
|
|
|
|
* Title::newFromText.
|
|
|
|
|
* @param $text String: link text
|
|
|
|
|
* @param $query String: optional query part
|
|
|
|
|
* @param $trail String: optional trail. Alphabetic characters at the start of this string will
|
|
|
|
|
* be included in the link text. Other characters will be appended after
|
|
|
|
|
* the end of the link.
|
|
|
|
|
* @param $prefix String: optional prefix. As trail, only before instead of after.
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2009-06-08 22:33:37 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
$query = wfCgiToArray( $query );
|
2011-04-03 11:44:11 +00:00
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $text === '' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$text = self::linkText( $nt );
|
2009-06-08 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
$ret = self::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
|
2009-06-08 22:33:37 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.16 Use link()
|
2009-06-08 22:33:37 +00:00
|
|
|
*
|
|
|
|
|
* Make a link for a title which definitely exists. This is faster than makeLinkObj because
|
|
|
|
|
* it doesn't have to do a database query. It's also valid for interwiki titles and special
|
|
|
|
|
* pages.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title Title object of target page
|
2009-06-08 22:33:37 +00:00
|
|
|
* @param $text String: text to replace the title
|
|
|
|
|
* @param $query String: link target
|
|
|
|
|
* @param $trail String: text after link
|
|
|
|
|
* @param $prefix String: text before link text
|
|
|
|
|
* @param $aprops String: extra attributes to the a-element
|
|
|
|
|
* @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
|
|
|
|
|
* @return the a-element
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeKnownLinkObj(
|
2011-03-21 16:15:56 +00:00
|
|
|
$title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = ''
|
|
|
|
|
) {
|
2009-06-08 22:33:37 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
if ( $text == '' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$text = self::linkText( $title );
|
2009-06-08 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
$attribs = Sanitizer::mergeAttributes(
|
|
|
|
|
Sanitizer::decodeTagAttributes( $aprops ),
|
|
|
|
|
Sanitizer::decodeTagAttributes( $style )
|
|
|
|
|
);
|
|
|
|
|
$query = wfCgiToArray( $query );
|
2011-04-03 11:44:11 +00:00
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2009-06-08 22:33:37 +00:00
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
$ret = self::link( $title, "$prefix$text$inside", $attribs, $query,
|
2009-06-08 22:33:37 +00:00
|
|
|
array( 'known', 'noclasses' ) ) . $trail;
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.16 Use link()
|
2009-06-08 22:33:37 +00:00
|
|
|
*
|
|
|
|
|
* Make a red link to the edit page of a given title.
|
|
|
|
|
*
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $title Title object of the target page
|
2009-06-08 22:33:37 +00:00
|
|
|
* @param $text String: Link text
|
|
|
|
|
* @param $query String: Optional query part
|
|
|
|
|
* @param $trail String: Optional trail. Alphabetic characters at the start of this string will
|
|
|
|
|
* be included in the link text. Other characters will be appended after
|
|
|
|
|
* the end of the link.
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $prefix String: Optional prefix
|
2009-06-08 22:33:37 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2009-06-08 22:33:37 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $text === '' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$text = self::linkText( $title );
|
2009-06-08 22:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-03 11:44:11 +00:00
|
|
|
$ret = self::link( $title, "$prefix$text$inside", array(),
|
2009-06-08 22:33:37 +00:00
|
|
|
wfCgiToArray( $query ), 'broken' ) . $trail;
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.16 Use link()
|
2009-06-08 22:33:37 +00:00
|
|
|
*
|
|
|
|
|
* Make a coloured link.
|
|
|
|
|
*
|
|
|
|
|
* @param $nt Title object of the target page
|
|
|
|
|
* @param $colour Integer: colour of the link
|
|
|
|
|
* @param $text String: link text
|
|
|
|
|
* @param $query String: optional query part
|
|
|
|
|
* @param $trail String: optional trail. Alphabetic characters at the start of this string will
|
|
|
|
|
* be included in the link text. Other characters will be appended after
|
|
|
|
|
* the end of the link.
|
2010-05-20 20:36:12 +00:00
|
|
|
* @param $prefix String: Optional prefix
|
2009-06-08 22:33:37 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
static function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2010-08-26 19:40:29 +00:00
|
|
|
if ( $colour != '' ) {
|
2011-04-03 11:44:11 +00:00
|
|
|
$style = self::getInternalLinkAttributesObj( $nt, $text, $colour );
|
2011-03-02 10:57:55 +00:00
|
|
|
} else {
|
|
|
|
|
$style = '';
|
|
|
|
|
}
|
2011-04-03 11:44:11 +00:00
|
|
|
return self::makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
|
2009-06-08 22:33:37 +00:00
|
|
|
}
|
2009-06-13 13:41:48 +00:00
|
|
|
|
2009-06-08 22:33:37 +00:00
|
|
|
/**
|
2010-08-05 16:22:42 +00:00
|
|
|
* Returns the attributes for the tooltip and access key.
|
2009-06-08 22:33:37 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function tooltipAndAccesskeyAttribs( $name ) {
|
2009-09-08 20:59:44 +00:00
|
|
|
global $wgEnableTooltipsAndAccesskeys;
|
2009-09-11 10:59:15 +00:00
|
|
|
if ( !$wgEnableTooltipsAndAccesskeys )
|
2010-02-03 04:54:20 +00:00
|
|
|
return array();
|
2011-05-17 22:03:20 +00:00
|
|
|
# @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
|
2009-06-08 22:33:37 +00:00
|
|
|
# no attribute" instead of "output '' as value for attribute", this
|
|
|
|
|
# would be three lines.
|
|
|
|
|
$attribs = array(
|
2011-04-03 11:44:11 +00:00
|
|
|
'title' => self::titleAttrib( $name, 'withaccess' ),
|
|
|
|
|
'accesskey' => self::accesskey( $name )
|
2009-06-08 22:33:37 +00:00
|
|
|
);
|
|
|
|
|
if ( $attribs['title'] === false ) {
|
|
|
|
|
unset( $attribs['title'] );
|
|
|
|
|
}
|
|
|
|
|
if ( $attribs['accesskey'] === false ) {
|
|
|
|
|
unset( $attribs['accesskey'] );
|
|
|
|
|
}
|
2009-10-18 19:29:35 +00:00
|
|
|
return $attribs;
|
|
|
|
|
}
|
2011-01-06 18:53:53 +00:00
|
|
|
|
|
|
|
|
/**
|
2011-03-12 18:14:33 +00:00
|
|
|
* @deprecated since 1.14
|
2011-01-06 18:53:53 +00:00
|
|
|
* Returns raw bits of HTML, use titleAttrib()
|
|
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
public static function tooltip( $name, $options = null ) {
|
2009-09-08 20:59:44 +00:00
|
|
|
global $wgEnableTooltipsAndAccesskeys;
|
2009-09-11 10:59:15 +00:00
|
|
|
if ( !$wgEnableTooltipsAndAccesskeys )
|
|
|
|
|
return '';
|
2011-05-17 22:03:20 +00:00
|
|
|
# @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
|
2009-06-08 22:33:37 +00:00
|
|
|
# no attribute" instead of "output '' as value for attribute", this
|
|
|
|
|
# would be two lines.
|
2011-04-03 11:44:11 +00:00
|
|
|
$tooltip = self::titleAttrib( $name, $options );
|
2009-06-08 22:33:37 +00:00
|
|
|
if ( $tooltip === false ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return Xml::expandAttributes( array(
|
2011-05-06 23:07:20 +00:00
|
|
|
'title' => $tooltip
|
2009-06-08 22:33:37 +00:00
|
|
|
) );
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2011-04-03 12:04:04 +00:00
|
|
|
|
2011-06-02 14:38:14 +00:00
|
|
|
/**
|
2011-07-18 23:01:08 +00:00
|
|
|
* @since 1.18
|
2011-06-02 14:38:14 +00:00
|
|
|
*/
|
2011-04-03 12:04:04 +00:00
|
|
|
class DummyLinker {
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2011-04-03 12:04:04 +00:00
|
|
|
/**
|
|
|
|
|
* Use PHP's magic __call handler to transform instance calls to a dummy instance
|
|
|
|
|
* into static calls to the new Linker for backwards compatibility.
|
|
|
|
|
*
|
|
|
|
|
* @param $fname String Name of called method
|
|
|
|
|
* @param $args Array Arguments to the method
|
|
|
|
|
*/
|
2011-06-30 18:38:32 +00:00
|
|
|
public function __call( $fname, $args ) {
|
2011-04-03 12:04:04 +00:00
|
|
|
return call_user_func_array( array( 'Linker', $fname ), $args );
|
|
|
|
|
}
|
|
|
|
|
}
|