如何通过脚本创建、阅读、更新和删除 Mediawiki 文章? [英] How can I create, read, update and delete Mediawiki articles via scripts?
问题描述
目前我正在尝试找出在 wiki 页面上执行 CRUD 操作的最简单方法(使用 PHP).
Currently I'm trying to figure out what's the easiest way to perform CRUD operations on wiki pages (using PHP).
我已经构建了一个媒体 wiki 扩展,可以在其中上传文件并解析其内容.根据内容,需要创建或更新相应的 wiki 文章.
I've built an media wiki extension where it's possible to upload a file and parse its content. Depending on the content it is necessary to either create or update the respective wiki articles.
问题是我是否已经有一些不错的实现(或最佳实践)可以使用,或者我是否必须从头开始使用 wiki api.
The question is if there are already some nice implementations (or best practices) which I might use or if I have to start from scratch with the wiki api.
推荐答案
好的,这比预期容易得多.只需创建一个文章对象并使用 doEdit
函数来创建或编辑页面:
Ok, this was a lot easier than expected. Just create an Article object and use the doEdit
function to create or edit a page:
$newArticle = new Article("Title")
$articleCreated = $newArticle->doEdit('content', 'summary', 'mode')
if ($articleCreated) {
$wgOut->addHTML("success");
}
$mode 是 EDIT_NEW
或 EDIT_UPDATE
.
And $mode is either EDIT_NEW
or EDIT_UPDATE
.
抱歉迟到了,但我不能在 8 小时内回答我自己的问题.
Sorry for the delayed answer, however I wasn't allowed to answer my own questions within 8 hours.
这篇关于如何通过脚本创建、阅读、更新和删除 Mediawiki 文章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!