mediawiki / 语义数据导入
0.4.0
2018-10-03 13:47 UTC
Requires
- php: >=5.6.0
- mediawiki/semantic-media-wiki: ~2.5
This package is auto-updated.
Last update: 2024-09-16 07:42:23 UTC
README
通过使用 Semantic MediaWiki 将类似于 CSV 的结构化数据导入 MediaWiki 页面的扩展。
它基本上将 CSV 行转换为 Semantic Subobjects。
基本用法
内容可以直接保存到 wikitext 页面(仅适用于较旧的维基)或作为纯 JSON 页面(仅通过特殊页面接口 Special:SDImport
)。
命名空间配置
在撰写本文时,CSV 列与 Semantic MediaWiki 属性的映射只能通过在 LocalSettings.php
中配置(自定义或非自定义)命名空间来完成。
# Example NS definition define("NS_SDImport", 2000); $GLOBALS["wgSDImportDataPage"][NS_SDImport] = array(); $GLOBALS["wgSDImportDataPage"][NS_SDImport]["edit"] = false; $GLOBALS["wgSDImportDataPage"][NS_SDImport]["separator"] = "\t"; $GLOBALS["wgSDImportDataPage"][NS_SDImport]["delimiter"] = '"'; $GLOBALS["wgSDImportDataPage"][NS_SDImport]["rowobject"] = "SDImport"; $GLOBALS["wgSDImportDataPage"][NS_SDImport]["rowfields"] = array("Page1", "Page2"); $GLOBALS["wgSDImportDataPage"][NS_SDImport]["typefields"] = array("Page", "Page"); $GLOBALS["wgSDImportDataPage"][NS_SDImport]["ref"] = array("ref" => "{{PAGENAME}}"); $GLOBALS["wgSDImportDataPage"][NS_SDImport]["prefields"] = array( "", "" ); $GLOBALS["wgSDImportDataPage"][NS_SDImport]["postfields"] = array( "", "" ); $GLOBALS["wgSDImportDataPage"][NS_SDImport]["json"] = true; # Whether content is stored directly in JSON $GLOBALS["wgSDImportDataPage"][NS_SDImport]["single"] = false; #Whether to store straight properties-values, but not Subobject (rowobject is ignored) $GLOBALS["wgSDImportDataPage"][NS_SDImport]["form"] = false; #Whether to show a form instead of a spreadsheet (as far as single is true) $wgExtraNamespaces[NS_SDImport] = "SDImport"; $GLOBALS['smwgNamespacesWithSemanticLinks'][NS_SDImport] = true;
SDImport 接口
有一个初步的 SDImport 特殊页面(Special:SDImport
),它简化了内容的上传(尤其是对于 JSON 页面)。
属性需要在命名空间配置中定义。
在撰写本文时
- 第一列:页面名称(在所选命名空间中)
- 其余列,根据行字段值...
JSON 模式
在 JSON 模式中定义的键具有比在命名空间配置中定义的键更高的优先级。
{ "meta": { "app": "SDI", "version": 0.1, "rowobject": "Entry", "rowfields": ["Relation1", "Relation2"] }, "data": [ [ "2", "4" ], [ "2", "5" ] ] }
有用的扩展
如果在 LocalSettings.php 中启用 $GLOBALS["wgSDImportDataPage"][NS_SDImport]["edit"] = true;
,则允许通过类似电子表格的界面修改内容。
但是,我们可能对另一种编辑方式感兴趣。为此,我们建议安装 2 个扩展
$wgDefaultUserOptions['usebetatoolbar'] = 1; // WikiEditor 扩展提供用户选项