User:Pannini/ArticleComments

From mediawiki.org

This is a modification for Extension:ArticleComments.

It adds the comments under the "Add a comment..." text. These comments are collapsible using javascript, the same than the comment form is hidden on page load.

To enable this, set $wgArticleCommentDefaults['displaycomments']=true; in your LocalSettings.php

Apply the folowing patch to the ArticleComments.php code :

--- ArticleComments ori.php	2008-10-06 17:17:32.000000000 +0200
+++ ArticleComments.php	2008-10-07 18:34:47.000000000 +0200
@@ -2,8 +2,10 @@
 /*
  * ArticleComments.php - A MediaWiki extension for adding comment sections to articles.
  * @author Jim R. Wilson
+ * @author Steren Giannini
  * @version 0.4.3
  * @copyright Copyright (C) 2007 Jim R. Wilson
+ * @copyright Copyright (C) 2008 Steren Giannini
  * @license The MIT License - http://www.opensource.org/licenses/mit-license.php 
  * -----------------------------------------------------------------------
  * Description:
@@ -243,6 +245,44 @@
     }
 
     $content .= "})();\n//]]></script>";
+
+    # Show the comments inside the page, under the "Make a comment" link.
+    # Note: To enable, set $wgArticleCommentDefaults['displaycomments']=true in LocalSettings.php
+    if (isset($params['displaycomments']) && $params['displaycomments']==true) {
+        global $wgTitle;
+            $talkTitle = $wgTitle->getTalkPage();
+            if ($talkTitle->exists()) {
+                $talkPage = new Article($talkTitle);
+                $content .='<div id="comments_text">';
+                $talkPage = new Article($talkTitle);
+
+                global $wgUser,$wgParser;
+                $psr = new Parser; $opt = ParserOptions::newFromUser($wgUser) ;
+                $opt->setTemplateCallback(true);
+                $talkpage_html = $psr->parse($talkPage->fetchContent(),$talkTitle,$opt,true,true)->getText();
+                $content.= $talkpage_html ;
+
+                $content .='</div>';
+            }
+        # Hides the comment text until the "Show comments" link is clicked
+        # Note: To disable, set $wgArticleCommentDefaults['hidecomments']=false in LocalSettings.php
+        if (!isset($params['hidecomments']) || 
+            ($params['hidecomments']!='false' &&
+            !$params['hidecomments']===false)) {
+            $content .= "<script type='text/javascript'>//<![CDATA[\n(function(){\n";
+            $content .= 
+                'var cf=document.getElementById("comments_text");'."\n".
+                'cf.style.display="none";'."\n".
+                'var p=document.createElement("p");'."\n".
+                'p.innerHTML="<a href=\'javascript:void(0)\' onclick=\''.
+                'document.getElementById(\\"comments_text\\").style.display=\\"block\\";'.
+                'this.style.display=\\"none\\";false'.
+                '\'>'.wfMsgForContent($ac.'show-comments-link').'</a>";'."\n".
+                'cf.parentNode.insertBefore(p,cf);'."\n";
+            $content .= "})();\n//]]></script>";
+        }
+    }
+
     return $content;
 }
 
@@ -282,12 +322,13 @@
     $wgMessageCache->addMessage('article-comments-comment-field', 'Comment: ');
     $wgMessageCache->addMessage('article-comments-submit-button', 'Submit');
     $wgMessageCache->addMessage('article-comments-leave-comment-link', 'Leave a comment ...');
+    $wgMessageCache->addMessage('article-comments-show-comments-link', 'Show comments ...');
     $wgMessageCache->addMessage('article-comments-invalid-field', 'The $1 provided <nowiki>[$2]</nowiki> is invalid.');
     $wgMessageCache->addMessage('article-comments-required-field', '$1 field is required.');
     $wgMessageCache->addMessage('article-comments-submission-failed', 'Comment Submission Failed');
     $wgMessageCache->addMessage('article-comments-failure-reasons', 'Sorry, your comment submission failed for the following reason(s):');
     $wgMessageCache->addMessage('article-comments-no-comments', 'Sorry, the article &quot;[[$1]]&quot; is not accepting comments at this time.');
-    $wgMessageCache->addMessage('article-comments-talk-page-starter', "<noinclude>Comments on [[$1]]\n<comments />\n----- __NOEDITSECTION__</noinclude>\n");
+    $wgMessageCache->addMessage('article-comments-talk-page-starter', "<noinclude>Comments on [[$1]]\n----- __NOEDITSECTION__ __NOTOC__ </noinclude>\n");
     $wgMessageCache->addMessage('article-comments-commenter-said', '$1 said ...');
     $wgMessageCache->addMessage('article-comments-summary', 'Comment provided by $1 - via ArticleComments extension');
     $wgMessageCache->addMessage('article-comments-submission-succeeded', 'Comment submission succeeded');