User:Andrewds1021/UserLastActivity

Note: This script is still in the testing phase.

This solution was created in response to Thread:1621411.

The purpose of this script is to retrieve and display the timestamp of the last logged action committed by the specified registered user on the local wiki. The script uses MediaWiki's api.php to retrieve this information. If it is able to retrieve the information, it inserts the date and time as the entire contents of the specified HTML element (removing all other content). In the event that the user has no logged actions on the local wiki, an appropriate message will be inserted instead. If there was an issue with retrieving the information (ex. specified user is not in the database), the contents of the specified HTML element are left untouched.

Use/Configuration
To have this script insert the timestamp of a user's most recent logged activity on the local wiki, start by specifying an HTML element for which the content will be replaced with the timestamp. For the selected element, assign the class  as well as one (or both) of the HTML attributes   and. The former attribute should be assigned the user's username while the latter should be assigned the user's user id. Using the user's user id prevents the need to change the assigned value in the event that the user changes their username via the UserRenameTool.

By default, the script searches both a user's contributions (i.e. edits) and log activity (ex. avatar uploads and page deletions) and uses the most recent of the two timestamps. This behavior can be changed by setting  and   to   to ignore edits and log activity respectively. In the event that both are disabled, the script will simply exit without attempting to retrieve any data.

The timestamp will be displayed based on the viewer's browser locale. In the event that the user was found but has not committed any logged actions, a "No Activity" message will be displayed instead. The script will attempt to select the proper message based on the viewer's language setting (Note: Currently, only English (en) is supported by the built-in list). If the script cannot find such a message, it will attempt to find the next best message (based on, in order, the page's language and the wiki's language). If the script still cannot find a corresponding message, it will use the English message. To edit/add to the built-in list of messages, set  to an object; using language codes as keys and desired messages as values.

Limitations/Additional Notes

 * 1) When specifying the username:
 * 2) *Underscores and spaces are interchangeable
 * 3) *Characters are interchangeable with their HTML character entities
 * 4) *The first character is case-insensitive
 * 5) If a user renames their account, a search based on the previous username will show as having no activity.
 * 6) The number of API requests is as follows:
 * 7) Desired improvements:
 * 8) *Better timestamp format control
 * 9) *More language support for the "no activity" message
 * 1) *More language support for the "no activity" message