【发布时间】:2016-02-03 13:26:44
【问题描述】:
我可以使用 LocalSettings.php 中的 $wgDefaultSkin 为 mediawiki 中的所有页面设置默认皮肤。但是,我想做的是更改特定页面的皮肤。
例如,我想将特定页面的皮肤设置为“chick”,而将所有其他页面的默认皮肤设置为“vector”。
这可能吗?
【问题讨论】:
标签: mediawiki
我可以使用 LocalSettings.php 中的 $wgDefaultSkin 为 mediawiki 中的所有页面设置默认皮肤。但是,我想做的是更改特定页面的皮肤。
例如,我想将特定页面的皮肤设置为“chick”,而将所有其他页面的默认皮肤设置为“vector”。
这可能吗?
【问题讨论】:
标签: 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];
}
}
我希望 cmets 尽可能多地解释代码:)
但是,正如我之前所说:您应该考虑这种变化的影响。用户打开不同的标题获得不同的页面外观可能会非常令人困惑。为每个页面设置一致的皮肤可能更明智(MediaWiki 开发人员尚未实现这样的功能是有原因的;))。
【讨论】: