X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FExternalEdit.php;h=346832538c657ae8f9637d3382df8fbf0f86982a;hb=ce00cb85843a2c89e9a9409fe383aa61e222218f;hp=1c58f442d841358b1356bba391aa1f7b3dad09c0;hpb=087a9f70c5c152b72dc6c539cf64e334a0f2d029;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ExternalEdit.php b/includes/ExternalEdit.php index 1c58f442d8..346832538c 100644 --- a/includes/ExternalEdit.php +++ b/includes/ExternalEdit.php @@ -1,7 +1,10 @@ */ @@ -15,53 +18,114 @@ * and save the modified data back to the server. * */ +class ExternalEdit extends ContextSource { + + /** + * Array of URLs to link to + * @var Array + */ + private $urls; + + /** + * Constructor + * @param $context IContextSource context to use + * @param $urls array + */ + public function __construct( IContextSource $context, array $urls = array() ) { + $this->setContext( $context ); + $this->urls = $urls; + } -class ExternalEdit { + /** + * Check whether external edit or diff should be used. + * + * @param $context IContextSource context to use + * @param $type String can be either 'edit' or 'diff' + * @return Bool + */ + public static function useExternalEngine( IContextSource $context, $type ) { + global $wgUseExternalEditor; - function __construct( $article, $mode ) { - global $wgInputEncoding; - $this->mArticle =& $article; - $this->mTitle =& $article->mTitle; - $this->mCharset = $wgInputEncoding; - $this->mMode = $mode; + if ( !$wgUseExternalEditor ) { + return false; + } + + $pref = $type == 'diff' ? 'externaldiff' : 'externaleditor'; + $request = $context->getRequest(); + + return !$request->getVal( 'internaledit' ) && + ( $context->getUser()->getOption( $pref ) || $request->getVal( 'externaledit' ) ); } - 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 ); - header( "Cache-control: no-cache" ); + /** + * 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 = wfLocalFile( $this->mTitle ); - $url = $image->getFullURL(); - $extension=substr($name, $pos); + $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"; + } } - $special=$wgLang->getNsText(NS_SPECIAL); + + $url = $this->getTitle()->getFullURL( + $this->getRequest()->appendQueryValue( 'internaledit', 1, true ) ); + $control = <<