擴展:CharInsert
CharInsert 发行状态: 稳定版 |
|
---|---|
实现 | 标签 , 页面操作 , MyWiki |
描述 | 用于创建JavaScript插入字符的按键。 |
作者 | Brion Vibber (Brooke Vibber留言) |
最新版本 | continuous updates |
兼容性政策 | 快照跟随MediaWiki发布。 master分支不向后兼容。 |
MediaWiki | >= 1.43 |
许可协议 | GNU通用公眾授權條款2.0或更新版本 |
下載 | |
<charinsert> |
|
季度下載量 | 70 (Ranked 73rd) |
正在使用的公开wiki数 | 9,224 (Ranked 15th) |
前往translatewiki.net翻譯CharInsert扩展 | |
問題 | 开启的任务 · 报告错误 |
CharInsert扩展用于创建点击时即可插入指定文字到编辑框中的JavaScript链接。
这些链接通常被用于MediaWiki:Edittools的系统消息中(例如在此维基上)。
語法
在<charinsert>
标签中列出你想要提供插入的字符或标签,用空格隔开。
你可以在標籤之間使用+符號去定義:
- 插入到被選擇的文字上或
- 如果没有文字被选择,则插入到光标所在处。
模板和含有空格的文字需要使用<nowiki>
包住:
<charinsert><nowiki>== + ==</nowiki> <nowiki>{{stub}}</nowiki></charinsert>
使用方法和輸出範例
单独字符
单独字符只需在charinsert标签内用空格间隔列出即可。
<charinsert>Á á Ć ć É é Í í Ĺ ĺ Ń ń Ó ó Ŕ ŕ Ś ś Ú ú Ý ý Ź ź</charinsert>
效果为:
Á á Ć ć É é Í í Ĺ ĺ Ń ń Ó ó Ŕ ŕ Ś ś Ú ú Ý ý Ź ź
组合字符
组合字符在“charinsert”标签内用“+”号连接后列出。
<charinsert>“+” ‘+’ «+» ‹+› „+“ ‚+‘ [[+]] {{+}}</charinsert>
效果为:
覆盖显示文字
MediaWiki版本: | ≥ 1.38 Gerrit change 748823 |
可以在label
属性中指定不同于原字符的显示文字(如果要使用此属性,需要对每个字符使用单独的<charinsert>
标签)。
<charinsert label="拉丁字母A">A</charinsert> <charinsert label="西里尔字母A">А</charinsert> <charinsert label="希腊字母Alpha">Α</charinsert>
效果为:
注意
- Generated JavaScript links also work in other areas around edit window, e.g. in MediaWiki:Copyrightwarning or MediaWiki:Newarticletext, on the page preloaded with Inputbox , and even from the text preview.
- They can also be used in MediaWiki:Uploadtext to insert image description templates.
- Unlike toolbar buttons on top, this extension doesn't provide a way to specify inserted "sample text".
- Use
to add new lines (\n). - Enclose white spaces in
<nowiki>...</nowiki>
tags when needed. - Add
<charinsert>...</charinsert>
tags into MediaWiki:Edittools.
安裝
- 下载文件,并将解压后的
CharInsert
文件夹移动到extensions/
目录中。
开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CharInsert - 将下列代码放置在您的LocalSettings.php 的底部:
wfLoadExtension( 'CharInsert' );
- If you use the gadget Edittools , update its code to the latest version (≥ April 3, 2020)
- 完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。
Advanced Installation
重要: You must have Extension:小工具 for this to work.
样式
To give the charinsert lists additional styling, wrap the contents of your Edittools between <div class="mw-charinsert-buttons">
and </div>
and add styling for them to your MediaWiki:Common.css.
This site (www.mediawiki.org) does that to make the links appear like buttons (as shown in the screenshot to the side).
The below stylesheet was used for that, copy it to your MediaWiki:Common.css to apply the same styling.
/**
* Styling for links generated by [[MediaWiki:Edittools]]
* @source https://www.mediawiki.org/wiki/Extension:CharInsert#Styling
* @updated 2020-03-17
*/
.mw-charinsert-buttons {
border: 1px solid #aaa;
margin-top: 10px;
padding: 1px;
font-size: 1.1em;
text-align: center;
}
.mw-charinsert-buttons a {
background-color: #cde !important;
color: #000;
border: thin #069 outset;
padding: 0 1px 1px;
font-weight: bold;
font-size: 0.9em;
text-decoration: none;
}
.mw-charinsert-buttons a:hover,
.mw-charinsert-buttons a:active {
background-color: #bcd;
border-style: inset;
}
.client-js .mw-edittools-section {
display: inline;
}
.client-js .mw-edittools-section input[type="button"] {
font-size: 0.9em;
margin-left: 1px;
padding-left: 1px;
padding-right: 1px;
}
Alternatively, you can choose a style closer to the Wikimedia Design Style Guide and the WikimediaUI theme:
/**
* Styling for links generated by [[MediaWiki:Edittools]] in WikimediaUI inspired theme.
* @source https://www.mediawiki.org/wiki/Extension:CharInsert#Styling
* @updated 2020-03-17
*/
.mw-charinsert-buttons {
margin-top: 8px;
border: 1px solid #c8ccd1;
padding: 2px 4px 4px;
font-size: 1.1em;
text-align: center;
}
.mw-charinsert-buttons a {
background-color: #f8f9fa !important;
color: #202122;
border: thin #36c outset;
padding: 0 1px 2px;
font-size: 0.9em;
font-weight: bold;
text-decoration: none;
}
.mw-charinsert-buttons a:hover {
background-color: #fff;
color: #404244;
}
.mw-charinsert-buttons a:active {
background-color: #c8ccd1;
border-style: inset;
}
.client-js .mw-edittools-section {
display: inline;
}
.client-js .mw-edittools-section input[type="button"] {
background-color: #f8f9fa;
color: #202122;
margin-left: 1px;
border-radius: 2px;
padding: 1px 6px;
font-size: 0.9em;
/* Apply pointer cursor to all interactive elements. */
cursor: pointer;
}
.client-js .mw-edittools-section input[type="button"]:hover {
background-color: #fff;
color: #404244;
}
.client-js .mw-edittools-section input[type="button"]:active {
background-color: #c8ccd1;
color: #000;
}
脚本
If you have many CharInsert links, one could use JavaScript to put them in separate groups and allow dynamic switching with a dropdown menu. For example to separate diacritical characters from wikisyntax etc. Several sites (such as mediawiki.org, de.wikipedia.org and en.wikipedia.org) have done this. They all implemented it in different ways though. Documented below is the way it is done on mediawiki.org:
- 1. Wrap all the charinsert tags on MediaWiki:Edittools into a
<div>
container and give it a descriptive, unique, ID (for example "mw-edittools-charinsert"): <div id="mw-edittools-charinsert" class="mw-charinsert-buttons" title="Click on the wanted special character."> ... </div>
- 2. Wrap each individual block of charinserts into
<p>
tags like this: <p class="mw-edittools-section" data-section-title="Wiki-Syntax" style="display: none;"> ... </p>
- 注意:
- Don't change the word 'mw-edittools-section'
- The text behind "data-section-title=" will identify this group in the dropdown menu.
- Make sure there is one group without the '
style="display: none;"
' directive: That will be the default choice in the dropdown menu. On this site, it is called 'Standard' while the other groups are named by the language for which the characters are significant.
- 3. Copy the contents of MediaWiki:Gadget-Edittools.js to an equally named page on your own wiki
- 4. Add the following code to your MediaWiki:Gadgets-definition:
* Edittools[ResourceLoader|default]|Edittools.js
English Wikipedia CharInsert menu
For implementing CharInsert menu like the one used on the English Wikipedia, either export gadgets: Charinsert-core, Charinsert-styles, and Charinsert and then import them on your own wiki through Special:Import or if you want to do it manually, copy the following four interface pages to your wiki:
- MediaWiki:Gadget-charinsert-core.js (Wikipedia) - Main JavaScript file.
- MediaWiki:Gadget-charinsert-styles.css (Wikipedia) - Creates surrounding boxes around the symbols/characters giving them the look of buttons.
- MediaWiki:Gadget-charinsert.js (Wikipedia) - CharInsert loader.
- MediaWiki:Gadget-charinsert (Wikipedia) - For the text shown in user preferences' gadgets section.
- In your MediaWiki:Gadgets-definition, add the following definitions:
* charinsert[ResourceLoader|default|peers=charinsert-styles]|charinsert.js * charinsert-core[ResourceLoader|hidden|dependencies=jquery.textSelection,user,mediawiki.storage]|charinsert-core.js * charinsert-styles[ResourceLoader|hidden|type=styles]|charinsert-styles.css
- MediaWiki:Edittools (Wikipedia) - Only for users with JavaScript turned off or unsupported (which disables the WikiEditor extension too), therefore not really necessary or useful either. It only shows symbols/characters as simple text below the editor window, which can then be copy-pasted and thus be of some help to editors. Apparently, it does not get activated in English Wikipedia for disabled JavaScript.
注意: This particular English Wikipedia character set also contains templates, which will need to be defined separately, if they are to be used on your Wiki.
英语维基百科解决方案验证时间:2018年11月6日
此扩展用于一个或多个维基媒体项目。 这可能意味着扩展足够稳定、运作足够良好,可以用在这样的高流量的网站上。 请在维基媒体的CommonSettings.php和InitialiseSettings.php配置文件中查找此扩展的名称以查看哪些网站安装了该扩展。 特定wiki上的已安装的扩展的完整列表位于Special:Version页面。 |
此扩展在以下wiki农场/托管网站和/或软件包中提供: 這不是一份權威名單。 即使某些wiki农场/托管网站和/或软件包未在这里列出,它们也可能提供此扩展。 请检查你的wiki农场/托管网站或软件包以确认提供情况。 |