From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- includes/ExternalEdit.php | 104 +++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 34 deletions(-) (limited to 'includes/ExternalEdit.php') diff --git a/includes/ExternalEdit.php b/includes/ExternalEdit.php index bf97c1a5..b8704758 100644 --- a/includes/ExternalEdit.php +++ b/includes/ExternalEdit.php @@ -18,60 +18,99 @@ * and save the modified data back to the server. * */ -class ExternalEdit { +class ExternalEdit extends ContextSource { + /** - * Title to perform the edit on - * @var Title + * Array of URLs to link to + * @var Array */ - private $title; + private $urls; /** - * Mode of editing - * @var String + * Constructor + * @param $context IContextSource context to use + * @param $urls array */ - private $mode; + public function __construct( IContextSource $context, array $urls = array() ) { + $this->setContext( $context ); + $this->urls = $urls; + } /** - * Constructor - * @param $title Title object we're performing the edit on - * @param $mode String What mode we're using. Only 'file' has any effect + * 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 function __construct( $title, $mode ) { - $this->title = $title; - $this->mode = $mode; + 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, $wgCanonicalServer, $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" ) { + if ( count( $this->urls ) ) { + $urls = $this->urls; + $type = "Diff text"; + } elseif ( $this->getRequest()->getVal( 'mode' ) == 'file' ) { $type = "Edit file"; - $image = wfLocalFile( $this->title ); - $url = $image->getCanonicalURL(); - $extension = $image->getExtension(); + $image = wfLocalFile( $this->getTitle() ); + $urls = array( 'File' => array( + 'Extension' => $image->getExtension(), + 'URL' => $image->getCanonicalURL() + ) ); } else { $type = "Edit text"; - $url = $this->title->getCanonicalURL( - array( 'action' => 'edit', 'internaledit' => 'true' ) ); # *.wiki file extension is used by some editors for syntax # highlighting, so we follow that convention - $extension = "wiki"; + $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 = <<