-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetup.php
173 lines (151 loc) · 4.91 KB
/
Setup.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* The MeetingMinutes extension provides JS and CSS to enable recording meeting
* minutes in SMW. See README.md.
*
* Documentation: https://github.com/enterprisemediawiki/SemanticMeetingMinutes
* Support: https://github.com/enterprisemediawiki/SemanticMeetingMinutes
* Source code: https://github.com/enterprisemediawiki/SemanticMeetingMinutes
*
* @addtogroup Extensions
* @author James Montalvo
* @copyright © 2014 by James Montalvo
* @licence GNU GPL v3+
*/
// FIXME: all function documentation is very generic...add specifics.
namespace MeetingMinutes;
class Setup {
/**
* Handler for ParserFirstCallInit hook; sets up parser functions.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
* @param $parser Parser object
* @param $frame FIXME: what does frame really do?
* @param $args array of arguments passed to parser function
* @return bool true in all cases
*/
static function setupParserFunctions ( &$parser ) {
// setup #synopsize parser function
$parser->setFunctionHook(
'synopsize',
array(
'MeetingMinutes\Setup',
'renderSynopsizeParserFunction'
),
SFH_OBJECT_ARGS
);
// setup #meetingminutestemplate parser function (just adds module to
// meeting minutes and meeting template)
$parser->setFunctionHook(
'meetingminutestemplate',
array(
'MeetingMinutes\Setup',
'renderMeetingMinutesTemplateParserFunction'
),
SFH_OBJECT_ARGS
);
// setup #meetingminutesform parser function (just adds module to
// meeting minutes form)
$parser->setFunctionHook(
'meetingminutesform',
array(
'MeetingMinutes\Setup',
'renderMeetingMinutesFormParserFunction'
),
SFH_OBJECT_ARGS
);
return true;
}
/**
* Handler for synopsize parser function.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
* @param $parser Parser object
* @param $frame FIXME: what does frame really do?
* @param $args array of arguments passed to parser function
* @return bool true in all cases
*/
static function renderSynopsizeParserFunction ( &$parser, $frame, $args ) {
$args = self::processArgs( $frame, $args, array("", 255, 1) );
$full_text = $args[0];
$max_length = $args[1];
$max_lines = $args[2];
$needle = "\n";
$newline_pos = 0;
for($i=0; $i<$max_lines; $i++) {
if ( $newline_pos ) {
$offset = $newline_pos + strlen($needle);
}
else {
$offset = 0;
}
$newline_pos = strpos($full_text, $needle, $offset);
}
if ($newline_pos) {
// trim to specified number of newlines
$synopsis = substr($full_text, 0, $newline_pos);
}
else {
$synopsis = $full_text;
}
// trim at max characters
if (strlen($synopsis) > $max_length) {
$synopsis = substr($synopsis, 0, $max_length);
$last_space = strrpos($synopsis, ' ');
$synopsis = substr($synopsis, 0, $last_space) . ' ...';
}
return $synopsis;
}
/**
* Processes arguments to parser function, setting defaults where required.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
* @param $frame FIXME: what does frame really do?
* @param $args array of arguments passed to parser function
* @param $defaults array of default values for arguments
* @return bool true in all cases
*/
static function processArgs( $frame, $args, $defaults ) {
$new_args = array();
$num_args = count($args);
$num_defaults = count($defaults);
$count = ($num_args > $num_defaults) ? $num_args : $num_defaults;
for ($i=0; $i<$count; $i++) {
if ( isset($args[$i]) )
$new_args[$i] = trim( $frame->expand($args[$i]) );
else
$new_args[$i] = $defaults[$i];
}
return $new_args;
}
/**
* Handler for meetingminutesform parser function.
* @param $parser Parser object
* @param $frame FIXME: what does frame really do?
* @param $args array of arguments passed to parser function
* @return bool true in all cases
*/
static function renderMeetingMinutesFormParserFunction ( &$parser, $frame, $args ) {
global $wgOut;
$wgOut->addModules( array( 'ext.meetingminutes.form' ) );
return ''; // currently doing nothing...parser function did not work for loading CSS.
}
/**
* Handler for meetingminutesform parser function.
* @param $parser Parser object
* @param $frame FIXME: what does frame really do?
* @param $args array of arguments passed to parser function
* @return bool true in all cases
*/
static function renderMeetingMinutesTemplateParserFunction ( &$parser, $frame, $args ) {
return ''; // currently doing nothing...parser function did not work for loading CSS.
}
/**
* Handler for BeforePageDisplay hook. Adds required modules for MeetingMinutes
* @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
* @param $out OutputPage object
* @param $skin Skin being used.
* @return bool true in all cases
*/
public static function onBeforePageDisplay( \OutputPage &$out, \Skin &$skin ) {
$out->addModules( array( 'ext.meetingminutes.template' ) );
return true;
}
}