在mediawiki中为各个页面设置默认外观

时间:2016-02-03 13:26:44

标签: mediawiki

我可以使用LocalSettings.php中的$ wgDefaultSkin为mediawiki中的所有页面设置默认外观。但是,我想要做的是更改特定单个页面的外观。

例如,我想将特定单个页面的外观设置为" chick",同时将所有其他页面的默认外观设置为" vector"。

这可能吗?

1 个答案:

答案 0 :(得分:0)

默认情况下,这是不可能的。 MediaWiki支持为所有页面设置默认外观。此外,任何用户都可以更改首选项中所有页面的外观。使用不同皮肤的不同页面对用户来说听起来很混乱,顺便说一句。

但是,您可以使用SkinPerPage extension以on-wiki可配置方式实现此目的;或SkinPerNamespace extension,它执行相同的操作,但每个命名空间(如名称所示;))。此外,通过一些开发时间,您可以在wiki-sysadmin(使用LocalSettings.php设置)可配置的方式实现此目的(这样您的用户就无法使用解析器功能更改皮肤首选项)。例如。您可以create an extension使用RequestContextCreateSkin hook根据给定的标题更改皮肤。 E.g:

<?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开发者尚未实现这样的功能的原因;);)。