X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FExternalEdit.php;h=9bdbd6cbf3984f1f51e9012c828aff7770c7522f;hb=e4ea0fa287e3d4324dca6108f6a852390920dbdd;hp=2c26d947abbcc1e1fe8e2547d60ba6daab9cc807;hpb=5d9d464e2140955e7b57dcb4361ddc8b65c42cd1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ExternalEdit.php b/includes/ExternalEdit.php index 2c26d947ab..9bdbd6cbf3 100644 --- a/includes/ExternalEdit.php +++ b/includes/ExternalEdit.php @@ -18,72 +18,110 @@ * and save the modified data back to the server. * */ -class ExternalEdit { - /** - * Title to perform the edit on - * @var Title - */ - private $title; +class ExternalEdit extends ContextSource { /** - * Mode of editing - * @var String + * Array of URLs to link to + * @var Array */ - private $mode; + private $urls; /** * Constructor - * @param $title Title object we're performing the edit on + * @param $context IContextSource context to use * @param $mode String What mode we're using. Only 'file' has any effect */ - public function __construct( $title, $mode ) { - $this->title = $article->getTitle(); - $this->mode = $mode; + public function __construct( IContextSource $context, array $urls = array() ) { + $this->setContext( $context ); + $this->urls = $urls; + } + + /** + * 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; + + 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 edit() { - global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang; - $wgOut->disable(); - header( 'Content-type: application/x-external-editor; charset=utf-8' ); - header( 'Cache-control: no-cache' ); + 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( $this->mode == "file" ) { - $type = "Edit file"; - $image = wfLocalFile( $this->title ); - $url = $image->getFullURL(); - $extension = $image->getExtension(); + if ( count( $this->urls ) ) { + $urls = $this->urls; + $type = "Diff text"; } else { - $type = "Edit text"; - $url = $this->title->getFullURL( - array( 'action' => 'edit', 'internaledit' => 'true' ) ); - # *.wiki file extension is used by some editors for syntax - # highlighting, so we follow that convention - $extension = "wiki"; + if ( $this->getRequest()->getVal( 'mode' ) == 'file' ) { + $type = "Edit file"; + $image = wfLocalFile( $this->getTitle() ); + $urls = array( 'File' => array( + 'Extension' => $image->getExtension(), + 'URL' => $image->getCanonicalURL() + ) ); + } else { + $type = "Edit text"; + # *.wiki file extension is used by some editors for syntax + # highlighting, so we follow that convention + $urls = array( 'File' => array( + 'Extension' => 'wiki', + 'URL' => $this->getTitle()->getCanonicalURL( + array( 'action' => 'edit', 'internaledit' => 'true' ) ) + ) ); + } } - $special = $wgLang->getNsText( NS_SPECIAL ); + + $files = ''; + foreach( $urls as $key => $vars ) { + $files .= "\n[$key]\n"; + foreach( $vars as $varname => $varval ) { + $files .= "$varname=$varval\n"; + } + } + + $url = $this->getTitle()->getFullURL( + $this->getRequest()->appendQueryValue( 'internaledit', 1, true ) ); + $control = <<