Extension:FacebookLikeButton

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

Release status: stable

Implementation Tag
Description Creates a Facebook Like and/or Send button(s).
Author(s) Piotr Zuk, Jmkim dot com
Last version 1.1.0 (2012-08-16)
MediaWiki 1.16
License GNU public License
Download FacebookLikeButton.tgz
Example http://jmnote.com/wiki/FacebookLikeButton
Hooks used
ParserFirstCallInit
Check usage and version matrix

Contents

What can this extension do? [edit]

Allows you to very simply include Facebook Like and/or Send button(s).

Usage [edit]

With the tag <fblike></fblike>

  • button_count : <fblike/> (with horizontal counting box. default)
Facelikebutton2.jpg
  • box_count: <fblike layout="box_count"/> (with vertical counting box)
Facelikebutton3.jpg
  • standard: <fblike layout="standard"/> (without counting box)
👍Like F icon.svg Alice, Bob like this.

Default layout = button_count (with horizontal counting box) and without send button ( send = false ).

Set send="true" to see the makes the Send button visible.

Download instructions [edit]

You can download the php file from FacebookLikeButton.tgz or copy and paste the code below to the file: $IP/extensions/FacebookLikeButton/FacebookLikeButton.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation [edit]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/FacebookLikeButton/FacebookLikeButton.php");

Code [edit]

<?php
/* Wiki FacebookLikeButton MediaWiki extension
 * Installation Instructions: http://www.mediawiki.org/wiki/Extension:FacebookLikeButton
 * 2012-08-16 Article URL support. The tag changed. HTML5 code.
 * For another language support, "en_US" can be replaced by "de_DE", "ja_JP" or "ko_KR".
 */
$wgExtensionFunctions[] = "facebooklikebuttonExtension";
function FacebookLikeButtonUrl() {
        $protocol = 'http';
        $port = '80';
        if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) { $protocol =  'https'; $port = '443'; }
        $port = $_SERVER['SERVER_PORT'] == $port ? '' : ':' . $_SERVER['SERVER_PORT'];
        return $protocol . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['SCRIPT_NAME'];
}
function facebooklikebuttonExtension() {
        global $wgParser;
        global $FacebookLikeButtonOnce;
        $wgParser->setHook( "fblike", "renderFacebookLikeButton" ); 
        $FacebookLikeButtonOnce='<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>';
} 
function renderFacebookLikeButton( $input, $argv ) { 
        global $wgRequest;
        global $FacebookLikeButtonOnce;
        $layout = @$argv['layout'];
        $send = @$argv['send'];
        if( $layout != 'standard' && $layout != 'box_count' ) $layout = 'button_count';
        if( $send != 'true' ) $send = 'false';
        $once = $FacebookLikeButtonOnce;
        $FacebookLikeButtonOnce = '';
        $full_url = FacebookLikeButtonUrl().'/'.$wgRequest->getText('title');
        return $once.'<div class="fb-like" data-href="'.$full_url.'" data-send="'. htmlspecialchars( $send ) .'" data-layout="'. htmlspecialchars( $layout ) .'" data-width="400"></div>';
}
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Wiki FacebookLikeButton',
        'version' => '1.1.0',
        'author' => 'Piotr Zuk, Jmkim dot com',
        'url' => 'http://www.mediawiki.org/wiki/Extension:FacebookLikeButton',
        'description' => 'Mediawiki FacebookLikeButton Extension'
);