Automation 在mediaWiki中手动创建分层类别的自动替代方案?

Automation 在mediaWiki中手动创建分层类别的自动替代方案?,automation,mediawiki,categories,bots,pywikibot,Automation,Mediawiki,Categories,Bots,Pywikibot,我想创建一个基于mediaWiki的网站,但我不想手动添加类别和子类别,而是想以自动化的方式添加它们,在那里我提供了类似xml文件和bot/script/algorithm/。。。浏览列表并自动创建类别和子类别及其页面。 目前还没有页面,但我想从一组干净的类别开始,帮助用户对页面进行排序 我找到了,但我不知道如何将其用于我的目的-它似乎只适用于现有页面的类别。您是否会使用pywikipediabot创建新类别的层次结构?如果是,如何使用?xml文件可以用作模板吗?我找到了一个解决方案,解决了我最

我想创建一个基于mediaWiki的网站,但我不想手动添加类别和子类别,而是想以自动化的方式添加它们,在那里我提供了类似xml文件和bot/script/algorithm/。。。浏览列表并自动创建类别和子类别及其页面。 目前还没有页面,但我想从一组干净的类别开始,帮助用户对页面进行排序


我找到了,但我不知道如何将其用于我的目的-它似乎只适用于现有页面的类别。您是否会使用pywikipediabot创建新类别的层次结构?如果是,如何使用?xml文件可以用作模板吗?

我找到了一个解决方案,解决了我最初批量创建类别的问题,但是我没有将问题标记为已结束,如果您知道更好的解决方案,请发布

MediaWiki具有导入功能。使用您的管理员帐户转到

http://yourMediaWiki/index.php/Special:Import
这允许您选择导入必须遵循特定结构的xml文件:请参阅

对于名称为“Test category”且文本为“category Testing”的类别,您必须创建如下“page”元素:

<page>
<title>Category:Test Category</title> <!-- Name of the category, don't forget to prefix with 'Categroy:' -->
<ns>14</ns> <!-- 14 is the namespace of categories -->
<id>n</id> <!-- identifier for category -->
<revision>
  <id>16</id> <!-- number of revision -->
  <timestamp>2013-02-10T22:07:46Z</timestamp> <!-- Creation date & time -->
  <contributor>
    <username>admin</username> <!-- Name of user who created the category -->
    <id>1</id> <!-- ID of the user -->
  </contributor>
  <comment></comment> <!-- Comment about the category. Can be left blank -->
  <sha1></sha1> <!-- sha1 hash can be left blank -->
  <text xml:space="preserve" bytes="1">Category Testing</text> <!-- It seems it doesn't matter what you write into the bytes attribute. -->
</revision>
</page>
<text xml:space="preserve" bytes="1">Category Testing [[Category:Parent Category]]</text>

类别:测试类别
14
N
16
2013-02-10T22:07:46Z
管理
1.
类别测试
如果要创建类别的层次结构,只需将父类别标记添加到文本元素中。假设类别应为“父类别”类别的一部分,则文本元素应如下所示:

<page>
<title>Category:Test Category</title> <!-- Name of the category, don't forget to prefix with 'Categroy:' -->
<ns>14</ns> <!-- 14 is the namespace of categories -->
<id>n</id> <!-- identifier for category -->
<revision>
  <id>16</id> <!-- number of revision -->
  <timestamp>2013-02-10T22:07:46Z</timestamp> <!-- Creation date & time -->
  <contributor>
    <username>admin</username> <!-- Name of user who created the category -->
    <id>1</id> <!-- ID of the user -->
  </contributor>
  <comment></comment> <!-- Comment about the category. Can be left blank -->
  <sha1></sha1> <!-- sha1 hash can be left blank -->
  <text xml:space="preserve" bytes="1">Category Testing</text> <!-- It seems it doesn't matter what you write into the bytes attribute. -->
</revision>
</page>
<text xml:space="preserve" bytes="1">Category Testing [[Category:Parent Category]]</text>
类别测试[[类别:父类别]]

如果您能够启动并运行pywikibot,则可以使用its类别

Mediawiki中的类别基本上是标准页面,但在名称空间14中。要在页面的wikitext中包含类别中的任何页面(包括属于类别的页面),请包含
[[Category:]

所以你可以这样做

>>> import pywikibot as pwb
#Your site will be different than this
>>> testwiki = pwb.Site('en','test')
>>> catA = pwb.Category(testwiki, 'testCatA')
>>> catA.namespace()
14
>>> catA._text = u'[[Category:testCatB]]'
>>> catA.save()
Page [[test:Category:TestCatA]] saved

现在您有了一个页面
Category:TestCatA
,它是
Category:TestCatB

的子类别。您可以包括您尝试使用的代码吗?我没有让pywikipediabot连接,但我通过一个不相关的机制找到了解决我最初问题的好方法。见下文。