0

我目前正在使用Extension:Push将文章从一个 MediaWiki (1.16) 安装(位于本地 Intranet 中且无法从外部访问)复制到另一个。但是,Push 只能通过让远程 MediaWiki 下载文件来复制文件,这在这种情况下是不可能的(由于某种原因,无法从外部访问 Intranet wiki)。

所以,我需要一些方法来直接绑定到 MediaWiki 的 Upload API。我目前的尝试如下:

$header = 'Content-Type: multipart/form-data; boundary='.$multipart_boundary.'\r\n'.
          'Cookie: '.$cookies;
$file_contents = file_get_contents ($imagePage->getDisplayedFile()->getFullUrl());
$content = "--".$multipart_boundary.'\r\n'.
           'Content-Disposition: form-data; name="file"; filename="'.basename($imagePage->getDisplayedFile()->getFullUrl()).'"\r\n'.
           'Content-Type: application/octet-stream\r\n\r\n'.
           $file_contents.'\r\n'.
           '--'.$multipart_boundary.'\r\n'.
           'Content-Disposition: form-data; name="action"\r\n\r\n'.
           'upload\r\n'.
           '--'.$multipart_boundary.'\r\n'.
           'Content-Disposition: form-data; name="format"\r\n\r\n'.
           'json\r\n'.
           '--'.$multipart_boundary.'\r\n'.
           'Content-Disposition: form-data; name="ignorewarnings"\r\n\r\n'.
           '1\r\n'.
           '--'.$multipart_boundary.'\r\n'.
           'Content-Disposition: form-data; name="token"\r\n\r\n'.
           $token.'\r\n';

$context = stream_context_create (array (
  'http' => array (
    'method' => 'POST',
    'header' => $header,
    'content' => $content,
    ),  
  )); 

$response = file_get_contents ($target, false, $context);

我没有收到任何错误消息(来自本地或远程 Apache),但文件也没有出现。任何人都知道出了什么问题,有一个可行的解决方案,或者至少可以将我指向相关的 mediawiki 功能,以便我可以在其中添加一些调试日志?

4

2 回答 2

1

我还没有尝试过,但是如果您在远程 Wiki(您知道其 URL)上创建页面,那么它看起来好像在http://www.mediawiki.org/wiki/中描述了这样做的方式API:Edit表示您需要获取一个编辑令牌,然后使用该令牌、您的页面内容等进行发布。您将返回 XML 格式的消息以跟踪成功或失败。

于 2011-02-23T18:56:36.693 回答
-1

好吧,原作者更新了扩展。这解决了问题。

于 2011-03-24T14:47:24.897 回答