Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37829656
en ru br
ALT Linux repos
S:1.11-alt2

Group :: Networking/WWW
RPM: mediawiki-extensions-Dia

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Dia/000075500000000000000000000000001201123512300115375ustar00rootroot00000000000000Dia/Dia.body.php000064400000000000000000000110601201123512300136770ustar00rootroot00000000000000<?php

function wfGetDIAsize( $filename ) {

global $wgDIANominalSize;

$xmlstr = file_get_contents( $filename );
$xmlstr = str_replace( "<dia:", "<", $xmlstr );
$xmlstr = str_replace( "</dia:", "</", $xmlstr );

$xml = new SimpleXMLElement( $xmlstr );

$xmin = -1;
$ymin = -1;
$xmax = -1;
$ymax = -1;

/*
* Get the total bounding box (for correct aspect ratio).
*
* Note: the loop expects $x1<=$x2 and $y1<=$y2, but dia does this for you.
*/
foreach( $xml->xpath('//attribute[@name="obj_bb"]') as $boundingbox ) {
sscanf( $boundingbox->rectangle['val'], "%f,%f;%f,%f", $x1, $y1, $x2, $y2 );

/* initialization */
if( $xmin == -1 )
$xmin = $x1;
if( $xmax == -1 )
$xmax = $x2;

if( $ymin == -1 )
$ymin = $y1;
if( $ymax == -1 )
$ymax = $y2;

if( $x1 < $xmin )
$xmin = $x1;
if( $x2 > $xmax )
$xmax = $x2;

if( $y1 < $ymin )
$ymin = $y1;
if( $y2 > $ymax )
$ymax = $y2;
}

# wfDebug( __METHOD__ . " dia: Total BB: $xmin,$ymin;$xmax,$ymax\n" );

$width = $xmax - $xmin;
$height = $ymax - $ymin;

# wfDebug( __METHOD__ . " dia: Size: ${width}x${height}\n" );

$aspect = $width / $height;

$nominal_width = $wgDIANominalSize;
$nominal_height = (int)($nominal_width / $aspect);

# wfDebug( __METHOD__ . " dia: Nominal size: ${nominal_width}x${nominal_height}\n" );

$res = array($nominal_width, $nominal_height);

return $res;
}

/**
* @addtogroup Media
*/
class DiaHandler extends ImageHandler {
function isEnabled() {
global $wgDIAConverters, $wgDIAConverter;
if ( !isset( $wgDIAConverters[$wgDIAConverter] ) ) {
wfDebug( "\$wgDIAConverter is invalid, disabling DIA rendering.\n" );
return false;
} else {
return true;
}
}

function mustRender( $file ) {
return true;
}

function canRender( $file ) {
return true;
}

function normaliseParams( $image, &$params ) {
global $wgDIAMaxSize;
if ( !parent::normaliseParams( $image, $params ) ) {
return false;
}

# Don't make an image bigger than wgMaxDIASize
$params['physicalWidth'] = $params['width'];
$params['physicalHeight'] = $params['height'];
if ( $params['physicalWidth'] > $wgDIAMaxSize ) {
$srcWidth = $image->getWidth( $params['page'] );
$srcHeight = $image->getHeight( $params['page'] );
$params['physicalWidth'] = $wgDIAMaxSize;
$params['physicalHeight'] = File::scaleHeight( $srcWidth, $srcHeight, $wgDIAMaxSize );
}
return true;
}

function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
global $wgDIAConverters, $wgDIAConverter, $wgDIAConverterPath;

# wfDebug( __METHOD__ . " dia: DiaHandler::doTransform\n" );

if ( !$this->normaliseParams( $image, $params ) ) {
return new TransformParameterError( $params );
}
$clientWidth = $params['width'];
$clientHeight = $params['height'];
$physicalWidth = $params['physicalWidth'];
$physicalHeight = $params['physicalHeight'];
$srcPath = $image->getPath();

if ( $flags & self::TRANSFORM_LATER ) {
return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath );
}

if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
wfMsg( 'thumbnail_dest_directory' ) );
}

$err = false;
if( isset( $wgDIAConverters[$wgDIAConverter] ) ) {
$cmd = str_replace(
array( '$path/', '$width', '$height', '$input', '$output' ),
array( $wgDIAConverterPath ? wfEscapeShellArg( "$wgDIAConverterPath/" ) : "",
intval( $physicalWidth ),
intval( $physicalHeight ),
wfEscapeShellArg( $srcPath ),
wfEscapeShellArg( $dstPath ) ),
$wgDIAConverters[$wgDIAConverter] ) . " 2>&1";
# wfDebug( __METHOD__ . " dia: \$cmd: $cmd\n" );
wfProfileIn( 'dia' );
wfDebug( __METHOD__.": $cmd\n" );
$err = wfShellExec( $cmd, $retval );
wfProfileOut( 'dia' );
}

$removed = $this->removeBadFile( $dstPath, $retval );
if ( $retval != 0 || $removed ) {
wfDebugLog( 'thumbnail',
sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
wfHostname(), $retval, trim($err), $cmd ) );
return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err );
} else {
return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath );
}
}

function getImageSize( $image, $path ) {
return wfGetDIAsize( $path );
}

function getThumbType( $ext, $mime ) {
return array( 'png', 'image/png' );
}

function getLongDesc( $file ) {
global $wgLang;
return wfMsg( 'dia-long-desc', $file->getWidth(), $file->getHeight(),
$wgLang->formatSize( $file->getSize() ) );
}
}


Dia/Dia.i18n.php000064400000000000000000000001621201123512300135220ustar00rootroot00000000000000<?php

$messages = array(
'dia-long-desc' => '(Dia diagram, nominally $1 × $2 pixels, file size: $3)',
);
Dia/Dia.php000064400000000000000000000051271201123512300127520ustar00rootroot00000000000000<?php
/**
* Setup for Dia extension, an extension that allows Dia (http://live.gnome.org/Dia) diagrams
* to be rendered in MediaWiki pages.
*
* @package MediaWiki
* @subpackage Extensions
* @author Marcel Toele, dwarfhouse.org
* @copyright © 2007 Marcel Toele
* @licence GNU General Public Licence 2.0 or later
*/

if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}

/****************************************************************************
* Credits
*/
$wgExtensionCredits['other'][] = array(
'name' => 'Dia',
'author' =>'Marcel Toele',
'url' => 'http://mediawiki.org/wiki/Extension:Dia',
'description' => 'Allows Dia diagrams to be rendered inside MediaWiki pages.',
);

/****************************************************************************
* Variables Default Settings Setup
*/

# Dia diagrams may be uploaded as drawings.
# Dia diagrams are converted to png before they can be rendered on a page.
# Future versions of the extension may also output SVG.
#
# An external program is required to perform this conversion:
$wgDIAConverters = array(
# dia -n -e testdiagram.png -t png -s 100 testdiagram.dia
'dia' => '$path/dia -n -e $output -t png -s $width $input',
);
/** Pick one of the above */
$wgDIAConverter = 'dia';
/** If not in the executable PATH, specify */
$wgDIAConverterPath = '';
/** The nominal width of a Dia file when rendered to png */
$wgDIANominalSize = 300;
/** Don't scale a Dia file larger than this */
$wgDIAMaxSize = 1024;

/****************************************************************************
* Functionality Setup
*/
# Add the DiaHandler via de Autoload mechanism.
$wgAutoloadClasses['DiaHandler'] = dirname(__FILE__) . '/Dia.body.php';
$wgMediaHandlers['application/x-dia-diagram'] = 'DiaHandler';

/****************************************************************************
* Internationalisation Setup
*/
global $wgHooks;
$wgHooks['MessagesPreLoad'][] = 'loadDiaI18n';
function loadDiaI18n() {
global $wgLang, $wgMessageCache;

# wfDebug( __METHOD__ . "dia: loadDiaI18n\n" );

static $initialized = false;

if( $initialized )
return true;

$messages = array();

$filename = dirname( __FILE__ ) . '/Dia.i18n.php';
include( $filename );
$wgMessageCache->addMessages( $messages ); # fall back messages

$filename = dirname( __FILE__ ) . '/Dia.i18n.' . $wgLang->getCode() . '.php';
if( file_exists( $filename ) )
include( $filename );

$initialized = true;
$wgMessageCache->addMessages( $messages );

return true;
}
Dia/README000064400000000000000000000034041201123512300124200ustar00rootroot00000000000000--------------------------------------------------------------------------
README for the Dia extension
Copyright © 2007 Marcel Toele
Licenses: GNU General Public Licence (GPL) v2.0 or up
GNU Free Documentation License (GFDL)
--------------------------------------------------------------------------

Description Allows Dia diagrams to be rendered inside MediaWiki pages.
Author(s) EleotleCram
MediaWiki 1.9 (maybe older versions too)

Installing

Copy the Dia directory into the extensions folder of your MediaWiki installation. Then add the following lines to your LocalSettings.php file (near the end):

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

Configuration

$wgDIANominalSize
The nominal width of a Dia file when rendered to png (default: 300px).

$wgDIAMaxSize
Don't scale a Dia file larger than this (default: 1024px).

Advanced Configuration

Dia diagrams may be uploaded as drawings. these diagrams are converted to png before they can be rendered on a page. An external program is required to perform this conversion. By default 'dia' itself is used to perform this conversion, but if you have a different tool to perform the conversion you can set it up here.

$wgDIAConverters
An associative array linking your conversion tool (as key) with the commandline to be used for your tool. In this commandline you can use the following variables:

* $input: The input filename
* $output: The output filename
* $width: The output width

$wgDIAConverter
The currently selected converter (default: 'dia').
$wgDIAConverterPath
If the currently selected converter is not in the default PATH environment variable, you can set the path here.

Note: Future versions of the extension may also output SVG.

History

* 20071031 Initial version.

Dia/mimetypes.patch000064400000000000000000000016441201123512300146010ustar00rootroot00000000000000Index: includes/mime.types
===================================================================
--- includes/mime.types (revision 27053)
+++ includes/mime.types (working copy)
@@ -25,6 +25,7 @@
application/x-chess-pgn pgn
application/x-cpio cpio
application/x-csh csh
+application/x-dia-diagram dia
application/x-director dcr dir dxr
application/x-dvi dvi
application/x-futuresplash spl
@@ -115,4 +116,4 @@
video/x-msvideo avi
video/x-ogg ogm ogg
video/x-sgi-movie movie
-x-conference/x-cooltalk ice
\ No newline at end of file
+x-conference/x-cooltalk ice
Index: includes/mime.info
===================================================================
--- includes/mime.info (revision 27053)
+++ includes/mime.info (working copy)
@@ -24,6 +24,7 @@
application/postscript [DRAWING]
application/x-latex [DRAWING]
application/x-tex [DRAWING]
+application/x-dia-diagram [DRAWING]


audio/mp3 audio/mpeg3 audio/mpeg [AUDIO]
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin