MediaWiki  REL1_19
ExternalEdit.php
Go to the documentation of this file.
00001 <?php
00021 class ExternalEdit extends ContextSource {
00022 
00027         private $urls;
00028 
00034         public function __construct( IContextSource $context, array $urls = array() ) {
00035                 $this->setContext( $context );
00036                 $this->urls = $urls;
00037         }
00038 
00046         public static function useExternalEngine( IContextSource $context, $type ) {
00047                 global $wgUseExternalEditor;
00048 
00049                 if ( !$wgUseExternalEditor ) {
00050                         return false;
00051                 }
00052 
00053                 $pref = $type == 'diff' ? 'externaldiff' : 'externaleditor';
00054                 $request = $context->getRequest();
00055 
00056                 return !$request->getVal( 'internaledit' ) &&
00057                         ( $context->getUser()->getOption( $pref ) || $request->getVal( 'externaledit' ) );
00058         }
00059 
00063         public function execute() {
00064                 global $wgContLang, $wgScript, $wgScriptPath, $wgCanonicalServer;
00065 
00066                 $this->getOutput()->disable();
00067 
00068                 $response = $this->getRequest()->response();
00069                 $response->header( 'Content-type: application/x-external-editor; charset=utf-8' );
00070                 $response->header( 'Cache-control: no-cache' );
00071 
00072                 $special = $wgContLang->getNsText( NS_SPECIAL );
00073 
00074                 # $type can be "Edit text", "Edit file" or "Diff text" at the moment
00075                 # See the protocol specifications at [[m:Help:External editors/Tech]] for
00076                 # details.
00077                 if ( count( $this->urls ) ) {
00078                         $urls = $this->urls;
00079                         $type = "Diff text";
00080                 } elseif ( $this->getRequest()->getVal( 'mode' ) == 'file' ) {
00081                         $type = "Edit file";
00082                         $image = wfLocalFile( $this->getTitle() );
00083                         $urls = array( 'File' => array(
00084                                 'Extension' => $image->getExtension(),
00085                                 'URL' => $image->getCanonicalURL()
00086                         ) );
00087                 } else {
00088                         $type = "Edit text";
00089                         # *.wiki file extension is used by some editors for syntax
00090                         # highlighting, so we follow that convention
00091                         $urls = array( 'File' => array(
00092                                 'Extension' => 'wiki',
00093                                 'URL' => $this->getTitle()->getCanonicalURL(
00094                                         array( 'action' => 'edit', 'internaledit' => 'true' ) )
00095                         ) );
00096                 }
00097 
00098                 $files = '';
00099                 foreach( $urls as $key => $vars ) {
00100                         $files .= "\n[$key]\n";
00101                         foreach( $vars as $varname => $varval ) {
00102                                 $files .= "$varname=$varval\n";
00103                         }
00104                 }
00105 
00106                 $url = $this->getTitle()->getFullURL(
00107                         $this->getRequest()->appendQueryValue( 'internaledit', 1, true ) );
00108 
00109                 $control = <<<CONTROL
00110 ; You're seeing this file because you're using Mediawiki's External Editor feature.
00111 ; This is probably because you selected use external editor in your preferences.
00112 ; To edit normally, either disable that preference or go to the URL:
00113 ; $url
00114 ; See http://www.mediawiki.org/wiki/Manual:External_editors for details.
00115 [Process]
00116 Type=$type
00117 Engine=MediaWiki
00118 Script={$wgCanonicalServer}{$wgScript}
00119 Server={$wgCanonicalServer}
00120 Path={$wgScriptPath}
00121 Special namespace=$special
00122 $files
00123 CONTROL;
00124                 echo $control;
00125         }
00126 }