Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Converting to extension registration and forcing a maximum width.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexia committed Jan 17, 2017
1 parent 1e40ef5 commit 8cf3ed4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 112 deletions.
9 changes: 5 additions & 4 deletions PDFEmbed.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static public function onParserFirstCallInit(Parser &$parser) {
* @return string HTML
*/
static public function generateTag($file, $args = [], Parser $parser, PPFrame $frame) {
global $pdfEmbed, $wgRequest, $wgUser;
global $wgPdfEmbed, $wgRequest, $wgUser;
$parser->disableCache();

if (strstr($file, '{{{') !== false) {
Expand All @@ -62,8 +62,8 @@ static public function generateTag($file, $args = [], Parser $parser, PPFrame $f

$file = wfFindFile(Title::newFromText($file));

$width = (array_key_exists('width', $args) ? intval($args['width']) : intval($pdfEmbed['width']));
$height = (array_key_exists('height', $args) ? intval($args['height']) : intval($pdfEmbed['height']));
$width = (array_key_exists('width', $args) ? intval($args['width']) : intval($wgPdfEmbed['width']));
$height = (array_key_exists('height', $args) ? intval($args['height']) : intval($wgPdfEmbed['height']));
$page = (array_key_exists('page', $args) ? intval($args['page']) : 1);

if ($file !== false) {
Expand All @@ -87,7 +87,8 @@ static private function embed(File $file, $width, $height, $page) {
'width' => $width,
'height' => $height,
'data' => $file->getFullUrl().'#page='.$page,
'type' => 'application/pdf'
'type' => 'application/pdf',
'style' => 'max-width: 100%;'
],
wfMessage('pdf_not_supported', $file->getFullUrl(), $file->getName())->escaped()
."<param name='page' value='$page' />"
Expand Down
35 changes: 0 additions & 35 deletions PDFEmbed.i18n.php

This file was deleted.

67 changes: 0 additions & 67 deletions PDFEmbed.php

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Configuration
If the default configuration needs to be altered add these settings to the LocalSettings.php file below the require:
```php
//Default width for the PDF object container.
$pdfEmbed['width'] = 800;
$wgPdfEmbed['width'] = 800;

//Default height for the PDF object container.
$pdfEmbed['height'] = 1090;
$wgPdfEmbed['height'] = 1090;
```
8 changes: 4 additions & 4 deletions classes/PDFHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static public function onParserFirstCallInit(Parser &$parser) {
* @return string HTML
*/
static public function generateTag($file, $args = [], Parser $parser, PPFrame $frame) {
global $pdfEmbed, $wgUser;
global $wgPdfEmbed, $wgUser;
$parser->disableCache();

if (!$wgUser->isAllowed('pdf')) {
Expand All @@ -48,8 +48,8 @@ static public function generateTag($file, $args = [], Parser $parser, PPFrame $f

$file = wfFindFile(Title::newFromText($file));

$width = ($args['width'] > 0 ? intval($args['width']) : intval($pdfEmbed['width']));
$height = ($args['height'] > 0 ? intval($args['height']) : intval($pdfEmbed['height']));
$width = ($args['width'] > 0 ? intval($args['width']) : intval($wgPdfEmbed['width']));
$height = ($args['height'] > 0 ? intval($args['height']) : intval($wgPdfEmbed['height']));

if ($file !== false) {
return self::embed($file, $width, $height);
Expand All @@ -68,7 +68,7 @@ static public function generateTag($file, $args = [], Parser $parser, PPFrame $f
* @return string HTML object.
*/
static private function embed(File $file, $width, $height) {
return "<object width='{$width}' height='{$height}' data='".urlencode($file->getFullUrl())." type='application/pdf'></object>";
return "<object width='{$width}' height='{$height}' style='max-width: 100%;' data='".urlencode($file->getFullUrl())." type='application/pdf'></object>";
}

/**
Expand Down
39 changes: 39 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "PDFEmbed",
"version": "2.0.0",
"author": "Alexia E. Smith",
"url": "https://www.mediawiki.org/wiki/Extension:PDFEmbed",
"descriptionmsg": "pdfembed_description",
"license-name": "LGPL-3.0",
"type": "parserhook",
"GroupPermissions": {
"sysop": {
"embed_pdf": true
}
},
"AvailableRights": [
"embed_pdf"
],
"MessagesDirs": {
"PDFEmbed": [
"i18n"
]
},
"AutoloadClasses": {
"PDFEmbed": "PDFEmbed.hooks.php",
"PDFHandler": "classes/PDFHandler.class.php"
},
"Hooks": {
"ParserFirstCallInit": "PDFEmbed::onParserFirstCallInit"
},
"config": {
"FileExtensions": [
"pdf"
],
"PdfEmbed": {
"width": 800,
"height": 1090
}
},
"manifest_version": 1
}

0 comments on commit 8cf3ed4

Please sign in to comment.