Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions QRLite.i18n.alias.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Aliases for QRLite extension
*
* @file
* @ingroup Extensions
*/

$specialPageAliases = [];

/** English (English) */
$specialPageAliases['en'] = [
'QRCodes' => [ 'QRCodes', 'QRCode' ],
];
6 changes: 5 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
"MediaWiki\\Extension\\QRLite\\": "./src/"
},
"ExtensionMessagesFiles": {
"QRLiteMagic": "QRLite.i18n.magic.php"
"QRLiteMagic": "QRLite.i18n.magic.php",
"QRLiteAlias": "QRLite.i18n.alias.php"
},
"MessagesDirs": {
"QRLite": [
"i18n"
]
},
"SpecialPages": {
"QRCodes": "MediaWiki\\Extension\\QRLite\\SpecialQRCodes"
},
"Hooks": {
"ParserFirstCallInit": "QRLite"
},
Expand Down
7 changes: 6 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"Fannon"
]
},
"qrlite-desc": "Generates QRCodes in .png or .svg format on-the-fly."
"qrlite-desc": "Generates QRCodes in .png or .svg format on-the-fly.",
"qrcodes": "QR Codes",
"qrlite-specialpage-url-label": "URL",
"qrlite-specialpage-url-help": "Enter a URL for which to create a QR Code.",
"qrlite-specialpage-size-label": "Size",
"qrlite-specialpage-size-help": "The rendered size will be 30 times this number, in pixels."
}
7 changes: 6 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"Fannon"
]
},
"qrlite-desc": "{{desc|name=QRLite|url=https://www.mediawiki.org/wiki/Extension:QRLite}}"
"qrlite-desc": "{{desc|name=QRLite|url=https://www.mediawiki.org/wiki/Extension:QRLite}}",
"qrcodes": "Title for the special page.",
"qrlite-specialpage-url-label": "Form field label.",
"qrlite-specialpage-url-help": "Form field help text.",
"qrlite-specialpage-size-label": "Form field label.",
"qrlite-specialpage-size-help": "Form field help text."
}
97 changes: 97 additions & 0 deletions src/SpecialQRCodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace MediaWiki\Extension\QRLite;

use FormSpecialPage;
use HTMLForm;

class SpecialQRCodes extends FormSpecialPage {

/** @var string */
private string $qrCodesHtml = '';

/**
* @inheritDoc
*/
public function __construct(
$name = 'QRCodes', $restriction = '', $listed = true,
$function = false, $file = '', $includable = true
) {
parent::__construct( $name, $restriction, $listed, $function, $file, $includable );
}

/**
* @inheritDoc
*/
protected function getDisplayFormat() {
return 'ooui';
}

/**
* @inheritDoc
*/
protected function getMessagePrefix() {
return 'qrlite';
}

/**
* @inheritDoc
*/
protected function alterForm( HTMLForm $form ) {
// @todo After dropping support for MW < 1.40, use $this->requiresPost() instead.
$form->setMethod( 'get' );
}

/**
* @inheritDoc
*/
public function execute( $par ) {
$this->addHelpLink( 'Help:Extension:QRLite' );
$this->checkPermissions();
parent::execute( $par );

if ( $this->qrCodesHtml ) {
$this->getForm()->showAlways();
$this->getOutput()->addHTML( $this->qrCodesHtml );
}
}

/**
* @inheritDoc
*/
protected function getFormFields() {
return [
'url' => [
'required' => true,
'type' => 'url',
'name' => 'url',
'label-message' => 'qrlite-specialpage-url-label',
'autofocus' => true,
'help' => $this->msg( 'qrlite-specialpage-url-help' )->text(),
],
'size' => [
'type' => 'int',
'name' => 'size',
'default' => 6,
'label-message' => 'qrlite-specialpage-size-label',
'help' => $this->msg( 'qrlite-specialpage-size-help' )->text(),
],
];
}

/**
* @inheritDoc
*/
public function onSubmit( array $data ) {
$params = [
'prefix' => $data['url'],
// 'format' => $data['format'] ?? null,
'size' => $data['size'] ?? null,
// 'margin' => $data['margin'] ?? null,
// 'ecc' => $data['ecc'] ?? null,
];
$this->qrCodesHtml = QRLiteFunctions::generateQRCode( array_filter( $params ) );
return true;
}

}