首页 > 解决方案 > 如何防止 MediaWiki 中#if 条件内的图像“隐藏”链接

问题描述

我们有一个图像,它的文件名中有一个可预测的数字。我根据数字是否在多个不同范围内来处理模板中图像的显示。如果它在任何这些范围内,则图像不(也不应该)存在。

一切正常,但我发现 Special:WantedFiles 仍然包含故意“丢失”图像的列表。每个“缺失”文件的唯一链接来自使用该模板的页面。看起来,即使页面没有正确地尝试显示图像,wiki 仍然在解释[[File:foobar]] 位,好像#if 测试正在以另一种方式解决,创建一个未使用的链接到一个不存在的文件。

以下是模板问题部分的简化版。ImageRangeTest 是范围检查模板;它工作正常,根据 {{{1}}} 数字是否在任何匹配范围内返回 0 或 1。

{{#ifeq: {{ImageRangeTest | {{{1}}} }} | 1 | This image does not exist. | [[File:{{{1}}}.png]] }}

那么,为什么当 ImageRangeTest 返回 1 时,“此图像不存在”。正确显示,但 File:{{{1}}}.png 仍然从同一页面获得隐藏链接,导致 File:{{{1}}}.png 显示在 Special:WantedFiles?

标签: templatesmediawiki

解决方案


What you want do is not possible currently. It's a 'hidden' link to you, but a normal link to the database. The table storing file inclusions does not differentiate on whether the image exists or not. Special:WantedFiles generates its content by querying that table among others.

Various requests to change this were declined as per back as 2006, such as this and this. Not the request were mostly about general links generated from templates but the underlying problem/issue is the samae as yours.

The only way to stop it from showing in that special page is to delink the name, that's to remove the square brackets, and I doubt if you'd like that.


推荐阅读