2016-02-03 65 views
0

我可以通過在LocalSettings.php中使用$ wgDefaultSkin來設置mediawiki中所有頁面的默認外觀。但是,我想要做的是更改特定單個頁面的皮膚。爲mediawiki中的單個頁面設置默認外觀

例如,我想將特定單個頁面的皮膚設置爲「小雞」,同時將所有其他頁面的默認皮膚設置爲「矢量」。

這可能嗎?

回答

0

默認情況下,這是不可能的。 MediaWiki支持爲所有頁面設置默認外觀。此外,任何用戶都可以更改首選項中所有頁面的外觀。用不同的外觀不同的頁面聽起來對用戶來說非常混亂,順便說一句。

但是,您可以使用SkinPerPage extension以維基可配置方式實現此目的;或者SkinPerNamespace extension,它的功能相同,但每個名稱空間(如名稱所示;))。此外,通過一些開發時間,您可以在wiki-sysadmin(使用LocalSettings.php設置)可配置方式(因此用戶無法使用解析器函數更改皮膚首選項)中實現此目的。例如。你可以使用RequestContextCreateSkin hookcreate 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開發者尚未實現此功能的原因仍然存在))。