From d93f0dc38d8f2f0410f409a3ef1f2e0d3a24ea40 Mon Sep 17 00:00:00 2001 From: mrsrec <6236968+mrsrec@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:54:31 -0800 Subject: [PATCH] add username warning Warning for people who select a username starting with a lowercase letter --- extension.json | 3 ++- resources/main.js | 19 ++++++++++++++++++- src/SpecialRequestAccount.php | 6 ++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/extension.json b/extension.json index b0df9cf..d2169b0 100644 --- a/extension.json +++ b/extension.json @@ -74,7 +74,8 @@ ], "localBasePath": "resources", "messages": [ - "scratch-confirmaccount-click-copy-alert" + "scratch-confirmaccount-click-copy-alert", + "createacct-normalization" ], "dependencies": [ "mediawiki.util", diff --git a/resources/main.js b/resources/main.js index 42a6556..182fd42 100644 --- a/resources/main.js +++ b/resources/main.js @@ -35,6 +35,7 @@ $(function () { if (!elem) return; elem.onclick = function() { copyToClipboard(document.getElementById("mw-scratch-confirmaccount-verifcode")); + mw.notify( mw.message( 'scratch-confirmaccount-click-copy-alert', { autoHide: true }, {autoHideSeconds: 5}) ); // Use an i18n message to send a notification } }); @@ -48,6 +49,22 @@ function copyToClipboard(temptext) { tempItem.focus(); tempItem.select(); document.execCommand('copy'); - mw.notify( mw.message( 'scratch-confirmaccount-click-copy-alert', { autoHide: true }, {autoHideSeconds: 5}) ); // Use an i18n message to send a notification tempItem.parentElement.removeChild(tempItem); } + + +$(function () { + const elem = document.getElementsByName("scratchusername")[0]; + if (!elem) return; + + elem.onblur = function() { + var currentname = elem.value || ""; + var usernameblock = new OO.ui.infuse(elem.parentElement.parentElement.parentElement.parentElement);// Pain + var noticebox = []; + if(currentname.length > 0 && currentname[0].match("[a-z]")){ + noticebox[0] = new mw.message("createacct-normalization", "", currentname[0].toUpperCase() + currentname.slice(1)).text(); + } + console.log(noticebox); + usernameblock.setNotices(noticebox); + } +}); \ No newline at end of file diff --git a/src/SpecialRequestAccount.php b/src/SpecialRequestAccount.php index ebca7d1..dc46662 100755 --- a/src/SpecialRequestAccount.php +++ b/src/SpecialRequestAccount.php @@ -186,12 +186,14 @@ function usernameAndVerificationArea() { new OOUI\TextInputWidget( [ 'name' => 'scratchusername', 'required' => true, - 'value' => $request->getText('scratchusername') + 'value' => $request->getText('scratchusername'), ] ), [ 'label' => wfMessage('scratch-confirmaccount-scratchusername')->text(), 'align' => 'top', - ] + 'infusable' => true + ], + ), new OOUI\FieldLayout( new OOUI\TextInputWidget( [