Extension:AvbDisqus

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

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 or newer
License MIT
Download http://devwiki.beloblotskiy.com/index.php5/AvbDisqus_(MediaWiki_extension)
Example http://devwiki.beloblotskiy.com/index.php5/AvbDisqus_(MediaWiki_extension)
Parameters

$wgAvbDisqusWebsiteName

Translate the AvbDisqus extension if possible

Check usage and version matrix; code metrics

Description[edit | edit source]

Enables easy addition of Disqus comments to a MediaWiki pages.

See demo-picture there: http://devwiki.beloblotskiy.com/images/4/42/Extensions-AvbDisqus.png

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

AvbDisqus (version 2)[edit | edit source]

Extension code[edit | edit source]

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):

<?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');
    die(1);
  }
 
 
  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');
		die(1);
	}
 
	$disqus_bottom_script = "<script type=\"text/javascript\">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    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);
    }());
</script>";
 
	$text .= $disqus_bottom_script;
	return true;
}


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

require_once("extensions/AvbDisqus/avbdisqus.php");
$wgAvbDisqusWebsiteName = strtolower("YOUR_DISQUS_WEBSITE_NAME");

Customization[edit | edit source]

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.)


Usage[edit | edit source]

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

  • Put code below into certain MediaWiki discussion page (in this example - Talk:MyPage).
<disqus></disqus>
  • 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)


Example can be found there: http://devwiki.beloblotskiy.com/index.php5/AvbDisqus_(MediaWiki_extension)

See also[edit | edit source]