Extension:Script And Google AdSense

From MediaWiki.org

Jump to: navigation, search
WARNING: the code or configuration described here poses a major security risk.

Problem: Vulnerable to Cross-site scripting attacks, because it passes user input directly to the browser. This may lead to user accounts being hijacked, among other things.
Solution: Don't use this extension on a publicly editable wiki. Use Extension:Google AdSense 2 for Google AdSense, and an extension such as HTMLets or RawMsg for insertion of JavaScript into wiki pages.
Signed: Mr.Z-man 21:09, 28 October 2008 (UTC)

Manual on MediaWiki Extensions
List of MediaWiki Extensions
MyScript extension

Release status: stable

Description Add Google AdSense to individual pages or any other scripts.
Author(s) Jung Lee aka Max Lee (zedomaxTalk)
Last Version 0.1
License No license specified
Download see below

Contents

[edit] What can this extension do?

This extension allow you to add Google AdSense ads or any other scripts.

[edit] Usage

Let's say you have this code from Google AdSense:

<script type="text/javascript"><!--
google_ad_client = "pub-3379402347635671";
//728x90, created 12/2/07
google_ad_slot = "6488952503";
google_ad_width = 728;
google_ad_height = 90;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

1. Replace <script type="text/javascript"> with <myscript>. 2. Replace </script> with </myscript>. 3. Replace <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> with <myscript src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></myscript>.

You should get something like this after the conversion:

<myscript><!--
google_ad_client = "pub-3379402347635671";
//728x90, created 12/2/07
google_ad_slot = "6488952503";
google_ad_width = 728;
google_ad_height = 90;
//--></myscript>
<myscript src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</myscript>

See example on my QuarterWiki site QuickStartGuide.

[edit] Installation

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

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

[edit] Code

<?php
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Script and Google AdSense Extension - 11/16/2007',
'author' => 'Max Lee http://zedomax.net',
'url' => 'http://zedomax.net',
'version' => 'v.0.1',
'description' => 'Add Google AdSense and other scripts for your pages',
);
 
# MyScript extension
 
# Usage:
/*
<myscript><!--
google_ad_client = "pub-3379402347635671";
//728x90, created 12/2/07
google_ad_slot = "6488952503";
google_ad_width = 728;
google_ad_height = 90;
//--></myscript>
<myscript src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</myscript>
 
*/
 
# To install it put this file in the extensions directory
# To activate the extension, include it from your LocalSettings.php
# with: require("extensions/wikiscript.php");
 
$wgExtensionFunctions[] = "wfMyScript";
 
function wfMyScript() {
    global $wgParser;
    # registers the <myscript> extension with the WikiText parser
    $wgParser->setHook( "myscript", "renderMyScript" );
}
 
# The callback function for converting the input text to HTML output
function renderMyScript( $input, $argv ) {
    if ($argv["src"]=='')
        $output = '<script type="text/javascript">';
    else
        $output = '<script src="'.$argv["src"].'" type="text/javascript">';
    $output .= $input;
    $output .= '</script>';
    return $output;
}

[edit] Examples

Sites using this extension

[edit] See also

Personal tools