* fixed typo
[lhc/web/wiklou.git] / includes / ExternalEdit.php
1 <?php
2 /**
3 * External editors support
4 *
5 * License: Public domain
6 *
7 * @file
8 * @author Erik Moeller <moeller@scireview.de>
9 */
10
11 /**
12 * Support for external editors to modify both text and files
13 * in external applications. It works as follows: MediaWiki
14 * sends a meta-file with the MIME type 'application/x-external-editor'
15 * to the client. The user has to associate that MIME type with
16 * a helper application (a reference implementation in Perl
17 * can be found in extensions/ee), which will launch the editor,
18 * and save the modified data back to the server.
19 *
20 */
21 class ExternalEdit {
22
23 function __construct( $article, $mode ) {
24 $this->mArticle =& $article;
25 $this->mTitle =& $article->mTitle;
26 $this->mCharset = 'UTF-8';
27 $this->mMode = $mode;
28 }
29
30 function edit() {
31 global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang;
32 $wgOut->disable();
33 $name=$this->mTitle->getText();
34 $pos=strrpos($name,".")+1;
35 header ( "Content-type: application/x-external-editor; charset=".$this->mCharset );
36 header( "Cache-control: no-cache" );
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 ; You're seeing this file because you're using Mediawiki's External Editor
56 ; feature. This is probably because you selected use external editor
57 ; in your preferences. To edit normally, either disable that preference
58 ; or go to the URL $url .
59 ; See http://www.mediawiki.org/wiki/Manual:External_editors for details.
60 [Process]
61 Type=$type
62 Engine=MediaWiki
63 Script={$wgServer}{$wgScript}
64 Server={$wgServer}
65 Path={$wgScriptPath}
66 Special namespace=$special
67
68 [File]
69 Extension=$extension
70 URL=$url
71 CONTROL;
72 echo $control;
73 }
74 }