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