Extension:RedditTag

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
RedditTag

Release status: experimental

Implementation  Parser extension
Description This extension allows you to provide a button to submit a page to Reddit or any subreddit.
Author(s)  Michael Mol (Short CircuitTalk)
Last Version  0.1 (02/07/2008)
License GPL version 2
Download Extension:RedditTag#Code
Example  Rosetta Code

check usage (experimental)

Contents

[edit] What does this extension do?

This extension allows an editor of your wiki to add a "Reddit this" button to a page, either submitting the page to the main reddit, or to a specific subreddit.

[edit] Usage

Simply add the code <reddit></reddit> anywhere you want a submit button to the main reddit to appear. If you want to target a specific subreddit, use the code <reddit foo></reddit>, where foo is the subdomain of the subreddit you wish to submit to. You can put this code in a template if you like, as the actual submission process occurs via a JavaScript call that asks the browser for the current URL.

[edit] Download Instructions

Copy and paste the code below. Save it as RedditTag.php.

[edit] Installation

[edit] BEFORE YOU USE THIS EXTENSION

Be aware that MediaWiki does not work very well under heavy load unless properly set up. Now think about what you're doing with this tag; You're explicitly advertising pages on your wiki on a massive popularity-based link sharing site. Every time you submit a link, you risk bringing thousands of page requests per minute to your site's server. This can easily get you in trouble with your hosting provider, be it shared hosting, VPS or any scenario where excesss activity can be a problem.

If you think your server can handle it, or if you're taking the "We'll cross that bridge when we come to it" approach, carry on.

[edit] Installation

Copy RedditTag.php to your extensions directory, then add

#include_once( "extensions/RedditTag.php" );

to your LocalSettings.php.

[edit] Code

<?php
# RedditTag.php
# Licensed under GPLv2
# (c) 2009 Michael Mol <mikemol@gmail.com>

# --- BEFORE YOU USE THIS EXTENSION ---
# Be aware that MediaWiki does not work very well under heavy load unless
# properly set up.  Ask me about the time I got Slashdotted on a shared
# hosting account.  Now think about what you're doing with this tag; You're
# explicitly advertising pages on your wiki on a massive popularity-based
# link sharing site.  Every time you submit a link, you risk bringing
# thousands of page requests per minute to your site's server, which
# can easily get you in trouble with your hosting provider, be it
# shared hosting, VPS or any scenario where excesss activity can be a
# problem.

# If you think your server can handle it, or if you're taking the "We'll
# cross that bridge when we come to it" approach, carry on, and may your
# server arrangements not go up in flames.

 
$wgExtensionFunctions[] = "RedditCodeTag";
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'RedditTag',
        'author' => 'Michael Mol',
        'version' => '0.1',
        'description' => 'A tag to allow the insertion of RedditThis buttons optionally targeted at a subreddit.',
        'url' => 'http://www.mediawiki.org/wiki/Extension:RedditTag'
);
$languages = array();
 
function RedditCodeTag()
{
        global $wgParser, $codeTag, $languages, $languagesPath;
 
        $wgParser->setHook('reddit', 'RedditThis');
}
 
function RedditThis($source, $settings){
        global $subReddit, $subRedditString, $staticRedditImg;
 
        $subReddit = htmlspecialchars(array_shift($settings));
        if('' != $subReddit )
        {
                $subRedditString = "/r/$subReddit";
        }
        # Replace with your preferred Reddit button image.
        # Only supporting static ones for now.
        $staticRedditImg = 'spreddit1.gif';
 
        # The quoting in this string is a pain.
        return '<a href="'
             . "http://www.reddit.com$subRedditString/submit"
             . '" onclick="window.location = '
             . "'http://www.reddit.com$subRedditString/submit?url='"
             . " + encodeURIComponent(window.location); return false"
             . '"> <img src="http://www.reddit.com/static/'
             . $staticRedditImg
             . '" alt="submit to reddit" border="0" /> </a>';
}

[edit] Websites using this extension