Module:User name utils/doc
| This is a documentation subpage for Module:User name utils. It may contain usage information, categories and other content that is not part of the original module page. |
Lua implementation of the getCanonical() and isValid() functions from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/refs/heads/master/includes/User/UserNameUtils.php
Originally created to validate usernames before creating a User info card, since the {{#uic:}} parser function adds pages to the category Category:Pages with an IP as user info card target if getCanonical() returns false.
Usage
[edit]{{#invoke:User name utils|getCanonical|name}} Returns a normalized version of name if valid, and an empty string if not valid. Normalization will, among other things, capitalize the first letter, remove the "User:" namespace prefix if present, replace underscores with spaces, and decode HTML entities.
{{#invoke:User name utils|isValid|name}} Returns "1" if name is a valid username (including leading capitalization and without the namespace), and an empty string if not valid. Note that "example" would be considered invalid because it does not have a leading capital letter, and "User:Example" would be considered invalid because the namespace is specified.
The p._getCanonical(name) and p._isValid(name) functions can be accessed directly from other Lua modules and behave similarly, except _getCanonical returns boolean false instead of an empty string for invalid names, and _isValid returns boolean true or false.