-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHooks.php
More file actions
93 lines (86 loc) · 2.54 KB
/
Hooks.php
File metadata and controls
93 lines (86 loc) · 2.54 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
<?php
/**
* @file
* @ingroup Extensions
* @license GPL-2.0-or-later
*/
class FormWizardHooks {
/**
* Hook for BeforePageDisplay.
*
* Enables JavaScript.
*
* @param OutputPage &$out The OutputPage object.
* @param Skin &$skin Skin object that will be used to generate the page,
* added in 1.13.
*/
public static function onBeforePageDisplay(
OutputPage &$out,
Skin &$skin
) {
$out->addModules( [
'ext.formWizard'
] );
}
public static function onParserSetup( &$parser ) {
// Create a function hook associating the "formwizard" magic word with renderExample()
$parser->setFunctionHook( 'formwizard', 'FormWizardHooks::showProjectButton' );
}
/**
* Converts an array of values in form [0] => "name=value" into a real
* associative array in form [name] => value. If no = is provided,
* true is assumed like this: [name] => true
*
* @param array $options
* @return array Parser function options
*/
public static function extractOptions( array $options ) {
$results = [];
foreach ( $options as $option ) {
$pair = explode( '=', $option, 2 );
if ( count( $pair ) === 2 ) {
$name = trim( $pair[0] );
$value = trim( $pair[1] );
$results[$name] = $value;
}
if ( count( $pair ) === 1 ) {
$name = trim( $pair[0] );
$results[$name] = true;
}
}
return $results;
}
/**
* Construct button from parser arguments.
*
* @param string $parser The parser name
* @return string Constructed button output
*/
public static function showProjectButton( $parser ) {
$options = self::extractOptions( array_slice( func_get_args(), 1 ) );
$setUpOptions = (object)$options;
if ( isset( $setUpOptions->project ) &&
isset( $setUpOptions->config ) &&
isset( $setUpOptions->mode )
) {
$parser->getOutput()->addJsConfigVars( 'formWizardProject', $options[ 'project' ] );
$parser->getOutput()->addJsConfigVars( 'formWizardConfig', $options[ 'config' ] );
$parser->getOutput()->addJsConfigVars( 'formWizardPageMode', $options[ 'mode' ] );
// The input parameters are wikitext with templates expanded.
// The output should be wikitext too.
$output = "<div id='mw-formwizard-init-form'>
<span class='mw-ui-button mw-ui-progressive'
id='mw-formwizard-launch'
role='button'
aria-disabled='false'>" . $options[ 'action' ] . "
</span>" .
"</div>";
} else {
$output = "<span class='error'>" .
wfMessage( 'formwizard-parser-function-error' )->text() .
"</span>";
}
$parser->getOutput()->preventClickjacking( true );
return $output;
}
}