Jump to content

Extension:Comments

From mediawiki.org
MediaWiki extensions manual
Comments
Release status: stable
Implementation Parser extension , Hook
Description Adds ‎<comments /> parser hook tag that allows commenting on articles
Author(s)
Latest version 5.0
MediaWiki 1.39+
Database changes Yes
Tables Comments
Comments_Vote
Comments_block
License GNU General Public License 2.0 or later
Download
  • $wgCommentsDefaultAvatar
  • $wgCommentsInRecentChanges
  • $wgCommentsAbuseFilterGroup
  • $wgCommentsSortDescending
‎<comments />
  • comment
  • commentadmin
  • commentlinks
  • comment-delete-own
Quarterly downloads 43 (Ranked 92nd)
Translate the Comments extension if it is available at translatewiki.net
Issues Open tasks · Report a bug

The Comments extension adds the ‎<comments /> parser hook tag to allow commenting on articles where the tag is present.

Comment actions are logged to Special:Log/comments, but by default they're hidden, just like patrol log entries. You can set $wgCommentsInRecentChanges = true; to show comments log entries in Special:RecentChanges (available in version 2.8+).

Majority of the code fixes were done by Misza and Jack Phoenix.

Installation

[edit]
  • Download and move the extracted Comments folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Comments
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Comments' );
    
  • Run the update script which will automatically create the necessary database tables that this extension needs.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
You will need to download the master version for the extension to work properly, as there is an issue with the branched versions.

Usage

[edit]
  • ‎<comments /> — basic comment form, sufficient for most things.
  • <comments allow="Derfel,Jack Phoenix,Misza" /> — only allows the users Derfel, Jack Phoenix and Misza to submit comments.
  • <comments voting="Plus" /> — prevents users from rating comments negatively (thumb down), allowing only positive (thumb up) votes.

Comments of the Day

[edit]

The extension also comes with a "Comments of the Day" feature (‎<commentsoftheday />), which by default is not enabled. You can enable this feature in the wiki's LocalSettings.php, by adding the following after the require_once line:

require_once "$IP/extensions/Comments/CommentsOfTheDay.php";

If the nocache argument is passed to the parser hook (like this: <commentsoftheday nocache=true />), the parser hook will not use memcached and will fetch the data from the database instead of cache. This is useful if you want to show the most up-to-date data, but it can be very server-intensive.

User rights

[edit]

This extension adds the following new user rights:

  • comment - which allows posting comments
  • commentlinks - which allows posting external links in comments
  • commentadmin - which allows deleting user-posted comments
  • comment-delete-own - which allows deleting one's own comments, e.g.
$wgGroupPermissions['sysop']['commentadmin'] = true;

By default, everyone, even anonymous users, can post comments, but posting comments that contain external links is limited to autoconfirmed users.

If you want anonymous users to be able to post external links, add this after the require_once:

$wgGroupPermissions['*']['commentlinks'] = true;

By default, only users in the commentadmin group can delete comments.

User points

[edit]
This is relevant only if the SocialProfile extension is installed and $wgUserLevels is properly configured.
  • $wgUserStatsPointValues['comment_plus'] — the number of points to give out when another user gives a "thumbs up" to your comment.
  • $wgUserStatsPointValues['comment_ignored'] — the number of points to give out when another user adds your comments to their ignore list (Special:CommentIgnoreList).

Parameters

[edit]
  • $wgCommentsDefaultAvatar — the path to an image which will be displayed instead of an avatar if social tools (SocialProfile extension) aren't installed. It should be 50x50px. Note that there is no default avatar image shipped with this extension. The default is defined in extension.json and links to an external image on shoutwiki.com server, an ad-driven wiki farm. You may prefer to set this parameter to point to a local file.
  • $wgCommentsInRecentChanges — by default, this variable is set to false. Set it to true to display comments log entries in Special:RecentChanges, too, in addition to the comments log at Special:Log/comments.
  • $wgCommentsSortDescending — by default, this variable is set to false. Set it to true to sort comments by date descending, with the new comment box and most recent comments at the top.
  • $wgCommentsAbuseFilterGroup — This is the custom group name for AbuseFilter for when the AbuseFilter extension is enabled. It ensures that AbuseFilter only pulls the filters related to Comments. If you want AbuseFilter to pull all the filters, enter 'default' here. The default value for this is 'comment', which ensures that AbuseFilter will only look for filters specifically written to target comments.

Magic words/Parser functions

[edit]

Comments includes two magic words and a parser function:

  • {{NUMBEROFCOMMENTS}} gives the entire number of comments on the wiki.
  • {{NUMBEROFCOMMENTSPAGE}} gives number of comments on the current page.
  • {{NUMBEROFCOMMENTSPAGE:<pagename>}} gives number of comments on the given page.

Hooks

[edit]

Comments extension adds three hooks, Comment::add, Comment::delete and Comment::isSpam.

Hook name When it is called Parameters
Comment::add After a comment has been added to the database, at the bottom of Comment::add function
  • $comment (instance of Comment class)
  • $commentID
  • $pageID
Comment::delete After a comment has been deleted and the caches have been purged (function delete on class Comment)
  • &$comment (instance of Comment class)
  • $commentID
  • $pageID
Comment::isSpam Called in Comment::isSpam before performing other spam checks.
  • &$text (user-supplied comment text to check against spam)
  • &$retVal (boolean; function return value, i.e. does the supplied text contain spam (true) or not (false))

Anti-spam

[edit]

Though (as of Q3/2023) Comments does not (yet) support ConfirmEdit, MediaWiki's de facto CAPTCHA extension, there are plenty of other anti-spam measures built in, including:

  • restricting who can add comments and/or comments that contain hyperlinks (see the #User rights section above)
  • support for $wgSpamRegex and $wgSummarySpamRegex
  • possibility for extension developers to implement custom spam checks via the Comment::isSpam hook point (see the #Hooks section above)
  • AbuseFilter interoperability — AbuseFilter can be made to check if the action variable's value is comment to write filters that apply only to comments made via the Comments extension; the new_wikitext variable contains the actual comment text, and the new_size variable is calculated on-demand based on the value of the new_wikitext variable. Refer to AbuseFilter's documentation for more details on how those variables and filters work.
    • The new configuration variable $wgCommentsAbuseFilterGroup can be set to 'default' to make existing AbuseFilter filters apply to comments as well. By default, it is set to 'comment', so only filters specifically designed to target comments will be executed against comments made via the Comments extension.

Internationalization

[edit]

The Comments extension currently has (partial or full) support for 68 different languages, including English. Please visit translatewiki.net if you want to translate Comments or other extensions of the social tools family of extensions into your language or modify existing translations.

See also

[edit]