Completed
Pull Request — master (#59)
by
unknown
05:02
created
SemanticFormsSelect.hooks.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 	 * This is attached to the MediaWiki 'ParserFirstCallInit' hook.
13 13
 	 *
14 14
 	 * @param $parser Parser
15
-	 * @return bool
15
+	 * @return null|boolean
16 16
 	 */
17 17
 	public static function onSemanticFormsSelectSetup ( & $parser ) {
18 18
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
 	 * @param $parser Parser
15 15
 	 * @return bool
16 16
 	 */
17
-	public static function onSemanticFormsSelectSetup ( & $parser ) {
17
+	public static function onSemanticFormsSelectSetup(& $parser) {
18 18
 
19
-		if ( !defined( 'PF_VERSION' ) ) {
20
-			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
+		if (!defined('PF_VERSION')) {
20
+			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.');
21 21
 		}
22 22
 
23
-		if ( isset( $GLOBALS['wgPageFormsFormPrinter'] )) {
24
-			$GLOBALS['wgPageFormsFormPrinter']->registerInputType( '\SFS\SemanticFormsSelectInput' );
23
+		if (isset($GLOBALS['wgPageFormsFormPrinter'])) {
24
+			$GLOBALS['wgPageFormsFormPrinter']->registerInputType('\SFS\SemanticFormsSelectInput');
25 25
 		}
26 26
 
27 27
 		return true;
Please login to merge, or discard this patch.
src/SemanticFormsSelectInput.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -65,9 +65,9 @@
 block discarded – undo
65 65
 	 * Returns the HTML code to be included in the output page for this input.
66 66
 	 * @deprecated use getHtmlText() instead
67 67
 	 *
68
-	 * @param $cur_value
69
-	 * @param $input_name
70
-	 * @param $is_mandatory
68
+	 * @param string $cur_value
69
+	 * @param string $input_name
70
+	 * @param boolean $is_mandatory
71 71
 	 * @param $is_disabled
72 72
 	 * @param $other_args
73 73
 	 * @return string
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	private static $data = array();
26 26
 
27
-	public function __construct( $inputNumber, $curValue, $inputName, $disabled, $otherArgs ) {
28
-		parent::__construct( $inputNumber, $curValue, $inputName, $disabled, $otherArgs );
27
+	public function __construct($inputNumber, $curValue, $inputName, $disabled, $otherArgs) {
28
+		parent::__construct($inputNumber, $curValue, $inputName, $disabled, $otherArgs);
29 29
 	}
30 30
 
31 31
 	public static function getName() {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @param $other_args
73 73
 	 * @return string
74 74
 	 */
75
-	public function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) {
75
+	public function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
76 76
 		global # $wgScriptSelectCount,
77 77
 		$wgScriptSelectCount, $sfgFieldNum, $wgUser, $wgParser;
78 78
 
@@ -81,72 +81,72 @@  discard block
 block discarded – undo
81 81
 		$staticvalue = false;
82 82
 		$data = array();
83 83
 
84
-		if ( array_key_exists( "query", $other_args ) ) {
84
+		if (array_key_exists("query", $other_args)) {
85 85
 			$query = $other_args["query"];
86
-			$query = str_replace( array( "~", "(", ")" ), array( "=", "[", "]" ), $query );
86
+			$query = str_replace(array("~", "(", ")"), array("=", "[", "]"), $query);
87 87
 
88 88
 			$selectField["query"] = $query;
89 89
 
90 90
 			// unparametrized query
91
-			if ( strpos( $query, '@@@@' ) === false ) {
92
-				$params = explode( ";", $query );
91
+			if (strpos($query, '@@@@') === false) {
92
+				$params = explode(";", $query);
93 93
 
94 94
 				// there is no need to run the parser, $query has been parsed already
95 95
 				//$params[0] = $wgParser->replaceVariables( $params[0] );
96 96
 
97
-				$values = QueryProcessor::getResultFromFunctionParams( $params, SMW_OUTPUT_WIKI );
97
+				$values = QueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI);
98 98
 
99 99
 				$staticvalue = true;
100 100
 			}
101 101
 
102
-		} elseif ( array_key_exists( "function", $other_args ) ) {
102
+		} elseif (array_key_exists("function", $other_args)) {
103 103
 			$query = $other_args["function"];
104
-			$query = '{{#' . $query . '}}';
105
-			$query = str_replace( array( "~", "(", ")" ), array( "=", "[", "]" ), $query );
104
+			$query = '{{#'.$query.'}}';
105
+			$query = str_replace(array("~", "(", ")"), array("=", "[", "]"), $query);
106 106
 
107 107
 			$selectField["function"] = $query;
108 108
 
109 109
 			// unparametrized function
110
-			if ( strpos( $query, '@@@@' ) === false ) {
111
-				$f = str_replace( ";", "|", $query );
110
+			if (strpos($query, '@@@@') === false) {
111
+				$f = str_replace(";", "|", $query);
112 112
 
113
-				$values = $wgParser->replaceVariables( $f );
113
+				$values = $wgParser->replaceVariables($f);
114 114
 
115 115
 				$staticvalue = true;
116 116
 			}
117 117
 		}
118 118
 
119
-		if ( $staticvalue ) {
120
-			$values = explode( ",", $values );
121
-			$values = array_map( "trim", $values );
122
-			$values = array_unique( $values );
119
+		if ($staticvalue) {
120
+			$values = explode(",", $values);
121
+			$values = array_map("trim", $values);
122
+			$values = array_unique($values);
123 123
 		} else {
124 124
 
125
-			if ( $wgScriptSelectCount == 0 ) {
125
+			if ($wgScriptSelectCount == 0) {
126 126
 				// this has been moved to getResourceModuleNames()
127 127
 				//Output::addModule( 'ext.sf_select.scriptselect' );
128 128
 			}
129 129
 			// $wgScriptSelectCount ++;
130 130
 
131
-			$data["selectismultiple"] = array_key_exists( "part_of_multiple", $other_args );
131
+			$data["selectismultiple"] = array_key_exists("part_of_multiple", $other_args);
132 132
 
133
-			$index = strpos( $input_name, "[" );
134
-			$data['selecttemplate'] = substr( $input_name, 0, $index );
133
+			$index = strpos($input_name, "[");
134
+			$data['selecttemplate'] = substr($input_name, 0, $index);
135 135
 
136 136
 			// Does hit work for multiple template?
137
-			$index = strrpos( $input_name, "[" );
138
-			$data['selectfield'] = substr( $input_name, $index + 1, strlen( $input_name ) - $index - 2 );
137
+			$index = strrpos($input_name, "[");
138
+			$data['selectfield'] = substr($input_name, $index + 1, strlen($input_name) - $index - 2);
139 139
 
140 140
 			$valueField = array();
141 141
 			$data["valuetemplate"] =
142
-				array_key_exists( "sametemplate", $other_args ) ? $data['selecttemplate'] : $other_args["template"];
142
+				array_key_exists("sametemplate", $other_args) ? $data['selecttemplate'] : $other_args["template"];
143 143
 			$data["valuefield"] = $other_args["field"];
144 144
 
145
-			$data['selectrm'] = array_key_exists( 'rmdiv', $other_args );
146
-			$data['label'] = array_key_exists( 'label', $other_args );
147
-			$data['sep'] = array_key_exists( 'sep', $other_args ) ? $other_args["sep"] : ',';
145
+			$data['selectrm'] = array_key_exists('rmdiv', $other_args);
146
+			$data['label'] = array_key_exists('label', $other_args);
147
+			$data['sep'] = array_key_exists('sep', $other_args) ? $other_args["sep"] : ',';
148 148
 
149
-			if ( array_key_exists( "query", $selectField ) ) {
149
+			if (array_key_exists("query", $selectField)) {
150 150
 				$data['selectquery'] = $selectField['query'];
151 151
 			} else {
152 152
 				$data['selectfunction'] = $selectField['function'];
@@ -160,32 +160,32 @@  discard block
 block discarded – undo
160 160
 
161 161
 		// TODO This needs clean-up
162 162
 
163
-		if ( array_key_exists( 'is_list', $other_args ) && $other_args['is_list'] == true ) {
163
+		if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) {
164 164
 			$is_list = true;
165 165
 		}
166 166
 
167
-		if ( $is_list ) {
167
+		if ($is_list) {
168 168
 			$extraatt = ' multiple="multiple" ';
169 169
 		}
170 170
 
171
-		if ( array_key_exists( "size", $other_args ) ) {
171
+		if (array_key_exists("size", $other_args)) {
172 172
 			$extraatt .= " size=\"{$other_args['size']}\"";
173 173
 		}
174 174
 
175 175
 		$classes = array();
176
-		if ( $is_mandatory ) {
176
+		if ($is_mandatory) {
177 177
 			$classes[] = "mandatoryField";
178 178
 		}
179
-		if ( array_key_exists( "class", $other_args ) ) {
179
+		if (array_key_exists("class", $other_args)) {
180 180
 			$classes[] = $other_args['class'];
181 181
 		}
182
-		if ( $classes ) {
183
-			$cstr = implode( " ", $classes );
182
+		if ($classes) {
183
+			$cstr = implode(" ", $classes);
184 184
 			$extraatt .= " class=\"$cstr\"";
185 185
 		}
186 186
 
187 187
 		$inname = $input_name;
188
-		if ( $is_list ) {
188
+		if ($is_list) {
189 189
 			$inname .= '[]';
190 190
 		}
191 191
 
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
 		$spanextra = $is_mandatory ? 'mandatoryFieldSpan' : '';
195 195
 		$ret = "<span class=\"inputSpan $spanextra\"><select name='$inname' id='input_$sfgFieldNum' $extraatt>";
196 196
 		$curvalues = null;
197
-		if ( $cur_value ) {
198
-			if ( $cur_value === 'current user' ) {
197
+		if ($cur_value) {
198
+			if ($cur_value === 'current user') {
199 199
 				$cur_value = $wgUser->getName();
200 200
 			}
201
-			if ( is_array( $cur_value ) ) {
201
+			if (is_array($cur_value)) {
202 202
 				$curvalues = $cur_value;
203 203
 			} else {
204
-				$curvalues = array_map( "trim", explode( ",", $cur_value ) );
204
+				$curvalues = array_map("trim", explode(",", $cur_value));
205 205
 			}
206 206
 
207 207
 		} else {
@@ -211,13 +211,13 @@  discard block
 block discarded – undo
211 211
 		// TODO handle empty value case.
212 212
 		$ret .= "<option></option>";
213 213
 
214
-		foreach ( $curvalues as $cur ) {
214
+		foreach ($curvalues as $cur) {
215 215
 			$ret .= "<option selected='selected'>$cur</option>";
216 216
 		}
217 217
 
218
-		if ( $staticvalue ) {
219
-			foreach ( $values as $val ) {
220
-				if ( !in_array( $val, $curvalues ) ) {
218
+		if ($staticvalue) {
219
+			foreach ($values as $val) {
220
+				if (!in_array($val, $curvalues)) {
221 221
 					$ret .= "<option>$val</option>";
222 222
 				}
223 223
 			}
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
 		$ret .= "</select></span>";
227 227
 		$ret .= "<span id=\"info_$sfgFieldNum\" class=\"errorMessage\"></span>";
228 228
 
229
-		if ( $other_args["is_list"] ) {
230
-			$hiddenname = $input_name . '[is_list]';
229
+		if ($other_args["is_list"]) {
230
+			$hiddenname = $input_name.'[is_list]';
231 231
 			$ret .= "<input type='hidden' name='$hiddenname' value='1' />";
232 232
 		}
233 233
 
234
-		if ( !$staticvalue ) {
235
-			$item = Output::addToHeadItem( $data );
234
+		if (!$staticvalue) {
235
+			$item = Output::addToHeadItem($data);
236 236
 			//$wgOut->addJsConfigVars('sf_select', array(json_encode( $data )));
237 237
 		}
238 238
 
Please login to merge, or discard this patch.
tests/phpunit/Unit/OutputTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 class OutputTest extends \PHPUnit_Framework_TestCase {
17 17
 
18 18
 	public function testCanConstruct() {
19
-		$this->assertInstanceOf( '\SFS\Output', new Output() );
19
+		$this->assertInstanceOf('\SFS\Output', new Output());
20 20
 	}
21 21
 
22 22
 	public function testAddToHeadItem() {
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 		$data['Foo'] = 'Bar';
25 25
 		$data['Spam'] = 'Eggs';
26 26
 
27
-		$ret = Output::addToHeadItem( $data );
27
+		$ret = Output::addToHeadItem($data);
28 28
 
29
-		$this->assertArrayHasKey( 'Foo', $ret );
30
-		$this->assertArrayHasKey( 'Spam', $ret );
29
+		$this->assertArrayHasKey('Foo', $ret);
30
+		$this->assertArrayHasKey('Spam', $ret);
31 31
 	}
32 32
 }
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( PHP_SAPI !== 'cli' ) {
4
-	die( 'Not an entry point' );
3
+if (PHP_SAPI !== 'cli') {
4
+	die('Not an entry point');
5 5
 }
6 6
 
7
-error_reporting( E_ALL | E_STRICT );
8
-date_default_timezone_set( 'UTC' );
9
-ini_set( 'display_errors', 1 );
7
+error_reporting(E_ALL | E_STRICT);
8
+date_default_timezone_set('UTC');
9
+ini_set('display_errors', 1);
10 10
 
11 11
 global $IP;
12 12
 
13 13
 //if ( !is_readable( $autoloaderClassPath = __DIR__ . '/../../SemanticMediaWiki/tests/autoloader.php' ) ) {
14
-if ( !is_readable( $autoloaderClassPath = $IP . '/extensions/SemanticMediaWiki/tests/autoloader.php' ) ) {
15
-	die( "\nThe Semantic MediaWiki test autoloader is not available\n" );
14
+if (!is_readable($autoloaderClassPath = $IP.'/extensions/SemanticMediaWiki/tests/autoloader.php')) {
15
+	die("\nThe Semantic MediaWiki test autoloader is not available\n");
16 16
 }
17 17
 
18 18
 // if ( !class_exists( 'SemanticFormsSelect' ) || ( $version = SemanticFormsSelect::getVersion() ) === null ) {
19
-if ( ExtensionRegistry::getInstance()->isLoaded( 'SemanticFormsSelect' ) ) {
20
-	die( "\nSemantic Forms Select is not available, please check your Composer or LocalSettings.\n" );
19
+if (ExtensionRegistry::getInstance()->isLoaded('SemanticFormsSelect')) {
20
+	die("\nSemantic Forms Select is not available, please check your Composer or LocalSettings.\n");
21 21
 }
22 22
 
23 23
 //print sprintf( "\n%-20s%s\n", "Semantic Forms Select: ", ExtensionRegistry::getInstance()->isLoaded( 'SemanticFormsSelect' ) );
@@ -26,4 +26,4 @@  discard block
 block discarded – undo
26 26
 $autoloader = require $autoloaderClassPath;
27 27
 //$autoloader->addPsr4( 'SFS\\Tests\\', __DIR__ . '/phpunit/Unit' );
28 28
 //$autoloader->addPsr4( 'SFS\\Tests\\Integration\\', __DIR__ . '/phpunit/Integration' );
29
-unset( $autoloader );
29
+unset($autoloader);
Please login to merge, or discard this patch.
src/Output.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @param array $data
27 27
 	 */
28
-	public static function addToHeadItem( Array $data = [] ) {
28
+	public static function addToHeadItem(Array $data = []) {
29 29
 		return self::$headItems[] = $data;
30 30
 	}
31 31
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
 		// to be used in JS like:
40 40
 		// var SFSelect_fobjs = $.parseJSON( mw.config.get( 'sf_select' ) );
41
-		$wgOut->addJsConfigVars('sf_select', json_encode( self::$headItems ));
41
+		$wgOut->addJsConfigVars('sf_select', json_encode(self::$headItems));
42 42
 
43 43
 		//self::$resourceModules = array();
44 44
 		//self::$headItems = array();
Please login to merge, or discard this patch.
src/ApiSemanticFormsSelect.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,22 +24,22 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function execute() {
26 26
 
27
-		$parser = new Parser( $GLOBALS['wgParserConf'] );
28
-		$parser->setTitle( Title::newFromText( 'NO TITLE' ) );
27
+		$parser = new Parser($GLOBALS['wgParserConf']);
28
+		$parser->setTitle(Title::newFromText('NO TITLE'));
29 29
 		$parser->mOptions = new ParserOptions();
30 30
 		$parser->mOutput = new ParserOutput();
31 31
 
32
-		$apiRequestProcessor = new SFS\ApiSemanticFormsSelectRequestProcessor( $parser );
33
-		$apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] );
32
+		$apiRequestProcessor = new SFS\ApiSemanticFormsSelectRequestProcessor($parser);
33
+		$apiRequestProcessor->setDebugFlag($GLOBALS['wgSF_Select_debug']);
34 34
 
35 35
 		$resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters(
36 36
 			$this->extractRequestParams()
37 37
 		);
38 38
 
39 39
 		$result = $this->getResult();
40
-		$result->setIndexedTagName( $resultValues->values, 'value' );
41
-		$result->addValue( $this->getModuleName(), 'values', $resultValues->values );
42
-		$result->addValue( $this->getModuleName(), 'count', $resultValues->count );
40
+		$result->setIndexedTagName($resultValues->values, 'value');
41
+		$result->addValue($this->getModuleName(), 'values', $resultValues->values);
42
+		$result->addValue($this->getModuleName(), 'count', $resultValues->count);
43 43
 
44 44
 		return true;
45 45
 	}
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @see ApiBase::getVersion
88 88
 	 */
89 89
 	public function getVersion() {
90
-		return __CLASS__ . ': 1.1';
90
+		return __CLASS__.': 1.1';
91 91
 	}
92 92
 
93 93
 }
Please login to merge, or discard this patch.