@@ -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( $input_name = "", $other_args ) {
|
|
| 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($input_name = "", $other_args) {
|
|
| 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 ); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @param Parser $parser |
| 35 | 35 | */ |
| 36 | - public function __construct( Parser $parser ) { |
|
| 36 | + public function __construct(Parser $parser) { |
|
| 37 | 37 | $this->parser = $parser; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @param boolean $debugFlag |
| 44 | 44 | */ |
| 45 | - public function setDebugFlag( $debugFlag ) { |
|
| 45 | + public function setDebugFlag($debugFlag) { |
|
| 46 | 46 | $this->debugFlag = $debugFlag; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -53,95 +53,95 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return string |
| 55 | 55 | */ |
| 56 | - public function getJsonDecodedResultValuesForRequestParameters( array $parameters ) { |
|
| 56 | + public function getJsonDecodedResultValuesForRequestParameters(array $parameters) { |
|
| 57 | 57 | |
| 58 | - if ( !isset( $parameters['query'] ) || !isset( $parameters['sep'] ) ) { |
|
| 59 | - throw new InvalidArgumentException( 'Missing an query parameter' ); |
|
| 58 | + if (!isset($parameters['query']) || !isset($parameters['sep'])) { |
|
| 59 | + throw new InvalidArgumentException('Missing an query parameter'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $this->parser->firstCallInit(); |
| 63 | 63 | $json = []; |
| 64 | 64 | |
| 65 | - if ( isset( $parameters['approach'] ) && $parameters['approach'] == 'smw' ) { |
|
| 66 | - $json = $this->doProcessQueryFor( $parameters['query'], $parameters['sep'] ); |
|
| 65 | + if (isset($parameters['approach']) && $parameters['approach'] == 'smw') { |
|
| 66 | + $json = $this->doProcessQueryFor($parameters['query'], $parameters['sep']); |
|
| 67 | 67 | } else { |
| 68 | - $json = $this->doProcessFunctionFor( $parameters['query'], $parameters['sep'] ); |
|
| 68 | + $json = $this->doProcessFunctionFor($parameters['query'], $parameters['sep']); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // I have no idea why we first encode and and then decode here?? |
| 72 | 72 | |
| 73 | - return json_decode( $json ); |
|
| 73 | + return json_decode($json); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - private function doProcessQueryFor( $querystr, $sep = "," ) { |
|
| 76 | + private function doProcessQueryFor($querystr, $sep = ",") { |
|
| 77 | 77 | |
| 78 | 78 | $querystr = str_replace( |
| 79 | - [ "<", ">", "sep=;" ], |
|
| 80 | - [ "<", ">", "sep={$sep};" ], |
|
| 79 | + ["<", ">", "sep=;"], |
|
| 80 | + ["<", ">", "sep={$sep};"], |
|
| 81 | 81 | $querystr |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - $rawparams = explode( ";", $querystr ); |
|
| 85 | - $f = str_replace( ";", "|", $rawparams[0] ); |
|
| 84 | + $rawparams = explode(";", $querystr); |
|
| 85 | + $f = str_replace(";", "|", $rawparams[0]); |
|
| 86 | 86 | |
| 87 | - $rawparams[0] = $this->parser->replaceVariables( $f ); |
|
| 87 | + $rawparams[0] = $this->parser->replaceVariables($f); |
|
| 88 | 88 | |
| 89 | - if ( $this->debugFlag ) { |
|
| 90 | - error_log( implode( "|", $rawparams ) ); |
|
| 89 | + if ($this->debugFlag) { |
|
| 90 | + error_log(implode("|", $rawparams)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
| 94 | - list( $query, $params ) = QueryProcessor::getQueryAndParamsFromFunctionParams( $rawparams, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY, false ); |
|
| 94 | + list($query, $params) = QueryProcessor::getQueryAndParamsFromFunctionParams($rawparams, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY, false); |
|
| 95 | 95 | |
| 96 | - $result = QueryProcessor::getResultFromQuery( $query, $params, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY ); |
|
| 96 | + $result = QueryProcessor::getResultFromQuery($query, $params, SMW_OUTPUT_WIKI, QueryProcessor::INLINE_QUERY); |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | - $values = $this->getFormattedValuesFrom( $sep, $result ); |
|
| 99 | + $values = $this->getFormattedValuesFrom($sep, $result); |
|
| 100 | 100 | |
| 101 | - return json_encode( [ |
|
| 101 | + return json_encode([ |
|
| 102 | 102 | "values" => $values, |
| 103 | - "count" => count( $values ) |
|
| 104 | - ] ); |
|
| 103 | + "count" => count($values) |
|
| 104 | + ]); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - private function doProcessFunctionFor( $query, $sep = "," ) { |
|
| 107 | + private function doProcessFunctionFor($query, $sep = ",") { |
|
| 108 | 108 | |
| 109 | 109 | $query = str_replace( |
| 110 | - [ "<", ">", "sep=;" ], |
|
| 111 | - [ "<", ">", "sep={$sep};" ], |
|
| 110 | + ["<", ">", "sep=;"], |
|
| 111 | + ["<", ">", "sep={$sep};"], |
|
| 112 | 112 | $query |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | - $f = str_replace( ";", "|", $query ); |
|
| 115 | + $f = str_replace(";", "|", $query); |
|
| 116 | 116 | |
| 117 | - if ( $this->debugFlag ) { |
|
| 118 | - error_log( $f ); |
|
| 117 | + if ($this->debugFlag) { |
|
| 118 | + error_log($f); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $values = $this->getFormattedValuesFrom( |
| 122 | 122 | $sep, |
| 123 | - $this->parser->replaceVariables( $f ) |
|
| 123 | + $this->parser->replaceVariables($f) |
|
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | - return json_encode( [ |
|
| 126 | + return json_encode([ |
|
| 127 | 127 | "values" => $values, |
| 128 | - "count" => count( $values ) |
|
| 129 | - ] ); |
|
| 128 | + "count" => count($values) |
|
| 129 | + ]); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - private function getFormattedValuesFrom( $sep, $values ) { |
|
| 132 | + private function getFormattedValuesFrom($sep, $values) { |
|
| 133 | 133 | |
| 134 | - if ( strpos( $values, $sep ) === false ) { |
|
| 135 | - return [ $values ]; |
|
| 134 | + if (strpos($values, $sep) === false) { |
|
| 135 | + return [$values]; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $values = explode( $sep, $values ); |
|
| 139 | - $values = array_map( "trim", $values ); |
|
| 140 | - $values = array_unique( $values ); |
|
| 138 | + $values = explode($sep, $values); |
|
| 139 | + $values = array_map("trim", $values); |
|
| 140 | + $values = array_unique($values); |
|
| 141 | 141 | |
| 142 | 142 | // TODO: sorting here will destroy any sort defined in the query, e.g. in case sorting for labels (instead of mainlable) |
| 143 | 143 | //sort( $values ); |
| 144 | - array_unshift( $values, "" ); |
|
| 144 | + array_unshift($values, ""); |
|
| 145 | 145 | |
| 146 | 146 | return $values; |
| 147 | 147 | } |