@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param array $data |
28 | 28 | */ |
29 | - public static function addToHeadItem( Array $data = [] ) { |
|
29 | + public static function addToHeadItem(Array $data = []) { |
|
30 | 30 | return self::$headItems[] = $data; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * |
36 | 36 | */ |
37 | 37 | public static function commitToParserOutput() { |
38 | - global $wgOut; # is there a better way to get $output/$parser without using a global? (testability!) |
|
38 | + global $wgOut; # is there a better way to get $output/$parser without using a global? (testability!) |
|
39 | 39 | |
40 | 40 | // to be used in JS like: |
41 | 41 | // var SFSelect_fobjs = $.parseJSON( mw.config.get( 'sf_select' ) ); |
42 | - $wgOut->addJsConfigVars('sf_select', json_encode( self::$headItems )); |
|
42 | + $wgOut->addJsConfigVars('sf_select', json_encode(self::$headItems)); |
|
43 | 43 | |
44 | 44 | //self::$resourceModules = array(); |
45 | 45 | //self::$headItems = array(); |
@@ -16,20 +16,20 @@ discard block |
||
16 | 16 | * @param $parser Parser |
17 | 17 | * @return bool |
18 | 18 | */ |
19 | - public static function onSemanticFormsSelectSetup ( & $parser ) { |
|
20 | - if ( !defined( 'PF_VERSION' ) ) { |
|
21 | - die( '<b>Error:</b><a href="https://github.com/SemanticMediaWiki/SemanticFormsSelect/">Semantic Forms Select</a> requires the <a href="https://www.mediawiki.org/wiki/Extension:PageForms">Page Forms</a> extension. Please install and activate this extension first.' ); |
|
19 | + public static function onSemanticFormsSelectSetup(& $parser) { |
|
20 | + if (!defined('PF_VERSION')) { |
|
21 | + die('<b>Error:</b><a href="https://github.com/SemanticMediaWiki/SemanticFormsSelect/">Semantic Forms Select</a> requires the <a href="https://www.mediawiki.org/wiki/Extension:PageForms">Page Forms</a> extension. Please install and activate this extension first.'); |
|
22 | 22 | } |
23 | 23 | |
24 | - if ( isset( $GLOBALS['wgPageFormsFormPrinter'] ) ) { |
|
25 | - $GLOBALS['wgPageFormsFormPrinter']->registerInputType( \SFS\SemanticFormsSelectInput::class ); |
|
24 | + if (isset($GLOBALS['wgPageFormsFormPrinter'])) { |
|
25 | + $GLOBALS['wgPageFormsFormPrinter']->registerInputType(\SFS\SemanticFormsSelectInput::class); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return true; |
29 | 29 | } |
30 | 30 | |
31 | 31 | public static function onRegistration() { |
32 | - if ( isset( $GLOBALS['wgAPIModules'] ) ) { |
|
32 | + if (isset($GLOBALS['wgAPIModules'])) { |
|
33 | 33 | $GLOBALS['wgAPIModules']['sformsselect'] = \SFS\ApiSemanticFormsSelect::class; |
34 | 34 | } |
35 | 35 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * Hook: ResourceLoaderTestModules |
39 | 39 | * @param array &$modules |
40 | 40 | */ |
41 | - public static function onResourceLoaderTestModules( array &$modules ) { |
|
41 | + public static function onResourceLoaderTestModules(array &$modules) { |
|
42 | 42 | $modules['qunit']['ext.sfs.unit'] = [ |
43 | 43 | 'scripts' => [ |
44 | 44 | 'res/sfs.js', |
@@ -109,8 +109,9 @@ |
||
109 | 109 | $rawparams = array_filter($rawparams, function($param) use ($name) { |
110 | 110 | return substr_compare( $param, "$name=", 0, strlen( "$name=" ) ) !== 0; |
111 | 111 | }); |
112 | - if ($value !== null) |
|
113 | - $rawparams[] = "$name=$value"; |
|
112 | + if ($value !== null) { |
|
113 | + $rawparams[] = "$name=$value"; |
|
114 | + } |
|
114 | 115 | }; |
115 | 116 | |
116 | 117 | $rawparams = explode( ";", $querystr ); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @since 1.3 |
37 | 37 | * |
38 | 38 | */ |
39 | - public function __construct( Parser $parser, $getSmwResultFromFunctionParams = null ) { |
|
39 | + public function __construct(Parser $parser, $getSmwResultFromFunctionParams = null) { |
|
40 | 40 | $this->parser = $parser; |
41 | 41 | $this->getSmwResultFromFunctionParams = $getSmwResultFromFunctionParams |
42 | 42 | ?? '\SFS\ApiSemanticFormsSelectRequestProcessor::defaultGetSmwResultFromFunctionParams'; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param boolean $debugFlag |
49 | 49 | */ |
50 | - public function setDebugFlag( $debugFlag ) { |
|
50 | + public function setDebugFlag($debugFlag) { |
|
51 | 51 | $this->debugFlag = $debugFlag; |
52 | 52 | } |
53 | 53 | |
@@ -58,110 +58,110 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - public function getJsonDecodedResultValuesForRequestParameters( array $parameters ) { |
|
61 | + public function getJsonDecodedResultValuesForRequestParameters(array $parameters) { |
|
62 | 62 | |
63 | - if ( !isset( $parameters['query'] ) || !isset( $parameters['sep'] ) ) { |
|
64 | - throw new InvalidArgumentException( 'Missing an query parameter' ); |
|
63 | + if (!isset($parameters['query']) || !isset($parameters['sep'])) { |
|
64 | + throw new InvalidArgumentException('Missing an query parameter'); |
|
65 | 65 | } |
66 | 66 | |
67 | - if ( !isset( $parameters['query'] ) || !isset( $parameters['sep'] ) ) { |
|
68 | - throw new InvalidArgumentException( 'Missing an query parameter' ); |
|
67 | + if (!isset($parameters['query']) || !isset($parameters['sep'])) { |
|
68 | + throw new InvalidArgumentException('Missing an query parameter'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $this->parser->firstCallInit(); |
72 | 72 | $json = []; |
73 | 73 | |
74 | - if ( isset( $parameters['approach'] ) && $parameters['approach'] == 'smw' ) { |
|
75 | - $json = $this->doProcessQueryFor( $parameters['query'], $parameters['sep'] ); |
|
74 | + if (isset($parameters['approach']) && $parameters['approach'] == 'smw') { |
|
75 | + $json = $this->doProcessQueryFor($parameters['query'], $parameters['sep']); |
|
76 | 76 | } else { |
77 | - $json = $this->doProcessFunctionFor( $parameters['query'], $parameters['sep'] ); |
|
77 | + $json = $this->doProcessFunctionFor($parameters['query'], $parameters['sep']); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // I have no idea why we first encode and and then decode here?? |
81 | 81 | |
82 | - return json_decode( $json ); |
|
82 | + return json_decode($json); |
|
83 | 83 | } |
84 | 84 | |
85 | - private function doProcessQueryFor( $querystr, $sep = "," ) { |
|
85 | + private function doProcessQueryFor($querystr, $sep = ",") { |
|
86 | 86 | |
87 | 87 | $querystr = str_replace( |
88 | - [ "<", ">", "sep=;" ], |
|
89 | - [ "<", ">", "sep={$sep};" ], |
|
88 | + ["<", ">", "sep=;"], |
|
89 | + ["<", ">", "sep={$sep};"], |
|
90 | 90 | $querystr |
91 | 91 | ); |
92 | 92 | |
93 | - $rawparams = $this->extractRawParameters( $querystr ); |
|
94 | - $f = str_replace( ";", "|", $rawparams[0] ); |
|
95 | - $rawparams[0] = $this->parser->replaceVariables( $f ); |
|
93 | + $rawparams = $this->extractRawParameters($querystr); |
|
94 | + $f = str_replace(";", "|", $rawparams[0]); |
|
95 | + $rawparams[0] = $this->parser->replaceVariables($f); |
|
96 | 96 | |
97 | - if ( $this->debugFlag ) { |
|
98 | - error_log( implode( "|", $rawparams ) ); |
|
97 | + if ($this->debugFlag) { |
|
98 | + error_log(implode("|", $rawparams)); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | $result = ($this->getSmwResultFromFunctionParams)($rawparams); |
102 | 102 | |
103 | - $values = $this->getFormattedValuesFrom( $sep, $result ); |
|
103 | + $values = $this->getFormattedValuesFrom($sep, $result); |
|
104 | 104 | |
105 | - return json_encode( [ |
|
105 | + return json_encode([ |
|
106 | 106 | "values" => $values, |
107 | - "count" => count( $values ) |
|
108 | - ] ); |
|
107 | + "count" => count($values) |
|
108 | + ]); |
|
109 | 109 | } |
110 | 110 | |
111 | - private function extractRawParameters( $querystr ) { |
|
111 | + private function extractRawParameters($querystr) { |
|
112 | 112 | $ensureParameter = function($name, $value) use (&$rawparams) { |
113 | 113 | $rawparams = array_filter($rawparams, function($param) use ($name) { |
114 | - return substr_compare( $param, "$name=", 0, strlen( "$name=" ) ) !== 0; |
|
114 | + return substr_compare($param, "$name=", 0, strlen("$name=")) !== 0; |
|
115 | 115 | }); |
116 | 116 | if ($value !== null) |
117 | 117 | $rawparams[] = "$name=$value"; |
118 | 118 | }; |
119 | 119 | |
120 | - $rawparams = explode( ";", $querystr ); |
|
120 | + $rawparams = explode(";", $querystr); |
|
121 | 121 | // The JavaScript part expects plainlist format for parsing |
122 | 122 | $ensureParameter('format', 'plainlist'); |
123 | 123 | |
124 | 124 | return $rawparams; |
125 | 125 | } |
126 | 126 | |
127 | - private function doProcessFunctionFor( $query, $sep = "," ) { |
|
127 | + private function doProcessFunctionFor($query, $sep = ",") { |
|
128 | 128 | |
129 | 129 | $query = str_replace( |
130 | - [ "<", ">", "sep=;" ], |
|
131 | - [ "<", ">", "sep={$sep};" ], |
|
130 | + ["<", ">", "sep=;"], |
|
131 | + ["<", ">", "sep={$sep};"], |
|
132 | 132 | $query |
133 | 133 | ); |
134 | 134 | |
135 | - $f = str_replace( ";", "|", $query ); |
|
135 | + $f = str_replace(";", "|", $query); |
|
136 | 136 | |
137 | - if ( $this->debugFlag ) { |
|
138 | - error_log( $f ); |
|
137 | + if ($this->debugFlag) { |
|
138 | + error_log($f); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $values = $this->getFormattedValuesFrom( |
142 | 142 | $sep, |
143 | - $this->parser->replaceVariables( $f ) |
|
143 | + $this->parser->replaceVariables($f) |
|
144 | 144 | ); |
145 | 145 | |
146 | - return json_encode( [ |
|
146 | + return json_encode([ |
|
147 | 147 | "values" => $values, |
148 | - "count" => count( $values ) |
|
149 | - ] ); |
|
148 | + "count" => count($values) |
|
149 | + ]); |
|
150 | 150 | } |
151 | 151 | |
152 | - private function getFormattedValuesFrom( $sep, $values ) { |
|
152 | + private function getFormattedValuesFrom($sep, $values) { |
|
153 | 153 | |
154 | - if ( strpos( $values ?? '', $sep ) === false ) { |
|
155 | - return [ $values ]; |
|
154 | + if (strpos($values ?? '', $sep) === false) { |
|
155 | + return [$values]; |
|
156 | 156 | } |
157 | 157 | |
158 | - $values = explode( $sep, $values ); |
|
159 | - $values = array_map( "trim", $values ); |
|
160 | - $values = array_unique( $values ); |
|
158 | + $values = explode($sep, $values); |
|
159 | + $values = array_map("trim", $values); |
|
160 | + $values = array_unique($values); |
|
161 | 161 | |
162 | 162 | // TODO: sorting here will destroy any sort defined in the query, e.g. in case sorting for labels (instead of mainlable) |
163 | 163 | //sort( $values ); |
164 | - array_unshift( $values, "" ); |
|
164 | + array_unshift($values, ""); |
|
165 | 165 | |
166 | 166 | return $values; |
167 | 167 | } |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | * @param $rawparams |
171 | 171 | * @return string |
172 | 172 | */ |
173 | - private static function defaultGetSmwResultFromFunctionParams( $rawparams ): string { |
|
174 | - list( $query, $params ) = |
|
175 | - SMWQueryProcessor::getQueryAndParamsFromFunctionParams( $rawparams, SMW_OUTPUT_WIKI, |
|
176 | - SMWQueryProcessor::INLINE_QUERY, false ); |
|
173 | + private static function defaultGetSmwResultFromFunctionParams($rawparams): string { |
|
174 | + list($query, $params) = |
|
175 | + SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawparams, SMW_OUTPUT_WIKI, |
|
176 | + SMWQueryProcessor::INLINE_QUERY, false); |
|
177 | 177 | |
178 | 178 | $result = |
179 | - SMWQueryProcessor::getResultFromQuery( $query, $params, SMW_OUTPUT_WIKI, |
|
180 | - SMWQueryProcessor::INLINE_QUERY ); |
|
179 | + SMWQueryProcessor::getResultFromQuery($query, $params, SMW_OUTPUT_WIKI, |
|
180 | + SMWQueryProcessor::INLINE_QUERY); |
|
181 | 181 | |
182 | 182 | return $result; |
183 | 183 | } |
@@ -27,17 +27,17 @@ discard block |
||
27 | 27 | public function execute() { |
28 | 28 | $parser = $this->getParser(); |
29 | 29 | |
30 | - $apiRequestProcessor = new \SFS\ApiSemanticFormsSelectRequestProcessor( $parser ); |
|
31 | - $apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] ); |
|
30 | + $apiRequestProcessor = new \SFS\ApiSemanticFormsSelectRequestProcessor($parser); |
|
31 | + $apiRequestProcessor->setDebugFlag($GLOBALS['wgSF_Select_debug']); |
|
32 | 32 | |
33 | 33 | $resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters( |
34 | 34 | $this->extractRequestParams() |
35 | 35 | ); |
36 | 36 | |
37 | 37 | $result = $this->getResult(); |
38 | - $result->setIndexedTagName( $resultValues->values, 'value' ); |
|
39 | - $result->addValue( $this->getModuleName(), 'values', $resultValues->values ); |
|
40 | - $result->addValue( $this->getModuleName(), 'count', $resultValues->count ); |
|
38 | + $result->setIndexedTagName($resultValues->values, 'value'); |
|
39 | + $result->addValue($this->getModuleName(), 'values', $resultValues->values); |
|
40 | + $result->addValue($this->getModuleName(), 'count', $resultValues->count); |
|
41 | 41 | |
42 | 42 | return true; |
43 | 43 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @see ApiBase::getVersion |
86 | 86 | */ |
87 | 87 | public function getVersion() { |
88 | - return __CLASS__ . ': 1.1'; |
|
88 | + return __CLASS__.': 1.1'; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | */ |
94 | 94 | protected function getParser(): Parser { |
95 | 95 | $parser = MediaWikiServices::getInstance()->getParserFactory()->create(); |
96 | - $parser->setTitle( Title::newFromText( 'NO TITLE' ) ); |
|
97 | - $parser->setOptions( new ParserOptions( $this->getUser() ) ); |
|
96 | + $parser->setTitle(Title::newFromText('NO TITLE')); |
|
97 | + $parser->setOptions(new ParserOptions($this->getUser())); |
|
98 | 98 | $parser->resetOutput(); |
99 | 99 | |
100 | 100 | return $parser; |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | |
29 | 29 | private $mSelectField; |
30 | 30 | |
31 | - public function __construct( $inputNumber, $curValue, $inputName, $disabled, $otherArgs ) { |
|
32 | - parent::__construct( $inputNumber, $curValue, $inputName, $disabled, $otherArgs ); |
|
31 | + public function __construct($inputNumber, $curValue, $inputName, $disabled, $otherArgs) { |
|
32 | + parent::__construct($inputNumber, $curValue, $inputName, $disabled, $otherArgs); |
|
33 | 33 | |
34 | 34 | // SelectField is a simple value object - we accept creating it in the constructor |
35 | 35 | $parser = MediaWikiServices::getInstance()->getParser(); |
36 | - $this->mSelectField = new SelectField( $parser ); |
|
36 | + $this->mSelectField = new SelectField($parser); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public static function getName() { |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | public function getResourceModuleNames() { |
49 | - return [ 'ext.sfs' ]; |
|
49 | + return ['ext.sfs']; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * This is currently just a wrapper for getHTML(). |
55 | 55 | */ |
56 | 56 | public function getHtmlText() { |
57 | - return self::getHTML( $this->mIsMandatory, $this->mIsDisabled, |
|
58 | - $this->mOtherArgs, $this->mCurrentValue, $this->mInputName ); |
|
57 | + return self::getHTML($this->mIsMandatory, $this->mIsDisabled, |
|
58 | + $this->mOtherArgs, $this->mCurrentValue, $this->mInputName); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -69,35 +69,35 @@ discard block |
||
69 | 69 | * @param string[] $other_args Array of other field parameters |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public function getHTML( $is_mandatory, $is_disabled, Array $other_args, $cur_value = "", $input_name = "" ) { |
|
72 | + public function getHTML($is_mandatory, $is_disabled, Array $other_args, $cur_value = "", $input_name = "") { |
|
73 | 73 | global $wgPageFormsFieldNum, $wgUser; |
74 | 74 | |
75 | 75 | // shortcut to the SelectField object |
76 | 76 | $selectField = $this->mSelectField; |
77 | 77 | |
78 | 78 | // get 'delimiter' before 'query' or 'function' |
79 | - $selectField->setDelimiter( $other_args ); |
|
79 | + $selectField->setDelimiter($other_args); |
|
80 | 80 | |
81 | - if ( array_key_exists( "query", $other_args ) ) { |
|
82 | - $selectField->setQuery( $other_args ); |
|
83 | - } elseif ( array_key_exists( "function", $other_args ) ) { |
|
84 | - $selectField->setFunction( $other_args ); |
|
81 | + if (array_key_exists("query", $other_args)) { |
|
82 | + $selectField->setQuery($other_args); |
|
83 | + } elseif (array_key_exists("function", $other_args)) { |
|
84 | + $selectField->setFunction($other_args); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( array_key_exists( "label", $other_args ) ) { |
|
88 | - $selectField->setLabel( $other_args ); |
|
87 | + if (array_key_exists("label", $other_args)) { |
|
88 | + $selectField->setLabel($other_args); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // parameters are only required if values needs to be retrieved dynamically |
92 | - if ( !$selectField->hasStaticValues() ) { |
|
93 | - $selectField->setSelectIsMultiple( $other_args ); |
|
94 | - $selectField->setSelectTemplate( $input_name ); |
|
95 | - $selectField->setSelectField( $input_name ); |
|
96 | - $selectField->setValueTemplate( $other_args ); |
|
97 | - $selectField->setValueField( $other_args ); |
|
98 | - $selectField->setSelectRemove( $other_args ); |
|
99 | - |
|
100 | - $item = Output::addToHeadItem( $selectField->getData() ); |
|
92 | + if (!$selectField->hasStaticValues()) { |
|
93 | + $selectField->setSelectIsMultiple($other_args); |
|
94 | + $selectField->setSelectTemplate($input_name); |
|
95 | + $selectField->setSelectField($input_name); |
|
96 | + $selectField->setValueTemplate($other_args); |
|
97 | + $selectField->setValueField($other_args); |
|
98 | + $selectField->setSelectRemove($other_args); |
|
99 | + |
|
100 | + $item = Output::addToHeadItem($selectField->getData()); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | Output::commitToParserOutput(); |
@@ -107,51 +107,51 @@ discard block |
||
107 | 107 | $extraatt = ""; |
108 | 108 | $is_list = false; |
109 | 109 | |
110 | - if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) { |
|
110 | + if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) { |
|
111 | 111 | $is_list = true; |
112 | 112 | } |
113 | 113 | |
114 | - if ( $is_list ) { |
|
114 | + if ($is_list) { |
|
115 | 115 | $extraatt = ' multiple="multiple" '; |
116 | 116 | } |
117 | 117 | |
118 | - if ( array_key_exists( "size", $other_args ) ) { |
|
118 | + if (array_key_exists("size", $other_args)) { |
|
119 | 119 | $extraatt .= " size=\"{$other_args['size']}\""; |
120 | 120 | } |
121 | 121 | |
122 | 122 | $classes = []; |
123 | - if ( $is_mandatory ) { |
|
123 | + if ($is_mandatory) { |
|
124 | 124 | $classes[] = "mandatoryField"; |
125 | 125 | } |
126 | - if ( array_key_exists( "class", $other_args ) ) { |
|
126 | + if (array_key_exists("class", $other_args)) { |
|
127 | 127 | $classes[] = $other_args['class']; |
128 | 128 | } |
129 | - if ( $classes ) { |
|
130 | - $cstr = implode( " ", $classes ); |
|
129 | + if ($classes) { |
|
130 | + $cstr = implode(" ", $classes); |
|
131 | 131 | $extraatt .= " class=\"$cstr\""; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $inname = $input_name; |
135 | - if ( $is_list ) { |
|
135 | + if ($is_list) { |
|
136 | 136 | $inname .= '[]'; |
137 | 137 | } |
138 | 138 | |
139 | 139 | // TODO Use Html:: |
140 | 140 | |
141 | 141 | $spanextra = $is_mandatory ? 'mandatoryFieldSpan' : ''; |
142 | - $is_single_select = (!$is_list) ? 'select-sfs-single' : '' ; |
|
142 | + $is_single_select = (!$is_list) ? 'select-sfs-single' : ''; |
|
143 | 143 | $ret = "<span class=\"inputSpan select-sfs $is_single_select $spanextra\"><select name='$inname' id='input_$wgPageFormsFieldNum' $extraatt>"; |
144 | 144 | |
145 | 145 | $curvalues = null; |
146 | - if ( $cur_value ) { |
|
147 | - if ( $cur_value === 'current user' ) { |
|
146 | + if ($cur_value) { |
|
147 | + if ($cur_value === 'current user') { |
|
148 | 148 | $cur_value = $wgUser->getName(); |
149 | 149 | } |
150 | - if ( is_array( $cur_value ) ) { |
|
150 | + if (is_array($cur_value)) { |
|
151 | 151 | $curvalues = $cur_value; |
152 | 152 | } else { |
153 | 153 | // delimiter for $cur_value is always ',' - PF seems to ignore $wgPageFormsListSeparator |
154 | - $curvalues = array_map( "trim", explode( $selectField->getDelimiter(), $cur_value ) ); |
|
154 | + $curvalues = array_map("trim", explode($selectField->getDelimiter(), $cur_value)); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | } else { |
@@ -160,38 +160,38 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | $labelArray = []; |
163 | - if ( array_key_exists( "label", $other_args ) && $curvalues ) { |
|
163 | + if (array_key_exists("label", $other_args) && $curvalues) { |
|
164 | 164 | // $labelArray = $this->getLabels( $curvalues ); |
165 | 165 | } |
166 | 166 | |
167 | 167 | // TODO handle empty value case. |
168 | 168 | $ret .= "<option></option>"; |
169 | 169 | |
170 | - if ( $selectField->hasStaticValues() ) { |
|
170 | + if ($selectField->hasStaticValues()) { |
|
171 | 171 | |
172 | 172 | $values = $selectField->getValues(); |
173 | 173 | |
174 | - if ( array_key_exists( "label", $other_args ) && $values ) { |
|
175 | - $labelArray = $this->getLabels( $values ); |
|
174 | + if (array_key_exists("label", $other_args) && $values) { |
|
175 | + $labelArray = $this->getLabels($values); |
|
176 | 176 | } |
177 | 177 | |
178 | - if ( is_array( $values ) ) { |
|
178 | + if (is_array($values)) { |
|
179 | 179 | |
180 | - foreach ( $values as $val ) { |
|
180 | + foreach ($values as $val) { |
|
181 | 181 | |
182 | 182 | $selected = ""; |
183 | 183 | |
184 | - if ( array_key_exists( $val, $labelArray ) ) { |
|
184 | + if (array_key_exists($val, $labelArray)) { |
|
185 | 185 | |
186 | - if ( in_array( $labelArray[ $val ][0], $curvalues ) ) { |
|
186 | + if (in_array($labelArray[$val][0], $curvalues)) { |
|
187 | 187 | $selected = " selected='selected'"; |
188 | 188 | } |
189 | 189 | |
190 | - $ret.="<option".$selected." value='".$labelArray[ $val ][0]."'>".$labelArray[ $val ][1]."</option>"; |
|
190 | + $ret .= "<option".$selected." value='".$labelArray[$val][0]."'>".$labelArray[$val][1]."</option>"; |
|
191 | 191 | |
192 | 192 | } else { |
193 | 193 | |
194 | - if ( in_array( $val, $curvalues ) ) { |
|
194 | + if (in_array($val, $curvalues)) { |
|
195 | 195 | $selected = " selected='selected'"; |
196 | 196 | } |
197 | 197 | |
@@ -201,22 +201,22 @@ discard block |
||
201 | 201 | } |
202 | 202 | } else { |
203 | 203 | |
204 | - foreach ( $curvalues as $cur ) { |
|
204 | + foreach ($curvalues as $cur) { |
|
205 | 205 | $selected = ""; |
206 | 206 | |
207 | - if ( array_key_exists( $cur, $labelArray ) ) { |
|
207 | + if (array_key_exists($cur, $labelArray)) { |
|
208 | 208 | |
209 | - if ( in_array( $labelArray[ $cur ][0], $curvalues ) ) { |
|
209 | + if (in_array($labelArray[$cur][0], $curvalues)) { |
|
210 | 210 | $selected = " selected='selected'"; |
211 | 211 | } |
212 | 212 | |
213 | - $ret.="<option".$selected." value='".$labelArray[ $cur ][0]."'>".$labelArray[ $cur ][1]."</option>"; |
|
213 | + $ret .= "<option".$selected." value='".$labelArray[$cur][0]."'>".$labelArray[$cur][1]."</option>"; |
|
214 | 214 | |
215 | 215 | } else { |
216 | - if ( in_array( $cur, $curvalues ) ) { |
|
216 | + if (in_array($cur, $curvalues)) { |
|
217 | 217 | $selected = " selected='selected'"; |
218 | 218 | } |
219 | - $ret.="<option".$selected.">$cur</option>"; |
|
219 | + $ret .= "<option".$selected.">$cur</option>"; |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | $ret .= "</select></span>"; |
226 | 226 | $ret .= "<span id=\"info_$wgPageFormsFieldNum\" class=\"errorMessage\"></span>"; |
227 | 227 | |
228 | - if ( $other_args["is_list"] ) { |
|
229 | - $hiddenname = $input_name . '[is_list]'; |
|
228 | + if ($other_args["is_list"]) { |
|
229 | + $hiddenname = $input_name.'[is_list]'; |
|
230 | 230 | $ret .= "<input type='hidden' name='$hiddenname' value='1' />"; |
231 | 231 | } |
232 | 232 | |
@@ -234,49 +234,49 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | |
237 | - private function getLabels( $labels ) { |
|
237 | + private function getLabels($labels) { |
|
238 | 238 | |
239 | - $labelArray = [ ]; |
|
239 | + $labelArray = []; |
|
240 | 240 | |
241 | - if ( is_array( $labels ) ) { |
|
242 | - foreach ( $labels as $label ) { |
|
241 | + if (is_array($labels)) { |
|
242 | + foreach ($labels as $label) { |
|
243 | 243 | |
244 | 244 | $labelKey = $label; |
245 | 245 | $labelValue = $label; |
246 | 246 | |
247 | 247 | // Tricky thing if ( ) already in name |
248 | - if ( strpos( $label, ")" ) && strpos( $label, "(" ) ) { |
|
248 | + if (strpos($label, ")") && strpos($label, "(")) { |
|
249 | 249 | |
250 | 250 | // Check Break |
251 | 251 | $openBr = 0; |
252 | 252 | $doneBr = 0; |
253 | 253 | $num = 0; |
254 | 254 | |
255 | - $labelArr = str_split ( $label ); |
|
255 | + $labelArr = str_split($label); |
|
256 | 256 | |
257 | - $end = count( $labelArr ) - 1; |
|
257 | + $end = count($labelArr) - 1; |
|
258 | 258 | $iter = $end; |
259 | 259 | |
260 | 260 | $endBr = $end; |
261 | 261 | $startBr = 0; |
262 | 262 | |
263 | - while ( $doneBr == 0 && $iter >= 0 ) { |
|
263 | + while ($doneBr == 0 && $iter >= 0) { |
|
264 | 264 | |
265 | - $char = $labelArr[ $iter ]; |
|
265 | + $char = $labelArr[$iter]; |
|
266 | 266 | |
267 | - if ( $char == ")" ) { |
|
267 | + if ($char == ")") { |
|
268 | 268 | $openBr = $openBr - 1; |
269 | 269 | |
270 | - if ( $num == 0 ) { |
|
270 | + if ($num == 0) { |
|
271 | 271 | $endBr = $iter; |
272 | 272 | $num = $num + 1; |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | - if ( $char == "(" ) { |
|
276 | + if ($char == "(") { |
|
277 | 277 | $openBr = $openBr + 1; |
278 | 278 | |
279 | - if ( $num > 0 && $openBr == 0 ) { |
|
279 | + if ($num > 0 && $openBr == 0) { |
|
280 | 280 | $startBr = $iter; |
281 | 281 | $doneBr = 1; |
282 | 282 | } |
@@ -286,12 +286,12 @@ discard block |
||
286 | 286 | |
287 | 287 | } |
288 | 288 | |
289 | - $labelValue = implode( "", array_slice( $labelArr, $startBr+1, $endBr-$startBr-1 ) ); |
|
290 | - $labelKey = implode( "", array_slice( $labelArr, 0, $startBr-1 ) ); |
|
289 | + $labelValue = implode("", array_slice($labelArr, $startBr + 1, $endBr - $startBr - 1)); |
|
290 | + $labelKey = implode("", array_slice($labelArr, 0, $startBr - 1)); |
|
291 | 291 | |
292 | 292 | } |
293 | 293 | |
294 | - $labelArray[ $label ] = [ $labelKey, $labelValue ] ; |
|
294 | + $labelArray[$label] = [$labelKey, $labelValue]; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | private $mValues = null; |
22 | 22 | private $mHasStaticValues = false; |
23 | 23 | |
24 | - private $mData = []; # array with all parameters |
|
24 | + private $mData = []; # array with all parameters |
|
25 | 25 | private $mQuery = ""; |
26 | 26 | private $mFunction = ""; |
27 | 27 | private $mSelectIsMultiple = false; |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | private $mLabel = false; |
34 | 34 | private $mDelimiter = ","; |
35 | 35 | |
36 | - public function __construct( & $parser ) { |
|
36 | + public function __construct(& $parser) { |
|
37 | 37 | $this->mParser = $parser; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Convenience function to process all parameters at once |
42 | 42 | */ |
43 | - public function processParameters( $other_args, $input_name = "" ) { |
|
44 | - if ( array_key_exists( "query", $other_args ) ) { |
|
45 | - $this->setQuery( $other_args ); |
|
46 | - } elseif ( array_key_exists( "function", $other_args ) ) { |
|
47 | - $this->setFunction( $other_args ); |
|
43 | + public function processParameters($other_args, $input_name = "") { |
|
44 | + if (array_key_exists("query", $other_args)) { |
|
45 | + $this->setQuery($other_args); |
|
46 | + } elseif (array_key_exists("function", $other_args)) { |
|
47 | + $this->setFunction($other_args); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
@@ -57,88 +57,88 @@ discard block |
||
57 | 57 | return $this->mData; |
58 | 58 | } |
59 | 59 | |
60 | - public function setQuery( $other_args ) { |
|
60 | + public function setQuery($other_args) { |
|
61 | 61 | $querystr = $other_args["query"]; |
62 | - $querystr = str_replace( [ "~", "(", ")" ], [ "=", "[", "]" ], $querystr ); |
|
62 | + $querystr = str_replace(["~", "(", ")"], ["=", "[", "]"], $querystr); |
|
63 | 63 | |
64 | 64 | //$this->mSelectField["query"] = $query; |
65 | 65 | $this->mQuery = $querystr; |
66 | 66 | $this->mData['selectquery'] = $querystr; |
67 | 67 | |
68 | 68 | // unparametrized query |
69 | - if ( strpos( $querystr, '@@@@' ) === false ) { |
|
70 | - $rawparams = explode( ";", $querystr ); |
|
69 | + if (strpos($querystr, '@@@@') === false) { |
|
70 | + $rawparams = explode(";", $querystr); |
|
71 | 71 | |
72 | 72 | // there is no need to run the parser, $query has been parsed already |
73 | 73 | //$params[0] = $wgParser->replaceVariables( $params[0] ); |
74 | 74 | |
75 | - list( $query, $params ) = QueryProcessor::getQueryAndParamsFromFunctionParams( $rawparams, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY, false ); |
|
75 | + list($query, $params) = QueryProcessor::getQueryAndParamsFromFunctionParams($rawparams, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY, false); |
|
76 | 76 | |
77 | - $result = QueryProcessor::getResultFromQuery( $query, $params, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY ); |
|
77 | + $result = QueryProcessor::getResultFromQuery($query, $params, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY); |
|
78 | 78 | |
79 | - $this->mValues = $this->getFormattedValuesFrom( $this->mDelimiter, $result ); |
|
79 | + $this->mValues = $this->getFormattedValuesFrom($this->mDelimiter, $result); |
|
80 | 80 | |
81 | - $this->setHasStaticValues( true ); |
|
81 | + $this->setHasStaticValues(true); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - public function setFunction( $other_args ) { |
|
85 | + public function setFunction($other_args) { |
|
86 | 86 | #global $wgParser; |
87 | 87 | |
88 | 88 | $function = $other_args["function"]; |
89 | - $function = '{{#' . $function . '}}'; |
|
90 | - $function = str_replace( [ "~", "(", ")" ], [ "=", "[", "]" ], $function ); |
|
89 | + $function = '{{#'.$function.'}}'; |
|
90 | + $function = str_replace(["~", "(", ")"], ["=", "[", "]"], $function); |
|
91 | 91 | |
92 | 92 | //$this->mSelectField["function"] = $function; |
93 | 93 | $this->mFunction = $function; |
94 | 94 | $this->mData['selectfunction'] = $function; |
95 | 95 | |
96 | 96 | // unparametrized function |
97 | - if ( strpos( $function, '@@@@' ) === false ) { |
|
98 | - $f = str_replace( ";", "|", $function ); |
|
97 | + if (strpos($function, '@@@@') === false) { |
|
98 | + $f = str_replace(";", "|", $function); |
|
99 | 99 | |
100 | - $this->setValues( $this->mParser->replaceVariables( $f ) ); |
|
100 | + $this->setValues($this->mParser->replaceVariables($f)); |
|
101 | 101 | |
102 | - $this->setHasStaticValues( true ); |
|
102 | + $this->setHasStaticValues(true); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - public function setSelectIsMultiple( Array $other_args ) { |
|
107 | - $this->mSelectIsMultiple = array_key_exists( "part_of_multiple", $other_args ); |
|
106 | + public function setSelectIsMultiple(Array $other_args) { |
|
107 | + $this->mSelectIsMultiple = array_key_exists("part_of_multiple", $other_args); |
|
108 | 108 | $this->mData["selectismultiple"] = $this->mSelectIsMultiple; |
109 | 109 | } |
110 | 110 | |
111 | - public function setSelectTemplate( $input_name = "" ) { |
|
112 | - $index = strpos( $input_name, "[" ); |
|
113 | - $this->mSelectTemplate = substr( $input_name, 0, $index ); |
|
111 | + public function setSelectTemplate($input_name = "") { |
|
112 | + $index = strpos($input_name, "["); |
|
113 | + $this->mSelectTemplate = substr($input_name, 0, $index); |
|
114 | 114 | $this->mData['selecttemplate'] = $this->mSelectTemplate; |
115 | 115 | } |
116 | 116 | |
117 | - public function setSelectField( $input_name = "" ) { |
|
118 | - $index = strrpos( $input_name, "[" ); |
|
119 | - $this->mSelectField = substr( $input_name, $index + 1, strlen( $input_name ) - $index - 2 ); |
|
117 | + public function setSelectField($input_name = "") { |
|
118 | + $index = strrpos($input_name, "["); |
|
119 | + $this->mSelectField = substr($input_name, $index + 1, strlen($input_name) - $index - 2); |
|
120 | 120 | $this->mData['selectfield'] = $this->mSelectField; |
121 | 121 | } |
122 | 122 | |
123 | - public function setValueTemplate( Array $other_args ) { |
|
123 | + public function setValueTemplate(Array $other_args) { |
|
124 | 124 | $this->mValueTemplate = |
125 | - array_key_exists( "sametemplate", $other_args ) ? $this->mSelectTemplate : $other_args["template"]; |
|
125 | + array_key_exists("sametemplate", $other_args) ? $this->mSelectTemplate : $other_args["template"]; |
|
126 | 126 | $this->mData["valuetemplate"] = $this->mValueTemplate; |
127 | 127 | } |
128 | 128 | |
129 | - public function setValueField( Array $other_args ) { |
|
129 | + public function setValueField(Array $other_args) { |
|
130 | 130 | $this->mValueField = $other_args["field"]; |
131 | 131 | $this->mData["valuefield"] = $this->mValueField; |
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | - public function setSelectRemove( Array $other_args ) { |
|
136 | - $this->mSelectRemove = array_key_exists( 'rmdiv', $other_args ); |
|
135 | + public function setSelectRemove(Array $other_args) { |
|
136 | + $this->mSelectRemove = array_key_exists('rmdiv', $other_args); |
|
137 | 137 | $this->mData['selectrm'] = $this->mSelectRemove; |
138 | 138 | } |
139 | 139 | |
140 | - public function setLabel( Array $other_args ) { |
|
141 | - $this->mLabel = array_key_exists( 'label', $other_args ); |
|
140 | + public function setLabel(Array $other_args) { |
|
141 | + $this->mLabel = array_key_exists('label', $other_args); |
|
142 | 142 | $this->mData['label'] = $this->mLabel; |
143 | 143 | } |
144 | 144 | |
@@ -146,15 +146,15 @@ discard block |
||
146 | 146 | * setDelimiter |
147 | 147 | * @param array $other_args |
148 | 148 | */ |
149 | - public function setDelimiter( Array $other_args ) { |
|
149 | + public function setDelimiter(Array $other_args) { |
|
150 | 150 | |
151 | 151 | $this->mDelimiter = $GLOBALS['wgPageFormsListSeparator']; |
152 | 152 | |
153 | - if ( array_key_exists( 'sep', $other_args ) ) { |
|
153 | + if (array_key_exists('sep', $other_args)) { |
|
154 | 154 | $this->mDelimiter = $other_args['sep']; |
155 | 155 | } else { |
156 | 156 | // Adding Backcompatibility |
157 | - if ( array_key_exists( 'delimiter', $other_args ) ) { |
|
157 | + if (array_key_exists('delimiter', $other_args)) { |
|
158 | 158 | $this->mDelimiter = $other_args['delimiter']; |
159 | 159 | } |
160 | 160 | } |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | * setValues |
175 | 175 | * @param string $values (comma separated, fully parsed list of values) |
176 | 176 | */ |
177 | - private function setValues( $values ) { |
|
178 | - $values = explode( $this->mDelimiter, $values ); |
|
179 | - $values = array_map( "trim", $values ); |
|
180 | - $values = array_unique( $values ); |
|
177 | + private function setValues($values) { |
|
178 | + $values = explode($this->mDelimiter, $values); |
|
179 | + $values = array_map("trim", $values); |
|
180 | + $values = array_unique($values); |
|
181 | 181 | $this->mValues = $values; |
182 | 182 | } |
183 | 183 | |
@@ -185,21 +185,21 @@ discard block |
||
185 | 185 | return $this->mHasStaticValues; |
186 | 186 | } |
187 | 187 | |
188 | - private function setHasStaticValues( $StaticValues ) { |
|
188 | + private function setHasStaticValues($StaticValues) { |
|
189 | 189 | $this->mHasStaticValues = $StaticValues; |
190 | 190 | } |
191 | 191 | |
192 | 192 | /** Copied from ApiSemanticFormsSelectRequestProcessor */ |
193 | 193 | |
194 | - private function getFormattedValuesFrom( $sep, $values ) { |
|
194 | + private function getFormattedValuesFrom($sep, $values) { |
|
195 | 195 | |
196 | - if ( strpos( $values, $sep ) === false ) { |
|
197 | - return [ $values ]; |
|
196 | + if (strpos($values, $sep) === false) { |
|
197 | + return [$values]; |
|
198 | 198 | } |
199 | 199 | |
200 | - $values = explode( $sep, $values ); |
|
201 | - $values = array_map( "trim", $values ); |
|
202 | - $values = array_unique( $values ); |
|
200 | + $values = explode($sep, $values); |
|
201 | + $values = array_map("trim", $values); |
|
202 | + $values = array_unique($values); |
|
203 | 203 | |
204 | 204 | // TODO: sorting here will destroy any sort defined in the query, e.g. in case sorting for labels (instead of mainlable) |
205 | 205 | //sort( $values ); |