Gergő Tisza has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376486 )

Change subject: Add ElectronVirtualRestService class
......................................................................

Add ElectronVirtualRestService class

Bug: T171838
Change-Id: Id15af95f448f740b976ee8fb4da781c0a3132e68
---
M autoload.php
A includes/libs/virtualrest/ElectronVirtualRestService.php
2 files changed, 81 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/86/376486/1

diff --git a/autoload.php b/autoload.php
index c7f13d5..b86c462 100644
--- a/autoload.php
+++ b/autoload.php
@@ -423,6 +423,7 @@
        'EditPage' => __DIR__ . '/includes/EditPage.php',
        'EditWatchlistCheckboxSeriesField' => __DIR__ . 
'/includes/specials/SpecialEditWatchlist.php',
        'EditWatchlistNormalHTMLForm' => __DIR__ . 
'/includes/specials/SpecialEditWatchlist.php',
+       'ElectronVirtualRestService' => __DIR__ . 
'/includes/libs/virtualrest/ElectronVirtualRestService.php',
        'EmailConfirmation' => __DIR__ . 
'/includes/specials/SpecialConfirmemail.php',
        'EmailInvalidation' => __DIR__ . 
'/includes/specials/SpecialEmailInvalidate.php',
        'EmailNotification' => __DIR__ . '/includes/mail/EmailNotification.php',
diff --git a/includes/libs/virtualrest/ElectronVirtualRestService.php 
b/includes/libs/virtualrest/ElectronVirtualRestService.php
new file mode 100644
index 0000000..5da68da
--- /dev/null
+++ b/includes/libs/virtualrest/ElectronVirtualRestService.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Virtual REST service for Electron
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/**
+ * Virtual REST service for Electron
+ * @since 1.30
+ */
+class ElectronVirtualRestService extends VirtualRESTService {
+       /**
+        * Example Electron requests:
+        *  GET /pdf/{$URL}
+        *  POST /pdf
+        *    (with the HTML as the POST body)
+        *
+        * @param array $params Key/value map
+        *   - url            : Electron server URL
+        *   - options        : Electron options, see 
https://github.com/wikimedia/mediawiki-services-electron-render#get-pdf---render-pdf
+        *   - timeout        : Request timeout (optional)
+        *   - HTTPProxy      : Use HTTP proxy (optional)
+        */
+       public function __construct( array $params ) {
+               // set up defaults and merge them with the given params
+               $mparams = array_merge( [
+                       'name' => 'electron',
+                       'url' => 'http://localhost:3000/',
+                       'options' => [],
+                       'forwardCookies' => false,
+                       'timeout' => null,
+                       'HTTPProxy' => null,
+               ], $params );
+               $mparams['options'] = array_merge( [
+                       'accessKey' => 'secret',
+               ], $mparams['options'] );
+               // Ensure that the url parameter has a trailing slash.
+               if ( substr( $mparams['url'], -1 ) !== '/' ) {
+                       $mparams['url'] .= '/';
+               }
+               parent::__construct( $mparams );
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function onRequests( array $reqs, Closure $idGeneratorFunc ) {
+               $result = [];
+               foreach ( $reqs as $key => $req ) {
+                       $req['url'] = $this->params['url'] . $req['url'];
+                       if ( $this->params['options'] ) {
+                               $parts = wfParseUrl( $req['url'] );
+                               $parts['query'] += $this->params['options'];
+                               $req['url'] = wfAssembleUrl( $parts );
+                       }
+                       if ( $this->params['timeout'] != null ) {
+                               $req['reqTimeout'] = $this->params['timeout'];
+                       }
+                       if ( $this->params['HTTPProxy'] ) {
+                               $req['proxy'] = $this->params['HTTPProxy'];
+                       }
+                       $result[$key] = $req;
+               }
+               return $result;
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/376486
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id15af95f448f740b976ee8fb4da781c0a3132e68
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to