2004-12-18 06:29:23 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Split off some of the internal bits from Skin.php.
|
|
|
|
|
* These functions are used for primarily page content:
|
|
|
|
|
* links, embedded images, table of contents. Links are
|
|
|
|
|
* also used in the skin.
|
|
|
|
|
* For the moment, Skin is a descendent class of Linker.
|
|
|
|
|
* In the future, it should probably be further split
|
|
|
|
|
* so that ever other bit of the wiki doesn't have to
|
|
|
|
|
* go loading up Skin to get at it.
|
|
|
|
|
*
|
2007-04-24 06:53:31 +00:00
|
|
|
* @addtogroup 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;
|
|
|
|
|
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct() {}
|
2005-04-27 07:48:14 +00:00
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
/**
|
2005-07-08 01:55:48 +00:00
|
|
|
* @deprecated
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function postParseLinkColour( $s = NULL ) {
|
2005-04-27 07:48:14 +00:00
|
|
|
return NULL;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function getExternalLinkAttributes( $link, $text, $class='' ) {
|
2006-03-17 01:02:14 +00:00
|
|
|
$link = htmlspecialchars( $link );
|
|
|
|
|
|
2006-06-12 05:33:48 +00:00
|
|
|
$r = ($class != '') ? " class=\"$class\"" : " class=\"external\"";
|
2006-03-17 01:02:14 +00:00
|
|
|
|
|
|
|
|
$r .= " title=\"{$link}\"";
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
function getInterwikiLinkAttributes( $link, $text, $class='' ) {
|
2006-03-17 01:02:14 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
$link = urldecode( $link );
|
|
|
|
|
$link = $wgContLang->checkTitleEncoding( $link );
|
2006-02-22 09:11:59 +00:00
|
|
|
$link = preg_replace( '/[\\x00-\\x1f]/', ' ', $link );
|
2004-12-18 06:29:23 +00:00
|
|
|
$link = htmlspecialchars( $link );
|
|
|
|
|
|
2006-06-12 05:33:48 +00:00
|
|
|
$r = ($class != '') ? " class=\"$class\"" : " class=\"external\"";
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2005-03-25 07:25:49 +00:00
|
|
|
$r .= " title=\"{$link}\"";
|
2004-12-18 06:29:23 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
2007-11-22 15:54:18 +00:00
|
|
|
function getInternalLinkAttributes( $link, $text, $class='' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$link = urldecode( $link );
|
|
|
|
|
$link = str_replace( '_', ' ', $link );
|
|
|
|
|
$link = htmlspecialchars( $link );
|
2007-11-22 15:54:18 +00:00
|
|
|
$r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : '';
|
2005-03-25 07:25:49 +00:00
|
|
|
$r .= " title=\"{$link}\"";
|
2004-12-18 06:29:23 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $nt Title object.
|
|
|
|
|
* @param $text String: FIXME
|
2007-11-22 15:54:18 +00:00
|
|
|
* @param $class String: CSS class of the link, default ''.
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2007-11-22 15:54:18 +00:00
|
|
|
function getInternalLinkAttributesObj( &$nt, $text, $class='' ) {
|
|
|
|
|
$r = ($class != '') ? ' class="' . htmlspecialchars( $class ) . '"' : '';
|
2005-03-25 07:25:49 +00:00
|
|
|
$r .= ' title="' . $nt->getEscapedText() . '"';
|
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
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $s
|
|
|
|
|
* @param integer $id
|
|
|
|
|
* @param integer $threshold
|
|
|
|
|
*/
|
|
|
|
|
function getLinkColour( $s, $threshold ) {
|
|
|
|
|
if( $threshold > 0 && $s!=false ) {
|
|
|
|
|
$colour = ( $s->page_len >= $threshold ||
|
|
|
|
|
$s->page_is_redirect ||
|
|
|
|
|
!Namespace::isContent( $s->page_namespace )
|
|
|
|
|
? '' : 'stub' );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$colour = '';
|
|
|
|
|
}
|
|
|
|
|
return $colour;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
/**
|
2006-02-01 04:34:47 +00:00
|
|
|
* This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
|
|
|
|
|
* it if you already have a title object handy. See makeLinkObj for further documentation.
|
2006-11-08 07:12:03 +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
|
2006-03-11 17:13:49 +00:00
|
|
|
* be included in the link text. Other characters will be appended after
|
2006-02-01 04:34:47 +00:00
|
|
|
* the end of the link.
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeLink( $title, $text = '', $query = '', $trail = '' ) {
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
$nt = Title::newFromText( $title );
|
2007-09-21 14:32:26 +00:00
|
|
|
if ( $nt instanceof Title ) {
|
2007-08-07 16:36:49 +00:00
|
|
|
$result = $this->makeLinkObj( $nt, $text, $query, $trail );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
|
|
|
|
|
$result = $text == "" ? $title : $text;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-01 04:34:47 +00:00
|
|
|
/**
|
|
|
|
|
* This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
|
|
|
|
|
* it if you already have a title object handy. See makeKnownLinkObj for further documentation.
|
|
|
|
|
*
|
2006-11-08 07:12:03 +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
|
2006-03-11 17:13:49 +00:00
|
|
|
* be included in the link text. Other characters will be appended after
|
2006-02-01 04:34:47 +00:00
|
|
|
* the end of the link.
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
|
2004-12-18 06:29:23 +00:00
|
|
|
$nt = Title::newFromText( $title );
|
2007-09-21 14:32:26 +00:00
|
|
|
if ( $nt instanceof Title ) {
|
|
|
|
|
return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $text == '' ? $title : $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-01 04:34:47 +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.
|
|
|
|
|
*
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param string $title The text of the title
|
|
|
|
|
* @param string $text Link text
|
|
|
|
|
* @param string $query Optional query part
|
|
|
|
|
* @param string $trail Optional trail. Alphabetic characters at the start of this string will
|
2006-03-11 17:13:49 +00:00
|
|
|
* be included in the link text. Other characters will be appended after
|
2006-02-01 04:34:47 +00:00
|
|
|
* the end of the link.
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$nt = Title::newFromText( $title );
|
2007-09-21 14:32:26 +00:00
|
|
|
if ( $nt instanceof Title ) {
|
|
|
|
|
return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $text == '' ? $title : $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-01 04:34:47 +00:00
|
|
|
/**
|
2007-11-22 15:54:18 +00:00
|
|
|
* @deprecated use makeColouredLinkObj
|
|
|
|
|
*
|
2006-02-01 04:34:47 +00:00
|
|
|
* This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
|
|
|
|
|
* it if you already have a title object handy. See makeStubLinkObj for further documentation.
|
|
|
|
|
*
|
2006-11-08 07:12:03 +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
|
2006-03-11 17:13:49 +00:00
|
|
|
* be included in the link text. Other characters will be appended after
|
2006-02-01 04:34:47 +00:00
|
|
|
* the end of the link.
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$nt = Title::newFromText( $title );
|
2007-09-21 14:32:26 +00:00
|
|
|
if ( $nt instanceof Title ) {
|
|
|
|
|
return $this->makeStubLinkObj( $nt, $text, $query, $trail );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2006-11-08 07:12:03 +00:00
|
|
|
wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $text == '' ? $title : $text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-03-11 17:13:49 +00:00
|
|
|
* Make a link for a title which may or may not be in the database. If you need to
|
2006-02-01 04:34:47 +00:00
|
|
|
* call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
|
|
|
|
|
* call to this will result in a DB query.
|
|
|
|
|
*
|
2006-11-08 07:12:03 +00:00
|
|
|
* @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.
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
|
2005-07-26 16:07:14 +00:00
|
|
|
global $wgUser;
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2007-09-21 14:32:26 +00:00
|
|
|
if ( !$nt instanceof Title ) {
|
|
|
|
|
# Fail gracefully
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $nt->isExternal() ) {
|
|
|
|
|
$u = $nt->getFullURL();
|
|
|
|
|
$link = $nt->getPrefixedURL();
|
|
|
|
|
if ( '' == $text ) { $text = $nt->getPrefixedText(); }
|
2006-11-08 07:12:03 +00:00
|
|
|
$style = $this->getInterwikiLinkAttributes( $link, $text, 'extiw' );
|
2004-12-18 06:29:23 +00:00
|
|
|
|
|
|
|
|
$inside = '';
|
|
|
|
|
if ( '' != $trail ) {
|
2006-11-23 08:25:56 +00:00
|
|
|
$m = array();
|
2004-12-18 06:29:23 +00:00
|
|
|
if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
|
|
|
|
|
$inside = $m[1];
|
|
|
|
|
$trail = $m[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2005-04-27 07:48:14 +00:00
|
|
|
return $t;
|
|
|
|
|
} elseif ( $nt->isAlwaysKnown() ) {
|
|
|
|
|
# Image links, special page links and self-links with fragements are always known.
|
2006-11-08 07:12:03 +00:00
|
|
|
$retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileIn( __METHOD__.'-immediate' );
|
2007-05-26 16:50:14 +00:00
|
|
|
|
|
|
|
|
# Handles links to special pages wich do not exist in the database:
|
|
|
|
|
if( $nt->getNamespace() == NS_SPECIAL ) {
|
|
|
|
|
if( SpecialPage::exists( $nt->getDbKey() ) ) {
|
|
|
|
|
$retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
|
|
|
|
|
} else {
|
|
|
|
|
$retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
|
|
|
|
|
}
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__.'-immediate' );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2007-05-26 16:50:14 +00:00
|
|
|
return $retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
# Work out link colour immediately
|
|
|
|
|
$aid = $nt->getArticleID() ;
|
|
|
|
|
if ( 0 == $aid ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2007-11-22 15:54:18 +00:00
|
|
|
$colour = '';
|
2007-05-09 21:09:59 +00:00
|
|
|
if ( $nt->isContentPage() ) {
|
2007-05-09 18:18:28 +00:00
|
|
|
$threshold = $wgUser->getOption('stubthreshold');
|
|
|
|
|
if ( $threshold > 0 ) {
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$s = $dbr->selectRow(
|
|
|
|
|
array( 'page' ),
|
2007-11-24 08:20:28 +00:00
|
|
|
array( 'page_len', 'page_is_redirect', 'page_namespace' ),
|
2007-09-21 14:32:26 +00:00
|
|
|
array( 'page_id' => $aid ), __METHOD__ ) ;
|
2007-11-24 08:20:28 +00:00
|
|
|
$colour = $this->getLinkColour( $s, $threshold );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-11-22 15:54:18 +00:00
|
|
|
$retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__.'-immediate' );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-03-11 17:13:49 +00:00
|
|
|
* Make a link for a title which definitely exists. This is faster than makeLinkObj because
|
2006-02-01 04:34:47 +00:00
|
|
|
* it doesn't have to do a database query. It's also valid for interwiki titles and special
|
|
|
|
|
* pages.
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
|
|
|
|
* @param $nt Title object of target page
|
|
|
|
|
* @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
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-11-08 07:12:03 +00:00
|
|
|
|
2007-09-21 14:32:26 +00:00
|
|
|
if ( !$nt instanceof Title ) {
|
|
|
|
|
# Fail gracefully
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-12-18 06:29:23 +00:00
|
|
|
$u = $nt->escapeLocalURL( $query );
|
2006-03-04 03:24:33 +00:00
|
|
|
if ( $nt->getFragment() != '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
if( $nt->getPrefixedDbkey() == '' ) {
|
|
|
|
|
$u = '';
|
|
|
|
|
if ( '' == $text ) {
|
|
|
|
|
$text = htmlspecialchars( $nt->getFragment() );
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-12-08 06:09:15 +00:00
|
|
|
$u .= $nt->getFragmentForURL();
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2006-03-04 03:24:33 +00:00
|
|
|
if ( $text == '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$text = htmlspecialchars( $nt->getPrefixedText() );
|
|
|
|
|
}
|
2006-03-04 03:24:33 +00:00
|
|
|
if ( $style == '' ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$style = $this->getInternalLinkAttributesObj( $nt, $text );
|
2006-03-04 03:24:33 +00:00
|
|
|
}
|
2005-08-02 11:49:53 +00:00
|
|
|
|
|
|
|
|
if ( $aprops !== '' ) $aprops = ' ' . $aprops;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
list( $inside, $trail ) = Linker::splitTrail( $trail );
|
2004-12-18 06:29:23 +00:00
|
|
|
$r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-02-01 04:34:47 +00:00
|
|
|
* Make a red link to the edit page of a given title.
|
|
|
|
|
*
|
2006-11-08 07:12:03 +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
|
2006-03-11 17:13:49 +00:00
|
|
|
* be included in the link text. Other characters will be appended after
|
2006-02-01 04:34:47 +00:00
|
|
|
* the end of the link.
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
if ( !$nt instanceof Title ) {
|
|
|
|
|
# Fail gracefully
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-26 17:06:48 +00:00
|
|
|
if( $nt->getNamespace() == NS_SPECIAL ) {
|
|
|
|
|
$q = $query;
|
|
|
|
|
} else if ( '' == $query ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$q = 'action=edit';
|
|
|
|
|
} else {
|
|
|
|
|
$q = 'action=edit&'.$query;
|
|
|
|
|
}
|
|
|
|
|
$u = $nt->escapeLocalURL( $q );
|
|
|
|
|
|
|
|
|
|
if ( '' == $text ) {
|
|
|
|
|
$text = htmlspecialchars( $nt->getPrefixedText() );
|
|
|
|
|
}
|
2007-11-22 15:54:18 +00:00
|
|
|
$style = $this->getInternalLinkAttributesObj( $nt, $text, 'new' );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
list( $inside, $trail ) = Linker::splitTrail( $trail );
|
2005-03-25 07:25:49 +00:00
|
|
|
$s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2007-09-21 14:32:26 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2004-12-18 06:29:23 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-11-22 15:54:18 +00:00
|
|
|
* @deprecated use makeColouredLinkObj
|
|
|
|
|
*
|
2006-02-01 04:34:47 +00:00
|
|
|
* Make a brown link to a short article.
|
|
|
|
|
*
|
2006-11-08 07:12:03 +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
|
2006-03-11 17:13:49 +00:00
|
|
|
* be included in the link text. Other characters will be appended after
|
2006-02-01 04:34:47 +00:00
|
|
|
* the end of the link.
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2007-11-30 16:56:05 +00:00
|
|
|
return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
|
2007-11-22 15:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make a coloured link.
|
|
|
|
|
*
|
|
|
|
|
* @param $title String: the text of the title
|
|
|
|
|
* @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.
|
|
|
|
|
*/
|
|
|
|
|
function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
|
|
|
|
|
|
|
|
|
if($colour != ''){
|
|
|
|
|
$style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
|
|
|
|
|
} else $style = '';
|
2007-04-26 20:27:21 +00:00
|
|
|
return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
|
2004-12-18 06:29:23 +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
|
|
|
*
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $size Integer
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $nt Title object.
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $text String
|
|
|
|
|
* @param $query String
|
|
|
|
|
* @param $trail String
|
|
|
|
|
* @param $prefix String
|
2006-11-08 07:12:03 +00:00
|
|
|
* @return string HTML of link
|
2005-06-01 10:29:34 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2005-06-01 10:29:34 +00:00
|
|
|
global $wgUser;
|
2005-08-16 23:36:16 +00:00
|
|
|
$threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
|
2007-11-22 15:54:18 +00:00
|
|
|
$colour = ( $size < $threshold ) ? 'stub' : '';
|
|
|
|
|
return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
|
2005-06-01 10:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/**
|
2006-02-01 04:34:47 +00:00
|
|
|
* Make appropriate markup for a link to the current article. This is currently rendered
|
|
|
|
|
* as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
|
|
|
|
|
* despite $query not being used.
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
if ( '' == $text ) {
|
|
|
|
|
$text = htmlspecialchars( $nt->getPrefixedText() );
|
|
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
list( $inside, $trail ) = Linker::splitTrail( $trail );
|
2006-05-27 00:31:06 +00:00
|
|
|
return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function fnamePart( $url ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$basename = strrchr( $url, '/' );
|
|
|
|
|
if ( false === $basename ) {
|
|
|
|
|
$basename = $url;
|
|
|
|
|
} else {
|
|
|
|
|
$basename = substr( $basename, 1 );
|
|
|
|
|
}
|
|
|
|
|
return htmlspecialchars( $basename );
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** Obsolete alias */
|
|
|
|
|
function makeImage( $url, $alt = '' ) {
|
|
|
|
|
return $this->makeExternalImage( $url, $alt );
|
2005-04-27 07:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function makeExternalImage( $url, $alt = '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
if ( '' == $alt ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$alt = $this->fnamePart( $url );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
$s = '<img src="'.$url.'" alt="'.$alt.'" />';
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
|
* Creates the HTML source for images
|
|
|
|
|
* @deprecated use makeImageLink2
|
|
|
|
|
*
|
|
|
|
|
* @param object $title
|
|
|
|
|
* @param string $label label text
|
|
|
|
|
* @param string $alt alt text
|
|
|
|
|
* @param string $align horizontal alignment: none, left, center, right)
|
|
|
|
|
* @param array $handlerParams Parameters to be passed to the media handler
|
|
|
|
|
* @param boolean $framed shows image in original size in a frame
|
|
|
|
|
* @param boolean $thumb shows image as thumbnail in a frame
|
|
|
|
|
* @param string $manualthumb image name for the manual thumbnail
|
|
|
|
|
* @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
|
|
|
|
|
$thumb = false, $manualthumb = '', $valign = '', $time = false )
|
2006-11-08 07:12:03 +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
|
|
|
$frameParams = array( 'alt' => $alt, 'caption' => $label );
|
|
|
|
|
if ( $align ) {
|
|
|
|
|
$frameParams['align'] = $align;
|
|
|
|
|
}
|
|
|
|
|
if ( $framed ) {
|
|
|
|
|
$frameParams['framed'] = true;
|
|
|
|
|
}
|
|
|
|
|
if ( $thumb ) {
|
2007-08-27 20:10:48 +00:00
|
|
|
$frameParams['thumbnail'] = true;
|
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 ( $manualthumb ) {
|
|
|
|
|
$frameParams['manualthumb'] = $manualthumb;
|
|
|
|
|
}
|
|
|
|
|
if ( $valign ) {
|
|
|
|
|
$frameParams['valign'] = $valign;
|
|
|
|
|
}
|
|
|
|
|
$file = wfFindFile( $title, $time );
|
2007-08-27 20:10:48 +00:00
|
|
|
return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make an image link
|
|
|
|
|
* @param Title $title Title object
|
|
|
|
|
* @param File $file File object, or false if it doesn't exist
|
|
|
|
|
*
|
|
|
|
|
* @param array $frameParams Associative array of parameters external to the media handler.
|
|
|
|
|
* Boolean parameters are indicated by presence or absence, the value is arbitrary and
|
|
|
|
|
* 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)
|
|
|
|
|
* valign Vertical alignment (baseline, sub, super, top, text-top, middle,
|
|
|
|
|
* bottom, text-bottom)
|
|
|
|
|
* alt Alternate text for image (i.e. alt attribute). Plain text.
|
|
|
|
|
* caption HTML for image caption.
|
|
|
|
|
*
|
|
|
|
|
* @param array $handlerParams Associative array of media handler parameters, to be passed
|
|
|
|
|
* to transform(). Typical keys are "width" and "page".
|
|
|
|
|
*/
|
|
|
|
|
function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array() ) {
|
2007-05-21 18:56:03 +00:00
|
|
|
global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
|
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() ) {
|
|
|
|
|
wfDebug( __METHOD__.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
|
|
|
|
|
return $this->makeKnownLinkObj( $title );
|
|
|
|
|
}
|
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;
|
|
|
|
|
if ( !isset( $fp['align'] ) ) $fp['align'] = '';
|
|
|
|
|
if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
|
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
|
|
|
|
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 ( 'center' == $fp['align'] )
|
2006-11-08 07:12:03 +00:00
|
|
|
{
|
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'] ) ) {
|
|
|
|
|
$hp['width'] = $file->getWidth( $page );
|
|
|
|
|
|
|
|
|
|
if( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
|
2007-04-20 19:24:53 +00:00
|
|
|
$wopt = $wgUser->getOption( 'thumbsize' );
|
2007-04-20 12:31:36 +00:00
|
|
|
|
2007-04-20 19:24:53 +00:00
|
|
|
if( !isset( $wgThumbLimits[$wopt] ) ) {
|
|
|
|
|
$wopt = User::getDefaultOption( 'thumbsize' );
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
// Use width which is smaller: real image width or user preference width
|
|
|
|
|
// 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
|
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
|
|
|
$prefWidth = isset( $fp['upright'] ) ?
|
2007-08-27 11:24:53 +00:00
|
|
|
round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
|
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
|
|
|
$wgThumbLimits[$wopt];
|
|
|
|
|
if ( $hp['width'] <= 0 || $prefWidth < $hp['width'] ) {
|
|
|
|
|
$hp['width'] = $prefWidth;
|
|
|
|
|
}
|
2007-04-20 19:24:53 +00:00
|
|
|
}
|
2007-04-20 12:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-27 11:24:53 +00:00
|
|
|
if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
|
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'] == '' ) {
|
|
|
|
|
$fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
|
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
|
|
|
return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp ).$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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 && $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 ) {
|
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 = $this->makeBrokenImageLinkObj( $title );
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2007-08-31 02:51:23 +00:00
|
|
|
$s = $thumb->toHtml( array(
|
|
|
|
|
'desc-link' => true,
|
|
|
|
|
'alt' => $fp['alt'],
|
2007-08-31 14:01:27 +00:00
|
|
|
'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
|
|
|
|
|
'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ) );
|
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 ( '' != $fp['align'] ) {
|
|
|
|
|
$s = "<div class=\"float{$fp['align']}\"><span>{$s}</span></div>";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
return str_replace("\n", ' ',$prefix.$s.$postfix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make HTML for a thumbnail including image, border and caption
|
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
|
|
|
* @param Title $title
|
|
|
|
|
* @param File $file File object or false if it doesn't exist
|
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
|
|
|
function makeThumbLinkObj( Title $title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
|
|
|
|
|
$frameParams = array(
|
|
|
|
|
'alt' => $alt,
|
|
|
|
|
'caption' => $label,
|
|
|
|
|
'align' => $align
|
|
|
|
|
);
|
|
|
|
|
if ( $framed ) $frameParams['framed'] = true;
|
|
|
|
|
if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
|
2007-08-20 21:37:48 +00:00
|
|
|
return $this->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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array() ) {
|
2007-04-20 12:31:36 +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'] = '';
|
|
|
|
|
if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
|
|
|
|
|
|
|
|
|
|
if ( empty( $hp['width'] ) ) {
|
2007-05-21 18:56:03 +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
|
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
|
|
|
$manual_title = Title::makeTitleSafe( NS_IMAGE, $fp['manualthumb'] );
|
2007-05-30 21:02:32 +00:00
|
|
|
if( $manual_title ) {
|
|
|
|
|
$manual_img = wfFindFile( $manual_title );
|
|
|
|
|
if ( $manual_img ) {
|
|
|
|
|
$thumb = $manual_img->getUnscaledThumb();
|
|
|
|
|
} 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
|
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->getUnscaledThumb( $page );
|
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
|
|
|
}
|
|
|
|
|
|
2007-04-20 12:31:36 +00:00
|
|
|
$query = $page ? 'page=' . urlencode( $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
|
|
|
$url = $title->getLocalURL( $query );
|
2004-12-18 06:29:23 +00:00
|
|
|
|
|
|
|
|
$more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
|
|
|
|
|
$magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
|
|
|
|
|
$textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
|
|
|
|
|
|
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;\">";
|
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
|
|
|
$s .= $this->makeBrokenImageLinkObj( $title );
|
2006-02-06 05:19:46 +00:00
|
|
|
$zoomicon = '';
|
2007-05-30 21:02:32 +00:00
|
|
|
} elseif ( !$thumb ) {
|
|
|
|
|
$s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
|
2004-12-18 06:29:23 +00:00
|
|
|
$zoomicon = '';
|
|
|
|
|
} else {
|
2007-08-31 02:51:23 +00:00
|
|
|
$s .= $thumb->toHtml( 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'],
|
2007-08-31 02:51:23 +00:00
|
|
|
'img-class' => 'thumbimage',
|
|
|
|
|
'desc-link' => true ) );
|
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'] ) ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$zoomicon="";
|
|
|
|
|
} else {
|
|
|
|
|
$zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
|
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
|
|
|
'<a href="'.$url.'" class="internal" title="'.$more.'">'.
|
2004-12-18 06:29:23 +00:00
|
|
|
'<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
|
2006-12-22 20:31:10 +00:00
|
|
|
'width="15" height="11" alt="" /></a></div>';
|
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="thumbcaption"'.$textalign.'>'.$zoomicon.$fp['caption']."</div></div></div>";
|
2004-12-18 06:29:23 +00:00
|
|
|
return str_replace("\n", ' ', $s);
|
|
|
|
|
}
|
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
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title Image title
|
|
|
|
|
* @param string $text Link label
|
|
|
|
|
* @param string $query Query string
|
|
|
|
|
* @param string $trail Link trail
|
|
|
|
|
* @param string $prefix Link prefix
|
|
|
|
|
* @return string
|
2005-04-17 08:30:15 +00:00
|
|
|
*/
|
2007-06-09 16:19:38 +00:00
|
|
|
public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
|
|
|
|
|
global $wgEnableUploads;
|
|
|
|
|
if( $title instanceof Title ) {
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
if( $wgEnableUploads ) {
|
|
|
|
|
$upload = SpecialPage::getTitleFor( 'Upload' );
|
|
|
|
|
if( $text == '' )
|
|
|
|
|
$text = htmlspecialchars( $title->getPrefixedText() );
|
2007-06-12 23:10:12 +00:00
|
|
|
$q = 'wpDestFile=' . $title->getPartialUrl();
|
2007-06-09 16:19:38 +00:00
|
|
|
if( $query != '' )
|
|
|
|
|
$q .= '&' . $query;
|
|
|
|
|
list( $inside, $trail ) = self::splitTrail( $trail );
|
2007-11-22 15:54:18 +00:00
|
|
|
$style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
|
2007-06-09 16:19:38 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
|
|
|
|
|
. $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
|
|
|
|
|
} else {
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2005-04-17 08:30:15 +00:00
|
|
|
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/** @deprecated use Linker::makeMediaLinkObj() */
|
|
|
|
|
function makeMediaLink( $name, $unused = '', $text = '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$nt = Title::makeTitleSafe( NS_IMAGE, $name );
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->makeMediaLinkObj( $nt, $text );
|
2004-12-18 06:29:23 +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.
|
|
|
|
|
* @param $text String: pre-sanitized HTML
|
|
|
|
|
* @return string HTML
|
|
|
|
|
*
|
|
|
|
|
* @public
|
2005-02-21 01:56:50 +00:00
|
|
|
* @todo Handle invalid or missing images better.
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function makeMediaLinkObj( $title, $text = '' ) {
|
2005-02-21 01:56:50 +00:00
|
|
|
if( is_null( $title ) ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
### HOTFIX. Instead of breaking, return empty string.
|
2005-02-21 01:56:50 +00:00
|
|
|
return $text;
|
2004-12-18 06:29:23 +00:00
|
|
|
} else {
|
2007-05-30 21:02:32 +00:00
|
|
|
$img = wfFindFile( $title );
|
|
|
|
|
if( $img ) {
|
2005-06-16 05:36:10 +00:00
|
|
|
$url = $img->getURL();
|
|
|
|
|
$class = 'internal';
|
|
|
|
|
} else {
|
2006-10-30 06:25:31 +00:00
|
|
|
$upload = SpecialPage::getTitleFor( 'Upload' );
|
2007-06-05 19:06:32 +00:00
|
|
|
$url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDbKey() ) );
|
2005-06-16 05:36:10 +00:00
|
|
|
$class = 'new';
|
2005-02-21 01:56:50 +00:00
|
|
|
}
|
|
|
|
|
$alt = htmlspecialchars( $title->getText() );
|
|
|
|
|
if( $text == '' ) {
|
|
|
|
|
$text = $alt;
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
$u = htmlspecialchars( $url );
|
2006-06-12 05:33:48 +00:00
|
|
|
return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function specialLink( $name, $key = '' ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
|
|
if ( '' == $key ) { $key = strtolower( $name ); }
|
|
|
|
|
$pn = $wgContLang->ucfirst( $name );
|
2006-11-08 07:12:03 +00:00
|
|
|
return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
|
|
|
|
|
wfMsg( $key ) );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = null ) {
|
|
|
|
|
$style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
|
2006-05-22 21:17:38 +00:00
|
|
|
global $wgNoFollowLinks, $wgNoFollowNsExceptions;
|
|
|
|
|
if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {
|
2005-01-19 09:33:19 +00:00
|
|
|
$style .= ' rel="nofollow"';
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
$url = htmlspecialchars( $url );
|
|
|
|
|
if( $escape ) {
|
|
|
|
|
$text = htmlspecialchars( $text );
|
|
|
|
|
}
|
|
|
|
|
return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
* @return string HTML fragment
|
|
|
|
|
* @private
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function userLink( $userId, $userText ) {
|
2006-03-16 19:04:25 +00:00
|
|
|
$encName = htmlspecialchars( $userText );
|
|
|
|
|
if( $userId == 0 ) {
|
2006-12-02 08:52:54 +00:00
|
|
|
$contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
|
2006-11-08 07:12:03 +00:00
|
|
|
return $this->makeKnownLinkObj( $contribsPage,
|
2006-12-02 08:52:54 +00:00
|
|
|
$encName);
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
|
|
|
|
$userPage = Title::makeTitle( NS_USER, $userText );
|
2006-11-08 07:12:03 +00:00
|
|
|
return $this->makeLinkObj( $userPage, $encName );
|
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.)
|
|
|
|
|
*
|
|
|
|
|
* @param int $userId User identifier
|
|
|
|
|
* @param string $userText User name or IP address
|
|
|
|
|
* @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
|
|
|
|
|
* @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
|
|
|
|
|
* @return string
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2007-08-06 07:09:59 +00:00
|
|
|
public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0 ) {
|
2006-03-16 19:04:25 +00:00
|
|
|
global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
|
|
|
|
|
$talkable = !( $wgDisableAnonTalk && 0 == $userId );
|
2007-08-06 07:09:59 +00:00
|
|
|
$blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK;
|
2006-03-16 19:04:25 +00:00
|
|
|
|
|
|
|
|
$items = array();
|
|
|
|
|
if( $talkable ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$items[] = $this->userTalkLink( $userId, $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
2006-03-16 21:17:32 +00:00
|
|
|
if( $userId ) {
|
2007-01-23 19:56:01 +00:00
|
|
|
// check if the user has an edit
|
|
|
|
|
if( $redContribsWhenNoEdits && User::edits( $userId ) == 0 ) {
|
2007-07-12 17:32:18 +00:00
|
|
|
$style = " class='new'";
|
2007-01-23 19:56:01 +00:00
|
|
|
} else {
|
|
|
|
|
$style = '';
|
|
|
|
|
}
|
2006-12-02 08:52:54 +00:00
|
|
|
$contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
|
2007-01-23 19:56:01 +00:00
|
|
|
|
|
|
|
|
$items[] = $this->makeKnownLinkObj( $contribsPage, wfMsgHtml( 'contribslink' ), '', '', '', '', $style );
|
2006-03-16 21:17:32 +00:00
|
|
|
}
|
2006-03-16 19:04:25 +00:00
|
|
|
if( $blockable && $wgUser->isAllowed( 'block' ) ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$items[] = $this->blockLink( $userId, $userText );
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( $items ) {
|
|
|
|
|
return ' (' . implode( ' | ', $items ) . ')';
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-23 19:56:01 +00:00
|
|
|
/**
|
|
|
|
|
* Alias for userToolLinks( $userId, $userText, true );
|
|
|
|
|
*/
|
|
|
|
|
public function userToolLinksRedContribs( $userId, $userText ) {
|
|
|
|
|
return $this->userToolLinks( $userId, $userText, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
* @return string HTML fragment with user talk link
|
|
|
|
|
* @private
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function userTalkLink( $userId, $userText ) {
|
2006-03-16 19:04:25 +00:00
|
|
|
$userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
|
2007-04-08 13:40:33 +00:00
|
|
|
$userTalkLink = $this->makeLinkObj( $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.
|
2006-03-16 19:04:25 +00:00
|
|
|
* @return string HTML fragment with block link
|
2006-11-08 07:12:03 +00:00
|
|
|
* @private
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function blockLink( $userId, $userText ) {
|
2006-12-02 08:52:54 +00:00
|
|
|
$blockPage = SpecialPage::getTitleFor( 'Blockip', $userText );
|
2006-11-08 07:12:03 +00:00
|
|
|
$blockLink = $this->makeKnownLinkObj( $blockPage,
|
2006-12-02 08:52:54 +00:00
|
|
|
wfMsgHtml( 'blocklink' ) );
|
2006-03-16 19:04:25 +00:00
|
|
|
return $blockLink;
|
|
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
|
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.
|
2006-03-16 19:04:25 +00:00
|
|
|
* @return string HTML
|
|
|
|
|
*/
|
2007-10-01 19:50:25 +00:00
|
|
|
function revUserLink( $rev ) {
|
|
|
|
|
if( $rev->userCan( Revision::DELETED_USER ) ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
|
|
|
|
$link = wfMsgHtml( 'rev-deleted-user' );
|
|
|
|
|
}
|
2006-06-23 06:31:46 +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.
|
2006-03-16 19:04:25 +00:00
|
|
|
* @return string HTML
|
|
|
|
|
*/
|
2007-10-01 19:50:25 +00:00
|
|
|
function revUserTools( $rev ) {
|
|
|
|
|
if( $rev->userCan( Revision::DELETED_USER ) ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
$link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
|
2007-10-01 19:50:25 +00:00
|
|
|
' ' .
|
|
|
|
|
$this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
|
|
|
|
$link = wfMsgHtml( 'rev-deleted-user' );
|
|
|
|
|
}
|
2006-06-23 06:31:46 +00:00
|
|
|
if( $rev->isDeleted( Revision::DELETED_USER ) ) {
|
2007-03-14 15:50:06 +00:00
|
|
|
return '<span class="history-deleted">' . $link . '</span>';
|
|
|
|
|
}
|
|
|
|
|
return $link;
|
|
|
|
|
}
|
2007-03-16 16:01:07 +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
|
|
|
*
|
Some small doc tweaks to reduce Doxygen warnings, namely:
* @link. You might think @link would surely mean "here comes a web URL" ... but @link is a valid command
in Doxygen, which means an entirely different kind of link (an internal link to somewhere, so that you can separate
documentation and implementation). The result is a mess, and the best solution I can see is to use "@see" instead of "@link".
* Warning: argument `nourl' of command @param is not found in the argument list of Linker::makeMediaLinkObj($title,$text='')
* Moving few class descriptions to right above classes, and/or formatting into Javadoc style.
* "@addtogroup Special Pages" --> "@addtogroup SpecialPage" so that all special pages have the same @addtogroup tag.
* @fixme --> @todo (must have missed these before)
* "@param $specialPage @see" remove the "@" in the "@see" to stop warning.
* @throws wants type, then a brief description, to stop warning.
This last one is for PHPdocumentor only, but it fixes something for PHPDocumentor, and should be neutral for Doxygen:
* WARNING in includes/api/ApiFormatYaml_spyc.php on line 860: docblock template never terminated with /**#@-*/
2007-04-18 09:50:10 +00:00
|
|
|
* @param string $comment
|
2006-11-21 22:49:25 +00:00
|
|
|
* @param mixed $title Title object (to generate link to the section in autocomment) or null
|
2006-11-17 03:59:32 +00:00
|
|
|
* @param bool $local Whether section links should refer to local page
|
2004-12-18 06:29:23 +00:00
|
|
|
*/
|
2006-11-21 18:38:06 +00:00
|
|
|
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 );
|
2004-12-18 06:29:23 +00:00
|
|
|
$comment = htmlspecialchars( $comment );
|
|
|
|
|
|
2007-05-09 20:05:08 +00:00
|
|
|
# Render autocomments and make links:
|
|
|
|
|
$comment = $this->formatAutoComments( $comment, $title, $local );
|
|
|
|
|
$comment = $this->formatLinksInComment( $comment );
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* @param $comment Comment text
|
|
|
|
|
* @param $title An optional title object used to links to sections
|
|
|
|
|
*
|
|
|
|
|
* @todo Document the $local parameter.
|
|
|
|
|
*/
|
|
|
|
|
private function formatAutocomments( $comment, $title = NULL, $local = false ) {
|
2006-11-23 08:25:56 +00:00
|
|
|
$match = array();
|
2007-05-10 01:07:10 +00:00
|
|
|
while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
|
2004-12-18 06:29:23 +00:00
|
|
|
$pre=$match[1];
|
|
|
|
|
$auto=$match[2];
|
|
|
|
|
$post=$match[3];
|
|
|
|
|
$link='';
|
2006-01-13 19:58:23 +00:00
|
|
|
if( $title ) {
|
|
|
|
|
$section = $auto;
|
2004-12-18 06:29:23 +00:00
|
|
|
|
2006-05-31 07:29:02 +00:00
|
|
|
# Generate a valid anchor name from the section title.
|
|
|
|
|
# Hackish, but should generally work - we strip wiki
|
|
|
|
|
# syntax, including the magic [[: that is used to
|
|
|
|
|
# "link rather than show" in case of images and
|
|
|
|
|
# interlanguage links.
|
|
|
|
|
$section = str_replace( '[[:', '', $section );
|
2006-01-13 19:58:23 +00:00
|
|
|
$section = str_replace( '[[', '', $section );
|
|
|
|
|
$section = str_replace( ']]', '', $section );
|
2006-11-17 03:59:32 +00:00
|
|
|
if ( $local ) {
|
|
|
|
|
$sectionTitle = Title::newFromText( '#' . $section);
|
|
|
|
|
} else {
|
|
|
|
|
$sectionTitle = wfClone( $title );
|
|
|
|
|
$sectionTitle->mFragment = $section;
|
|
|
|
|
}
|
2006-11-08 07:12:03 +00:00
|
|
|
$link = $this->makeKnownLinkObj( $sectionTitle, wfMsg( 'sectionlink' ) );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
$sep='-';
|
|
|
|
|
$auto=$link.$auto;
|
|
|
|
|
if($pre) { $auto = $sep.' '.$auto; }
|
|
|
|
|
if($post) { $auto .= ' '.$sep; }
|
|
|
|
|
$auto='<span class="autocomment">'.$auto.'</span>';
|
|
|
|
|
$comment=$pre.$auto.$post;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-09 20:05:08 +00:00
|
|
|
return $comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-06-07 22:16:19 +00:00
|
|
|
* Formats wiki links and media links in text; all other wiki formatting
|
|
|
|
|
* is ignored
|
|
|
|
|
*
|
2007-10-04 18:59:50 +00:00
|
|
|
* @fixme doesn't handle sub-links as in image thumb texts like the main parser
|
2007-06-07 22:16:19 +00:00
|
|
|
* @param string $comment Text to format links in
|
|
|
|
|
* @return string
|
2007-05-09 20:05:08 +00:00
|
|
|
*/
|
2007-06-07 22:16:19 +00:00
|
|
|
public function formatLinksInComment( $comment ) {
|
2007-10-04 18:59:50 +00:00
|
|
|
return preg_replace_callback(
|
|
|
|
|
'/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
|
|
|
|
|
array( $this, 'formatLinksInCommentCallback' ),
|
|
|
|
|
$comment );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function formatLinksInCommentCallback( $match ) {
|
2007-05-09 20:05:08 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
2006-12-03 04:09:48 +00:00
|
|
|
$medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
|
|
|
|
|
$medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
|
2007-10-04 18:59:50 +00:00
|
|
|
|
|
|
|
|
$comment = $match[0];
|
2007-05-09 20:05:08 +00:00
|
|
|
|
2007-10-04 18:59:50 +00:00
|
|
|
# Handle link renaming [[foo|text]] will show link as "text"
|
|
|
|
|
if( "" != $match[3] ) {
|
|
|
|
|
$text = $match[3];
|
|
|
|
|
} else {
|
|
|
|
|
$text = $match[1];
|
|
|
|
|
}
|
|
|
|
|
$submatch = array();
|
|
|
|
|
if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
|
|
|
|
|
# Media link; trail not supported.
|
|
|
|
|
$linkRegexp = '/\[\[(.*?)\]\]/';
|
|
|
|
|
$thelink = $this->makeMediaLink( $submatch[1], "", $text );
|
|
|
|
|
} else {
|
|
|
|
|
# Other kind of link
|
|
|
|
|
if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
|
|
|
|
|
$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
|
|
|
}
|
2007-10-04 18:59:50 +00:00
|
|
|
$linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
|
|
|
|
|
if (isset($match[1][0]) && $match[1][0] == ':')
|
|
|
|
|
$match[1] = substr($match[1], 1);
|
|
|
|
|
$thelink = $this->makeLink( $match[1], $text, "", $trail );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
2007-10-04 18:59:50 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
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
|
|
|
*
|
2006-11-17 03:59:32 +00:00
|
|
|
* @param string $comment
|
2006-11-21 22:49:25 +00:00
|
|
|
* @param mixed $title Title object (to generate link to section in autocomment) or null
|
2006-11-17 03:59:32 +00:00
|
|
|
* @param bool $local Whether section links should refer to local page
|
2006-11-08 07:12:03 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2005-02-21 12:23:52 +00:00
|
|
|
*/
|
2006-11-21 18:38:06 +00:00
|
|
|
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
|
2005-02-22 06:04:03 +00:00
|
|
|
if( $comment == '' || $comment == '*' ) {
|
2005-02-21 12:23:52 +00:00
|
|
|
return '';
|
|
|
|
|
} else {
|
2006-11-17 03:59:32 +00:00
|
|
|
$formatted = $this->formatComment( $comment, $title, $local );
|
2006-06-12 05:33:48 +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
|
|
|
*
|
|
|
|
|
* @param Revision $rev
|
|
|
|
|
* @param bool $local Whether section links should refer to local page
|
2006-11-08 07:12:03 +00:00
|
|
|
* @return string HTML
|
2006-03-16 19:04:25 +00:00
|
|
|
*/
|
2007-10-01 19:50:25 +00:00
|
|
|
function revComment( Revision $rev, $local = false ) {
|
|
|
|
|
if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
|
2006-11-17 03:59:32 +00:00
|
|
|
$block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local );
|
2006-03-16 19:04:25 +00:00
|
|
|
} else {
|
2007-10-01 19:50:25 +00:00
|
|
|
$block = " <span class=\"comment\">" .
|
|
|
|
|
wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
|
2006-03-16 19:04:25 +00:00
|
|
|
}
|
2006-06-23 06:31:46 +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
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function tocIndent() {
|
2005-01-15 23:21:52 +00:00
|
|
|
return "\n<ul>";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function tocUnindent($level) {
|
2005-01-15 23:21:52 +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
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function tocLine( $anchor, $tocline, $tocnumber, $level ) {
|
2006-06-12 05:33:48 +00:00
|
|
|
return "\n<li class=\"toclevel-$level\"><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
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function tocLineEnd() {
|
2005-01-15 23:21:52 +00:00
|
|
|
return "</li>\n";
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-08 07:12:03 +00:00
|
|
|
/** @todo document */
|
|
|
|
|
function tocList($toc) {
|
2005-05-05 21:00:49 +00:00
|
|
|
global $wgJsMimeType;
|
2007-09-21 14:32:26 +00:00
|
|
|
$title = wfMsgHtml('toc') ;
|
2005-12-04 01:12:54 +00:00
|
|
|
return
|
2006-01-07 13:09:30 +00:00
|
|
|
'<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
|
2005-12-04 01:12:54 +00:00
|
|
|
. '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
|
|
|
|
|
. $toc
|
2006-03-24 16:07:50 +00:00
|
|
|
# no trailing newline, script should not be wrapped in a
|
|
|
|
|
# paragraph
|
|
|
|
|
. "</ul>\n</td></tr></table>"
|
2005-12-04 01:12:54 +00:00
|
|
|
. '<script type="' . $wgJsMimeType . '">'
|
|
|
|
|
. ' if (window.showTocToggle) {'
|
2007-04-02 13:21:09 +00:00
|
|
|
. ' var tocShowText = "' . wfEscapeJsString( wfMsg('showtoc') ) . '";'
|
|
|
|
|
. ' var tocHideText = "' . wfEscapeJsString( wfMsg('hidetoc') ) . '";'
|
2005-12-04 01:12:54 +00:00
|
|
|
. ' showTocToggle();'
|
|
|
|
|
. ' } '
|
|
|
|
|
. "</script>\n";
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-02 15:46:55 +00:00
|
|
|
/**
|
|
|
|
|
* Used to generate section edit links that point to "other" pages
|
|
|
|
|
* (sections that are really part of included pages).
|
|
|
|
|
*
|
|
|
|
|
* @param $title Title string.
|
|
|
|
|
* @param $section Integer: section number.
|
|
|
|
|
*/
|
2007-01-08 02:11:45 +00:00
|
|
|
public function editSectionLinkForOther( $title, $section ) {
|
2006-02-01 04:34:47 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2007-07-02 15:46:55 +00:00
|
|
|
return $this->doEditSectionLink( $title, $section, '', 'EditSectionLinkForOther' );
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-10-18 06:53:19 +00:00
|
|
|
/**
|
2007-07-02 15:46:55 +00:00
|
|
|
* @param $nt Title object.
|
2006-11-08 07:12:03 +00:00
|
|
|
* @param $section Integer: section number.
|
|
|
|
|
* @param $hint Link String: title, or default if omitted or empty
|
2006-03-04 03:24:33 +00:00
|
|
|
*/
|
2007-07-02 15:46:55 +00:00
|
|
|
public function editSectionLink( Title $nt, $section, $hint='' ) {
|
|
|
|
|
if( $hint != '' ) {
|
|
|
|
|
$hint = wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) );
|
|
|
|
|
$hint = " title=\"$hint\"";
|
|
|
|
|
}
|
|
|
|
|
return $this->doEditSectionLink( $nt, $section, $hint, 'EditSectionLink' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implement editSectionLink and editSectionLinkForOther.
|
|
|
|
|
*
|
|
|
|
|
* @param $nt Title object
|
|
|
|
|
* @param $section Integer, section number
|
|
|
|
|
* @param $hint String, for HTML title attribute
|
|
|
|
|
* @param $hook String, name of hook to run
|
|
|
|
|
* @return String, HTML to use for edit link
|
|
|
|
|
*/
|
2007-07-23 21:40:05 +00:00
|
|
|
protected function doEditSectionLink( Title $nt, $section, $hint, $hook ) {
|
2004-12-18 06:29:23 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
$editurl = '§ion='.$section;
|
2007-07-02 15:46:55 +00:00
|
|
|
$url = $this->makeKnownLinkObj(
|
|
|
|
|
$nt,
|
|
|
|
|
wfMsg('editsection'),
|
|
|
|
|
'action=edit'.$editurl,
|
|
|
|
|
'', '', '', $hint
|
|
|
|
|
);
|
2007-06-05 01:50:33 +00:00
|
|
|
$result = null;
|
2007-07-02 15:46:55 +00:00
|
|
|
|
|
|
|
|
// The two hooks have slightly different interfaces . . .
|
|
|
|
|
if( $hook == 'EditSectionLink' ) {
|
2007-12-03 19:47:11 +00:00
|
|
|
wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $hint, $url, &$result ) );
|
2007-07-02 15:46:55 +00:00
|
|
|
} elseif( $hook == 'EditSectionLinkForOther' ) {
|
2007-12-03 19:47:11 +00:00
|
|
|
wfRunHooks( 'EditSectionLinkForOther', array( &$this, $nt, $section, $url, &$result ) );
|
2007-07-02 15:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For reverse compatibility, add the brackets *after* the hook is run,
|
|
|
|
|
// and even add them to hook-provided text.
|
|
|
|
|
if( is_null( $result ) ) {
|
|
|
|
|
$result = wfMsg( 'editsection-brackets', $url );
|
|
|
|
|
} else {
|
|
|
|
|
$result = wfMsg( 'editsection-brackets', $result );
|
|
|
|
|
}
|
|
|
|
|
return "<span class=\"editsection\">$result</span>";
|
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
|
|
|
|
|
*
|
|
|
|
|
* @param int $level The level of the headline (1-6)
|
|
|
|
|
* @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
|
|
|
|
|
* This *must* be at least '>' for no attribs
|
|
|
|
|
* @param string $anchor The anchor to give the headline (the bit after the #)
|
|
|
|
|
* @param string $text The text of the header
|
|
|
|
|
* @param string $link HTML to add for the section edit link
|
|
|
|
|
*
|
|
|
|
|
* @return string HTML headline
|
|
|
|
|
*/
|
|
|
|
|
public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
|
2007-12-31 23:51:53 +00:00
|
|
|
return "<a name=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
|
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
|
|
|
*
|
2005-04-27 07:48:14 +00:00
|
|
|
* @static
|
|
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
static function splitTrail( $trail ) {
|
2005-04-27 07:48:14 +00:00
|
|
|
static $regex = false;
|
|
|
|
|
if ( $regex === false ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$regex = $wgContLang->linkTrail();
|
|
|
|
|
}
|
|
|
|
|
$inside = '';
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @param Revision $rev
|
|
|
|
|
*/
|
|
|
|
|
function generateRollback( $rev ) {
|
2007-07-07 00:17:51 +00:00
|
|
|
return '<span class="mw-rollback-link">['
|
|
|
|
|
. $this->buildRollbackLink( $rev )
|
|
|
|
|
. ']</span>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build a raw rollback link, useful for collections of "tool" links
|
|
|
|
|
*
|
|
|
|
|
* @param Revision $rev
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function buildRollbackLink( $rev ) {
|
|
|
|
|
global $wgRequest, $wgUser;
|
2006-11-16 22:53:01 +00:00
|
|
|
$title = $rev->getTitle();
|
2007-07-07 00:17:51 +00:00
|
|
|
$extra = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
|
|
|
|
|
$extra .= '&token=' . urlencode( $wgUser->editToken( array( $title->getPrefixedText(),
|
|
|
|
|
$rev->getUserText() ) ) );
|
|
|
|
|
return $this->makeKnownLinkObj(
|
|
|
|
|
$title,
|
|
|
|
|
wfMsgHtml( 'rollbacklink' ),
|
|
|
|
|
'action=rollback&from=' . urlencode( $rev->getUserText() ) . $extra
|
|
|
|
|
);
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @param array $templates Array of templates from Article::getUsedTemplate
|
|
|
|
|
* or similar
|
2006-11-20 05:15:51 +00:00
|
|
|
* @param bool $preview Whether this is for a preview
|
|
|
|
|
* @param bool $section Whether this is for a section edit
|
2006-11-17 03:42:23 +00:00
|
|
|
* @return string HTML output
|
|
|
|
|
*/
|
2006-11-20 05:15:51 +00:00
|
|
|
public function formatTemplates( $templates, $preview = false, $section = false) {
|
2006-11-17 03:42:23 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
2007-01-22 23:50:42 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2006-11-17 03:42:23 +00:00
|
|
|
|
|
|
|
|
$outText = '';
|
|
|
|
|
if ( count( $templates ) > 0 ) {
|
|
|
|
|
# Do a batch existence check
|
|
|
|
|
$batch = new LinkBatch;
|
|
|
|
|
foreach( $templates as $title ) {
|
|
|
|
|
$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 ) {
|
2006-11-21 03:22:18 +00:00
|
|
|
$outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
|
2006-12-31 01:35:26 +00:00
|
|
|
} elseif ( $section ) {
|
2006-11-21 03:22:18 +00:00
|
|
|
$outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
|
2006-12-31 01:35:26 +00:00
|
|
|
} else {
|
2006-11-21 03:22:18 +00:00
|
|
|
$outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
|
2006-12-31 01:35:26 +00:00
|
|
|
}
|
2006-11-21 03:22:18 +00:00
|
|
|
$outText .= '</div><ul>';
|
2006-12-31 01:35:26 +00:00
|
|
|
|
2006-11-17 03:42:23 +00:00
|
|
|
foreach ( $templates as $titleObj ) {
|
2006-12-31 01:35:26 +00:00
|
|
|
$r = $titleObj->getRestrictions( 'edit' );
|
|
|
|
|
if ( in_array( 'sysop', $r ) ) {
|
|
|
|
|
$protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
|
|
|
|
|
} elseif ( in_array( 'autoconfirmed', $r ) ) {
|
|
|
|
|
$protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
|
|
|
|
|
} else {
|
|
|
|
|
$protected = '';
|
|
|
|
|
}
|
|
|
|
|
$outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . ' ' . $protected . '</li>';
|
2006-11-17 03:42:23 +00:00
|
|
|
}
|
|
|
|
|
$outText .= '</ul>';
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $outText;
|
|
|
|
|
}
|
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
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function formatSize( $size ) {
|
|
|
|
|
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-11 00:57:30 +00:00
|
|
|
* Given the id of an interface element, constructs the appropriate title
|
|
|
|
|
* and accesskey attributes from the system messages. (Note, this is usu-
|
|
|
|
|
* ally 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 05:18:30 +00:00
|
|
|
*
|
|
|
|
|
* @param string $name Id of the element, minus prefixes.
|
|
|
|
|
* @return string title and accesskey attributes, ready to drop in an
|
|
|
|
|
* element (e.g., ' title="This does something [x]" accesskey="x"').
|
|
|
|
|
*/
|
|
|
|
|
public function tooltipAndAccesskey($name) {
|
2007-11-13 09:03:49 +00:00
|
|
|
$fname="Linker::tooltipAndAccesskey";
|
|
|
|
|
wfProfileIn($fname);
|
2007-01-10 05:18:30 +00:00
|
|
|
$out = '';
|
|
|
|
|
|
|
|
|
|
$tooltip = wfMsg('tooltip-'.$name);
|
|
|
|
|
if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
|
2007-01-10 05:51:10 +00:00
|
|
|
// Compatibility: formerly some tooltips had [alt-.] hardcoded
|
|
|
|
|
$tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
|
2007-01-10 05:18:30 +00:00
|
|
|
$out .= ' title="'.htmlspecialchars($tooltip);
|
|
|
|
|
}
|
|
|
|
|
$accesskey = wfMsg('accesskey-'.$name);
|
|
|
|
|
if ($accesskey && $accesskey != '-' && !wfEmptyMsg('accesskey-'.$name, $accesskey)) {
|
|
|
|
|
if ($out) $out .= " [$accesskey]\" accesskey=\"$accesskey\"";
|
|
|
|
|
else $out .= " title=\"[$accesskey]\" accesskey=\"$accesskey\"";
|
|
|
|
|
} elseif ($out) {
|
|
|
|
|
$out .= '"';
|
|
|
|
|
}
|
2007-11-13 09:03:49 +00:00
|
|
|
wfProfileOut($fname);
|
2007-01-10 05:18:30 +00:00
|
|
|
return $out;
|
|
|
|
|
}
|
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
|
|
|
*
|
|
|
|
|
* @param string $name Id of the element, minus prefixes.
|
|
|
|
|
* @return string title attribute, ready to drop in an element
|
|
|
|
|
* (e.g., ' title="This does something"').
|
|
|
|
|
*/
|
|
|
|
|
public function tooltip($name) {
|
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
|
|
$tooltip = wfMsg('tooltip-'.$name);
|
|
|
|
|
if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
|
|
|
|
|
$out = ' title="'.htmlspecialchars($tooltip).'"';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
2004-12-18 06:29:23 +00:00
|
|
|
}
|