User:SoledadKabocha/markBlockedPlus

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
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
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  with the argument   (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. 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  begins with a dollar sign (whether or not it is part of a  -  parameter); therefore,   should not be set to begin with a dollar sign, until further notice.

Configuration
These settings are changed by inserting a line such as  directly above the aforementioned   line; replace   with the actual name of each setting.

Settings present in original mark-blocked script
CSS style to apply to the  class, used for finitely-blocked users (the shorter of the two tiers, if mbLongThreshold has been set) CSS style to apply to the  class, used for indefinitely-blocked users 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 #.) CSS style to apply to the tipbox that indicates a blocked user, which has the class Tooltip text to add for blocked users; the following symbols are handled specially:
 * mbTempStyle (string; default ' ')
 * mbIndefStyle (string; default ' ')
 * mbTipBox (boolean; default )
 * mbTipBoxStyle (string; default ' ')
 * mbTooltip (string; default ' ')
 * is replaced by the length of the block
 * is replaced by the blocking administrator's username
 * is replaced by the date and time the block started
 * 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.

Opacity to apply to user links for which an API query is still in progress 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)
 * mbLoadingOpacity (numeric; default )
 * mbNoAutoStart (boolean; default )

New features
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) Whether to process user links on edit pages (the original script's behavior was equivalent to, presumably for performance and/or compatibility with other scripts) 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 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, e.g.. If this is set, blocks shorter than this number of milliseconds will be given the CSS class, while equal or longer blocks will be given. When this is true, the calculations for mbLongThreshold and mbPseudoIndefThreshold are based on the remaining time of the block rather than its total duration. Name of the link group in which the portlet link will be placed when  is  ; by default, it is located near the "Move" link. ' ' puts it in the "Toolbox" section of the sidebar Text to use for the portlet link that is added when  is  If this is set, blocks longer than this number of milliseconds will be CSS-styled as if they were indefinite. 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. Whether errors in API queries should be reported in Firefox's Error Console or the equivalent in other browsers; this is  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  and tell me the exact error message. Whether to show the edit count of a registered user 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.) Whether to show the (abs-olute) date and time that the account was registered Whether to show the (rel-ative) time interval ago that the account was registered Whether to show a message for usernames which are not registered 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 CSS style to apply to the  class, used for finite blocks in the longer of the two tiers (requires mbLongThreshold to be set) Number of initial characters to remove from the string in  before adding it to the tooltip of the  [B] tipbox; the default 2 removes a semicolon and space Letter (or other text) to show inside the tipbox for blocked users 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. CSS style to apply to the user-info tipbox, which has the class Letter (or other text) to show inside the tipbox for user info other than blocks Message to show for usernames which are not registered
 * mbEnableOnMainspaceDiff (boolean; default )
 * mbEnableWhenEditing (boolean; default )
 * mbLinkClassifierRedirWarn (boolean; default )
 * mbLocalContribsName (string or array of strings) &mdash; was available in an older version of the original mark-blocked script (accepting only a single string)
 * mbLongThreshold (integer; no default, which disables the two-tier system)
 * mbLongThreshIsRemainingTime (boolean; default )
 * mbOnDemandLinkLoc (string; default ' ')
 * mbOnDemandLinkText (string; default ' ')
 * mbPseudoIndefThreshold (integer; no default, so this feature is disabled by default)
 * mbRemoveWaitingCSSOnError (boolean; default )
 * mbReportApiErrors (boolean; default )
 * 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 )
 * mbShowGroups (boolean; default )
 * mbShowRegDateAbs (boolean; default )
 * mbShowRegDateRel (boolean; default )
 * mbShowUnregistered (boolean; default )
 * mbShowYears (boolean; default )
 * mbTemp2Style (string; default same as mbTempStyle)
 * mbTipBoxCharsToTrim (integer; default )
 * mbTipBoxText (string; default ' ')
 * mbTipBoxInfo (boolean; default )
 * mbTipBoxInfoStyle (string; default ' ')
 * mbTipBoxInfoText (string; default ' ')
 * mbUnregisteredText (string; default ' ')

Bugs fixed and other changes from original mark-blocked script

 * This script makes extra efforts to [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=539365718&oldid=539320640 ensure] that configuration variables are of the expected data type. This was needed because Firefox 19 seems to make some element IDs readable as properties of the  object. Hence, if a page contained an  with the same name as a configuration setting (such as this documentation page), the script would fail trying to perform string operations on a page element.
 * The original script hard-coded the English and Russian localizations for . I have changed it to [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=522497451&oldid=522430102 detect the localized name(s) automatically].
 * This script [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=517421087&oldid=517334992 ignores] links added to section headings by User:Bility/copySectionLink; it looks cluttered to place a tipbox there. Also, the functionality is redundant given that such links would only ever be marked on user and user talk pages, where the "User page" tab would be marked too.
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=513451999&oldid=513449420 strips leading and trailing spaces] from usernames. In the original script, if someone typed a space between  and the username or IP, the space would make its way to the API query, and the API would reject the request.
 * This script adds the CSS class  if it finds a link containing a malformed username (see the next few items). There are no default rules for this class; you need to write your own rules in a user stylesheet if desired.
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=514697757&oldid=514529692 ignores] the username . The API rejects queries for that username because it treats it as "empty."
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=561729062&oldid=559917000 ignores] Special:Contributions/newbies so as to avoid unnecessary API queries for the username.
 * This script [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=522259204&oldid=521595508 now respects] the 64-character limit that the API asserts on usernames. This prevents the script from failing when it encounters e.g., which was formerly used in the arbitration enforcement request template. (TODO: why is the limit 64 characters?)
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=533320302&oldid=528368247 skips] usernames that contain certain invalid characters, including but not limited to U+FFFD (which appears as a question mark inside a diamond; examples can be found on the [ last two pages at 100 users/page of Special:ListUsers here on the English Wikipedia].) Apparently the technical restrictions were different in earlier versions of MediaWiki.
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=525485658&oldid=522497451 normalizes the first letter of usernames to be uppercase] before doing any further processing. This prevents  from being treated differently from  ; on a page containing both, the former would not be marked, and the latter would have its tooltip amended twice (discussion of example).
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=528368247&oldid=525485658 explicitly detects and ignores] extraneous "User:" prefixes such as User:User:Example. This avoids a problem in which the tooltip for User:Example would be amended twice if such a link were also present. The code has since been [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=547030979&oldid=540402132 revised] to additionally handle "User talk:" and to work with non-English languages.
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=515843757&oldid=515842665 removes only the portlet link itself] once said link is clicked, rather than the link's parent as the original script did. On at least the Vector skin, the latter would wrongly remove the entire portlet, disabling the "Move" link as well.
 * This script [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=536763216&oldid=533320302 examines block reasons] for possible indications of a compromised account, and it adds the CSS class  if such an indication is found. There are no default rules for this class.
 * This script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=559917000&oldid=559914215 removes] custom tooltips that users may have applied in their signatures, to ensure that the tooltips generated by the script will be visible.
 * For time intervals at least 1 day but shorter than 10 days, this script [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=515049271&oldid=515048274 shows] e.g. 9d 1h . The original script showed 9.01d ; that was confusing for users in the United States, for whom the period is normally a decimal point.
 * Since purges redirect back to a "view" of the page that was purged, I decided to have the script simply give up if the action is ever purge, which should be impossible at least on WMF wikis.
 * [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=578329454&oldid=575033729 Configuration option to enable the script on diffs in mainspace]
 * [//en.wikipedia.org/w/index.php?title=User%3ASoledadKabocha%2FmarkBlockedPlus.js&diff=519268643&oldid=517421087 See the "Compatibility with linkclassifier" section above].

TODO
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

 * 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; )
 * 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 [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=582592379&oldid=582305826 automatically calling another script after this one finishes], if I can think of a good use case

Moderately difficult enhancements

 * Make year calculation handle leap years correctly
 * Add [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/common.css&diff=prev&oldid=522943818 extra CSS rules] which use  on background properties in order to make said properties apply correctly inside of  and similar templates (which contain  s with class  ). This would require some (regex?) trickery to parse   and   looking for   and other background properties, inserting   at the end of each. Do other WMF wikis have this issue?
 * Make  correctly handle the case where   begins with a dollar sign; would require some restructuring as commented [//en.wikipedia.org/w/index.php?title=User:SoledadKabocha/markBlockedPlus.js&diff=547389163&oldid=547030979 here]
 * Check whether the userlink contains a  or other element that has its own   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

 * Option to retrieve most recent user rename log entry, if it exists &mdash;  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?