X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FExternalEdit.php;h=11e942308c2b491c73cb431bf26814c8f6519a18;hb=893ff1ed77d6f0f3deba85ba240a74e16ed8cd02;hp=02f14c3241d488cfdd88f8d029667a46347b40ff;hpb=7bbe971aec2d548de981a12ed08a7b56a536dcdb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ExternalEdit.php b/includes/ExternalEdit.php index 02f14c3241..11e942308c 100644 --- a/includes/ExternalEdit.php +++ b/includes/ExternalEdit.php @@ -1,15 +1,14 @@ - * @package MediaWiki */ /** - * - * @package MediaWiki - * * Support for external editors to modify both text and files * in external applications. It works as follows: MediaWiki * sends a meta-file with the MIME type 'application/x-external-editor' @@ -19,59 +18,115 @@ * and save the modified data back to the server. * */ +class ExternalEdit extends ContextSource { -class ExternalEdit { + /** + * Array of URLs to link to + * @var Array + */ + private $urls; - function ExternalEdit ( $article, $mode ) { - global $wgInputEncoding; - $this->mArticle =& $article; - $this->mTitle =& $article->mTitle; - $this->mCharset = $wgInputEncoding; - $this->mMode = $mode; + /** + * Constructor + * @param $context IContextSource context to use + * @param $urls array + */ + public function __construct( IContextSource $context, array $urls = array() ) { + $this->setContext( $context ); + $this->urls = $urls; } - - function edit() { - global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang; - $wgOut->disable(); - $name=$this->mTitle->getText(); - $pos=strrpos($name,".")+1; - header ( "Content-type: application/x-external-editor; charset=".$this->mCharset ); - + + /** + * Check whether external edit or diff should be used. + * + * @param $context IContextSource context to use + * @param string $type can be either 'edit' or 'diff' + * @return Bool + */ + public static function useExternalEngine( IContextSource $context, $type ) { + global $wgUseExternalEditor; + + if ( !$wgUseExternalEditor ) { + return false; + } + + $pref = $type == 'diff' ? 'externaldiff' : 'externaleditor'; + $request = $context->getRequest(); + + return !$request->getVal( 'internaledit' ) && + ( $context->getUser()->getOption( $pref ) || $request->getVal( 'externaledit' ) ); + } + + /** + * Output the information for the external editor + */ + public function execute() { + global $wgContLang, $wgScript, $wgScriptPath, $wgCanonicalServer; + + $this->getOutput()->disable(); + + $response = $this->getRequest()->response(); + $response->header( 'Content-type: application/x-external-editor; charset=utf-8' ); + $response->header( 'Cache-control: no-cache' ); + + $special = $wgContLang->getNsText( NS_SPECIAL ); + # $type can be "Edit text", "Edit file" or "Diff text" at the moment # See the protocol specifications at [[m:Help:External editors/Tech]] for # details. - if(!isset($this->mMode)) { - $type="Edit text"; - $url=$this->mTitle->getFullURL("action=edit&internaledit=true"); + if ( count( $this->urls ) ) { + $urls = $this->urls; + $type = "Diff text"; + } elseif ( $this->getRequest()->getVal( 'mode' ) == 'file' ) { + $type = "Edit file"; + $image = wfLocalFile( $this->getTitle() ); + if ( $image ) { + $urls = array( + 'File' => array( + 'Extension' => $image->getExtension(), + 'URL' => $image->getCanonicalURL() + ) + ); + } else { + $urls = array(); + } + } else { + $type = "Edit text"; # *.wiki file extension is used by some editors for syntax # highlighting, so we follow that convention - $extension="wiki"; - } elseif($this->mMode=="file") { - $type="Edit file"; - $image = Image::newFromTitle( $this->mTitle ); - $img_url = $image->getURL(); - if(strpos($img_url,"://")) { - $url = $img_url; - } else { - $url = $wgServer . $img_url; + $urls = array( 'File' => array( + 'Extension' => 'wiki', + 'URL' => $this->getTitle()->getCanonicalURL( + array( 'action' => 'edit', 'internaledit' => 'true' ) ) + ) ); + } + + $files = ''; + foreach( $urls as $key => $vars ) { + $files .= "\n[$key]\n"; + foreach( $vars as $varname => $varval ) { + $files .= "$varname=$varval\n"; } - $extension=substr($name, $pos); } - $special=$wgLang->getNsText(NS_SPECIAL); + + $url = $this->getTitle()->getFullURL( + $this->getRequest()->appendQueryValue( 'internaledit', 1, true ) ); + $control = <<