Extension:QRCodeOnLoad

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Qr Code OnLoad

Release status: experimental

Implementation Parser function, Media
Description Creates a QR-Code with the coded URL of the actual site and displays it.
Author(s) User:Mailer2010
Last version 1.0 (2011-10-13)
MediaWiki 1.17+
License LGPL
Download No link
Check usage and version matrix

This extension codes the URL of the actual page into a QR-Code by using Google APIs and displays the QR-Code on the page. Everything happens on-load. So nothing is beeing uploaded or inserted in the article, except the parsing function.

Contents

Installation [edit]

  1. Copy&Paste the code of the latest version to your extensions folder \QRCodeOnLoad\QRCodeOnLoad.php.
  2. Insert the following line to your LocalSettings.php
#QRCodeOnLoad - Generates and displays a QR-Code with the coded URL of the page
require_once("$IP/extensions/QRCodeOnLoad/QRCodeOnLoad.php");

Usage [edit]

Insert {{#QRCodeOnLoad:}} into the article where you wish to see the URL as QR-Code. Without any parameters a 100pxx100px left floating QR-Code is generated. It is possible to set a custom size of the QR-Code with parameters. {{#QRCodeOnLoad: 250 | 250}} would create a size of 250px

Information [edit]

I am neither a programmer, nor do I really understand PHP. I found some examples about how to create a QR-Code and put them together. With the example parser function of MediaWiki I created this extension. I basically created it for use in my intranet wiki installation. So if you have any suggestions or improvements, feel free to edit the code.

To Do [edit]

Possibly someone can help me out with some things:

  • How to display the QRCode in the sidebar
  • How to improve the layout of the QRCode Image, now it's limited to float left
  • ...

Source-Code for QRCodeOnLoad.php Version 1.0 [edit]

<?php
$wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,     // Magic so that svn revision number can be shown
        'name' => "QRCodeOnLoad",
        'description' => "2011/10/12: Using Google APIs, this extension creates a QRCode with the coded URL of the actual site and displays it, onload of the page.",    
        'version' => 1, 
        'author' => "Mailer2010",
        'url' => "",
);
 
$wgHooks['ParserFirstCallInit'][] = 'QRCodeOnLoad_Setup';
$wgHooks['LanguageGetMagic'][]    = 'QRCodeOnLoad_Magic';
 
function QRCodeOnLoad_Setup( &$parser ) 
        {
    $parser->setFunctionHook( 'QRCodeOnLoad', 'QRCodeOnLoad' );
    return true;
        }
 
function QRCodeOnLoad_Magic( &$magicWords, $langCode ) 
        {
    $magicWords['QRCodeOnLoad'] = array( 0, 'QRCodeOnLoad' );
    return true;
        }
 
function strleft($s1, $s2) 
        { 
        return substr($s1, 0, strpos($s1, $s2)); 
        }
 
function FormatURL() 
        { 
        $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 
        $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
        $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
        return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; 
        } 
 
function QRCodeOnLoad( $parser, $w, $h ) 
        {
        if (empty($w)) { $w = 100 ;}
        if (empty($h)) { $h = 100 ;}
    $url = FormatURL() ;
        $url = urlencode($url);
        $output = '<div style="float:left;padding-right:10px;padding-bottom:5px;>"><img src="http://chart.apis.google.com/chart?chs='.$w.'x'.$h.'&cht=qr&chld=L|0&chl='.$url.'" title="QR-Code" alt="QR-Code" width="'.$w.'" height="'.$h.'" /></div>' ;
 
        return array( $output, 'noparse' => true, 'isHTML' => true );
        }