Fix for r92187
[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 * Title to perform the edit on
24 * @var Title
25 */
26 private $title;
27
28 /**
29 * Mode of editing
30 * @var String
31 */
32 private $mode;
33
34 /**
35 * Constructor
36 * @param $title Title object we're performing the edit on
37 * @param $mode String What mode we're using. Only 'file' has any effect
38 */
39 public function __construct( $title, $mode ) {
40 $this->title = $title;
41 $this->mode = $mode;
42 }
43
44 /**
45 * Output the information for the external editor
46 */
47 public function edit() {
48 global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang;
49 $wgOut->disable();
50 header( 'Content-type: application/x-external-editor; charset=utf-8' );
51 header( 'Cache-control: no-cache' );
52
53 # $type can be "Edit text", "Edit file" or "Diff text" at the moment
54 # See the protocol specifications at [[m:Help:External editors/Tech]] for
55 # details.
56 if( $this->mode == "file" ) {
57 $type = "Edit file";
58 $image = wfLocalFile( $this->title );
59 $url = $image->getFullURL();
60 $extension = $image->getExtension();
61 } else {
62 $type = "Edit text";
63 $url = $this->title->getFullURL(
64 array( 'action' => 'edit', 'internaledit' => 'true' ) );
65 # *.wiki file extension is used by some editors for syntax
66 # highlighting, so we follow that convention
67 $extension = "wiki";
68 }
69 $special = $wgLang->getNsText( NS_SPECIAL );
70 $control = <<<CONTROL
71 ; You're seeing this file because you're using Mediawiki's External Editor
72 ; feature. This is probably because you selected use external editor
73 ; in your preferences. To edit normally, either disable that preference
74 ; or go to the URL $url .
75 ; See http://www.mediawiki.org/wiki/Manual:External_editors for details.
76 [Process]
77 Type=$type
78 Engine=MediaWiki
79 Script={$wgServer}{$wgScript}
80 Server={$wgServer}
81 Path={$wgScriptPath}
82 Special namespace=$special
83
84 [File]
85 Extension=$extension
86 URL=$url
87 CONTROL;
88 echo $control;
89 }
90 }