From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Release status: stable
Implementation Tag
Description Adds Disqus comments into wiki page
Author(s) Alexey Beloblotskiy (beloblotskiytalk)
Latest version 2.0 (2009-09-24)
MediaWiki 1.13+
License MIT License
Download copy code below
Example wikikandidat.com
Translate the AvbDisqus extension if it is available at translatewiki.net
Check usage and version matrix.


Enables easy addition of Disqus comments to a MediaWiki pages.

AvbDisqus is MediaWiki tag extension which adds Disqus comments into wiki site.

AvbDisqus (version 2)[edit]

Extension code[edit]

Extension body is written on PHP. Create file

<MediaWiki Root Folder>/extensions/AvbDisqus/avbdisqus.php

and put this code into it.

Extension code (avbdisqus.php):

// AvbDisqus v2
if( !defined( 'MEDIAWIKI' ) ) die( -1 );
/* Setup */
$wgExtensionCredits['other'][] = array(
   'path' => __FILE__,
   'name' => 'AvbDisqus',
   'author' => array( 'Alexey Beloblotskiy', ),
   'version' => '2.0',
   'url' => 'https://www.mediawiki.org/wiki/Extension:AvbDisqus',
   'description' => 'Adds Disqus comments into wiki page

// Disqus settings.
// "Website Name" field in Disqus basic settings for your site.
$wgAvbDisqusWebsiteName = strtolower("");
// Register disqus tag.
$wgExtensionFunctions[] = "AvbDisqusExtension";
// Add hook on SkinAfterBottomScripts (paste the Disqus comment count code).
$wgHooks['SkinAfterBottomScripts'][] = 'onSkinAfterBottomScripts_AddAvbDisqusScript';
// ------------ Disqus tag --------------
function AvbDisqusExtension() {
    global $wgParser;
    # register the extension with the WikiText parser
    # the first parameter is the name of the new tag.
    # In this case it defines the tag <example> ... </example>
    # the second parameter is the callback function for
    # processing the text between the tags
    $wgParser->setHook( "disqus", "render_AvbDisqus" );
// Renders Disqus embed code
function render_AvbDisqus($input, $argv, $parser = null) {
  global $wgAvbDisqusWebsiteName;
  if ($wgAvbDisqusWebsiteName == "") {
    echo('Please, set $wgAvbDisqusWebsiteName in LocalSettings.php');
  if (!$parser) $parser =& $GLOBALS['wgParser'];
  $output = "<!-- avb: AvbDisqus home: http://devwiki.beloblotskiy.com/index.php5?title=AvbDisqus_(MediaWiki_extension) --><div id=\"disqus_thread\"></div><script type=\"text/javascript\" src=\"http://disqus.com/forums/" . $wgAvbDisqusWebsiteName . "/embed.js\"></script><noscript><a href=\"http://" . $wgAvbDisqusWebsiteName . ".disqus.com/?url=ref\">View the discussion thread.</a></noscript><a href=\"http://disqus.com\" class=\"dsq-brlink\">blog comments powered by <span class=\"logo-disqus\">Disqus</span></a>";
  return $output;
// --------------------- Disqus bottom script -------------------------
// Event 'SkinAfterBottomScripts': At the end of Skin::bottomScripts()
// $skin: Skin object
// &$text: bottomScripts Text
// Append to $text to add additional text/scripts after the stock bottom scripts.
// Documentation: \mediawiki-1.13.0\docs\hooks.txt
function onSkinAfterBottomScripts_AddAvbDisqusScript($skin, &$text) 
	global $wgAvbDisqusWebsiteName;
	if ($wgAvbDisqusWebsiteName == "") {
		echo('Please, set $wgAvbDisqusWebsiteName in LocalSettings.php');
	$disqus_bottom_script = "<script type=\"text/javascript\">
    var disqus_shortname = '".$wgAvbDisqusWebsiteName."'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function () {
        var s = document.createElement('script'); s.async = true;
        s.type = 'text/javascript';
        s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
        (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);

	$text .= $disqus_bottom_script;
	return true;

And one more step - add the lines below at the end of your LocalSettings.php

$wgAvbDisqusWebsiteName = strtolower("YOUR_DISQUS_WEBSITE_NAME");


Change value of $wgAvbDisqusWebsiteName in LocalSettings.php: insert your disqus website name instead of YOUR_DISQUS_WEBSITE_NAME. (Website name is in your Disqus Comments Basic Settings.)


Insert <disqus></disqus> tag where you want to see Disqus Comments form. Don't write anything between <disqus> and </disqus>: AvbDisqus extension ignores this text (in this version). Maybe in future I'll use this text to pass some arguments to extension.

My practice[edit]

  • Put code below into certain MediaWiki discussion page (in this example - Talk:MyPage).
  • Put [[Talk:MyPage|Discuss this article]] ([[Task:MyPage#disqus_thread]]) at the end of article (this is example for MyPage article). AvbDisqus add Disqus special JavaScript code at the end of page to replace link with #disqus_thread ending with number of comments. So, you will see:
Discuss this article (0 Comments)

See also[edit]