jenkins-bot has submitted this change and it was merged.
Change subject: Adjust to redirect directly to a RESTbase URL
......................................................................
Adjust to redirect directly to a RESTbase URL
Bug: T150427
Change-Id: I3273ca18aaaf97d47f57769c35e8deb133be5073
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M specials/SpecialElectronPdf.php
M tests/browser/features/support/pages/selectionscreen_page.rb
5 files changed, 15 insertions(+), 119 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 75e4b5f..8a98267 100644
--- a/extension.json
+++ b/extension.json
@@ -14,13 +14,7 @@
"SpecialElectronPdf": "specials/SpecialElectronPdf.php"
},
"config": {
- "ElectronPdfService": {
- "serviceUrl":"https://pdf-electron.wmflabs.org",
- "format":"pdf",
- "key":"secret",
- "pageUrl":""
- },
- "ElectronPdfServiceMaxDocumentSize": 1073741824
+ "ElectronPdfServiceRESTbaseURL": "/api/rest_v1/page/pdf/"
},
"ExtensionMessagesFiles": {
"ElectronPdfServiceAlias": "ElectronPdfService.i18n.alias.php"
diff --git a/i18n/en.json b/i18n/en.json
index 95a26c6..17ea04c 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -16,7 +16,5 @@
"electronPdfService-sidebar-portlet-heading": "Print/export",
"electronPdfService-sidebar-portlet-print-text": "Download as PDF",
"electronPdfService-invalid-page-title": "Invalid page",
- "electronPdfService-invalid-page-text": "The specified page is not
valid.",
- "electronPdfService-page-notfound-title": "Page not found by service",
- "electronPdfService-page-notfound-text": "The service was not able to
resolve the specified link."
+ "electronPdfService-invalid-page-text": "The specified page is not
valid."
}
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 6e7c3c6..c328165 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -19,7 +19,5 @@
"electronPdfService-sidebar-portlet-heading": "Title of the portlet in
which the link is shown.\n\n{{Identical|Print/Export}}",
"electronPdfService-sidebar-portlet-print-text": "Text of
print-pdf-link in sidebar.",
"electronPdfService-invalid-page-title": "Used as title for the error
message when specified page was not a valid article.",
- "electronPdfService-invalid-page-text": "Used as error message when
specified page was not a valid article.",
- "electronPdfService-page-notfound-title": "Used as title for the error
message when Electron service was not able to resolve the given URL to the
article.",
- "electronPdfService-page-notfound-text": "Used as error message when
Electron service was not able to resolve the given URL to the article."
+ "electronPdfService-invalid-page-text": "Used as error message when
specified page was not a valid article."
}
diff --git a/specials/SpecialElectronPdf.php b/specials/SpecialElectronPdf.php
index 8c5797f..e16b070 100644
--- a/specials/SpecialElectronPdf.php
+++ b/specials/SpecialElectronPdf.php
@@ -9,19 +9,6 @@
use MediaWiki\MediaWikiServices;
class SpecialElectronPdf extends SpecialPage {
- /**
- * @var $tempFileHandle
- *
- * Temporary file the PDF will be written to
- */
- public $tempFileHandle;
-
- /**
- * @var int $totalBytesWritten
- *
- * Variable to keep track of total number of bytes written to the
temporary file
- */
- public $totalBytesWritten;
/**
* @var Config $config
@@ -58,8 +45,8 @@
$stats->increment( 'electronpdf.action.' . $action );
switch ( $action ) {
- case 'download-electron-pdf':
- $this->renderAndShowPdf( $title );
+ case 'redirect-to-electron':
+ $this->redirectToElectron( $title );
return;
case 'redirect-to-collection':
$this->redirectToCollection(
$collectionDownloadUrl );
@@ -95,7 +82,7 @@
( new OOUI\Tag() )
->addClasses( [
'mw-electronPdfService-selection-body' ] )
->appendContent(
- $this->getLabeledOptionField(
'download-electron-pdf', 'single', true ),
+ $this->getLabeledOptionField(
'redirect-to-electron', 'single', true ),
$this->getLabeledOptionField(
'redirect-to-collection', 'two' ),
$this->getHiddenField( 'page',
$title->getText() ),
$this->getHiddenField(
'coll-download-url', $collectionDownloadUrl ),
@@ -164,67 +151,6 @@
return $element;
}
- /**
- * @param Title $title page to download as PDF
- */
- public function renderAndShowPdf( Title $title ) {
- if ( !$this->getRequest()->checkUrlExtension() ) {
- $this->getOutput()->showErrorPage(
- 'electronPdfService-page-notfound-title',
- 'electronPdfService-page-notfound-text'
- );
- return;
- }
- $tempFile = TempFSFile::factory( 'electron_', 'pdf' );
- $this->tempFileHandle = fopen( $tempFile->getPath(), 'w+' );
- $this->totalBytesWritten = 0;
-
- $request = MWHttpRequest::factory( $this->constructServiceUrl(
$title ) );
- $request->setCallback( [ $this, 'writeToTempFile' ] );
-
- if ( $request->execute()->isOK() ) {
- $this->sendPdfToOutput( $title->getPrefixedText() );
- } else {
- $this->getOutput()->showErrorPage(
- 'electronPdfService-page-notfound-title',
- 'electronPdfService-page-notfound-text'
- );
- }
-
- fclose( $this->tempFileHandle );
- $tempFile->purge();
- return;
- }
-
- /**
- * Callback used by the MWHttpRequest to the Electron service writing
the result into a file
- * If writing fails or the $maxDocumentSize is reached it returns -1 to
abort the HTTP fetch.
- *
- * @param resource $res
- * @param string $content
- * @return int
- */
- public function writeToTempFile( $res, $content ) {
- $maxDocumentSize = $this->config->get(
'ElectronPdfServiceMaxDocumentSize' );
- $bytes = fwrite(
- $this->tempFileHandle,
- $content,
- $maxDocumentSize - $this->totalBytesWritten + 1
- );
-
- if ( $bytes === false ) {
- return -1;
- }
-
- $this->totalBytesWritten += $bytes;
-
- if ( $this->totalBytesWritten > $maxDocumentSize ) {
- return -1;
- }
-
- return $bytes;
- }
-
public function setHeaders() {
parent::setHeaders();
$this->addModules();
@@ -244,39 +170,19 @@
* @param Title $title
* @return string
*/
- private function constructServiceUrl( Title $title ) {
- $electronPdfService = $this->config->get( 'ElectronPdfService'
);
+ private function getServiceUrl( Title $title ) {
+ $restBaseUrl = $this->config->get(
'ElectronPdfServiceRESTbaseURL' );
- // for testing the functionality on localhost please set
- // $wgElectronPdfService["pageUrl"] to a publicly accessible
URL in your LocalSettings.php!
- if ( !isset( $electronPdfService["pageUrl"] ) ) {
- $pageUrl = $title->getCanonicalURL();
- } else {
- $pageUrl = $electronPdfService["pageUrl"];
- }
- $serviceUrl =
- $electronPdfService["serviceUrl"] . '/' .
- $electronPdfService["format"] .
- '?accessKey=' . $electronPdfService["key"] .
- '&url=' . urlencode( $pageUrl );
-
- return $serviceUrl;
+ return $restBaseUrl . urlencode( $title->getPrefixedText() );
}
/**
- * @param string $page
+ * @param Title $title
*/
- private function sendPdfToOutput( $page ) {
- $fileMetaData = stream_get_meta_data( $this->tempFileHandle );
- $contentDisposition = FileBackend::makeContentDisposition(
'inline', $page . '.pdf' );
-
- $headers = [
- 'Content-Type:application/pdf',
- 'Content-Length: ' . filesize( $fileMetaData['uri'] ),
- 'Content-Disposition: ' . $contentDisposition
- ];
-
- StreamFile::stream( $fileMetaData['uri'], $headers );
+ private function redirectToElectron( Title $title ) {
+ $this->getOutput()->redirect(
+ $this->getServiceUrl( $title )
+ );
}
/**
diff --git a/tests/browser/features/support/pages/selectionscreen_page.rb
b/tests/browser/features/support/pages/selectionscreen_page.rb
index 7f9f5b3..d2a1be0 100644
--- a/tests/browser/features/support/pages/selectionscreen_page.rb
+++ b/tests/browser/features/support/pages/selectionscreen_page.rb
@@ -2,7 +2,7 @@
include PageObject
div(:selectionscreen_header, css: '.mw-electronPdfService-selection-header')
- radio_button(:singlecolumn_selection, css:
'.mw-electronPdfService-selection-form [value=download-electron-pdf]')
+ radio_button(:singlecolumn_selection, css:
'.mw-electronPdfService-selection-form [value=redirect-to-electron]')
radio_button(:twocolumn_selection, css:
'.mw-electronPdfService-selection-form [value=redirect-to-collection]')
button(:pdf_download_button, css: '.mw-electronPdfService-selection-form
.oo-ui-buttonElement-button')
end
--
To view, visit https://gerrit.wikimedia.org/r/322121
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3273ca18aaaf97d47f57769c35e8deb133be5073
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ElectronPdfService
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits