5
* Copyright (c) 2007-2008 by the original authors of AnyWikiDraw
6
* and all its contributors.
9
* The copyright of this software is owned by the authors and
10
* contributors of the AnyWikiDraw project ("the copyright holders").
11
* You may not use, copy or modify this software, except in
12
* accordance with the license agreement you entered into with
13
* the copyright holders. For details see accompanying license terms.
18
* WARNING: This is an extension for MediaWiki 1.7 through 1.10 only.
19
* Do not use it with other versions of MediaWiki without extensive testing!
22
* With the AnyWikiDraw extension it is possible to define new tags of the form
24
* {{#drawing:image.svg|width|height}}
26
* - The tag needs to be put into two curly braces.
27
* - The name of the tag is #drawing:
28
* - The parameter image.svg specifies the name of the image file.
29
* - If you specify an image file that does not yet exist in your Wiki, the image
30
* is created the first time you save a drawing.
31
* - The parameter width specifies the width of the image.
32
* - The parameter height specifies the height of the image.
34
* The enable drawing for the image HappyWiki.svg, which has a width of 400 and
35
* a height of 300 pixels, insert the following tag into a page:
37
* {{#drawing:HappyDrawing.svg|300|200}}
39
* To activate the extension, include it from your LocalSettings.php
40
* with: include("extensions/AnyWikiDraw/AnyWikiDraw.php");
42
* @author Werner Randelshofer
43
* @version $Id: AnyWikiDraw.php 127 2009-07-05 12:04:33Z rawcoder $
48
global $wgAnywikidrawVersion;
49
$wgAnyWikiDrawVersion = '0.13.2';
51
# Define a setup function
52
$wgExtensionFunctions[] = 'wfAnyWikiDrawParserFunction_Setup';
54
# Add a hook to initialise the magic word
55
$wgHooks['LanguageGetMagic'][] = 'wfAnyWikiDrawParserFunction_Magic';
57
# Define a special page
58
$wgAutoloadClasses['AnyWikiDraw'] = dirname(__FILE__) . '/AnyWikiDraw_body.php';
59
$wgSpecialPages['AnyWikiDraw'] = 'AnyWikiDraw';
60
$wgHooks['LoadAllMessages'][] = 'wfAnyWikiDrawLoadMessages';
63
function wfAnyWikiDrawParserFunction_Setup() {
65
# Set a function hook associating the "drawing" magic word with our function
66
$wgParser->setFunctionHook( 'drawing', 'wfAnyWikiDrawParserFunction_Render' );
69
function wfAnyWikiDrawParserFunction_Magic( &$magicWords, $langCode ) {
71
# The first array element is case sensitive, in this case it is not case sensitive
72
# All remaining elements are synonyms for our parser function
73
$magicWords['drawing'] = array( 0, 'drawing' );
74
# unless we return true, other parser functions extensions won't get loaded.
78
function wfAnyWikiDrawParserFunction_Render( &$parser, $name = null, $width = null, $height = null ) {
79
global $wgUser, $wgLang, $wgTitle, $wgRightsText, $wgOut, $wgArticlePath, $wgScriptPath, $wgEnableUploads;
80
$skin = $wgUser->getSkin();
81
wfAnyWikiDrawLoadMessages();
83
// Don't cache pages with drawings on it
84
$parser->disableCache();
88
if ($name == null || strlen($name) == 0) {
89
$error .= '<br>Please specify a name for your drawing.';
92
(! is_numeric($width) || $width < 1 || $width > 2000)) {
93
$error .= '<br>Please specify the width as a number between 1 and 2000 or leave it away.';
95
if ($height != null &&
96
(! is_numeric($height) || $height < 1 || $height > 2000)) {
97
$error .= '<br>Please specify the height as a number between 1 and 2000 or leave it away.';
99
if (strlen($error) > 0) {
100
$error = '<b>Sorry.</b>'.$error.'<br>'.
101
'Usage: <code>{{#drawing:<i>image.svg</i>|<i>width</i>||<i>height</i>}}</code><br>'.
102
'Example: <code>{{#drawing:HappyDrawing.svg|400|300}}</code><br>';
103
return array($error, 'isHTML'=>true, 'noparse'=>true);
106
# The parser function itself
107
# The input parameters are wikitext with templates expanded
108
# The output should be wikitext too, but in this case, it is HTML
109
#return array("param1 is $param1 and param2 is $param2", 'isHTML');
111
# Generate the image HTML as if viewed by a web request
112
$image = Image::newFromName($name);
115
$isProtected = $parser->getTitle()->isProtected();
117
if ($width == null && $image->getWidth() != -1) {
118
$width = $image->getWidth();
120
if ($height == null && $image->getHeight() != -1) {
121
$height = $image->getHeight();
125
$output = '<table><tr><td>';
126
if ($wgEnableUploads && ! $isProtected &&
127
key_exists('drawingtitle', $_POST) &&
128
$_POST['drawingtitle'] == $name) {
130
// edit the drawing using the applet
131
global $wgUsePathInfo;
132
if ($wgUsePathInfo) {
133
$downloadURL = str_replace('$1', 'Special:AnyWikiDraw?image='.htmlspecialchars($image->getName()), $wgArticlePath);
135
$downloadURL = str_replace('$1', 'Special:AnyWikiDraw&image='.htmlspecialchars($image->getName()), $wgArticlePath);
137
$uploadURL = str_replace('$1', 'Special:AnyWikiDraw', $wgArticlePath);
139
'<a name="anywikidraw" id="anywikidraw">'.
140
'<applet codebase="/" archive="'.$wgScriptPath.'/extensions/AnyWikiDraw/AnyWikiDrawForMediaWiki.jar"'.
141
' code="org.anywikidraw.mediawiki.MediaWikiDrawingApplet.class"'.
142
' width="'.htmlspecialchars(min(max($width+4, 600), 800)).'" '.
143
' height="'.htmlspecialchars(min(max($height+140, 480), 600)).'">'.
145
// The following parameters are used to tell AnyWikiDraw how to communicate with MediaWiki:
147
'<param name="DrawingName" value="'.htmlspecialchars($name).'">'.
148
'<param name="DrawingWidth" value="'.htmlspecialchars($width).'">'.
149
'<param name="DrawingHeight" value="'.htmlspecialchars($height).'">'.
150
(($image->getURL() !== '') ? '<param name="DrawingURL" value="'.$downloadURL.'">' : '').
151
'<param name="PageURL" value="'.htmlspecialchars($wgTitle->getLocalURL()).'">'.
152
'<param name="UploadURL" value="'.$uploadURL.'">'.
154
// The following parameters are used to configure the drawing applet:
156
'<param name="Locale" value="'.$wgUser->getOption('language','en').'"/>'.
158
// The following parameters are used to configure Sun's Java Plug-In:
160
'<param name="codebase_lookup" value="false"/>'.
161
'<param name="classloader_cache" value="false"/>'.
162
'<param name="java_arguments" value="-Djnlp.packEnabled=true"/>'.
163
'<param name="image" value="lib/Splash.gif"/>'.
164
'<param name="boxborder" value="false"/>'.
165
'<param name="centerimage" value="true"/>'.
170
$output .= '<div style="'.
171
'background-color: #C9CDD6; border: 1px solid #ccc; padding: 5px 10px 5px 10px; text-align: left; '.
172
'font-size: 12px; line-height: 16px; '.
174
wfMsg(($image->getURL() == '') ? 'anywikidraw_license_terms_new_work' : 'anywikidraw_license_terms_derived_work',
175
'<a href='.wfMsgForContent('copyrightpage').'>'.wfMsg('copyrightpage').'</a>', '<a href="./Image:'.$name.'">Image:'.$name.'</a>').
178
// Retrieve the page object of the image to determine, whether the user may edit it
179
$filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name );
180
$nt = Title::newFromText( $filtered );
181
if(! is_null( $nt ) ) {
182
$nt =& Title::makeTitle( NS_IMAGE, $nt->getDBkey() );
185
// Determine if the user has permission to edit the image
186
$userCanEdit = $wgEnableUploads &&
188
(is_null($nt) || $nt->userCanEdit()) &&
189
($image->getURL() == null || $wgUser->isAllowed( 'reupload' ));
191
// Determine if the user may edit images using the specified
192
// filename extension.
194
$extension = array_pop(explode( '.', $filtered ));
195
global $wgFileExtensions;
196
$userCanEdit = in_array($extension, $wgFileExtensions);
199
// If the user can edit the image, display an edit link.
200
// We do not display the edit link, if the user is already
201
// editing a drawing.
202
if ($userCanEdit && ! key_exists('drawingtitle', $_POST)) {
203
$formId = 'Form'.rand();
204
global $wgUsePathInfo;
205
if ($wgUsePathInfo) {
206
$action = $wgTitle->getLocalURL().'#anywikidraw';
208
//$action = str_replace('?','#anywikidraw?',$wgTitle->getLocalURL());
209
$action = $wgTitle->getLocalURL();
211
$output .= '<form name="'.$formId.'" method="post" action="'.$action.'">'.
212
'<input type="hidden" name="drawingtitle" value="'.htmlspecialchars($name).'">'.
214
'[<a href="javascript:document.'.$formId.'.submit();">'.wfMsg('edit').'</a>]'.
215
'<noscript><input type="submit" name="submit" value="'.wfMsg('edit').'"></input></noscript>'.
219
// render the drawing
220
$image->width = $width; // FIXME This is an ugly hack to get a view URL
221
$viewURL = $image->getViewURL();
223
if ($image->getURL() == '') {
224
// the drawing does not exist yet, render an empty rectangle
225
$output .= '<div style="border:1px solid #000;text-align:center;'.
226
(($width != null) ? 'width:'.$width.'px;' : '').
227
(($height != null) ? 'height:'.$height.'px;' : '').'"'.
228
'>'.htmlspecialchars($name).'</div>';
229
} else if (substr($name,-4) == '.svg' && $viewURL == null) {
230
// SVG images need an object tag
231
$output .= '<object '.
232
'type="image/svg+xml" '.
233
'data="'.(($viewURL != null) ? $viewURL : $image->getURL()).'" '.
234
(($width != null) ? 'width="'.$width.'" ' : '').
235
(($height != null) ? 'height="'.$height.'" ' : '').
238
// All other image types need an img tag
239
// Render the image map, if it exists
240
$thumbnail = $image->getThumbnail($width);
241
$isImageMap = $thumbnail != null && file_exists($thumbnail->path.'.map');
242
$mapId = 'Map'.rand();
244
$output .= '<map name="'.$mapId.'">'.
245
file_get_contents($thumbnail->path.'.map').
250
$output .= '<a href="./Image:'.$name.'">';
252
// Note: We append the timestamp of the image to the
253
// view URL as a query string. This way, we ensure,
254
// that the browser always displays the last edited version
257
'src="'.(($viewURL != null) ? $viewURL : $image->getURL()).
258
'?version='.$image->nextHistoryLine()->img_timestamp.'" '.
259
(($width != null) ? 'width="'.$width.'" ' : '').
260
(($height != null) ? 'height="'.$height.'" ' : '').
261
'alt="Image:'.$name.'" '.
262
'title="Image:'.$name.'" '.
263
(($isImageMap) ? 'usemap="#'.$mapId.'" ' : '').
269
// If the user can edit the image, display an edit link.
270
// We do not display the edit link, if the user is already
271
// editing a drawing.
272
if ($userCanEdit && ! key_exists('drawingtitle', $_POST)) {
273
$output .= '</form>';
278
$output .= '</tr></td></table>';
280
return array($output, 'isHTML'=>true, 'noparse'=>true);
283
function wfAnyWikiDrawLoadMessages() {
284
global $wgAnyWikiDrawMessagesLoaded;
285
global $wgMessageCache;
286
if ( $wgAnyWikiDrawMessagesLoaded ) return;
287
$wgAnyWikiDrawMessagesLoaded = true;
289
require( dirname( __FILE__ ) . '/AnyWikiDraw.i18n.php' );
290
foreach ( $messages as $lang => $msgs ) {
291
$wgMessageCache->addMessages( $msgs, $lang );
b'\\ No newline at end of file'