Extension:MpDisqus
From MediaWiki.org
|
Release status: beta |
|||
|---|---|---|---|
| Implementation | Skin | ||
| Description | Integrates Disqus commenting service at bottom of each page | ||
| Last Version | 0.1 (2009-10-28) | ||
| MediaWiki | 1.16 or newer | ||
| License | GPL | ||
| Download | Extension:MpDisqus#Code | ||
| Example | http://hääwiki.fi/wiki/Sandbox | ||
|
|||
|
|||
|
check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
This extension automatically integrates the Disqus commenting service on each MediaWiki-page, right after the content area.
[edit] Download instructions
Please cut and paste the code found below and place it in $IP/extensions/MpDisqus/MpDisqus.php and $IP/extensions/MpDisqus/MpDisqus.i18n.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
To install this extension, add the following to LocalSettings.php:
$wgMpDisqusWebsiteName = "insert_disqus_site_id_here"; $wgMpDisqusExclude = array("Main Page", "*:*"); require_once("$IP/extensions/MpDisqus/MpDisqus.php");
[edit] Configuration parameters
$wgMpDisqusWebsiteName: This is the site alias assigned by the disqus service.
$wgMpDisqusExclude: This parameter let's you specify a list of pages where no disqus-comments should be displayed.
[edit] Code
[edit] MpDisqus.php
<?php /** * Disqus Integration extension * * @file * @ingroup Extensions * * This file contains the main include file for the mpDisqus extension of * MediaWiki. * * Usage: Add the following line in LocalSettings.php: * require_once( "$IP/extensions/MpDisqus/MpDisqus.php" ); * * @author Michael Platzer <michael.platzer@gmail.com> * @license GPL * @version 0.1 */ // Check environment if ( !defined( 'MEDIAWIKI' ) ) { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); } // Credits $wgExtensionCredits['specialpage'][] = array( 'name' => 'MpDisqus', 'version' => '0.1', 'author' => 'Michael Platzer', 'description' => 'Integrates Disqus commenting service', 'descriptionmsg' => 'mpdisqus-desc', 'url' => 'http://www.mediawiki.org/wiki/Extension:MpDisqus' ); // Disqus settings. // "Website Name" field in Disqus basic settings for your site. $wgMpDisqusWebsiteName = strtolower(""); // Add hooks $wgHooks['SkinAfterContent'][] = 'onSkinAfterContent_AddMpDisqus1'; $wgHooks['SkinAfterBottomScripts'][] = 'onSkinAfterBottomScripts_AddMpDisqus2'; // Add messages $dir = dirname( __FILE__ ) . '/'; $wgExtensionMessagesFiles['MpDisqus'] = $dir . 'MpDisqus.i18n.php'; // Helper method function mpDisqusInArray($needle, $haystack) { # this function allows wildcards in the array to be searched foreach ($haystack as $value) { if (true === fnmatch($value, $needle)) { return true; } } return false; } // Event 'SkinAfterContent': Allows extensions to add text after the page content and article metadata. // &$data: (string) Text to be printed out directly (without parsing) // This hook should work in all skins. Just set the &$data variable to the text you're going to add. // Documentation: \mediawiki-1.16.0\docs\hooks.txt function onSkinAfterContent_AddMpDisqus1(&$data) { global $wgMpDisqusWebsiteName, $wgMpDisqusExclude, $wgTitle, $wgRequest; if ($wgRequest->getVal('action', 'view') != "view") { return true; } if ($wgMpDisqusExclude != NULL && mpDisqusInArray($wgTitle->getFullText(), $wgMpDisqusExclude) == 1) { return true; } if ($wgMpDisqusWebsiteName == "") { echo('Please, set $wgMpDisqusWebsiteName in LocalSettings.php'); die(1); } $before = wfMsgForContent('mpdisqus-before'); $after = wfMsgForContent('mpdisqus-after'); $data = $before . "<script type=\"text/javascript\"> //<![CDATA[ var disqus_developer = 0; var disqus_url = \"" . $wgRequest->getFullRequestURL() . "\"; var disqus_title = \"" . $wgTitle->getText() . "\"; //]]> </script> <br /><div id=\"disqus_thread\"></div><script type=\"text/javascript\" src=\"http://disqus.com/forums/" . $wgMpDisqusWebsiteName . "/embed.js\"></script><noscript><a href=\"http://disqus.com/forums/" . $wgMpDisqusWebsiteName . "/?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>" . $after; return true; } // 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.16.0\docs\hooks.txt function onSkinAfterBottomScripts_AddMpDisqus2($skin, &$text) { global $wgMpDisqusWebsiteName, $wgMpDisqusExclude, $wgTitle, $wgRequest; if ($wgRequest->getVal('action', 'view') != "view") { return true; } if ($wgMpDisqusExclude != NULL && mpDisqusInArray($wgTitle->getFullText(), $wgMpDisqusExclude) == 1) { return true; } if ($wgMpDisqusWebsiteName == "") { echo('Please, set $wgMpDisqusWebsiteName in LocalSettings.php'); die(1); } $disqus_bottom_script = "<script type=\"text/javascript\"> //<![CDATA[ (function() { var links = document.getElementsByTagName('a'); var query = '?'; for(var i = 0; i < links.length; i++) { if(links[i].href.indexOf('#disqus_thread') >= 0) { query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&'; } } document.write('<script charset=\"utf-8\" type=\"text/javascript\" src=\"http://disqus.com/forums/" . $wgMpDisqusWebsiteName . "/get_num_replies.js' + query + '\"></' + 'script>'); })(); //]]> </script>"; $text .= $disqus_bottom_script; return true; }
[edit] MpDisqus.i18n.php
<?php /** * Internationalisation file for MpDisqus extension. * * @addtogroup Extensions */ $messages = array(); $messages['en'] = array( 'mpdisqus-desc' => 'Integrates Disqus commenting service', 'mpdisqus-before' => '<h2>Share your opinion</h2>', 'mpdisqus-after' => '' ); $messages['fi'] = array( 'mpdisqus-before' => '<h2>Jaa mielipiteesi</h2>', 'mpdisqus-after' => '' ); $messages['de'] = array( 'mpdisqus-before' => '<h2>Teile deine Meinung mit</h2>', 'mpdisqus-after' => '' );