From 18417195c737e9ed6cc581c0ba17d033e71c9b7e Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Tue, 9 May 2023 15:38:03 +0800 Subject: [PATCH] Add Special:QRCodes special page A first draft for a special page to display QR Codes. Bug: #4 --- QRLite.i18n.alias.php | 14 ++++++ extension.json | 6 ++- i18n/en.json | 7 ++- i18n/qqq.json | 7 ++- src/SpecialQRCodes.php | 97 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 QRLite.i18n.alias.php create mode 100644 src/SpecialQRCodes.php diff --git a/QRLite.i18n.alias.php b/QRLite.i18n.alias.php new file mode 100644 index 0000000..0a432b5 --- /dev/null +++ b/QRLite.i18n.alias.php @@ -0,0 +1,14 @@ + [ 'QRCodes', 'QRCode' ], +]; diff --git a/extension.json b/extension.json index cbd6ee0..ee7dd2d 100644 --- a/extension.json +++ b/extension.json @@ -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" }, diff --git a/i18n/en.json b/i18n/en.json index b07fd17..775b812 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -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." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 03c0f4c..eaa32b7 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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." } diff --git a/src/SpecialQRCodes.php b/src/SpecialQRCodes.php new file mode 100644 index 0000000..57bcd29 --- /dev/null +++ b/src/SpecialQRCodes.php @@ -0,0 +1,97 @@ +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; + } + +}