<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AComments_2.0</id>
	<title>Development:Comments 2.0 - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3AComments_2.0"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Comments_2.0&amp;action=history"/>
	<updated>2026-05-07T15:03:39Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Comments_2.0&amp;diff=10920&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Comments_2.0&amp;diff=10920&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:05Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Comments_2.0&amp;diff=10919&amp;oldid=prev</id>
		<title>1&gt;Mudrd8mz: Text replacement - &quot;class=&quot;nicetable&quot;&quot; to &quot;class=&quot;wikitable&quot;&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Comments_2.0&amp;diff=10919&amp;oldid=prev"/>
		<updated>2021-07-14T13:23:46Z</updated>

		<summary type="html">&lt;p&gt;Text replacement - &amp;quot;class=&amp;quot;nicetable&amp;quot;&amp;quot; to &amp;quot;class=&amp;quot;wikitable&amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Moodle 2.0}}==Objectives==&lt;br /&gt;
&lt;br /&gt;
The goals of comments 2.0:&lt;br /&gt;
&lt;br /&gt;
* Manage comments centrally&lt;br /&gt;
* Use a consistent approach for all comments throughout Moodle&lt;br /&gt;
* Easily integrate comments 2.0 with existing modules&lt;br /&gt;
* Works no matter Javascript is enabled or not&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The comments 2.0 provides APIs to:&lt;br /&gt;
# Add comments&lt;br /&gt;
# Manage comments&lt;br /&gt;
# Delete comments&lt;br /&gt;
&lt;br /&gt;
And provides a fancy ajax interface to add/delete comments without loading a new page.&lt;br /&gt;
&lt;br /&gt;
==Comments database table==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Default&lt;br /&gt;
! Info&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(10)&lt;br /&gt;
| auto-incrementing&lt;br /&gt;
| The unique ID for this comment.&lt;br /&gt;
|-&lt;br /&gt;
| userid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| who wrote this comment&lt;br /&gt;
|-&lt;br /&gt;
| contextid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| The context id defined in context table - identifies the instance of plugin owning the comment.&lt;br /&gt;
|-&lt;br /&gt;
| itemid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| Some plugin specific item id (eg. forum post, blog entry or assignment submission)&lt;br /&gt;
|-&lt;br /&gt;
| commentarea&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| for example, in user profile, you can comment user&amp;#039;s description or interests, but they share the same itemid(==userid), we need comment_area to separate them&lt;br /&gt;
|-&lt;br /&gt;
| timecreated&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| timemodified&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| content&lt;br /&gt;
| text&lt;br /&gt;
|&lt;br /&gt;
| content of comment&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Use Comments API==&lt;br /&gt;
&lt;br /&gt;
===Add an option to format_text function===&lt;br /&gt;
&lt;br /&gt;
Using this format_text function will add a comment icon automatically at the end of the text:&lt;br /&gt;
&lt;br /&gt;
For example, using the following code in the forum module will add a comment icon to every post:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$to = new stdclass;&lt;br /&gt;
$cmt-&amp;gt;contextid = $modcontext-&amp;gt;id;&lt;br /&gt;
$cmt-&amp;gt;area      = &amp;#039;format_post&amp;#039;;&lt;br /&gt;
$cmt-&amp;gt;itemid    = $post-&amp;gt;id;&lt;br /&gt;
$options-&amp;gt;comments = $cmt;&lt;br /&gt;
echo format_text($post-&amp;gt;message, $post-&amp;gt;messageformat, $options, $course-&amp;gt;id).&amp;quot;&amp;lt;hr /&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use comment class===&lt;br /&gt;
To use Comments API elsewhere, using following code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$options-&amp;gt;area    = &amp;#039;database_entry&amp;#039;;&lt;br /&gt;
$options-&amp;gt;context = $context;&lt;br /&gt;
$options-&amp;gt;itemid  = $record-&amp;gt;id;&lt;br /&gt;
$options-&amp;gt;showcount = true;&lt;br /&gt;
$comment = new comment($options);&lt;br /&gt;
$comment-&amp;gt;output(false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
If you are using comments API in module context, you&amp;#039;d better add pluginname option, it will help comments API find callback functions faster:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$options-&amp;gt;area    = &amp;#039;database_entry&amp;#039;;&lt;br /&gt;
$options-&amp;gt;pluginname = &amp;#039;data&amp;#039;;&lt;br /&gt;
$options-&amp;gt;context = $context;&lt;br /&gt;
$options-&amp;gt;itemid  = $record-&amp;gt;id;&lt;br /&gt;
$options-&amp;gt;component = &amp;#039;mod_data&amp;#039;;&lt;br /&gt;
$options-&amp;gt;showcount = true;&lt;br /&gt;
$comment = new comment($options);&lt;br /&gt;
$comment-&amp;gt;output(false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
==Comments API overview==&lt;br /&gt;
&lt;br /&gt;
Generally speaking, only two functions you need to know to get comments 2.0 worked:&lt;br /&gt;
# Use comment::init to initialize comments 2.0&lt;br /&gt;
# Use $comment-&amp;gt;output to display comments&lt;br /&gt;
&lt;br /&gt;
The comment class has been implemented in comment/lib.php.&lt;br /&gt;
===class comment()===&lt;br /&gt;
====__construct($contextid, $comment_area, $itemid))====&lt;br /&gt;
Initialize class members&lt;br /&gt;
&lt;br /&gt;
====init()====&lt;br /&gt;
It is a static function used to initialize comments, setting up languages, which must be called before html head printed&lt;br /&gt;
&lt;br /&gt;
====output($return = false)====&lt;br /&gt;
Will print the html snippet for commenting interface, if set $return as true, it will return html string instead of printing out.&lt;br /&gt;
&lt;br /&gt;
====print_comments($params = array())====&lt;br /&gt;
Used by non-javascript comment interface, will print a list of comments.&lt;br /&gt;
&lt;br /&gt;
====add($content)====&lt;br /&gt;
Public instance funciton, add a comment to database, used in comment/comment_ajax.php&lt;br /&gt;
&lt;br /&gt;
====count()====&lt;br /&gt;
Counting the number of comments&lt;br /&gt;
&lt;br /&gt;
====delete($id)====&lt;br /&gt;
Delete a comment from database, used in comment/comment_ajax.php&lt;br /&gt;
&lt;br /&gt;
====delete_comments====&lt;br /&gt;
Delete all comments in a specific contexts (like all comments belonging to a forum post)&lt;br /&gt;
&lt;br /&gt;
==Javascript API==&lt;br /&gt;
Comments 2.0 implemented a YUI3 module M.core_comment to deal with the communication between browsers and moodle.&lt;br /&gt;
It can be found in comment/comment.js&lt;br /&gt;
&lt;br /&gt;
Call M.core_comment.init will create an instance of CommentHelper class. You don&amp;#039;t need to make any calls to this instance, it simply works out of box.&lt;br /&gt;
&lt;br /&gt;
== Moodle modules callback ==&lt;br /&gt;
Comments API allows modules/blocks/blog to decide how comments display.&lt;br /&gt;
&lt;br /&gt;
=== Data validation ===&lt;br /&gt;
Plugins must implement pluginname_comment_validate callback to validate comments parameters, it must return true to pass validation.&lt;br /&gt;
&lt;br /&gt;
===Permission control===&lt;br /&gt;
Modules must implement function &amp;#039;&amp;#039;&amp;#039;pluginname_comment_permissions&amp;#039;&amp;#039;&amp;#039; to return post and view permission.&lt;br /&gt;
&lt;br /&gt;
Blocks need to overwrite &amp;#039;&amp;#039;&amp;#039;blockname_comment_permissions&amp;#039;&amp;#039;&amp;#039; function of block_base.&lt;br /&gt;
&lt;br /&gt;
Blog need to implement &amp;#039;&amp;#039;&amp;#039;blog_comment_permissions&amp;#039;&amp;#039;&amp;#039; function.&lt;br /&gt;
&lt;br /&gt;
This function will return an array: array(&amp;#039;post&amp;#039;=&amp;gt;true, &amp;#039;view&amp;#039;=&amp;gt;true)&lt;br /&gt;
&lt;br /&gt;
=== Check new added comment ===&lt;br /&gt;
The callback function allows you to change the comment content before inserting into database or reject this comment.&lt;br /&gt;
&lt;br /&gt;
It takes two arguments, the comment object which contains comment details, and $params which contains context and course information.&lt;br /&gt;
&lt;br /&gt;
Modules can implement a function named &amp;#039;&amp;#039;&amp;#039;modname_comment_add&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Blocks need to overwrite &amp;#039;&amp;#039;&amp;#039;blockname_comment_add&amp;#039;&amp;#039;&amp;#039; function.&lt;br /&gt;
&lt;br /&gt;
Blog need to implement &amp;#039;&amp;#039;&amp;#039;blog_comment_add&amp;#039;&amp;#039;&amp;#039; function.&lt;br /&gt;
&lt;br /&gt;
This function should return a boolean value. &lt;br /&gt;
&lt;br /&gt;
=== Filter/format comments ===&lt;br /&gt;
This callback allows modules check/format comments when user request to display comments.&lt;br /&gt;
&lt;br /&gt;
It takes the same arguments as pluginname_comment_add&lt;br /&gt;
&lt;br /&gt;
Modules can implement a function named &amp;#039;&amp;#039;&amp;#039;pluginname_comment_display&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Blocks need to overwrite &amp;#039;&amp;#039;&amp;#039;blockname_comment_display&amp;#039;&amp;#039;&amp;#039; function.&lt;br /&gt;
&lt;br /&gt;
Blog need to implement &amp;#039;&amp;#039;&amp;#039;blog_comment_display&amp;#039;&amp;#039;&amp;#039; function.&lt;br /&gt;
&lt;br /&gt;
It will return the comment object.&lt;br /&gt;
&lt;br /&gt;
=== Define a comment template ===&lt;br /&gt;
Modules can implement a function named &amp;#039;&amp;#039;&amp;#039;pluginname_comment_template&amp;#039;&amp;#039;&amp;#039;, which allow modules define a comment template.&lt;br /&gt;
The template must have 4 embedding variables, ___id___, ___content___, ___time___, ___name___, they will be replaced with html id, comments content, comment time and commenter name&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* MDL-19118 - Comments 2.0 issue&lt;/div&gt;</summary>
		<author><name>1&gt;Mudrd8mz</name></author>
	</entry>
</feed>