-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathS5SlideShow.php
More file actions
272 lines (247 loc) · 10.1 KB
/
S5SlideShow.php
File metadata and controls
272 lines (247 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/**
* Extension to create slide shows from wiki pages using improved S5 (http://meyerweb.com/eric/tools/s5/)
* Copyright (c) 2010+ Vitaliy Filippov <vitalif@mail.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
/**
* @author Vitaliy Filippov <vitalif@mail.ru>
* @package MediaWiki
* @subpackage Extensions
*/
if (!defined('MEDIAWIKI'))
die();
$dir = dirname(__FILE__);
//--- Default configuration ---//
// Headings with this text will be treated as slide headings
// false = do not treat subsections as slides by default
$egS5SlideHeadingMark = false;
// All lists on slides with this text in heading will be shown step-by-step
$egS5SlideIncMark = '\(step\)';
// Slides with this text in heading will be shown centered
$egS5SlideCenterMark = '\(center\)';
// Filesystem path to slideshow template file
$egS5SlideTemplateFile = $dir.'/slide.htm';
// In scaled slideshow mode, images are scaled proportionally
// with all other elements. This means you can set image size
// with [[File:xxx.jpg|150px]] - these 150px will also be relative
// to other elements. But, without the following hack, the
// images will be added to slides downsampled, and then, in
// slideshow mode, they will be probably scaled back, which leads
// to reduced quality.
// If this setting is true, hack into parser when in slideshow
// mode and output original images with HTML width/height set -
// i.e. hand off scaling to the browser - instead of outputting
// downsampled thumbnails. (default = true)
$egS5BrowserScaleHack = true;
//Default Style for presentations. Useful for not redefining 'default' style
//but change all presentations by default to some "corporate" style.
$egS5DefaultStyle = 'default';
//Should Slides be scaled by default?
$egS5Scaled = false;
//--- End configuration ---//
/* Extension setup */
$wgExtensionMessagesFiles['S5SlideShow'] = $dir.'/S5SlideShow.i18n.php';
$wgHooks['UnknownAction'][] = 'S5SlideShowHooks::UnknownAction';
$wgAutoloadClasses['S5SlideShow'] = $dir.'/S5SlideShow.class.php';
$wgAutoloadClasses['S5SkinArticle'] = $dir.'/S5SlideShow.class.php';
$wgExtensionFunctions[] = 'S5SlideShowHooks::Setup';
$wgHooks['ParserFirstCallInit'][] = 'S5SlideShowHooks::ParserFirstCallInit';
$wgHooks['ArticleFromTitle'][] = 'S5SlideShowHooks::ArticleFromTitle';
$wgHooks['AlternateEdit'][] = 'S5SlideShowHooks::AlternateEdit';
$wgHooks['MagicWordwgVariableIDs'][] = 'S5SlideShowHooks::MagicWordwgVariableIDs';
$wgHooks['ParserGetVariableValueSwitch'][] = 'S5SlideShowHooks::ParserGetVariableValueSwitch';
class S5SlideShowHooks
{
static $styles = array(
'core.css' => 's5-core.css',
'base.css' => 's5-base.css',
'framing.css' => 's5-framing.css',
'pretty.css' => '$skin/pretty.css',
);
static $parsingSlide = false;
// Setup parser hooks for S5
static function ParserFirstCallInit($parser)
{
if (!isset($parser->extS5Hooks))
{
$parser->setHook('slideshow', 'S5SlideShow::slideshow_view');
$parser->setHook('slide', 'S5SlideShow::slideshow_legacy');
$parser->setHook('slides', 'S5SlideShow::slides_view');
$parser->setHook('slidecss', 'S5SlideShow::slidecss_view');
}
elseif ($parser->extS5Hooks == 'parse')
{
$parser->setHook('slideshow', array($parser->extS5, 'slideshow_parse'));
$parser->setHook('slide', array($parser->extS5, 'slideshow_parse'));
$parser->setHook('slides', 'S5SlideShow::empty_tag_hook');
$parser->setHook('slidecss', 'S5SlideShow::empty_tag_hook');
}
elseif ($parser->extS5Hooks == 'parse2')
{
$parser->setHook('slideshow', 'S5SlideShow::empty_tag_hook');
$parser->setHook('slide', 'S5SlideShow::empty_tag_hook');
$parser->setHook('slides', array($parser->extS5, 'slides_parse'));
$parser->setHook('slidecss', array($parser->extS5, 'slidecss_parse'));
}
return true;
}
// Setup hook for image scaling hack
static function Setup()
{
global $egS5BrowserScaleHack, $wgHooks;
if ($egS5BrowserScaleHack)
$wgHooks['ImageBeforeProduceHTML'][] = 'S5SlideShowHooks::ImageBeforeProduceHTML';
}
// Hook that creates {{S5SLIDESHOW}} magic word
static function MagicWordwgVariableIDs(&$mVariablesIDs)
{
$mVariablesIDs[] = 's5slideshow';
return true;
}
// Hook that evaluates {{S5SLIDESHOW}} magic word
static function ParserGetVariableValueSwitch($parser, $varCache, $index, &$ret)
{
if ($index == 's5slideshow')
$ret = empty(self::$parsingSlide) ? '' : '1';
return true;
}
// Render pictures differently in slide show mode
static function ImageBeforeProduceHTML($skin, $title, $file, $frameParams, $handlerParams, $time, &$res)
{
global $wgVersion;
if (empty(self::$parsingSlide) || !$file || !$file->exists() || !isset($handlerParams['width']))
return true;
$fp = &$frameParams;
$hp = &$handlerParams;
$center = false;
if (isset($fp['align']) && $fp['align'] == 'center')
{
$center = true;
$fp['align'] = 'none';
}
$thumb = $file->getUnscaledThumb(isset($hp['page']) ? array('page' => $hp['page']) : false);
$params = array(
'alt' => @$fp['alt'],
'title' => @$fp['title'],
);
if (version_compare($wgVersion, '1.22', '>='))
{
$params['override-height'] = ceil($thumb->getHeight() * $hp['width'] / $thumb->getWidth());
$params['override-width'] = $hp['width'];
}
else
{
$thumb->height = ceil($thumb->height * $hp['width'] / $thumb->width);
$thumb->width = $hp['width'];
}
if (!empty($fp['link-url']))
$params['custom-url-link'] = $fp['link-url'];
elseif (!empty($fp['link-title']))
$params['custom-title-link'] = $fp['link-title'];
elseif (!empty($fp['no-link']))
{
}
else
$params['desc-link'] = true;
$res .= $thumb->toHtml($params);
if (isset($fp['thumbnail']))
{
$outerWidth = $thumb->getWidth()+2;
$res = "<div class=\"thumb t$fp[align]\" style='border:0'>".
"<div class=\"thumbinner\">$res</div><div class='thumbcaption'>$fp[caption]</div></div>";
}
if (isset($fp['align']) && $fp['align'])
$res = "<div class=\"float$fp[align]\">$res</div>";
if ($center)
$res = "<div class=\"center\">$res</div>";
return false;
}
// Hook for ?action=slide
static function UnknownAction($action, $article)
{
global $wgMaxRedirects, $wgRequest;
if ($action == 'slide')
{
$s5skin = trim($wgRequest->getVal('s5skin'));
if (preg_match('/[^\w-]/', $s5skin))
$s5skin = '';
$print = $wgRequest->getVal('print');
if ($print)
{
preg_match_all('/\d+/s', $print, $print, PREG_PATTERN_ORDER);
$print = $print[0];
}
else
$print = false;
if ($wgRequest->getVal('s5css'))
{
// Get CSS for a given S5 style (from wiki-pages)
S5SlideShow::genStyle($s5skin, $print);
return false;
}
// Check if the article is readable
$title = $article->getTitle();
for ($r = 0; $r < $wgMaxRedirects && $title->isRedirect(); $r++)
{
if (!$title->userCan('read'))
return true;
$title = $article->followRedirect();
$article = new Article($title);
}
// Hack for CustIS live preview
// TODO remove support for loading text from session object and
// replace it by support for save-staying-in-edit-mode extension
$content = $wgRequest->getVal('wpTextbox1');
if (!$content && ($t1 = $wgRequest->getSessionData('wpTextbox1')))
{
$content = $t1;
$wgRequest->setSessionData('wpTextbox1', NULL);
}
// Generate presentation HTML content
$slideShow = new S5SlideShow($title, $content);
if ($s5skin)
$slideShow->attr['style'] = $s5skin;
$slideShow->genSlideFile($print);
return false;
}
return true;
}
// Used to display CSS files on S5 skin CSS pages when they don't exist
static function ArticleFromTitle($title, &$article)
{
if ($title->getNamespace() == NS_MEDIAWIKI &&
preg_match('#^S5/([\w-]+)/((core|base|framing|pretty).css)$#s', $title->getText(), $m))
{
$file = dirname(__FILE__).'/'.str_replace('$skin', $m[1], self::$styles[$m[2]]);
if (file_exists($file))
{
$article = new S5SkinArticle($title, $m[1], $file);
return false;
}
}
return true;
}
// Used to display CSS files on S5 skin CSS pages in edit mode
static function AlternateEdit($editpage)
{
if ($editpage->mArticle instanceof S5SkinArticle &&
!$editpage->mArticle->exists())
$editpage->mPreloadText = $editpage->mArticle->getContent();
return true;
}
}