Extension:GrowButton

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

Release status: stable

Implementation Parser extension
Description This extension allows users to add social button(s) for Grow!.
Author(s) skh☆★
Last version 0.2 (2012-3-22)
MediaWiki 1.18.x
License CC-BY-SA
Download see below
Example tetrisbabel.net
Check usage and version matrix; Bookmarking stats

Contents

What can this extension do?[edit]

This extension allows users to add social button(s) for Grow!.

Usage[edit]

Insert the Grow parser tag into your wiki page. Users need register an Grow account and enter the API Key number with the Tag. 

Example:

<grow>abcd-1234-xyz9</grow>

For now, you can use only the rectangle type button.

Download instructions[edit]

Copy and paste following code and save as GrowTag.php.

Installation[edit]

To install it put this file in the extensions directory. To activate the extension, include it from your LocalSettings.php with:

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

Once activated, you should see Grow button appear at the your edits.

Code[edit]

for GrowTag.php

<?php //{{MediaWikiExtension}}<source lang="php">
/*
 * GrowTag.php - Provides grow tag for embedding a Grow Button into a page.
 * @author SKH
 * @version 0.2
 * @copyright Copyright (C) 2012 SKH
 * -----------------------------------------------------------------------
 * Description:
 *     This is a MediaWiki extension which adds an additional tag, <grow>, for embedding
 *     grow into wiki articles.
 * Requirements:
 *     MediaWiki 1.18.x or higher
 *     PHP 4.x, 5.x or higher
 * Installation:
 *     1. Drop this script (GrowTag.php) in $IP/extensions
 *         Note: $IP is your MediaWiki install dir.
 *     2. Enable the extension by adding this line to your LocalSettings.php:
 *            require_once('extensions/GrowTag.php');
 * Usage:
 *     Once installed, you may utilize GrowTag by placing grow> tag in an
 *     article's text:
 *         <grow>abcd-1234-xyz9</grow>
 * -----------------------------------------------------------------------
 * Copyright (c) 2012 SKH
 */
 
# Confirm MW environment
if (defined('MEDIAWIKI')) {
 
# Credits
$wgExtensionCredits['parserhook'][] = array(
    'name'=>'GrowTag',
    'author'=>'SKH',
    'url'=>'http://tetrisbabel.net',
    'description'=>'Provides grow tag embedding a Grow Button into a page.',
    'version'=>'0.1'
);
 
# Register Extension initializer
$wgExtensionFunctions[] = "wfGrowTagExtension";
 
# Extension initializer
function wfGrowTagExtension() {
    global $wgParser;
    $wgParser->setHook( "grow", "renderGrowTag" );
}
 
/**
 * Callback function for embedding video.
 * @param String $input Text between open and close tags - should always be empty or null.
 * @param Array $params Array of tag attributes.
 * @param Parser $parser Instance of Parser performing the parse.
 */
function renderGrowTag( $input, $params, &$parser ) {
 
    # Check for '$input' parameter and ensure it has a valid value
if ( $input == null ) {
   return '<div class="errorbox">Error:Input any Grow ID.</div>';
} else {
   $v = htmlspecialchars($input);
}
 
 
if (preg_match('%[^A-Za-z0-9_-]%',$v)) {
    return '<div class="errorbox">'.sprintf('Invalid Grow ID supplied: [%s]', $v).'</div>'; 
}
 
    return
htmlspecialchars_decode('<script type="text/javascript" src="http://growbutton.com/javascripts/button.js?apikey='.$v.'&amp;shape?=square"></script>');
}
 
}