Facebook, Twitter, Google+ buttons in MediaWiki

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

If you’re looking for a way to add Facebook, Twitter, Google+ buttons in your MediaWiki installation, you may be disappointed – there are no plugins offering all three social buttons. There are some other plugins, but they are often outdated, don’t work with current MediaWiki versions, or are simply broken.

How about doing a small change to your skin then and adding the buttons yourself?


I’ve added the code to skins/Vector.php, between these lines:

                        <h1 id="firstHeading" class="firstHeading"><?php $this->html( 'title' ) ?></h1>
                        <!-- /firstHeading -->
 
<!-- The code for Facebook, Twitter, Google+ buttons in MediaWiki goes here! -->
 
                        <!-- bodyContent -->


The actual code is like below, and is loosely based on “Facebook, Twitter & Google+ Social Widgets” WordPress plugin. You may need to substitute http with https, depending on your site's main URL.

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&amp;send=false&amp;layout=button_count&amp;width=120&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21"
scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:120px; height:21px;" allowTransparency="true"></iframe></div>
<div style="display:inline;">
<a rel="nofollow" href="http://twitter.com/share?url=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>" class="twitter-share-button" data-count="horizontal">Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>
<div style="display:inline;"><g:plusone size="medium" href="<?php echo ('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>"></g:plusone>
<script type="text/javascript">(function(){var po=document.createElement('script');po.type='text/javascript';po.async=true;po.src='https://apis.google.com/js/plusone.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(po,s);})();</script>
</div></div>

You can see a screenshot below; the buttons will be shown on all MediaWiki pages:

Facebook-Twitter-Google+-buttons-in-MediaWiki.png