Open main menu

Extension:Google News Bar

MediaWiki extensions manual
OOjs UI icon advanced.svg
Google News Bar
Release status: beta
Implementation Tag
Description Add a Google News Bar to your wiki pages.
Author(s) csw
Latest version 0.1
MediaWiki 1.6.8+
License No license specified
Download see below
newstitle, newskey
Translate the Google News Bar extension if it is available at translatewiki.net
Check usage and version matrix.

Contents

What can this extension do?Edit

This extension adds a Google News Bar to your wiki pages.

UsageEdit

<googleNewsBar newstitle="pakistan" newskey="pakistan">Loading ... </googleNewsBar>

InstallationEdit

You will need a Google AJAX API key for your site (can be obtained here).

ParametersEdit

newstitle 
the title you want to display for your Google News Bar
newskey 
the keywords that Google will use to fetch related news and display on your wiki page

Changes to LocalSettings.phpEdit

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

CodeEdit

<?php
# Save the extension to your extensions folder as googleNewsBarExtension.php.
# To activate the extension, include it from your LocalSettings.php with: 
#  require_once("$IP/extensions/googleNewsBarExtension.php");
# Usage example: 
#  <googleNewsBar newstitle="Baidu In The News" newskey="Baidu China">Loading ... </googleNewsBar>

$wgExtensionFunctions[] = "googleNewsBarExtension";
$googleNewsBarKey = "put_your_google_api_key_here";

# Credits for 'Special:Version' page
$wgExtensionCredits['other'][] = array(
       'name' => 'Google News Bar',
       'version' => '071007',
       'author' => 'China Stock Market Wiki and others',
       'description' => 'adds capability to enable Google News bar to your wiki site',
       'url' => 'http://www.mediawiki.org/wiki/Extension:Google_News_Bar'
       );

# Register the extension with the WikiText parser
function googleNewsBarExtension( ) {
  global $wgParser;
  $wgParser->setHook( "googleNewsBar", "renderGoogleNewsBar");
}

# The callback function for converting the input text to HTML output
function renderGoogleNewsBar( $input, $argv, &$parser ) {
  global $googleNewsBarKey;

  $output = "<div id='newsBar-bar'><span style='color:#676767;font-size:11px;margin:10px;padding:4px'>Loading...</span>  </div>";
  $output .= "<script src='http://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-nbw&key=" . $googleNewsBarKey . "' ";
  $output .= "type='text/javascript'></script>";
  $output .= "<style type='text/css'> @import url('http://www.google.com/uds/css/gsearch.css'); </style>";
  $output .= "<script type='text/javascript'>  window._uds_nbw_donotrepair = true;  </script>";
  $output .= "<script src='http://www.google.com/uds/solutions/newsbar/gsnewsbar.js?mode=new' type='text/javascript'></script>";
  $output .= "<style type='text/css'>  @import url('http://www.google.com/uds/solutions/newsbar/gsnewsbar.css');  </style>";
  $output .= '<script type="text/javascript">function LoadNewsBar(){ var newsBar; var options ={largeResultSet:false, title:';
  $output .= '"'.$argv['newstitle'].'"'.', horizontal:false, autoExecuteList:{executeList:';

  $output .= '["'.$argv['newskey'].'"]'.'}}; newsBar=new GSnewsBar(document.getElementById("newsBar-bar"), options);}';
  // for multiple keywords use newskey1="my keyword" newskey2=... and replace the line before by the next commented code :
  /*
  $output .= '[';

  $keyw = array();
  foreach ($argv as $key => $value) {
    if (ereg("^newskey[0-9]*", $key))
      $keyw[$key] = "\"".$value."\"";
  }

  $output .= implode(",", $keyw);

  $output .= ']'.'}}; newsBar=new GSnewsBar(document.getElementById("newsBar-bar"), options);}';
  */

  $output .= 'GSearch.setOnLoadCallback(LoadNewsBar);</script>';

  return $output;
}


Google Blog BarEdit

What can this extension do?Edit

This extension adds a Google Blog Bar to your wiki pages. preview available on FlyerWiki

UsageEdit

<googleblogBar newstitle="VOTE-FOR.IT AIRLINE NEWS" newskey="site:travel.vote-for.it">Loading ... </googleblogBar> 

CodeEdit

<?php
# Save the extension to your extensions folder as googleNewsBarExtension.php.
# To activate the extension, include it from your LocalSettings.php with: 
#  require_once("$IP/extensions/googleNewsBarExtension.php");
# Usage example: 
#  <googleblogBar newstitle="VOTE-FOR.IT AIRLINE NEWS" newskey="site:travel.vote-for.it">Loading ... </googleblogBar> 
 
$wgExtensionFunctions[] = "googleblogBarExtension";
$googleblogBarKey = "put_your_google_api_key_here";
 
# Credits for 'Special:Version' page
$wgExtensionCredits['other'][] = array(
       'name' => 'Google News Bar',
       'version' => '071007',
       'author' => 'China Stock Market Wiki and others',
       'description' => 'adds capability to enable Google News bar to your wiki site',
       'url' => 'http://www.mediawiki.org/wiki/Extension:Google_News_Bar'
       );
 
# Register the extension with the WikiText parser
function googleblogBarExtension( ) {
  global $wgParser;
  $wgParser->setHook( "googleblogBar", "renderGoogleblogBar");
}
 
# The callback function for converting the input text to HTML output
function renderGoogleblogBar( $input, $argv, &$parser ) {
  global $googleblogBarKey;
 
  $output = "<div id='blogBar-bar'><span style='color:#676767;font-size:11px;margin:10px;padding:4px'>Loading...</span>  </div>";
  $output .= "<script src='http://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-blbw&key=" . $googleblogBarKey . "' ";
  $output .= "type='text/javascript'></script>";
  $output .= "<style type='text/css'> @import url('http://www.google.com/uds/css/gsearch.css'); </style>";
  $output .= "<script src='http://www.google.com/uds/solutions/blogbar/gsblogbar.js?mode=new' type='text/javascript'></script>";
  $output .= "<style type='text/css'>  @import url('http://www.google.com/uds/solutions/blogbar/gsblogbar.css');  </style>";
  $output .= '<script type="text/javascript">function LoadblogBar(){ var blogBar; var options ={largeResultSet:false, title:';
  $output .= '"'.$argv['newstitle'].'"'.', horizontal:false, autoExecuteList:{executeList:';
  $output .= '["'.$argv['newskey'].'"]'.'}}; blogBar=new GSblogBar(document.getElementById("blogBar-bar"), options);}';
  $output .= 'GSearch.setOnLoadCallback(LoadblogBar);</script>';
 
  return $output;
}