Thcipriani has uploaded a new change for review. https://gerrit.wikimedia.org/r/295510
Change subject: Fixup qrcode-generating js, to stop race condition. ...................................................................... Fixup qrcode-generating js, to stop race condition. Previously there was a race condition where the qrcode would not show if the startup module finished loading prior to the div that should contain the qrcode being loaded. This quite commonly happened on wikipedia during a hit where js is cached (But does not happen locally, my theory is that that is due to how packets get split over the network but not from localhost). Change it to use a normal RL module, as that seems best practise. Also do not load the qrcode js on special pages that do not use it. Finially, remove position:top as its not needed. Bug: T136988 Change-Id: I5139f222207203d834bdc979b21c1fc94f242ac2 (cherry picked from commit 185bce5859b7aebefec7bad81aaf5a62b40b6e6d) --- M extension.json A modules/ext.oath.showqrcode.js M special/SpecialOATHDisable.php M special/SpecialOATHEnable.php M special/SpecialOATHLogin.php 5 files changed, 30 insertions(+), 20 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OATHAuth refs/changes/10/295510/1 diff --git a/extension.json b/extension.json index f4081c9..242b2c8 100644 --- a/extension.json +++ b/extension.json @@ -51,14 +51,21 @@ "ResourceModules": { "ext.oathauth": { "scripts": [ - "modules/jquery.qrcode.js", - "modules/qrcode.js" + "jquery.qrcode.js", + "qrcode.js" + ] + }, + "ext.oath.showqrcode": { + "scripts": [ + "ext.oath.showqrcode.js" ], - "position": "top" + "dependencies": [ + "ext.oathauth" + ] } }, "ResourceFileModulePaths": { - "localBasePath": "", + "localBasePath": "modules", "remoteExtPath": "OATHAuth" }, "SpecialPages": { diff --git a/modules/ext.oath.showqrcode.js b/modules/ext.oath.showqrcode.js new file mode 100644 index 0000000..9c7d2b5 --- /dev/null +++ b/modules/ext.oath.showqrcode.js @@ -0,0 +1,6 @@ +(function ( $ ) { + $( function () { + var $elm = $( '.mw-display-qrcode' ); + $elm.qrcode( $elm.data( 'mw-qrcode-url' ) ); + } ); +} )( jQuery ); diff --git a/special/SpecialOATHDisable.php b/special/SpecialOATHDisable.php index aa7160f..3ae265c 100644 --- a/special/SpecialOATHDisable.php +++ b/special/SpecialOATHDisable.php @@ -37,7 +37,6 @@ $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); $form->getOutput()->setPagetitle( $this->msg( 'oathauth-disable' ) ); - $form->getOutput()->addModules( 'ext.oathauth' ); } /** diff --git a/special/SpecialOATHEnable.php b/special/SpecialOATHEnable.php index 7e4a46a..49439e7 100644 --- a/special/SpecialOATHEnable.php +++ b/special/SpecialOATHEnable.php @@ -38,7 +38,7 @@ $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); $form->getOutput()->setPagetitle( $this->msg( 'oathauth-enable' ) ); - $form->getOutput()->addModules( 'ext.oathauth' ); + $form->getOutput()->addModules( 'ext.oath.showqrcode' ); } /** @@ -80,19 +80,18 @@ } $secret = $key->getSecret(); + $qrcodeUrl = "otpauth://totp/" + . rawurlencode( $this->OATHUser->getAccount() ) + . "?secret=" + . rawurlencode( $secret ); - $this->getOutput()->addHTML( ResourceLoader::makeInlineScript( - Xml::encodeJsCall( 'mw.loader.using', array( - array( 'ext.oathauth' ), - new XmlJsCode( - 'function () {' - . '$("#qrcode").qrcode("otpauth://totp/' - . rawurlencode( $this->OATHUser->getAccount() ) - . '?secret=' . $secret . '");' - . '}' - ) - ) ) - ) ); + $qrcodeElement = Html::element( 'div', [ + 'data-mw-qrcode-url' => $qrcodeUrl, + 'class' => 'mw-display-qrcode', + // Include width/height, so js won't re-arrange layout + // OTOH, this will cause non-js browsers to see a big empty space. + 'style' => 'width: 256px; height: 256px;' + ] ); return array( 'app' => array( @@ -103,7 +102,7 @@ ), 'qrcode' => array( 'type' => 'info', - 'default' => '<div id="qrcode"></div>', + 'default' => $qrcodeElement, 'raw' => true, 'section' => 'step2', ), diff --git a/special/SpecialOATHLogin.php b/special/SpecialOATHLogin.php index 76f247a..0749535 100644 --- a/special/SpecialOATHLogin.php +++ b/special/SpecialOATHLogin.php @@ -39,7 +39,6 @@ $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); $form->getOutput()->setPagetitle( $this->msg( 'oathauth-login' ) ); - $form->getOutput()->addModules( 'ext.oathauth' ); } /** -- To view, visit https://gerrit.wikimedia.org/r/295510 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5139f222207203d834bdc979b21c1fc94f242ac2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/OATHAuth Gerrit-Branch: wmf/1.28.0-wmf.6 Gerrit-Owner: Thcipriani <tcipri...@wikimedia.org> Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits