Jump to content

User:SoledadKabocha/markBlockedPlus

From Wikipedia, the free encyclopedia

This is a modified copy of the original mark-blocked script, with added functionality to retrieve other information about user accounts, inspired by User:Equazcion/sysopdetector.js.

This script operates on links to user pages, user talk pages, or user contributions (including the "User page" tab at the top of a user or user talk page). This differs from sysopdetector and the similar script User:PleaseStand/User info, which add messages to user/user talk pages near the title heading.

By default, usernames of finitely-blocked users are struck out (User:Example), and usernames of indefinitely-blocked users are struck out and italicized (User:Example).

Also, the script adds information to the link's tooltip showing the user's most recent block log entry (if the user is currently blocked), groups (optionally), edit count (optionally), and registration date (optionally). If the link points to a username which is not registered, a message stating so can also be added to the tooltip.

Time intervals are shown in seconds, hours:minutes, days, or (optionally) years as appropriate.

Installation

[edit]

Copy and paste the following line to your current skin's JS file or common JS file:

importScript('User:SoledadKabocha/markBlockedPlus.js'); //I don't care about linkback; talk-page post preferred instead

The comment (//) is obviously optional.

Compatibility with linkclassifier

[edit]

If you use markBlockedPlus with Anomie's original linkclassifier, both scripts will appear to work, but occasional problems may occur. Specifically, markBlockedPlus may not reliably modify the tooltips of links that are redirected user or user talk pages (e.g. User talk:ClueBot NG). This happens because markBlockedPlus sometimes finishes first, allowing linkclassifier to override its changes to tooltips.

User:SoledadKabocha/linkclassifier2.js is a copy of User:Anomie/linkclassifier.js, modified to call the function defined at window.LinkClassifierChainedFunc with the argument window.LinkClassifierChainedFuncArg (if they exist) once it is finished processing all links. markBlockedPlus uses this feature to ensure that it executes only after linkclassifier has finished.

Therefore, if you want to install both linkclassifier and markBlockedPlus, add the following lines to your common.js or skin.js for linkclassifier (you may omit the last line if you have defined custom CSS rules for the classes added bylinkclassifier, and you may modify the comments as desired):

//ensure that linkclassifier loads before markBlockedPlus
importScript( 'User:SoledadKabocha/linkclassifier2.js' ); //I don't care about linkback
//etc. (other code may go here, such as markBlockedPlus configuration)
window.LinkClassifierChainedFunc = {
  if ( typeof markBlocked === 'function' ) { markBlocked( ); }
  else { importScript( 'User:SoledadKabocha/markBlockedPlus.js' ); } //I don't care about linkback
  //etc.
}
importStylesheet( 'User:Anomie/linkclassifier.css' ); //Linkback: [[User:Anomie/linkclassifier.css]]

Also, if you need to limit markBlockedPlus to working within a specific page element, assign that element to window.LinkClassifierChainedFuncArg. For example, with User:Js/ajaxPreview:

window.ajaxPreviewExec = function( previewArea ) {
  window.LinkClassifierChainedFuncArg = previewArea;
  LinkClassifier.onDemand(); // FIXME: should call markBlocked(previewArea) when done, but doesn't work anymore?
  // more code here if desired
}

markBlockedPlus supports an option to notify that the username at the beginning of the tooltip may differ from the one for which blocks/other info are shown if the user (talk) page is a redirect. This may generate false-positive warnings on blocked users if window.mbTooltip begins with a dollar sign (whether or not it is part of a $1-$4 parameter); therefore, window.mbTooltip should not be set to begin with a dollar sign, until further notice.

Configuration

[edit]

These settings are changed by inserting a line such as window.mbTipBox = true; directly above the aforementioned importScript(... line; replace mbTipBox with the actual name of each setting.

Settings present in original mark-blocked script

[edit]
  • mbTempStyle (string; default 'opacity: 0.7; text-decoration: line-through')
    CSS style to apply to the user-blocked-temp class, used for finitely-blocked users (the shorter of the two tiers, if mbLongThreshold has been set)
  • mbIndefStyle (string; default 'opacity: 0.4; font-style: italic; text-decoration: line-through')
    CSS style to apply to the user-blocked-indef class, used for indefinitely-blocked users
  • mbTipBox (boolean; default false)
    When true, a small square with the letter [B] (configurable) is added before a link to a blocked user, and the tooltip is added to the square instead of the link itself. (The original script displayed #.)
  • mbTipBoxStyle (string; default 'font-size:smaller; background:#FFFFF0; border:1px solid #FEA; padding:0 0.3em; color:#AAA')
    CSS style to apply to the tipbox that indicates a blocked user, which has the class user-blocked-tipbox
  • mbTooltip (string; default '; blocked ($1) by $2: $3 ($4 ago)')
    Tooltip text to add for blocked users; the following symbols are handled specially:
    • $1 is replaced by the length of the block
    • $2 is replaced by the blocking administrator's username
    • $3 is replaced by the date and time the block started
    • $4 is replaced by the length of time ago the block started
When linkclassifier is in use, it is not recommended for this setting to begin with a dollar sign, as doing so may cause false warnings about the page redirecting to a different username to be included in the tooltip.
  • mbLoadingOpacity (numeric; default 0.85)
    Opacity to apply to user links for which an API query is still in progress
  • mbNoAutoStart (boolean; default false)
    Whether to trigger the script from a portlet link rather than automatically on page load (TODO: document where the link appears in each commonly-used skin)

New features

[edit]
  • mbEnableOnMainspaceDiff (boolean; default false)
    Whether to enable the script on mainspace diffs (the default is false only to match the original script's behavior, in which it is disabled unconditionally in mainspace)
  • mbEnableWhenEditing (boolean; default false)
    Whether to process user links on edit pages (the original script's behavior was equivalent to false, presumably for performance and/or compatibility with other scripts)
  • mbLinkClassifierRedirWarn (boolean; default true)
    Whether to show a warning message for redirected user(talk) pages when linkclassifier is installed; linkclassifier changes the tooltip to mention the redirect target, but this script shows information for the username originally specified by the link, which may be confusing. The message currently reads, Info shown for (original username); redirects to different username or IP
  • mbLocalContribsName (string or array of strings) — was available in an older version of the original mark-blocked script (accepting only a single string)
    Name of the contributions page on the wiki where the script is being used, not including the "Special:" namespace prefix. If not specified, the script will query the API for this information.
    You may also use this setting to enable marking of links that point to other special pages such as EmailUser. If you wish to do so, use an array that also includes 'Contributions', e.g. window.mbLocalContributionsName = ['Contributions', 'EmailUser'].
  • mbLongThreshold (integer; no default, which disables the two-tier system)
    If this is set, blocks shorter than this number of milliseconds will be given the CSS class user-blocked-temp, while equal or longer blocks will be given user-blocked-temp2.
  • mbLongThreshIsRemainingTime (boolean; default false)
    When this is true, the calculations for mbLongThreshold and mbPseudoIndefThreshold are based on the remaining time of the block rather than its total duration.
  • mbOnDemandLinkLoc (string; default 'p-cactions')
    Name of the link group in which the portlet link will be placed when mbNoAutoStart is true; by default, it is located near the "Move" link. 'p-tb' puts it in the "Toolbox" section of the sidebar
  • mbOnDemandLinkText (string; default 'XX')
    Text to use for the portlet link that is added when mbNoAutoStart is true
  • mbPseudoIndefThreshold (integer; no default, so this feature is disabled by default)
    If this is set, blocks longer than this number of milliseconds will be CSS-styled as if they were indefinite.
  • mbRemoveWaitingCSSOnError (boolean; default true)
    Whether to restore links to normal opacity if the last API query encounters an error. This currently has no effect if the failed request is not the last request the script needs to make, in which case the script will abort with the waiting CSS still applied. This feature may be removed, temporarily or permanently, in the future.
  • mbReportApiErrors (boolean; default false)
    Whether errors in API queries should be reported in Firefox's Error Console or the equivalent in other browsers; this is false by default only to match the original script's behavior
    Any error probably indicates a bug in this script, unless you are being rate-limited. If you see a page on which many usernames are not being processed, please set this to true and tell me the exact error message.
    • If true, the script will abort and not process any more usernames once any error is found.
    • If false, the chunk of 50 usernames that contains the error will not be processed, but the script will attempt to continue with the next chunk of 50 usernames.
  • mbShowEditCount (boolean; default true)
    Whether to show the edit count of a registered user
  • mbShowGroups (boolean; default true)
    Whether to show the groups to which the user belongs; * will not be shown, but user will (this differs from sysopdetector, which hides both. If you want me to change this behavior or to make it customizable, please post on the talk page.)
  • mbShowRegDateAbs (boolean; default true)
    Whether to show the (abs-olute) date and time that the account was registered
  • mbShowRegDateRel (boolean; default false)
    Whether to show the (rel-ative) time interval ago that the account was registered
  • mbShowUnregistered (boolean; default true)
    Whether to show a message for usernames which are not registered
  • mbShowYears (boolean; default false)
    Whether to show time intervals of a year or longer in units of years and days, as opposed to days alone; the calculation is based on 365-day years, so it will be inaccurate for any interval that spans a leap year
  • mbTemp2Style (string; default same as mbTempStyle)
    CSS style to apply to the user-blocked-temp2 class, used for finite blocks in the longer of the two tiers (requires mbLongThreshold to be set)
  • mbTipBoxCharsToTrim (integer; default 2)
    Number of initial characters to remove from the string in mbTooltip before adding it to the tooltip of the [B] tipbox; the default 2 removes a semicolon and space
  • mbTipBoxText (string; default 'B')
    Letter (or other text) to show inside the tipbox for blocked users
  • mbTipBoxInfo (boolean; default false)
    When true, a small square with the letter [i] is added before an user link, and the tooltip containing information other than the block-log entry is added to this square rather than to the link itself.
  • mbTipBoxInfoStyle (string; default 'font-size:smaller; background:#FFFFF0; border:1px solid #FEA; padding:0 0.3em; color:#AAA')
    CSS style to apply to the user-info tipbox, which has the class user-info-tipbox
  • mbTipBoxInfoText (string; default 'i')
    Letter (or other text) to show inside the tipbox for user info other than blocks
  • mbUnregisteredText (string; default '\nnot registered')
    Message to show for usernames which are not registered

Bugs fixed and other changes from original mark-blocked script

[edit]

TODO

[edit]

I don't have a lot of time to work on anything that is an enhancement (as opposed to a defect). If you want one of these features, please mention so on the talk page.

Easy enhancements

[edit]
  • Configurable threshold for number of days below which hours should be shown (currently 10 per original script)
  • Proper rounding rather than truncation in time-interval display (partially done)
  • Other means of error reporting (browser console; add a portlet link which shows an alert dialog; mw.notify)
  • Ignore section edit links: they would normally be marked on user (talk) pages, where the functionality is redundant with the marking of the "User page" tab and a tipbox would create unnecessary clutter
  • Change the CSS style applied to user links in a more distinctive way when an API error occurs
  • Provide a means for the user to configure custom CSS classes to be added to user links based on regex tests of the block reason (similar to what is currently done to detect compromised accounts)
    • Or consider adding another class for vanished accounts
  • Provide customization for the warning message used by mbLinkClassifierRedirWarn
  • Restore the functionality that allows automatically calling another script after this one finishes, if I can think of a good use case

Moderately difficult enhancements

[edit]
  • Make year calculation handle leap years correctly
  • Add extra CSS rules which use !important on background properties in order to make said properties apply correctly inside of {{user}} and similar templates (which contain <span>s with class plainlinks). This would require some (regex?) trickery to parse mbTempStyle and mbIndefStyle looking for background-color and other background properties, inserting !important at the end of each. Do other WMF wikis have this issue?
  • Make tipNameDiffers correctly handle the case where mbTooltip begins with a dollar sign; would require some restructuring as commented here
  • Check whether the userlink contains a <span> or other element that has its own title attribute, and if so, append to the custom title instead of removing it. This is "moderately difficult" because I'm not too experienced with jQuery and because it might potentially interact with the linkclassifier redirect warnings.
  • Do something useful with partial blocks – the script currently does not distinguish them from full blocks. This would require me to read some API documentation

Difficult enhancements

[edit]
  • Option to retrieve most recent user rename log entry, if it exists — lelimit=1 would limit the response to the most recent entry if we queried a single user. For multiple users, such a query could fail by exceeding the limit. Should we request a higher limit and then parse the (multi-user) response manually? Should we make an extra API query for each user? Or should this feature be written as a separate script?

Footnotes

[edit]
  1. ^ I have not yet tested the script on a non-English WMF project. However, it has been tested quite extensively on the English Wikipedia and on a non-WMF wiki. I have thought as carefully as possible (and made some test API queries) to ensure that my changes are correct in principle.
  2. ^ a b c For performance reasons, if you want to use this script on a wiki other than the English Wikipedia, you may wish to use a version of the code that does not incorporate the changes labeled with this footnote.

    Changes related to linkclassifier compatibility have been omitted because linkclassifier is not expected to be used verbatim on other wikis; it contains categories specific to the English Wikipedia. If your wiki has a suitably-modified linkclassifier, feel free to talk to me, and I will change this.
    Compromised account detection has been omitted since it is inherently dependent on the words for "compromised," "password" etc. in any given language. This may be made configurable in the future.