Skip to content

Commit

Permalink
DocViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
toniher committed Nov 10, 2014
1 parent 3c2a67d commit bd2737a
Show file tree
Hide file tree
Showing 36 changed files with 52,391 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DocViewer.i18n.magic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$magicWords = array();

/** English (English) */
$magicWords['en'] = array(
'docviewer' => array( 0, 'docviewer' ),
);
35 changes: 35 additions & 0 deletions DocViewer.i18n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* This is a backwards-compatibility shim, generated by:
* https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
*
* Beginning with MediaWiki 1.23, translation strings are stored in json files,
* and the EXTENSION.i18n.php file only exists to provide compatibility with
* older releases of MediaWiki. For more information about this migration, see:
* https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
*
* This shim maintains compatibility back to MediaWiki 1.17.
*/
$messages = array();
if ( !function_exists( 'wfJsonI18nShim1b3b6a389f517def' ) ) {
function wfJsonI18nShim1b3b6a389e417def( $cache, $code, &$cachedData ) {
$codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] );
foreach ( $codeSequence as $csCode ) {
$fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
if ( is_readable( $fileName ) ) {
$data = FormatJson::decode( file_get_contents( $fileName ), true );
foreach ( array_keys( $data ) as $key ) {
if ( $key === '' || $key[0] === '@' ) {
unset( $data[$key] );
}
}
$cachedData['messages'] = array_merge( $data, $cachedData['messages'] );
}

$cachedData['deps'][] = new FileDependency( $fileName );
}
return true;
}

$GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShim1b3b6a389f517def';
}
34 changes: 34 additions & 0 deletions DocViewer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php


if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}

$GLOBALS['wgExtensionCredits']['parserhook'][] = array(
'path' => __FILE__,
'name' => 'DocViewer',
'version' => '0.1',
'url' => 'https://github.com/SimilisTools/mediawiki-DocViewer',
'author' => array( 'Toniher' ),
'descriptionmsg' => 'docviewer-desc',
);

$GLOBALS['wgAutoloadClasses']['DocViewer'] = __DIR__.'/DocViewer_body.php';
$GLOBALS['wgMessagesDirs']['DocViewer'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['DocViewer'] = __DIR__ . '/DocViewer.i18n.php';
$GLOBALS['wgExtensionMessagesFiles']['DocViewerMagic'] = __DIR__ . '/DocViewer.i18n.magic.php';

$wgHooks['ParserFirstCallInit'][] = 'wfRegisterDocViewer';

// Path wrapup for ViewerJS
$GLOBALS['wgDocViewerViewerJSPath'] = __DIR__ . '/libs/ViewerJS#../../..';

/**
* @param $parser Parser
* @return bool
*/
function wfRegisterDocViewer( $parser ) {
$parser->setFunctionHook( 'docviewer', 'DocViewer::generateViewer', SFH_OBJECT_ARGS );
return true;
}
59 changes: 59 additions & 0 deletions DocViewer_body.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

class DocViewer {

/**
* @param $parser Parser
* @param $frame PPFrame
* @param $args array
* @return string
*/
public static function generateViewer( &$parser, $frame, $args ) {

global $wgDocViewerViewerJSPath;

$attrs = array();
# First value is File in wiki format

if ( count( $args ) > 0 ) {

$fileName = array_shift( $args );

$fileName = trim( $frame->expand( $file ) ); // Clean file

// Wer may need to remove namespace here
$file = wfFindFile( $fileName );
if ( $file && is_object( $file ) ) {
$filepath = $file->getFullPath();
$attrs["src"] = $wgDocViewerViewerJSPath.$filepath;
}

foreach ( $args as $arg ) {
$arg_clean = trim( $frame->expand( $arg ) );
$arg_proc = explode( "=", $arg_clean, 2 );

if ( count( $arg_proc ) == 1 ){
// kind of disabled = disabled
$attrs[ trim( $arg_proc[0] ) ] = trim( $arg_proc[0] );
} else {
if ( count( $arg_proc ) == 2 ) {
$attrs[ trim( $arg_proc[0] ) ] = trim( $arg_proc[1] );
}
}
}
}
// Default params
$attrs["id"] = "viewer";

// <iframe style="float:right;" id="viewer" src = "/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe>
$tag = Html::element(
'iframe',
$attrs
);

return $parser->insertStripItem( $tag, $parser->mStripState );
}



}
3 changes: 3 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"docviewer-desc": "Extension for embedding a document viewer for PDF, ODF and other kind of documents."
}
3 changes: 3 additions & 0 deletions i18n/en.json~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"alink-desc": "Creates custom anchor links"
}
Loading

0 comments on commit bd2737a

Please sign in to comment.