我可以通过在LocalSettings.php中使用$ wgDefaultSkin来设置mediawiki中所有页面的默认外观。但是,我想要做的是更改特定单个页面的皮肤。为mediawiki中的单个页面设置默认外观
例如,我想将特定单个页面的皮肤设置为“小鸡”,同时将所有其他页面的默认皮肤设置为“矢量”。
这可能吗?
我可以通过在LocalSettings.php中使用$ wgDefaultSkin来设置mediawiki中所有页面的默认外观。但是,我想要做的是更改特定单个页面的皮肤。为mediawiki中的单个页面设置默认外观
例如,我想将特定单个页面的皮肤设置为“小鸡”,同时将所有其他页面的默认皮肤设置为“矢量”。
这可能吗?
默认情况下,这是不可能的。 MediaWiki支持为所有页面设置默认外观。此外,任何用户都可以更改首选项中所有页面的外观。用不同的外观不同的页面听起来对用户来说非常混乱,顺便说一句。
但是,您可以使用SkinPerPage extension以维基可配置方式实现此目的;或者SkinPerNamespace extension,它的功能相同,但每个名称空间(如名称所示;))。此外,通过一些开发时间,您可以在wiki-sysadmin(使用LocalSettings.php设置)可配置方式(因此用户无法使用解析器函数更改皮肤首选项)中实现此目的。例如。你可以使用RequestContextCreateSkin
hook的create an extension根据给定的标题更改皮肤。例如: -
<?php
/**
* RequestContextCreateSkin handler. Used to change the skin, based on the given title.
*
* @param IContextSource $context The context, in which this hook was called.
* @param Skin|null|string $skin The Skin object or the skin name, if a skin was
* created already, null if not.
*/
public static function onRequestContextCreateSkin($context, &$skin) {
// get the Config object of your extension to get the configuration we need
$config = ConfigFactory::getDefaultInstance()->makeConfig('your-extension-config');
// that's the Title object of the request, from which this hook was called, mostly the Title
// of the page requested by the user. getPrefixedText() returns the full text of the title, including
// the namespace but without the fragment hash (e.g. Category:TestTitle)
$title = $context->getTitle()->getPrefixedText();
// get the configuration variable $wgFakeExtensionSkinTitleMap, which should be an array map of
// titles to skin names in the following format:
// array(
// 'TestTitle' => 'chick',
// 'TestTitle2' => 'monobook',
//);
$skinTitleMap = $config->get('FakeExtensionSkinTitleMap');
if (!is_array($skinTitleMap)) {
// if the map isn't an array, throw an exception. You could also just log a debug message or do anything else,
// for this example the exception is good enough
throw new InvalidArgumentException(
'$wgFakeExtensionSkinTitleMap needs to be an array, ' . gettype($skinTitleMap) . ' given.');
}
// check, if the current title is configured in our map, which would indicate, that we use our own skin for it
if (isset($skinTitleMap[$title])) {
// set the skin. You could handle the skin object creation here, too, but if you return a string, the caller
// of the RequestContextCreateSkin will handle the creation. Probably it's wise to run Skin::normalizeKey()
// to be sure, that the skin name can be loaded, see the docs for it:
// https://doc.wikimedia.org/mediawiki-core/master/php/classSkin.html#af36919e77cfd51eb35767eb311155077
$skin = $skinTitleMap[$title];
}
}
我希望注释解释了代码,就像你需要了解它:)
然而,就像我前面说的:你应该考虑这种变化的影响。对于用户来说,为他打开的不同标题获得不同的页面外观可能会令人困惑。为每个页面创建一个一致的外观可能更明智(MediaWiki开发者尚未实现此功能的原因仍然存在))。