Commit 8cf3ed44 authored by Alexia's avatar Alexia

Converting to extension registration and forcing a maximum width.

parent 1e40ef57
......@@ -35,7 +35,7 @@ class PDFEmbed {
* @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) {
......@@ -62,8 +62,8 @@ class PDFEmbed {
$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) {
......@@ -87,7 +87,8 @@ class PDFEmbed {
'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' />"
......
<?php
/**
* This is a backwards-compatibility shim, generated by:
* https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
*
* Beginning with MediaWiki 1.23, translation strings are stored in json files,
* and the EXTENSION.i18n.php file only exists to provide compatibility with
* older releases of MediaWiki. For more information about this migration, see:
* https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
*
* This shim maintains compatibility back to MediaWiki 1.17.
*/
$messages = array();
if ( !function_exists( 'wfJsonI18nShim3c31c114726db32d' ) ) {
function wfJsonI18nShim3c31c114726db32d( $cache, $code, &$cachedData ) {
$codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] );
foreach ( $codeSequence as $csCode ) {
$fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
if ( is_readable( $fileName ) ) {
$data = FormatJson::decode( file_get_contents( $fileName ), true );
foreach ( array_keys( $data ) as $key ) {
if ( $key === '' || $key[0] === '@' ) {
unset( $data[$key] );
}
}
$cachedData['messages'] = array_merge( $data, $cachedData['messages'] );
}
$cachedData['deps'][] = new FileDependency( $fileName );
}
return true;
}
$GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShim3c31c114726db32d';
}
<?php
/**
* PDFEmbed
* PDFEmbed Mediawiki Settings
*
* @author Alexia E. Smith
* @license LGPLv3 http://opensource.org/licenses/lgpl-3.0.html
* @package PDFEmbed
* @link http://www.mediawiki.org/wiki/Extension:PDFEmbed
*
**/
/******************************************/
/* Credits */
/******************************************/
$credits = [
'path' => __FILE__,
'name' => 'PDFEmbed',
'author' => 'Alexia E. Smith',
'url' => 'https://www.mediawiki.org/wiki/Extension:PDFEmbed',
'descriptionmsg' => 'pdfembed_description',
'version' => '1.1.2',
'license-name' => 'LGPL-3.0'
];
$wgExtensionCredits['parserhook'][] = $credits;
/******************************************/
/* Language Strings, Page Aliases, Hooks */
/******************************************/
$extDir = __DIR__;
$wgAvailableRights[] = 'embed_pdf';
$wgExtensionMessagesFiles['PDFEmbed'] = "{$extDir}/PDFEmbed.i18n.php";
$wgMessagesDirs['PDFEmbed'] = "{$extDir}/i18n";
$wgAutoloadClasses['PDFEmbed'] = "{$extDir}/PDFEmbed.hooks.php";
$wgAutoloadClasses['PDFHandler'] = "{$extDir}/classes/PDFHandler.class.php";
$wgHooks['ParserFirstCallInit'][] = 'PDFEmbed::onParserFirstCallInit';
//Future
//$wgMediaHandlers['application/pdf'] = 'PDFHandler';
/******************************************/
/* Initialize Settings */
/******************************************/
//All settings are include order friendly. Meaning the extension include can come before or after the settings and not override them.
//Setup sysop to have this by default.
if (!array_key_exists('embed_pdf', $wgGroupPermissions['sysop'])) {
$wgGroupPermissions['sysop']['embed_pdf'] = true;
}
//Add the PDF file extension into the allowed list.
if (!in_array('pdf', $wgFileExtensions)) {
$wgFileExtensions[] = 'pdf';
}
if (!isset($pdfEmbed['width'])) {
$pdfEmbed['width'] = 800;
}
if (!isset($pdfEmbed['height'])) {
$pdfEmbed['height'] = 1090;
}
......@@ -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;
```
......@@ -35,7 +35,7 @@ class PDFHandler {
* @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')) {
......@@ -48,8 +48,8 @@ class PDFHandler {
$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);
......@@ -68,7 +68,7 @@ class PDFHandler {
* @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>";
}
/**
......
{
"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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment