MediaWiki
REL1_20
|
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 if ( $image ) { 00084 $urls = array( 00085 'File' => array( 00086 'Extension' => $image->getExtension(), 00087 'URL' => $image->getCanonicalURL() 00088 ) 00089 ); 00090 } else{ 00091 $urls = array(); 00092 } 00093 } else { 00094 $type = "Edit text"; 00095 # *.wiki file extension is used by some editors for syntax 00096 # highlighting, so we follow that convention 00097 $urls = array( 'File' => array( 00098 'Extension' => 'wiki', 00099 'URL' => $this->getTitle()->getCanonicalURL( 00100 array( 'action' => 'edit', 'internaledit' => 'true' ) ) 00101 ) ); 00102 } 00103 00104 $files = ''; 00105 foreach( $urls as $key => $vars ) { 00106 $files .= "\n[$key]\n"; 00107 foreach( $vars as $varname => $varval ) { 00108 $files .= "$varname=$varval\n"; 00109 } 00110 } 00111 00112 $url = $this->getTitle()->getFullURL( 00113 $this->getRequest()->appendQueryValue( 'internaledit', 1, true ) ); 00114 00115 $control = <<<CONTROL 00116 ; You're seeing this file because you're using Mediawiki's External Editor feature. 00117 ; This is probably because you selected use external editor in your preferences. 00118 ; To edit normally, either disable that preference or go to the URL: 00119 ; $url 00120 ; See http://www.mediawiki.org/wiki/Manual:External_editors for details. 00121 [Process] 00122 Type=$type 00123 Engine=MediaWiki 00124 Script={$wgCanonicalServer}{$wgScript} 00125 Server={$wgCanonicalServer} 00126 Path={$wgScriptPath} 00127 Special namespace=$special 00128 $files 00129 CONTROL; 00130 echo $control; 00131 } 00132 }