User:Joncutrer/Extensions/Google Adsense Search
From Meta, a Wikimedia project coordination wiki
Google Adsense Search Extension is a handy little MediaWiki Extension that allows you to insert a Google Adsense search box throughout your content with the option of prefilling the search box with a relevant keyword for your page.
- Google Adsense Search Extension (down since March 2006)
- Click here to find the latest version of this extension (down since March 2006)
This extension overcomes one of the limits of MediaWiki, the ability to use the full html tag set such as form tags and various others. Here is the script and instructions to install, if you find this extension usefull please provide a link back here or directly to http://stockphotoss.com/ (down since March 2006)
Step 1. Copy the following code and save it into your MediaWiki's extensions directory as adsensesearch.php.
<?php
# Google Adsense WikiMedia extension
# with WikiMedia's extension mechanism it is possible to define
# new tags of the form
# <adsensesearch> keyword </adsensesearch>
# the function registered by the extension gets the text between the
# tags as input and places a google search box prefilled with the keyword
# on the page.
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/adsensesearch.php");
$wgExtensionFunctions[] = "wfassExtension";
function wfassExtension() {
global $wgParser;
# register the extension with the WikiText parser
# the first parameter is the name of the new tag.
# In this case it defines the tag <absHTML> ... </absHTML>
# the second parameter is the callback function for
# processing the text between the tags
$wgParser->setHook( "adsensesearch", "renderass" );
}
# The callback function for converting the input text to HTML output
function renderass( $input ) {
$output = "
<!-- Search Google -->
<!-- Search Google -->
<center>
<form method=\"get\" action=\"http://www.google.com/custom\" target=\"_top\">
<table bgcolor=\"#ffffff\">
<tr><td nowrap=\"nowrap\" valign=\"top\" align=\"left\" height=\"32\">
<a href=\"http://www.google.com/\">
<img src=\"http://www.google.com/logos/Logo_25wht.gif\" border=\"0\" alt=\"Google\" align=\"middle\"></img></a>
<input type=\"text\" name=\"q\" size=\"31\" maxlength=\"255\" value=\"$input\"></input>
<input type=\"submit\" name=\"sa\" value=\"Search\"></input>
<input type=\"hidden\" name=\"client\" value=\"pub-1019399818408254\"></input>
<input type=\"hidden\" name=\"forid\" value=\"1\"></input>
<input type=\"hidden\" name=\"channel\" value=\"9632115871\"></input>
<input type=\"hidden\" name=\"ie\" value=\"ISO-8859-1\"></input>
<input type=\"hidden\" name=\"oe\" value=\"ISO-8859-1\"></input>
<input type=\"hidden\" name=\"cof\" value=\"GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:
0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;\"></input>
<input type=\"hidden\" name=\"hl\" value=\"en\"></input>
</td></tr></table>
</form>
</center>
<!-- Search Google -->
";
return $output;
}
?>
Step 2. Add the following line to your LocalSettings.php file
include("extensions/adsensesearch.php");
Step 3. Insert some HTML in one of your pages as follows.
<adsensesearch>Stock Photos</adsensesearch>
Other Extensions I have created
[edit] Related Extensions
- AdSense extension