Extension:Add to Any Share/Save/Bookmark Button

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
AddToAny Share/Bookmark Button

Release status: stable

Bookmark Button & Smart Menu version .1.png
Description Helps visitors share, bookmark, and email your pages using any service, such as Facebook, Twitter, Delicious, Digg, and over 100 more.
Author(s) micropattalk
Latest version 0.1
MediaWiki 1.6+
License MIT
Download http://www.addtoany.com/ext/mediawiki/add-to-any-share-save.zip
Example http://www.yahowto.com

Translate the Add to Any Share/Save/Bookmark Button extension if possible

Check usage and version matrix; code metrics

What can this extension do?[edit | edit source]

Save 171 16.gif Share icon 16 16.png

Helps visitors share, save, bookmark, and e-mail your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more.

The button comes with AddToAny's customizable Smart Menu, which places the services visitors use at the top of the menu, based on each visitor's browsing history.

  • AddToAny Smart Menu
  • Includes all services (100+)
  • E-mail using
    • Gmail
    • Yahoo! Mail
    • Live Hotmail
    • AOL
    • Program
    • AddToAny emailer (generic example)
  • Services updated automatically
  • Optimized to always load content first
  • Many more publisher and user features
  • Bookmarking tab
    • "Add to Favorites" (automatic for Internet Explorer)
    • "Bookmark" (instructions for other browsers)


Download instructions[edit | edit source]

Download and unpack the folder (and all contents) to $IP/extensions/add-to-any-share-save/. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation[edit | edit source]

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

$everyPage=true;
require_once("$IP/extensions/add-to-any-share-save/add-to-any-share-save.php");

Alter Location of Button[edit | edit source]

Quick fix to shift button from the left to the right. This was required because it was very annoying trying to edit the page but having the pop up appearing all the time. All I did was put a DIV around the button and give it negative top margin so it is now in a better location. Others may wish for nicer coding, however this seems to work fine.

Steps:

  1. Open add-to-any-share-save.php (it will be in your extensions/add-to-any-share-save/ directory)
  2. Go to line 72, and insert the following code directly after the apostrophe (') and before <a class=...: <div style="width:100%;text-align:right;margin-top:-21px;">
  3. Go to line 75 and insert </div> immediately after </script> and before the apostrophe (').
  4. Save the file and upload it to the directory.

Official website[edit | edit source]

Code[edit | edit source]

  <?php
 
/*
 * add-to-any-share-save - Helps visitors share, save, bookmark, and email your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more.
 * @authors AddToAny
 * @version 0.1
 * @copyright Copyright (C) addtoany.com
 * @license The MIT License - http://www.opensource.org/licenses/mit-license.php 
 * -----------------------------------------------------------------------
 * Description:
 *     Helps visitors share, save, bookmark, and email your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more. 
 *     The button comes with AddToAny's customizable Smart Menu, which places the services visitors use at the top of the menu, based on each visitor's browsing history.
 * Requirements:
 *     MediaWiki 1.6.x+
 * Installation:
 *     1. Upload the `add-to-any-share-save` folder (and all contents) to your MediaWiki extensions directory so you have: `/extensions/add-to-any-share-save/`
 *     2. Enable the extension by adding this line to your LocalSettings.php:
 *            require_once('extensions/add-to-any-share-save/add-to-any-share-save.php');
 * Version Notes:
 *     0.1:
 *        Initial release. AddToAny is available for MediaWiki!
 * To-do:
 *     1. Have the <sharesave /> tag (functions below) additionally load the external JavaScript call before the </body> tag - please get in touch if you have any ideas on how to do this!
 */
 
// Confirm MW environment
if (defined('MEDIAWIKI')) {
 
 
	// OPTIONS
	$wg_addtoany_share_save_button_filename = "share_save_171_16.png"; // Located in /extensions/add-to-any-share-save/
	$wg_addtoany_share_save_button_width = "171";
	$wg_addtoany_share_save_button_height = "16";
 
 
	// Version
	define('ADDTOANY_SHARE_SAVE_VERSION','0.1');
 
	// Credits
	$wgExtensionCredits['parserhook'][] = array(
		'name'=>'AddToAny Share/Bookmark Button',
		'author'=>'AddToAny',
		'url'=>'http://www.addtoany.com/contact/',
		'description'=>'Helps visitors share, save, bookmark, and email your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more.',
		'version'=>ADDTOANY_SHARE_SAVE_VERSION
	);
 
	// Call Share/Save widget
	$wgHooks['SkinSubPageSubtitle'][] = 'wf_addtoany_share_save_below_header';
	// $wgExtensionFunctions[] = 'wf_addtoany_share_save_ExtensionSetup';
 
	function wf_addtoany_share_save_markup(){
		// MediaWiki globals
		global $wgTitle, $wgScriptPath, $wgHooks;
 
		// AddToAny Share/Save extension globals
		global $wg_addtoany_share_save_button_filename, 
			$wg_addtoany_share_save_button_width, 
			$wg_addtoany_share_save_button_height;
 
		$button_src = $wg_addtoany_share_save_button_filename;
		$button_width = ' width="'.$wg_addtoany_share_save_button_width.'"';
		$button_height = ' height="'.$wg_addtoany_share_save_button_height.'"';
 
		// Load external JavaScript before closing </body> tag
		$wgHooks['SkinAfterBottomScripts'][] = 'wf_addtoany_share_save_external_script_call';
 
		$link_title = $wgTitle->getText();
		$link_url = $wgTitle->getFullURL();
 
		$markup = 
			'<a class="a2a_dd" href="http://www.addtoany.com/share_save?linkurl=' . rawurlencode($link_url) . '&amp;linkname=' . rawurlencode($link_title) . '">' .
			'<img src="'.$wgScriptPath.'/extensions/add-to-any-share-save/'.$button_src.'"' . $button_width.$button_height . ' alt="Share/Bookmark"/>' .
			'</a>' .
			'<script type="text/javascript">a2a_linkname="' .$link_title. '";a2a_linkurl="' .$link_url. '";</script>';
 
		return $markup;
	}
 
	function wf_addtoany_share_save_below_header(&$subpages) {
		$subpages .= wf_addtoany_share_save_markup();
		return true;
	}
 
	function wf_addtoany_share_save_external_script_call($skin, &$text='') {
		$text .= '<script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>';
		return true;
	}
 
	/* 
 
		See "To-do" section above
 
	// Sets up the parser hook and global messages
	function wf_addtoany_share_save_ExtensionSetup() {
		global $wgParser, $wgMessageCache;
 
		// <sharesave /> tag
		$wgParser->setHook('sharesave', 'wf_addtoany_share_save_ParserHook');
	}
 
	// Parser hook for the <sharesave /> tag extension.
	function wf_addtoany_share_save_ParserHook($text, $params, &$parser) {
 
		$output = '';
 
		$output .= wf_addtoany_share_save_markup();
 
		return $output;
	}
	*/
 
} // Closing MW Environment wrapper

Usage[edit | edit source]

Usage:

  • default = AddToAny on every Page below header
  • $everyPage = true : AddToAny on every Page below header
  • $everyPage = false : embedding AddToAny, where the tag is with the tag <addtoany/>

new Code[edit | edit source]

<?php
 
/*
 * add-to-any-share-save - Helps visitors share, save, bookmark, and email your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more.
 * @authors Add to Any
 * @version 0.1
 * @copyright Copyright (C) addtoany.com
 * @license The MIT License - http://www.opensource.org/licenses/mit-license.php 
 * -----------------------------------------------------------------------
 * Description:
 *     Helps visitors share, save, bookmark, and email your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more. 
 *     The button comes with Add to Any's customizable Smart Menu, which places the services visitors use at the top of the menu, based on each visitor's browsing history.
 * Requirements:
 *     MediaWiki 1.6+
 * Installation:
 *     1. Upload the `add-to-any-share-save` folder (and all contents) to your MediaWiki extensions directory so you have: `/extensions/add-to-any-share-save/`
 *     2. Enable the extension by adding this line to your LocalSettings.php:
 *            require_once('extensions/add-to-any-share-save/add-to-any-share-save.php');
 * Version Notes:
 *     0.1:
 *        Initial release. Add to Any is available for MediaWiki!
 * To-do:
 *     1. Have the <sharesave /> tag (functions below) additionally load the external JavaScript call before the </body> tag - please get in touch if you have any ideas on how to do this!
 */
 
 
 
// Confirm MW environment
if (defined('MEDIAWIKI')) {
 
 
	// OPTIONS
	$wg_addtoany_share_save_button_filename = "share_save_171_16.png"; // Located in /extensions/add-to-any-share-save/
	$wg_addtoany_share_save_button_width = "171";
	$wg_addtoany_share_save_button_height = "16";
 
 
 
	// Version
	define('ADDTOANY_SHARE_SAVE_VERSION','0.1');
 
	// Credits
	$wgExtensionCredits['parserhook'][] = array(
		'name'=>'Add to Any Share/Save/Bookmark Button',
		'author'=>'Add to Any',
		'url'=>'http://www.addtoany.com/contact/',
		'description'=>'Helps visitors share, save, bookmark, and email your pages using any service, such as Delicious, Digg, Facebook, Twitter, and over 100 more.',
		'version'=>ADDTOANY_SHARE_SAVE_VERSION
	);
 
	// Call Share/Save widget
	// $wgExtensionFunctions[] = 'wf_addtoany_share_save_ExtensionSetup';
 
 
 
	//if $everyPage isn't set -> default = addToAny in every Page below header
	if(!isset($everyPage))
	  $everyPage=true;
 
	//EF is in the house!! YIIIHHAAAA
	if($everyPage)
	 {
	 //addToAny below every Header
	 $wgHooks['SkinSubPageSubtitle'][] = 'wf_addtoany_share_save_below_header';
	 }
	else 
	 {
	 //addToAny in the area, you embedded the tag
	$wgHooks['ParserFirstCallInit'][] = 'wf_addtoany_per_tag';
	 }
 
	 function wf_addtoany_per_tag( &$parser ) {
	$parser->setHook("addtoany","add_to_any_per_tag");
	return true;
}
 
	function add_to_any_per_tag( $in, $param=array(), $parser=null, $frame=false) {
 
	return wf_addtoany_share_save_markup();
}
 
 
	function wf_addtoany_share_save_below_header(&$subpages) {
 
		$subpages .=wf_addtoany_share_save_markup();
		return true;
	}
 
 
 
	function wf_addtoany_share_save_markup(){
		// MediaWiki globals
		global $wgTitle, $wgScriptPath, $wgHooks;
 
		// Add to Any Share/Save extension globals
		global $wg_addtoany_share_save_button_filename, 
			$wg_addtoany_share_save_button_width, 
			$wg_addtoany_share_save_button_height;
 
		$button_src = $wg_addtoany_share_save_button_filename;
		$button_width = ' width="'.$wg_addtoany_share_save_button_width.'"';
		$button_height = ' height="'.$wg_addtoany_share_save_button_height.'"';
 
		// Load external JavaScript before closing </body> tag
		$wgHooks['SkinAfterBottomScripts'][] = 'wf_addtoany_share_save_external_script_call';
 
		$link_title = $wgTitle->getText();
		$link_url = $wgTitle->getFullURL();
 
		$markup = 
			'<a class="a2a_dd" href="http://www.addtoany.com/share_save?linkurl=' . rawurlencode($link_url) . '&amp;linkname=' . rawurlencode($link_title) . '">' .
			'<img src="'.$wgScriptPath.'/extensions/add-to-any-share-save/'.$button_src.'"' . $button_width.$button_height . ' alt="Share/Save/Bookmark"/>' .
			'</a>' .
			'<script type="text/javascript">a2a_linkname="' .$link_title. '";a2a_linkurl="' .$link_url. '";</script>';
 
		return $markup;
	}
 
 
 
	function wf_addtoany_share_save_external_script_call($skin, &$text='') {
		$text .= '<script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>';
		return true;
	}
 
	/* 
 
		See "To-do" section above
 
	// Sets up the parser hook and global messages
	function wf_addtoany_share_save_ExtensionSetup() {
		global $wgParser, $wgMessageCache;
 
		// <sharesave /> tag
		$wgParser->setHook('sharesave', 'wf_addtoany_share_save_ParserHook');
	}
 
	// Parser hook for the <sharesave /> tag extension.
	function wf_addtoany_share_save_ParserHook($text, $params, &$parser) {
 
		$output = '';
 
		$output .= wf_addtoany_share_save_markup();
 
		return $output;
	}
	*/
 
} // Closing MW Environment wrapper


Sites that use Add to Any Share/Save/Bookmark Button[edit | edit source]