Fandom Developers Wiki
Advertisement

UserLastActivity is a script that displays the date and time (datetime) of the most recent logged local activity by a specified user. The user may be specified by name or id. The format of the datetime is automatically determined by Javascript's toLocalString function. If the specified user does not have activity on the wiki, the script will display a "no activity" message instead of a datetime. If the script cannot find the specified user, nothing will be displayed.

Installation

Configuration

The configuration options for this script simply provide a means to restrict the type of logs used to determine the datetime. The options are properties of the script's configuration object which can be created in a community's JS with the following lines of code.

if (!window.andrewds1021) {
    window.andrewds1021 = {
        user_last_activity: {}
    };
} else if (!window.andrewds1021.user_last_activity) {
    window.andrewds1021.user_last_activity = {};
}

The two types of logs that can be searched are contributions and log events. These correspond to what would be returned by visiting Special:Contributions/Username and Special:Log/Username respectively. At this time, the script does not allow log events to be filtered by event type. By default, the script uses both types of logs when determining the datetime. To prevent use of contributions, place this line of code below the code creating the script's configuration object.

window.andrewds1021.user_last_activity.edits = false;

To prevent the use of logs, use this line instead.

window.andrewds1021.user_last_activity.logs = false;

If both log types are disabled, the script will not return any datetimes and all placeholders will remain unaltered.

Usage

The script must know where and for which users to insert datetimes. The location of the insertion should be indicated using a placeholder element. To indicate that an element is a placeholder for this script, add UserLastActivity as a class to the element. The contents of a placeholder element will be replaced with the corresponding datetime. The user may be specified by either name or id. The script will attempt to use the id first. If the id is deemed invalid, the script will attempt to use the name instead. If the name is also deemed invalid, the corresponding placeholder will remain unaltered. The name or id of the user is specified by adding the appropriate attribute to the placeholder.

data-userlastactivity-username

This attribute is used to specify the user by name. The name is case-sensitive and underscores will be replaced with spaces. Some characters may need to be escaped. To escape a character, use its HTML entity. Characters that do not require escaping may still be specified as HTML entities if desired. If the user has renamed their account, this attribute must be updated to match the new name. If not, the script will return the "no activity" message.

data-userlastactivity-userid

This attribute is used to specify the user by id. A user's id should remain the same even if their account gets renamed. Valid ids should be integers greater than 0.

Example

Table

{| class="wikitable"
  |-
  ! colspan="2" rowspan="2" |
  ! colspan="8" | ID Value
  |-
  ! None !! Declared !! Empty !! Anon (0) !! Removed (3) !! Invalid (-1) !! Valid (9605025)
  |-
  ! rowspan="15" | Name Value
  ! None
  | class="UserLastActivity" | No Change
  | class="UserLastActivity" data-userlastactivity-userid | No Change
  | class="UserLastActivity" data-userlastactivity-userid="" | No Change
  | class="UserLastActivity" data-userlastactivity-userid="0" | No Change
  | class="UserLastActivity" data-userlastactivity-userid="3" | No Change
  | class="UserLastActivity" data-userlastactivity-userid="-1" | No Change
  | class="UserLastActivity" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Declared
  | class="UserLastActivity" data-userlastactivity-username | No Change
  | class="UserLastActivity" data-userlastactivity-username data-userlastactivity-userid | No Change
  | class="UserLastActivity" data-userlastactivity-username data-userlastactivity-userid="" | No Change
  | class="UserLastActivity" data-userlastactivity-username data-userlastactivity-userid="0" | No Change
  | class="UserLastActivity" data-userlastactivity-username data-userlastactivity-userid="3" | No Change
  | class="UserLastActivity" data-userlastactivity-username data-userlastactivity-userid="-1" | No Change
  | class="UserLastActivity" data-userlastactivity-username data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Empty
  | class="UserLastActivity" data-userlastactivity-username="" | No Change
  | class="UserLastActivity" data-userlastactivity-username="" data-userlastactivity-userid | No Change
  | class="UserLastActivity" data-userlastactivity-username="" data-userlastactivity-userid="" | No Change
  | class="UserLastActivity" data-userlastactivity-username="" data-userlastactivity-userid="0" | No Change
  | class="UserLastActivity" data-userlastactivity-username="" data-userlastactivity-userid="3" | No Change
  | class="UserLastActivity" data-userlastactivity-username="" data-userlastactivity-userid="-1" | No Change
  | class="UserLastActivity" data-userlastactivity-username="" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Anon (An unknown anonymous user)
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" | No Change
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" data-userlastactivity-userid | No Change
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" data-userlastactivity-userid="" | No Change
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" data-userlastactivity-userid="0" | No Change
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" data-userlastactivity-userid="3" | No Change
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" data-userlastactivity-userid="-1" | No Change
  | class="UserLastActivity" data-userlastactivity-username="An unknown anonymous user" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Anon IP (72.34.11.146)
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" | No Change
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" data-userlastactivity-userid | No Change
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" data-userlastactivity-userid="" | No Change
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" data-userlastactivity-userid="0" | No Change
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" data-userlastactivity-userid="3" | No Change
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" data-userlastactivity-userid="-1" | No Change
  | class="UserLastActivity" data-userlastactivity-username="72.34.11.146" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Non-Existent (Andrewds1022)
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" | No Change
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" data-userlastactivity-userid | No Change
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" data-userlastactivity-userid="" | No Change
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" data-userlastactivity-userid="0" | No Change
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" data-userlastactivity-userid="3" | No Change
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" data-userlastactivity-userid="-1" | No Change
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1022" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Valid (Andrewds1021)
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" data-userlastactivity-userid | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" data-userlastactivity-userid="" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" data-userlastactivity-userid="0" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" data-userlastactivity-userid="3" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" data-userlastactivity-userid="-1" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  | class="UserLastActivity" data-userlastactivity-username="Andrewds1021" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
  |-
  ! Non-Latin Characters (机智的小鱼君)
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" | Datetime for [[User:机智的小鱼君|机智的小鱼君]] ([[Special:Contributions/机智的小鱼君|contribs]]|[[Special:Logs/机智的小鱼君|logs]])
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" data-userlastactivity-userid | Datetime for [[User:机智的小鱼君|机智的小鱼君]] ([[Special:Contributions/机智的小鱼君|contribs]]|[[Special:Logs/机智的小鱼君|logs]])
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" data-userlastactivity-userid="" | Datetime for [[User:机智的小鱼君|机智的小鱼君]] ([[Special:Contributions/机智的小鱼君|contribs]]|[[Special:Logs/机智的小鱼君|logs]])
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" data-userlastactivity-userid="0" | Datetime for [[User:机智的小鱼君|机智的小鱼君]] ([[Special:Contributions/机智的小鱼君|contribs]]|[[Special:Logs/机智的小鱼君|logs]])
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" data-userlastactivity-userid="3" | Datetime for [[User:机智的小鱼君|机智的小鱼君]] ([[Special:Contributions/机智的小鱼君|contribs]]|[[Special:Logs/机智的小鱼君|logs]])
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" data-userlastactivity-userid="-1" | Datetime for [[User:机智的小鱼君|机智的小鱼君]] ([[Special:Contributions/机智的小鱼君|contribs]]|[[Special:Logs/机智的小鱼君|logs]])
  | class="UserLastActivity" data-userlastactivity-username="机智的小鱼君" data-userlastactivity-userid="9605025" | Datetime for [[User:Andrewds1021|Andrewds1021]] ([[Special:Contributions/Andrewds1021|contribs]]|[[Special:Logs/Andrewds1021|logs]])
|}
ID Value
None Declared Empty Anon (0) Removed (3) Invalid (-1) Valid (9605025)
Name Value None No Change No Change No Change No Change No Change No Change Datetime for Andrewds1021 (contribs|logs)
Declared No Change No Change No Change No Change No Change No Change Datetime for Andrewds1021 (contribs|logs)
Empty No Change No Change No Change No Change No Change No Change Datetime for Andrewds1021 (contribs|logs)
Anon (An unknown anonymous user) No Change No Change No Change No Change No Change No Change Datetime for Andrewds1021 (contribs|logs)
Anon IP (72.34.11.146) No Change No Change No Change No Change No Change No Change Datetime for Andrewds1021 (contribs|logs)
Non-Existent (Andrewds1022) No Change No Change No Change No Change No Change No Change Datetime for Andrewds1021 (contribs|logs)
Valid (Andrewds1021) Datetime for Andrewds1021 (contribs|logs) Datetime for Andrewds1021 (contribs|logs) Datetime for Andrewds1021 (contribs|logs) Datetime for Andrewds1021 (contribs|logs) Datetime for Andrewds1021 (contribs|logs) Datetime for Andrewds1021 (contribs|logs) Datetime for Andrewds1021 (contribs|logs)
Non-Latin Characters (机智的小鱼君) Datetime for 机智的小鱼君 (contribs|logs) Datetime for 机智的小鱼君 (contribs|logs) Datetime for 机智的小鱼君 (contribs|logs) Datetime for 机智的小鱼君 (contribs|logs) Datetime for 机智的小鱼君 (contribs|logs) Datetime for 机智的小鱼君 (contribs|logs) Datetime for Andrewds1021 (contribs|logs)

Additional Notes

  • This script makes multiple serial API requests to retrieve the necessary data. If the current page does not contain any placeholders, no requests will be made. Otherwise, the total number of requests is two more than the number of valid unique users specified on the page.
  • Due to a difference in API behavior, migration to UCP revealed a previously undetected issue with the script. This issue appears when a page has more than 50 elements requiring user activity data. A rework is required to fix this issue and will likely take some time. For now, there should be no issue as long as the number of elements requiring user data is less than 50 per page.
  • This script does not account for activity in Feeds-based discussion features. Unless and until Feeds activity is available to wiki-side JS, it will not be possible to incorporate that activity.
Text above can be found here (edit)
Advertisement