配置MW:文章浮动目录

来自Wikioe
跳到导航 跳到搜索


关于

目标:实现“文章页面中的浮动目录”功能。

效果如:BioHos生命健康创投百科

实现

做过的操作:

  1. 从 mediawiki.org 导入了:Template:TOCTemplate:TOC-nopaddingTemplate:TOCright
    • (跨wiki前缀写的是“mediawiki.org”不知道对不对。改为“commons”重新上传一次还是不好使)
  2. 安装扩展“Scribunto”、“TemplateStyles”、“JsonConfig”。
  3. 修改配置文件:
    # 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;
    

备注