Extension:FollowButton

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

Release status: beta

Implementation Tag
Description Adds <followbutton> tag for displaying follow buttons.
Author(s) Toni Hermoso Pulido (Tonihertalk)
Last version 0.1
MediaWiki 1.16, 1.17
PHP 5.2.x, 5.3.x
License GPL 2.0 or higher
Download Below this page
Example http://www.viquimedia.cat
Tags
<followbutton>
Check usage and version matrix

Parser that inserts a Follow Button anywhere in a wiki page.

Contents

Services [edit]

Usage [edit]

For now, only Twitter is available and you have the following parameters:

  • lang (2 letter language code. Only a few available in twitter. English by default)
  • color (dark or light, light by default)
  • count (true or false, true by default)
  • service (now only Twitter, by default)

Put your username between the tags (no @ is needed).

Example: (for a Twitter Follow Button in Spanish with no counter): <followbutton count=false lang="es">toniher</followbutton>

Download instructions [edit]

Please cut and paste the code found below and place it in $IP/extensions/FollowButton/FollowButton.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Also copy i18n file in $IP/extensions/FollowButton/FollowButton.i18n.php

Installation [edit]

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

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/FollowButton/FollowButton.php");

Code [edit]

FollowButton.php [edit]

<?php
/**
 * Copyright (C) 2011 Toni Hermoso Pulido <toniher@cau.cat>
 * http://www.cau.cat
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 */
// Twitter script bits from: https://twitter.com/about/resources/followbutton
 
if ( !defined( 'MEDIAWIKI' ) ) {
        echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
        die( 1 );
}
$wgExtensionCredits['other'][] = array(
        'path' => __FILE__,
        'name' => 'FollowButton', 
        'author' => array( 'Toniher' ), 
        'url' => 'http://mediawiki.org/wiki/Extension:FollowButton',
        'description' => 'Adds popular social networks Follow Buttons to your wiki',
        'descriptionmsg' => 'followbutton-desc',
);
 
$wgExtensionFunctions[] = "FollowButtonExtension";
$wgFollowButtonIP = dirname( __FILE__ );
$wgExtensionMessagesFiles['FollowButton'] = "$wgFollowButtonIP/FollowButton.i18n.php";
 
function FollowButtonExtension() {
    global $wgParser;
    $wgParser->setHook( "followbutton", "wfFollowButton" );
}
 
function wfFollowButton( $input, $argv ) {
 
        $service = "Twitter";
        if (isset($argv['service'])) { $service = $argv['service']; }
 
        if (strtolower($service) == 'twitter') {
 
                //Defaults
                $color = "light";
                $count = true;
                $label = "Follow";
                $lang = "en";
 
                //Strings
                $langstr = "";
                $colorstr = "";
                $countstr = "";
 
                //Conditions
                if (isset($argv['color'])) {$color = $argv['color'];}
                if (isset($argv['count'])) {$count = $argv['count'];}
                if (isset($argv['lang'])) {
                        $lang = $argv['lang'];
                        // We take langcode and langcode-{country,variantcode}
                        if (preg_match('/^\s*\w{2,3}\s*$/', $argv['lang'])) {
                                $langstr = "data-lang=\"".$lang."\"";
                        }
                        elseif (preg_match('/^\s*(\w{2,3})\-(\w+)\s*$/', $argv['lang'], $langbits)) {
                                $langstr = "data-lang=\"".$langbits[1]."\"";
                        }
                }
 
                if (strtolower($color) == 'dark') {
                        $colorstr = "data-button=\"grey\" data-text-color=\"#FFFFFF\" data-link-color=\"#00AEFF\"";
                }
                if ($count != true) {
                        $countstr = "data-show-count=\"false\"";
                }
 
 
                $output = "<a href=\"http://twitter.com/".$input."\" class=\"twitter-follow-button\" ".$colorstr." ".$countstr." ".$langstr." >".$label.
" @".$input."</a><script src=\"http://platform.twitter.com/widgets.js\" type=\"text/javascript\"></script>";    
        }
 
        return $output;
}
?>

FollowButton.i18n.php [edit]

<?php
/**
 * Internationalisation file for Follow Button extension.
 *
*/
 
$messages = array();
 
$messages['en'] = array(
        'followbutton-desc' => 'Adds popular social networks Follow Buttons to your wiki'
);
 
$messages['ca'] = array(
        'followbutton-desc' => 'Afegeix botons de seguiment de xarxes socials populars al vostre wiki'
);
 
$messages['es'] = array(
        'followbutton-desc' => 'Añade botones de seguimiento de redes sociales populares en su wiki'
);
?>

See also [edit]