e1841f5273a0519f314a0136e3cae581638d9a2e
[lhc/web/wiklou.git] / includes / ExternalEdit.php
1 <?php
2 /**
3 * License: Public domain
4 *
5 * @author Erik Moeller <moeller@scireview.de>
6 * @package MediaWiki
7 */
8
9 /**
10 *
11 * @package MediaWiki
12 *
13 * Support for external editors to modify both text and files
14 * in external applications. It works as follows: MediaWiki
15 * sends a meta-file with the MIME type 'application/x-external-editor'
16 * to the client. The user has to associate that MIME type with
17 * a helper application (a reference implementation in Perl
18 * can be found in extensions/ee), which will launch the editor,
19 * and save the modified data back to the server.
20 *
21 */
22
23 class ExternalEdit {
24
25 function __construct( $article, $mode ) {
26 global $wgInputEncoding;
27 $this->mArticle =& $article;
28 $this->mTitle =& $article->mTitle;
29 $this->mCharset = $wgInputEncoding;
30 $this->mMode = $mode;
31 }
32
33 function edit() {
34 global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang;
35 $wgOut->disable();
36 $name=$this->mTitle->getText();
37 $pos=strrpos($name,".")+1;
38 header ( "Content-type: application/x-external-editor; charset=".$this->mCharset );
39
40 # $type can be "Edit text", "Edit file" or "Diff text" at the moment
41 # See the protocol specifications at [[m:Help:External editors/Tech]] for
42 # details.
43 if(!isset($this->mMode)) {
44 $type="Edit text";
45 $url=$this->mTitle->getFullURL("action=edit&internaledit=true");
46 # *.wiki file extension is used by some editors for syntax
47 # highlighting, so we follow that convention
48 $extension="wiki";
49 } elseif($this->mMode=="file") {
50 $type="Edit file";
51 $image = new Image( $this->mTitle );
52 $img_url = $image->getURL();
53 if(strpos($img_url,"://")) {
54 $url = $img_url;
55 } else {
56 $url = $wgServer . $img_url;
57 }
58 $extension=substr($name, $pos);
59 }
60 $special=$wgLang->getNsText(NS_SPECIAL);
61 $control = <<<CONTROL
62 [Process]
63 Type=$type
64 Engine=MediaWiki
65 Script={$wgServer}{$wgScript}
66 Server={$wgServer}
67 Path={$wgScriptPath}
68 Special namespace=$special
69
70 [File]
71 Extension=$extension
72 URL=$url
73 CONTROL;
74 echo $control;
75 }
76 }
77 ?>