-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmoothGallery.php
149 lines (126 loc) · 4.88 KB
/
SmoothGallery.php
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
<?php
# Copyright (C) 2004 Ryan Lane <[email protected]>
#
# 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 2 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# http://www.gnu.org/copyleft/gpl.html
# SmoothGallery extension. Creates galleries of images that are in your wiki.
#
# SmoothGallery.php
#
# Extension info available at http://www.mediawiki.org/wiki/Extension:SmoothGallery
# SmoothGallery available at http://smoothgallery.jondesign.net/
#
# sgallery Parser Function changes contributed by David Claughton <[email protected]>
# infopane sliding and opacity patch provided by David Claughton <[email protected]>
if ( !defined( 'MEDIAWIKI' ) )
die( -1 );
/**
* Add extension information to Special:Version
*/
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'SmoothGallery parser extension',
'version' => '1.2.0',
'author' => 'Ryan Lane',
'descriptionmsg' => 'smoothgallery-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:SmoothGallery',
);
$wgHooks['ParserFirstCallInit'][] = 'efSmoothGallerySetHooks';
$wgHooks['OutputPageParserOutput'][] = 'smoothGalleryParserOutput';
$dir = dirname( __FILE__ ) . '/';
$wgMessagesDirs['SmoothGallery'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['SmoothGallery'] = $dir . 'SmoothGallery.i18n.php';
$wgExtensionMessagesFiles['SmoothGalleryMagic'] = $dir . 'SmoothGallery.i18n.magic.php';
$wgAutoloadClasses['SmoothGallery'] = $dir . 'SmoothGalleryClass.php';
$wgAutoloadClasses['SmoothGalleryParser'] = $dir . 'SmoothGalleryParser.php';
// sane defaults. always initialize to avoid register_globals vulnerabilities
$wgSmoothGalleryDelimiter = "\n";
$wgSmoothGalleryExtensionPath = $wgScriptPath . '/extensions/SmoothGallery';
$wgSmoothGalleryAllowExternal = false;
$wgSmoothGalleryThumbHeight = "75px";
$wgSmoothGalleryThumbWidth = "100px";
function efSmoothGallerySetHooks( $parser ) {
$parser->setHook( 'sgallery', 'initSmoothGalleryTag' );
$parser->setHook( 'sgalleryset', 'initSmoothGalleryTagSet' );
$parser->setFunctionHook( 'sgallery', 'initSmoothGalleryPF' );
return true;
}
// FIXME: split off to a hook file and use $wgHooks['ParserFirstCallInit'] to init tags
function initSmoothGalleryPF( $parser ) {
global $wgSmoothGalleryDelimiter;
$numargs = func_num_args();
if ( $numargs < 2 ) {
$input = "#SmoothGallery: no arguments specified";
return str_replace( '§', '<', '§pre>§nowiki>' . $input . '§/nowiki>§/pre>' );
}
// fetch all user-provided arguments (skipping $parser)
$input = "";
$argv = array();
$arg_list = func_get_args();
for ( $i = 1; $i < $numargs; $i++ ) {
$p1 = $arg_list[$i];
$aParam = explode( '=', $p1, 2 );
if ( count( $aParam ) < 2 ) {
continue;
}
SmoothGallery::debug( 'sgallery tag parameter: ', $aParam );
if ( $aParam[0] == "imagelist" ) {
$input = $aParam[1];
continue;
}
$sKey = trim( $aParam[0] );
$sVal = trim( $aParam[1] );
if ( $sKey != '' ) {
$argv[$sKey] = $sVal;
}
}
$output = initSmoothGallery( $input, $argv, $parser );
return array( $output, 'noparse' => true, 'isHTML' => true );
}
function initSmoothGalleryTag( $input, $argv, $parser ) {
$output = initSmoothGallery( $input, $argv, $parser );
return $output;
}
function initSmoothGallery( $input, $argv, $parser, $calledAsSet = false ) {
$sgParser = new SmoothGalleryParser( $input, $argv, $parser, $calledAsSet );
$sgGallery = new SmoothGallery();
$sgGallery->setParser( $parser );
$sgGallery->setSet( $calledAsSet );
$sgGallery->setArguments( $sgParser->getArguments() );
$sgGallery->setGalleries( $sgParser->getGalleries() );
$sgGallery->checkForErrors();
if ( $sgGallery->hasErrors() ) {
return $sgGallery->getErrors();
} else {
return $sgGallery->toHTML();
}
}
function initSmoothGalleryTagSet( $input, $args, $parser ) {
$output = initSmoothGallery( $input, $args, $parser, true );
return $output;
}
/**
* Hook callback that injects messages and things into the <head> tag
* Does nothing if $parserOutput->mSmoothGalleryTag is not set
*/
function smoothGalleryParserOutput( $outputPage, $parserOutput ) {
if ( !empty( $parserOutput->mSmoothGalleryTag ) ) {
SmoothGallery::setGalleryHeaders( $outputPage );
}
if ( !empty( $parserOutput->mSmoothGallerySetTag ) ) {
SmoothGallery::setGallerySetHeaders( $outputPage );
}
return true;
}