配置MW:文章浮动目录
跳到导航
跳到搜索
关于
目标:实现“文章页面中的浮动目录”功能。 效果如:BioHos生命健康创投百科
实现
做过的操作:
- 从 mediawiki.org 导入了:Template:TOC、Template:TOC-nopadding、Template:TOCright。
- (跨wiki前缀写的是“mediawiki.org”不知道对不对。改为“commons”重新上传一次还是不好使)
- 安装扩展“Scribunto”、“TemplateStyles”、“JsonConfig”。
- 修改配置文件:
# by Eijux, 2021/05/16 22:07:01 # To import Template:TOC etc from mediawiki.org. wfLoadExtension( 'Scribunto' ); wfLoadExtension( 'TemplateStyles' ); wfLoadExtension( 'JsonConfig' ); # #$wgJsonConfigEnableLuaSupport = true; # JsonConfig uses a very flexible (and a bit complicated) settings system. Both Commons wiki and all other wikis will need this code block to set up a cross-wiki shareable storage: #$wgJsonConfigModels['Tabular.JsonConfig'] = 'JsonConfig\JCTabularContent'; #$wgJsonConfigs['Tabular.JsonConfig'] = array( # 'namespace' => 486, // === NS_DATA, but the constant is not defined yet # 'nsName' => 'Data', # 'isLocal' => false, # 'pattern' => '/.\.tab$/' #); # Commons wiki will need to specify that data should be stored locally: #$wgJsonConfigs['Tabular.JsonConfig']['store'] = true; # Other wikis will need to set how to access remote data: #$wgJsonConfigs['Tabular.JsonConfig']['remote'] = 'https://commons.wikimedia.org/w/api.php'; if ( $wmgEnableJsonConfigDataMode ) { // Safety: before extension.json, these values were initialized by JsonConfig.php if ( !isset( $wgJsonConfigModels ) ) { $wgJsonConfigModels = []; } if ( !isset( $wgJsonConfigs ) ) { $wgJsonConfigs = []; } $wgJsonConfigEnableLuaSupport = true; // https://www.mediawiki.org/wiki/Extension:JsonConfig#Configuration $wgJsonConfigModels['Tabular.JsonConfig'] = 'JsonConfig\JCTabularContent'; $wgJsonConfigs['Tabular.JsonConfig'] = [ 'namespace' => 486, 'nsName' => 'Data', // page name must end in ".tab", and contain at least one symbol 'pattern' => '/.\.tab$/', 'license' => 'CC0-1.0', 'isLocal' => false, ]; $wgJsonConfigModels['Map.JsonConfig'] = 'JsonConfig\JCMapDataContent'; $wgJsonConfigs['Map.JsonConfig'] = [ 'namespace' => 486, 'nsName' => 'Data', // page name must end in ".map", and contain at least one symbol 'pattern' => '/.\.map$/', 'license' => 'CC0-1.0', 'isLocal' => false, ]; // Enable Tabular data namespace on Commons - T148745 // Enable Map (GeoJSON) data namespace on Commons - T149548 // TODO: Consider whether this hard-coding to Commons is appropriate if ( $wgDBname === 'commonswiki' ) { // Ensure we have a stable cross-wiki title resolution // See JCSingleton::parseTitle() $wgJsonConfigInterwikiPrefix = "meta"; $wgJsonConfigs['Tabular.JsonConfig']['store'] = true; $wgJsonConfigs['Map.JsonConfig']['store'] = true; } else { $wgJsonConfigInterwikiPrefix = "commons"; $wgJsonConfigs['Tabular.JsonConfig']['remote'] = [ 'url' => 'https://commons.wikimedia.org/w/api.php' ]; $wgJsonConfigs['Map.JsonConfig']['remote'] = [ 'url' => 'https://commons.wikimedia.org/w/api.php' ]; } } # Scribunto Configuration $wgScribuntoDefaultEngine = 'luastandalone'; # Integrating extensions: Then in your LocalSettings.php after all the extension registrations, add: $wgScribuntoUseGeSHi = true; $wgScribuntoUseCodeEditor = true;
备注
- 【2021/05/17 02:38:48】但还没弄好,好像是“JsonConfig”的配置有问题,相关模板页错误:
- 网上类似问题链接:
- 【2021/12/21 12:29:13】要实现对应效果,应该考虑修改 MediaWiki:Common.js、MediaWiki:Common.css(应用于全局的 js、css。或者是其他作用域的 js、css)。
- 参考:
- “萌娘百科”的浮动目录效果(右侧有可折叠的浮动目录)
- “萌娘百科”由用户:850710247liu设计的浮动目录效果(没找到如何加载使用的)
- “维基百科:用户工具#辅助阅读”其中“浮动目录”的“站外源代码”就是“萌娘百科”给出的使用源。(不知道如何使用)