Extension:Googledocviewer

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

Release status: stable

Implementation Parser function
Description Allows documents to be embeded on a page using the viewers from google docs
Author(s) Reddo
Last version 0.2
MediaWiki 1.10.x+
License GPL
Download see below

Check usage (experimental)

The GoogleDocViewer extension adds the <doc> tag for embedding a Google Doc in view, edit, or published mode (provided that the user is currently logged into their Google account and has access to the document).

[edit] Installation

  1. Copy GoogleDocViewer.php to the new file GoogleDocViewer.php in your MediaWiki extensions directory.
  2. Enable the extension by adding this line to the bottom of your LocalSettings.php:
require_once('extensions/GoogleDocViewer.php');

[edit] Usage

Google Doc URLs are structured like this: docs.google.com/a/<site>/document/<mode>?id=<id>. To embed this document, use:

  • <doc id=<id> site=<site> mode=<mode> title="My Title"/>
  • Example: <doc id="12345ABC" site="yoursite.com" mode="edit" title="My Title"/>

[edit] Options

  • id (required)
  • mode (edit|view|pub)
  • width
  • height
  • title
  • site

[edit] Alternate version options

  • type (document|spreadsheet)
  • literal (a|b|c|d or other - docs.google.com/<literal>/<site>/...)
  • don't support site option
  • added options check by asset() function

[edit] Source of GoogleDocViewer.php

<?php
 
$wgExtensionCredits['parserhook'][] = array(
        'name'                        => 'Google Doc Viewer',
        'author'              => 'Reddo',
        'version'             => '0.2.1',
        'url'                 => 'http://www.mediawiki.org/wiki/Extension:Googledocviewer',
        'description' => 'Allows documents to be embedded on a page and viewed using googles viewers',
);
 
$wgExtensionFunctions[] = 'docviewer';
 
function docviewer()
{
        global $wgParser;
        $wgParser->setHook('doc', 'embedviewer');
}
 
function embedviewer($content, $args)
{
        if (!$args['id']) {return '<font color="red">Usage: &lt;doc id=...[ width=...][ height=...][ mode=(view|edit|pub)][ title=...][ site=...] /&gt;</font>';}
 
        $id            = urlencode($args['id']);
        $mode  = $args['mode']           ? $args['mode']            : 'pub'; // view, pub, or edit
        $title = $args['title']  ? $args['title']   : '';
        $width = $args['width']  ? $args['width']   : '100%';
        $height        = $args['height'] ? $args['height']  : '100%';
        $site  = $args['site']           ? $args['site']            : 'your-site.com';
 
        $html =
                '<table border=0 width="100%">'.
                        '<tr>'.
                                '<th align="left" width="85%">'.
                                        ($title ? '<h2>'.$title.'</h2>' : '').
                                '</th>'.
                                '<th align="right">'.
                                        '<a target="_blank" href="https://docs.google.com/a/'.$site.'/document/edit?id='.$id.'">'.
                                                'Open in New Tab'.
                                        '</a>'.
                                '</th>'.
                        '</tr>'.
                '</table>'.
                '<iframe src=https://docs.google.com/a/'.$site.'/document/'.$mode.'?id='.$id.'&amp;embedded=true width='.$width.' height='.$height.'></iframe>';
 
        return $html;
}
?>

[edit] Alternate version of GoogleDocViewer.php with spreadsheet support

<?php
 
$wgExtensionCredits['parserhook'][] = array(
        'name'                => 'Google Doc Viewer',
        'author'              => 'Changes added by sp spas@work[at]gmail.com',
        'version'             => 'beta',
        'url'                 => 'http://www.mediawiki.org/wiki/Extension:Googledocviewer',
        'description' => 'Allows documents to be embedded on a page and viewed using googles viewers',
);
 
$wgExtensionFunctions[] = 'docviewer';
 
function docviewer()
{
        global $wgParser;
        $wgParser->setHook('doc', 'embedviewer');
}
 
function embedviewer($content, $args)
{
    if (!isset($args['id'])) {
        return '<font color="red">Usage: &lt;doc id=...[ width=...][ height=...][ mode=(view|edit|pub)][ title=...][ site=...] [literal=...] [type=...] /&gt;</font>';
    }
 
        $id      = urlencode($args['id']);
        $mode    = isset($args['mode'])    ? $args['mode']            : 'pub'; // view, pub, or edit
        $title   = isset($args['title'])   ? $args['title']   : '';
        $site    = isset($args['site'])    ? $args['site']    : '';
        $width   = isset($args['width'])   ? $args['width']   : '100%';
        $height  = isset($args['height'])  ? $args['height']  : '100%';
        $literal = isset($args['literal']) ? $args['literal'] : 'a';
        $type    = isset($args['type'])    ? $args['type']    : 'document';
 
        switch ($type) {
        case 'document':
            $html =
                '<table border=0 width="100%">'.
                        '<tr>'.
                                '<th align="left" width="85%">'.
                                        ($title ? '<h2>'.$title.'</h2>' : '').
                                '</th>'.
                                '<th align="right">'.
                                        '<a target="_blank" href="https://docs.google.com/'. $type .'/'. $literal .'/'.$id.'/edit">'.
                                                'Open in new window'.
                                        '</a>'.
                                '</th>'.
                        '</tr>'.
                '</table>'.
                '<iframe src=https://docs.google.com/'.$literal.'/'. $type .'/'.$mode.'?id='.$id.'&embedded=true width='.$width.' height='.$height.'></iframe>';
            break;
        case 'spreadsheet':
            $html =
                '<table border=0 width="100%">'.
                        '<tr>'.
                                '<th align="left" width="85%">'.
                                        ($title ? '<h2>'.$title.'</h2>' : '').
                                '</th>'.
                                '<th align="right">'.
                                        '<a target="_blank" href="https://docs.google.com/'. $type .'/ccc?key='.$id.'">'.
                                                'Open in new window'.
                                        '</a>'.
                                '</th>'.
                        '</tr>'.
                '</table>'.
                '<iframe src="https://docs.google.com/'. $type .'/'.$mode.'?key='.$id.'&single=true&gid=0&output=html&widget=true" width='.$width.' height='.$height.'></iframe>';            
            break;
        default:
            return '<font color="red">Name of document type is not correct!</font>';
            break;
        }
        return $html;
}
?>
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox