MediaWiki扩展:指定图片链接
天下维客,你可以修改的网络知识库
| MediaWiki扩展简明教程 | Inputbox帮助文档 | 使用Spam黑名单 | 内容折叠隐藏 | 动态文章列表 | 指定图片链接 |
| 代码高亮处理 | 预置初始编辑文本 | 页面访问限制 | 所见即所得编辑器 | QQ在线信息 | |
| 交流:扩展使用 | 投票与评分 | 内容随机展示 | wikitex | 改进设想 | ...更多 |
| 加入google地图和51地图标注功能 | Ajax五颗星评分插件 |
在默认情况下,mediawiki系统中[[Image:XXX]]形式的图片会指向其自身的相关页面(即大图及图片附注页面),而这在很多时候不方便,无法通过图片引导读者的进一步阅读。
使用本扩展,可以指定图片的链接,使其指向另外的位置。
本扩展适用于Mediawiki 1.5.x、1.6.x版本。
目录 |
[编辑]
参数
| 参数 | 类型 | 说明 | 举例 |
|---|---|---|---|
| wikipage | 必备 | 指定链接目标的条目名称 | wikipage=首页 |
| tooltip | 可选 | 当鼠标光标移到图片上时,弹出的气泡中提示文字 | tooltip=Sampletext |
| img_src | 必备 | 指定要显示的图片名称 | img_src=Image:Sample.gif |
| img_width | 可选 | 你可以任意设置图片的显示宽度 不使用本参数时,图片以实际宽度显示;反之以指定尺寸显示。 | img_width=10px |
| img_height | 可选 | 指定图片的显示高度 用法同上 | img_height=10px |
| img_alt | 可选 | 当用户的浏览器禁止图片时,显示的替代文本 | img_alt=Text |
[编辑]
用法举例
<linkedimage> wikipage=Main_Page tooltip=Main Page img_src=Image:Sample.gif img_width=10% img_height=10px img_alt=Sampletext </linkedimage>
[编辑]
安装
- 复制LinkedImages.php到extensions文件夹
- 在localsettings.php中增加include("extensions/LinkedImages.php");(建议放在文件末尾)
[编辑]
LinkedImages.php代码
版本号: 0.2
<?php
/**
* This file contains the main include file for the LinkedImage extension of
* MediaWiki.
*
* Usage: require_once("path/to/LinkedImage.php"); in LocalSettings.php
*
* This extension requires MediaWiki 1.5 or higher.
*
* @author Alexander Kraus <kraus.alexander@gmail.com>
* @copyright Public domain
* @license Public domain
* @package MediaWikiExtensions
* @version 0.2
*/
/**
* Register the LinkedImage extension with MediaWiki
*/
$wgExtensionFunctions[] = 'wfLinkedImage';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'LinkedImage',
'author' => 'Alexander Kraus',
'url' => 'http://meta.wikimedia.org/wiki/LinkedImage',
);
//renderLinkedImage();
/**
* Sets the tag that this extension looks for and the function by which it
* operates
*/
function wfLinkedImage()
{
global $wgParser, $wgMessageCache;
$wgMessageCache->addMessages( array(
'linkedimage_nowikipage'=> 'LinkedImage: No link target specified! e.g. \'wikipage=Main_page\'',
'linkedimage_noimg' => 'LinkedImage: No image specified! e.g. \'img_src=Image:LinkedImage.png\''
)
);
$wgParser->setHook('linkedimage', 'renderLinkedImage');
}
function renderLinkedImage($input)
{
$linkedimage=new LinkedImage();
$linkedimage->getBoxOption($linkedimage->wikipage, $input,'wikipage');
$linkedimage->getBoxOption($linkedimage->tooltip, $input,'tooltip');
$linkedimage->getBoxOption($linkedimage->img_src, $input,'img_src');
$linkedimage->getBoxOption($linkedimage->img_height, $input,'img_height');
$linkedimage->getBoxOption($linkedimage->img_width, $input,'img_width');
$linkedimage->getBoxOption($linkedimage->img_alt, $input,'img_alt');
$linkedimage->getBoxOption($linkedimage->img_border, $input,'img_border');
// render and return linked image ...
return $linkedimage->render();
}
class LinkedImage {
var $wikipage;
var $tooltip;
var $img_src;
var $img_alt;
var $img_height;
var $img_width;
var $img_border;
public function LinkedImage() {
$this->setWikipage('');
$this->setTooltip('');
$this->setImg_src('');
$this->setImg_alt('');
$this->setImg_height('');
$this->setImg_width('');
$this->setImg_border('');
}
private function setWikipage($value){ $this->wikipage=$value; }
private function getWikipage(){ return $this->wikipage; }
private function setTooltip($value){ $this->tooltip=$value; }
private function getTooltip(){ return $this->tooltip; }
private function getTooltipHTML(){
if ($this->tooltip != '') {
return 'title="'.$this->getTooltip().'" ';
} else {
return '';
}
}
private function setImg_src($value){ $this->img_src=$value; }
private function getImg_src(){ return $this->img_src; }
private function getImg_srcHTML($getImageUrl=false){
if ($this->img_src != '') {
if ($getImageUrl) {
return 'src="'.$this->image->getUrl().'" ';
} else {
return 'src="'.$this->img_src.'" ';
}
} else {
return '';
}
}
private function setImg_alt($value){ $this->img_alt=$value; }
private function getImg_alt(){ return $this->img_alt; }
private function getImg_altHTML(){
if ($this->img_alt != '') {
return 'alt="'.$this->img_alt.'" ';
} else {
return '';
}
}
private function setImg_height($value){ $this->img_heigth=$value;}
private function getImg_height(){ return $this->img_height;}
private function getImg_heightHTML(){
if ($this->img_height != '') {
return 'height="'.$this->img_height.'" ';
} else {
return 'height="'.$this->image->getHeight().'" ';
}
}
private function setImg_width($value){ $this->img_width=$value; }
private function getImg_width(){ return $this->img_width; }
private function getImg_widthHTML(){
if ($this->img_width != '') {
return 'width="'.$this->img_width.'" ';
} else {
return 'width="'.$this->image->getWidth().'" ';
}
}
private function setImg_border($value){ $this->img_border=$value; }
private function getImg_border(){ return $this->img_border; }
private function getImg_borderHTML(){
if ($this->img_border != '') {
return 'border="'.$this->img_border.'" ';
} else {
return $this->img_border;
}
}
public function render() {
global $wgArticlePath;
// check param wikipage existence
if ($this->getWikipage() == '') {
return htmlspecialchars( wfMsg( 'linkedimage_nowikipage' ) );
}
// check param img_src existence
if ($this->getImg_src() == '') {
return htmlspecialchars( wfMsg( 'linkedimage_noimg' ) );
}
// create mediawiki image object ...
$this->image = new Image( Title::newFromText( $this->img_src ) );
// return link ...
return '<a href="'.str_replace( "$1", $this->wikipage, $wgArticlePath ).'" '.$this->getTooltipHTML().'>
<img '. $this->getImg_srcHTML(true) . $this->getImg_altHTML() . $this->getImg_widthHTML() . $this->getImg_heightHTML() . $this->getImg_borderHTML() . '></a>';
} // End render()
public function getBoxOption(&$value,&$input,$name,$isNumber=false) {
if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
if($isNumber) {
$value=intval($matches[1]);
} else {
$value=htmlspecialchars($matches[1]);
}
}
} // End getBoxOption()
}
?>
原文参见: LinkedImage
| MediaWiki扩展简明教程 | Inputbox帮助文档 | 使用Spam黑名单 | 内容折叠隐藏 | 动态文章列表 | 指定图片链接 |
| 代码高亮处理 | 预置初始编辑文本 | 页面访问限制 | 所见即所得编辑器 | QQ在线信息 | |
| 交流:扩展使用 | 投票与评分 | 内容随机展示 | wikitex | 改进设想 | ...更多 |
| 加入google地图和51地图标注功能 | Ajax五颗星评分插件 |



