Extension:Comments

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Comments

Release status: stable

Comments.png
Implementation Parser extension
Description Adds <comments> parser hook tag that allows commenting on articles
Author(s) David Pean
Misza
Jack Phoenix
Latest version 3.0 (2013-12-06)
MediaWiki 1.19+
Tables Comments
Comments_Vote
Comments_block
License GNU General Public License 2.0 or later
Download
Parameters
  • $wgCommentsDefaultAvatar
  • $wgCommentsInRecentChanges
Tags
<comments />
Added rights
  • comment
  • commentadmin
  • commentlinks
Hooks used
MagicWordwgVariableIDs

ParserFirstCallInit
ParserGetVariableValueSwitch
LoadExtensionSchemaUpdates

Translate the Comments extension if possible

Check usage and version matrix; code metrics
Bugs: list open list all report

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 | edit source]

  1. Download the files into $IP/extensions/Comments
  2. Add
    require_once "$IP/extensions/Comments/Comment.php";
    into the wiki's LocalSettings.php
  3. Create the three required database tables by running maintenance/update.php, the MediaWiki core updater script
  4. Installation can now be verified through the wiki's Special:Version

Usage[edit | edit source]

  • <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 | edit source]

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 just 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 | edit source]

This extension adds three new user rights, comment (which allows posting comments), commentlinks (which allows posting external links in comments) and commentadmin (which allows deleting user-posted comments).

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 links, add this after the require_once:

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

Only users in the commentadmin group can delete comments.

User points[edit | edit source]

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

Parameters[edit | edit source]

  • $wgCommentsDefaultAvatar — path to an image which will be displayed instead of an avatar if social tools (SocialProfile extension) aren't installed. Should be 50x50px.
  • $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.

Magic words/Parser functions[edit | edit source]

Comments includes 2 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 | edit source]

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 into the database, on the bottom of Comment::add function
  • &$commentClass (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)
  • &$commentClass (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))

Internationalization[edit | edit source]

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 into your language.

TODO list[edit | edit source]

  1. HTML output is not valid XHTML - would be nice if it were but we can live without that
  2. Would be nice if there was a special page that gives a overview of all uses of the Comments extension on all pages (for an adminstrator to be able to moderate easier)

Version history[edit | edit source]

Version Version control system revision Release date Comments
3.0 gerrit:99632 6 December 2013 AJAX pagination, better anti-spam measures, fixes loop issue (an unclosed comments tag would cause an infinite loop)
2.9 gerrit:98375 5 December 2013 {{NUMBEROFCOMMENTSPAGE}} magic word to show the amount of comments a particular page has
2.8 gerrit:76455 28 July 2013 Fixes bug #51115 and many other issues. Tested against MediaWiki 1.21.1, requires at least MediaWiki 1.19 or newer.
2.7 r115137 4 May 2012 Fixes bug #34345, so "Delete Comment" links work again.
2.6 r111059 9 February 2012 Don't show voting buttons to users who don't have the "comment" user right.
2.6 r111040 9 February 2012 Fixes bug #34284 — redirect the user to the page they came from by sticking the returnto parameter to the URL.
2.6 r111037 9 February 2012 Don't show "reply" links to users who aren't allowed to comment.
2.6 r108577 11 January 2012 Removed the usage of deprecated LanguageGetMagic hook.
2.5 r108296 7 January 2012 First version that fully supports ResourceLoader and thus requires MediaWiki 1.18 or newer.
2.4.1 r108295 7 January 2012 Bugfix to Special:CommentIgnoreList: anonymous users can now be removed from the comment ignore list.
2.4.1 r97062 14 September 2011 Initial public release, phase II changes:
  • initial ResourceLoader support added
  • wfLoadExtensionMessages() cruft removed
  • CSS is no longer loaded in Comment::display(), but rather in the main extension setup file
  • initial ResourceLoader support
  • used $this->getTitle() instead of SpecialPage::getTitleFor( ... ) when appropriate
  • removed unused legacy (ArmchairGM) ChangeToStep() function from Comment.js
  • JavaScript file rewritten to be more object-oriented
  • i18n JS globals loaded via the MakeGlobalVariablesScript hook in displayComments()
  • using Title::getArticleID() instead of Title::$mArticleID in displayComments()
  • $wgCommentsLog variable was removed; comment logging is now unconditionally enabled, but hidden, like the patrol log
  • removed Comment::$title and Comment::setTitle() + the related code from displayComments() as unused
  • added initial support of normal MW parser hook args to displayComments()
  • removed Comment::$Userid and Comment::$Username in favor of $wgUser->getId() and $wgUser->getName() — addslashes srsly sucks. This fixes the annoying, ages-old doubleslashing issue: when [[User:Testing "for XSS]] would submit a comment, it'd show up as "Testing \"for XSS" and the link would be incorrect
  • new <commentsoftheday /> parser hook, see CommentsOfTheDay.php; load that file separately in your wiki's LocalSettings.php if you need it, it's not loaded by default
2.3 r1750 (ShoutWiki SVN) 21 July 2010 Expanded documentation, fixed an old FIXME (a better error message is now displayed if user doesn't have 'comment' user right instead of the "log in" message), removed unused $this->parser variable, fixed a bug in display() by removing the usage of $wgTitle ($wgTitle points to Special:CommentListGet instead of current page...^demon was right, $wgTitle is evil)
2.3 r1570 (ShoutWiki SVN) 29 March 2010 Documentation update, renamed a few variables and tweaked French (fr) translation
2.3 r1555 (ShoutWiki SVN) 27 March 2010 Spacing tweak in the main extension setup file
2.3 r1436 (ShoutWiki SVN) 17 February 2010 Removed an unused variable ($sk), changed some double quotes to single quotes, renamed a variable and broke some long lines in CommentClass.php
2.3 r1433 (ShoutWiki SVN) 12 February 2010 Removed unused $wgComments variable and add semicolons to JS variables
2.3 r1432 (ShoutWiki SVN) 12 February 2010 Fixed a bug in Special:CommentIgnoreList — it would return a "no such special page" error and was doing infinite looping by trying to redirect anons into itself instead of Special:UserLogin. Also changed a while() to foreach(), as per MediaWiki's coding conventions
2.3 r1425 (ShoutWiki SVN) 6 February 2010 Tweaked CommentClass.php so that it shows voted.gif if you have voted for a comment; partially reverts r848 (once again)
2.3 r1422 (ShoutWiki SVN) 31 January 2010 Tweaked Finnish (fi) translation of 'comment-reply-to' message
2.3 r1412 (ShoutWiki SVN) 28 January 2010
  • Shortened some long lines
  • while → foreach, per MediaWiki's coding conventions
  • Removed PHP4-isms (hooks in CommentClass.php)
  • Trimmed trailing spaces
2.3 r1377 (ShoutWiki SVN) 16 January 2010 Added two new Dutch (nl) translations and fixed "Problem at line 108 character 19: Use '===' to compare with '0'." in Comment.js
2.3 r1361 (ShoutWiki SVN) 5 January 2010 Fixed E_PARSE introduced in r1357
2.3 r1357 (ShoutWiki SVN) 5 January 2010 Initial Dutch (nl) translation and tweaks to French (fr) translation
2.3 r1335 (ShoutWiki SVN) 19 December 2009 Removed usage of deprecated ereg() function in CommentClass.php in favor of preg_match()
2.3 r1334 (ShoutWiki SVN) 19 December 2009 voted.gif, which was removed in r848, was added back
2.3 r1323 (ShoutWiki SVN) 12 December 2009 Coding style nitpicks
2.3 r1307 (ShoutWiki SVN) 5 December 2009 Version 2.3 — no longer requires SocialProfile
2.2 r1292 (ShoutWiki SVN) 28 November 2009 Fixed a fatal + PHP 5.3 bitching (Warning: Parameter 3 to displayComments() expected to be a reference, value given in ..\includes\parser\Parser.php on line 3243)
2.2 r1262 (ShoutWiki SVN) 7 November 2009
  • General coding style cleanup
  • Shortened lines in the JavaScript file
  • Bumped version number to 2.2
  • Removed useless $max_link_text_lenght global in CommentClass.php
  • Capitalized SQL keywords
  • Tweaked error suppression/restoration
  • else if → elseif
  • Tweaked French (fr) translation
2.1 r1237 (ShoutWiki SVN) 18 October 2009 Removed backwards compatibility code for the parser hook, as per r55838
2.1 r1084 (ShoutWiki SVN) 4 July 2009 Fix for previous commit, r1083.
2.1 r1083 (ShoutWiki SVN) 4 July 2009 New configuration global, $wgCommentsDefaultAvatar, for setting the URL of a default avatar which will be used on non-social wikis + bumped version to 2.1
2.0 r1082 (ShoutWiki SVN) 3 July 2009 Removed silly default AUTO_INCREMENT values from the SQL file
2.0 r1081 (ShoutWiki SVN) 3 July 2009
  • Fixed some E_STRICTs by suppressing warnings
  • Renamed some functions, removed a deprecated one
  • Added some class_exists() checks here and there so that this extension can be enabled for non-social wikis
  • JavaScript rewritten so that it doesn't require YUI anymore. Ideally those display statements should be moved into function changeOpac but that function doesn't know if it's supposed to show or hide something...
2.0 r1066 (ShoutWiki SVN) 2 July 2009 Added the Comment::delete hook into Comment::delete() for Extension:LinkFilter
2.0 r1064 (ShoutWiki SVN) 2 July 2009 Added the Comment::add hook into Comment::add() for Extension:LinkFilter
2.0 r1038 (ShoutWiki SVN) 26 June 2009 Fixed some E_STRICTs in CommentClass.php
2.0 r1036 (ShoutWiki SVN) 22 June 2009 Tweaked variable name as per the coding conventions
2.0 r1023 (ShoutWiki SVN) 13 June 2009 Removed displayCommentScorecard() function, related code snippets and some unused code from function display()
2.0 r1022 (ShoutWiki SVN) 13 June 2009 Removed EOL whitespace and some commented-out code
2.0 r1021 (ShoutWiki SVN) 13 June 2009 Cleanup & documentation to main class file
2.0 r1020 (ShoutWiki SVN) 13 June 2009 Added a semicolon after a function call in Comment.js
2.0 r1019 (ShoutWiki SVN) 13 June 2009 Cleanup to AjaxFunctions file — removed class_exists() checks for Publish stuff (we don't want that) + changed all $Comment variables to $comment as per coding conventions
2.0 r1018 (ShoutWiki SVN) 13 June 2009 Changed $ to document.getElementById in Comment.js
2.0 r1017 (ShoutWiki SVN) 13 June 2009 Removed a line which was commented out from Comment.js
2.0 r943 (ShoutWiki SVN) 21 May 2009 Removed EOL whitespace and added copyright
2.0 r920 (ShoutWiki SVN) 7 May 2009 Removed a fixme comment from Comment.js
2.0 r895 (ShoutWiki SVN) 2 May 2009 Changed urlencode to htmlspecialchars in Comment::display(). Code by Pinky
2.0 r894 (ShoutWiki SVN) 2 May 2009 Very odd CSS fix for an odd CSS issue. Reply/permalink links were misaligned in Monobook, Modern etc. but not in Nimbus or Monaco. This fixes those links for Monobook, Truglass, phpBB and partially for Modern (looks like it needs 40px or something). Nimbus and Monaco both override this later on back to 10px so it's also looking good on those skins.
2.0 r893 (ShoutWiki SVN) 2 May 2009 Added a space after every semicolon in Comments.css; no functional changes
2.0 r872 (ShoutWiki SVN) 25 April 2009 Added plurals for time-related messages ('comments-time-days', 'comments-time-hours', 'comments-time-minutes' and 'comments-time-seconds')
2.0 r871 (ShoutWiki SVN) 25 April 2009 Tweaked the wording of the 'comment-anon-message' internationalization message
2.0 r870 (ShoutWiki SVN) 25 April 2009 Cleanup to JavaScript file (double quotes → single quotes where appropriate, add missing semicolons, tweak spacing and so on)
2.0 r869 (ShoutWiki SVN) 25 April 2009 Fix show_comment JavaScript function — now actually shows the previously-hidden comment in addition to hiding the "you are ignoring the author of this comment" message
2.0 r868 (ShoutWiki SVN) 25 April 2009 JavaScript fix — alert would previously say "object Object", now it actually says "ok"
2.0 r867 (ShoutWiki SVN) 25 April 2009 Added internationalization messages 'group-commentadmin' and 'group-commentadmin-member' for Special:ListUsers
2.0 r866 (ShoutWiki SVN) 25 April 2009 Removed an unnecessary closing span tag for XHTML compliance in CommentClass.php, function display()
2.0 r865 (ShoutWiki SVN) 25 April 2009
  • Removed $wgAnonName global — replaced by 'comment-anon-name' internationalization message
  • Check for wfReadOnly() rather than for $wgReadOnly in CommentClass.php, function display()
2.0 r864 (ShoutWiki SVN) 25 April 2009
  • Cleaned up HTML output a bit
  • Cleaned up retarded internationalization construction (related to the comment auto-refresher feature)
  • Grammar fixes for French (fr) translations
2.0 r863 (ShoutWiki SVN) 25 April 2009 Converted a raw SQL query to use the Database wrapper class in CommentClass.php, function getCommentList()
2.0 r861 (ShoutWiki SVN) 25 April 2009 Use wfReadOnly() rather than $wgReadOnly + bumped version number from 1.1 to 2.0
1.1 r860 (ShoutWiki SVN) 25 April 2009 Totally removed the updateStats() function and calls to it in CommentClass.php
1.1 r854 (ShoutWiki SVN) 24 April 2009 Commented out the updateStats function in CommentClass.php, we don't need nor want it
1.1 r849 (ShoutWiki SVN) 24 April 2009 Call functions of Vote and Publish classes only if said classes exist in Comments_AjaxFunctions.php
1.1 r848 (ShoutWiki SVN) 24 April 2009
  • Removed references to voted.gif — no such image
  • wfMsgForContent → wfMsg
  • Tweaked internationalization messages
  • Add myself into authors
  • Semicolons & spacing for the JavaScript file
1.1 r847 (ShoutWiki SVN) 24 April 2009 Changed a double-equals comparison operator in Comments_AjaxFunctions.php to triple-equals comparison operator to fix a bug
1.1 r829 (ShoutWiki SVN) 18 April 2009 Spacing, removed some unused globals, fixed userlogin links for non-English languages (canonical name is not CamelCased), converted Title::makeTitle to SpecialPage::getTitleFor
1.1 r668 (ShoutWiki SVN) 13 March 2009 Removed unused globals, add spacing, changed some DB_MASTERs to DB_SLAVEs, converted a raw SQL query to use the Database class + XHTML compliance
1.1 r667 (ShoutWiki SVN) 13 March 2009 Cleanup to AJAX functions file — removed unused globals, added spacing and changed one DB_MASTER to DB_SLAVE
1.1 r450 (ShoutWiki SVN) 20 January 2009 Added internationalization messages for Special:ListGroupRights ('right-comment' and 'right-commentadmin')
1.1 r352 (ShoutWiki SVN) 28 December 2008 General code cleanup, coding style cleanup, marked one function as public static to stop PHP from whining, changed double quotes to single quotes, used DB_SLAVE instead of DB_MASTER for read queries, used MediaWiki's Database wrapper class whenever possible and added some newlines to HTML output
1.1 r262 (ShoutWiki SVN) 6 December 2008 Added calls to Database::commit() whereever needed
1.1 r172 (ShoutWiki SVN) 14 November 2008 Merged r3449 from Wikia codebase: "spam check no longer compatible..remove for now"
1.1 r137 (ShoutWiki SVN) 14 November 2008 Fixed a minor display bug by adding a linebreak to Comment::displayOrderForm() output right before it is returned and removed an unused global ($wgUploadPath) from the same function
1.1 r136 (ShoutWiki SVN) 30 October 2008 Added missing $wgUploadPath global declaration to Comment::display() in CommentClass.php
1.1 r135 (ShoutWiki SVN) 30 October 2008 Added new images directory, moved all images there and changed paths in CommentClass.php accordingly
1.1 r132 (ShoutWiki SVN) 29 October 2008 Loaded AJAX functions file in the main extension setup file
1.1 r108 (ShoutWiki SVN) 17 October 2008 Initial French translation
1.1 r72 (ShoutWiki SVN) 9 October 2008 Missing internationalization message 'comments-time-days' added
1.1 r70 (ShoutWiki SVN) 5 October 2008 Removed dependency on GlobalFunctionsNY.php and removed CSS duplication
1.1 r67 (ShoutWiki SVN) 4 October 2008 Fixed some database declarations again ($dbr should be used for slaves and $dbw for master)
1.1 First working version by Misza
1.0 Initial cleaned-up version of extensions/wikia/Comments/ by Jack Phoenix
Social tools
SocialProfile OverviewRoadmapDeveloper infoScreenshotsHistoryUserStatus (GSoC 2011 project)
Other social extensions Automatic Board WelcomeBlogPageFanBoxesNewUsersListPictureGamePollNYQuizGameRandomFeaturedUserRandomGameUnitRandomUsersWithAvatarsSiteMetricsSportsTeamsUserStatusUserWelcome
Semanticness Semantic Social Profile
Other related extensions
(which do not depend on SocialProfile)
AnswersCommentsLinkFilterMediaWikiChatNewSignupPageVideoVoteNYWikiForumWikiTextLoggedInOut