Extension:AvbDisqus
|
AvbDisqus Release status: stable |
|||
|---|---|---|---|
| 200px | |||
| Implementation | Tag | ||
| Description | Adds Disqus comments into wiki page | ||
| Author(s) | Alexey Beloblotskiy (beloblotskiyTalk) | ||
| Last 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) | ||
|
|||
|
Check usage (experimental) |
|||
Contents |
[edit] Description
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.
[edit] AvbDisqus (version 2)
[edit] Extension code
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 ); // 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");
[edit] Customization
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.)
[edit] Usage
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.
[edit] My practice
- 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_threadending 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)
[edit] See also
- DISQUS Comments Widget on MediaWikiWidgets.org site, it uses Widgets extension.
