创建 MediaWiki 模板以设置页面中的字体颜色

Create a MediaWiki template to set font color in pages

我刚安装了Mediawiki,发现对于新手来说配置起来非常复杂。

作为我的第一个条目,我想更改字体颜色:

{{ font color | green | green text }}

为此,我从维基百科 Special:Export 页面导入了 Template:Font color,但结果仍然没有得到彩色文本,但是:

{{ safesubst:#if:

| {{ safesubst:#if: 
     | {{ safesubst:#ifeq:  | yes
     | [[ {{ safesubst:#if:1|  }}|{{ safesubst:#if:1|  }}]]
     | [[|{{ safesubst:#if:1|  }}]]
     }}
   | {{ safesubst:#if:1|  }}
   }}
| {{ safesubst:#if: 
     | {{ safesubst:#ifeq:  | yes
     | [[ {{ safesubst:#if:1|  green text  }} |{{ safesubst:#if:1|  green text  }}]]
     | [[ {{ safesubst:#if:1|  }} |{{ safesubst:#if:1|  green text  }}]]
   }}
 | {{ safesubst:#if:1|  green text  }}
 }}

}} 

你能帮帮我吗?

MediaWiki 对那些只想拼凑一个 wiki 的新手来说很糟糕。它首先需要大量额外的工作才能变得体面,尤其是在模板方面。

也许您遗漏了 ParserFunctions or Scribunto 这样的扩展名?模板使用其他模板,您是否勾选了方框 "Include templates"?

how to import Wikipedia Templates into your own MediaWiki 上有一篇有用的博客 post。

你最好不要尝试从维基百科导入模板。这些年来它们变得异常复杂,您几乎需要成为 wiki 模板标记方面的专家才能更改任何内容。

相反,我建议您自己制作。它们可以非常简单,并且因为您拥有 wiki,所以您可以轻松添加您自己的自定义 CSS。例如,如果您想要不同颜色的文本,您可以执行以下操作。首先,向您的 MediaWiki:Common.css 页面添加一些规则:

.text-color-green {
  color: green;
}

.text-color-blue {
  color: blue;
}

.text-color-red {
  color: red;
}

然后使用以下内容创建 Template:Font color

<span class="text-color-{{{1}}}">{{{2}}}</span>

然后你可以用{{Font color|green|green text}}制作绿色文字,{{Font color|red|red text}}制作红色文字,等等

在 CSS 中执行此操作而不是使用内联样式可以方便以后更新样式,并且浏览器渲染速度应该更快。

更好的方法是使模板语义化。例如,如果您希望在某些内容获得批准时将文本颜色设置为绿色,您可以将以下内容添加到 MediaWiki:Common.css:

.approved {
  color: green;
}

然后用以下内容创建Template:Approved

<span class="approved">{{{1}}}</span>

然后您可以通过调用{{Approved|some approved text}}来制作批准的文本。然后,将来,如果您决定也需要将所有已批准的文本加粗,您只需将 font-weight: bold; 添加到 approved 样式,所有内容都会更新。