1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Scribunto; |
4
|
|
|
|
5
|
|
|
use Scribunto_LuaLibraryBase; |
6
|
|
|
use SMW\DIProperty; |
7
|
|
|
use FauxRequest; |
8
|
|
|
use ApiMain; |
9
|
|
|
|
10
|
|
|
use SMWQueryProcessor as QueryProcessor; |
11
|
|
|
use SMW\ApplicationFactory; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 1.0 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class ScribuntoLuaLibrary extends Scribunto_LuaLibraryBase { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @since 1.0 |
23
|
|
|
*/ |
24
|
5 |
|
public function register() { |
25
|
|
|
|
26
|
|
|
$lib = array( |
27
|
5 |
|
'getQueryResult' => array( $this, 'getQueryResult' ), |
28
|
5 |
|
'getPropertyType' => array( $this, 'getPropertyType' ), |
29
|
5 |
|
); |
30
|
|
|
|
31
|
5 |
|
$this->getEngine()->registerInterface( __DIR__ . '/' . 'mw.ext.smw.lua', $lib, array() ); |
32
|
5 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns query results in for of the standard API return format |
36
|
|
|
* |
37
|
|
|
* @since 1.0 |
38
|
|
|
* |
39
|
|
|
* @param string $queryString |
|
|
|
|
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
2 |
|
public function getQueryResult( $argString = null ) { |
44
|
|
|
|
45
|
2 |
|
$rawParameters = preg_split( "/(?<=[^\|])\|(?=[^\|])/", $argString ); |
46
|
|
|
|
47
|
2 |
|
list( $queryString, $parameters, $printouts ) = QueryProcessor::getComponentsFromFunctionParams( |
48
|
2 |
|
$rawParameters, |
49
|
|
|
false |
50
|
2 |
|
); |
51
|
|
|
|
52
|
2 |
|
QueryProcessor::addThisPrintout( $printouts, $parameters ); |
53
|
|
|
|
54
|
2 |
|
$query = QueryProcessor::createQuery( |
55
|
2 |
|
$queryString, |
56
|
2 |
|
QueryProcessor::getProcessedParams( $parameters, $printouts ), |
57
|
2 |
|
QueryProcessor::SPECIAL_PAGE, |
58
|
2 |
|
'', |
59
|
|
|
$printouts |
60
|
2 |
|
); |
61
|
|
|
|
62
|
2 |
|
$queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query )->toArray(); |
63
|
2 |
|
if(!empty($queryResult["results"])) { |
64
|
|
|
$queryResult["results"] = array_combine(range(1, count($queryResult["results"])), array_values($queryResult["results"])); |
65
|
|
|
} |
66
|
2 |
|
return array( $queryResult ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns property type |
71
|
|
|
* |
72
|
|
|
* @since 1.0 |
73
|
|
|
* |
74
|
|
|
* @param string $propertyName |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
3 |
|
public function getPropertyType( $propertyName = null ) { |
79
|
|
|
|
80
|
3 |
|
$this->checkType( 'getPropertyType', 1, $propertyName, 'string' ); |
81
|
3 |
|
$propertyName = trim( $propertyName ); |
82
|
|
|
|
83
|
3 |
|
if ( $propertyName === '' ) { |
84
|
1 |
|
return array( null ); |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
$property = DIProperty::newFromUserLabel( $propertyName ); |
88
|
|
|
|
89
|
2 |
|
if ( $property === null ) { |
90
|
|
|
return array( null ); |
91
|
|
|
} |
92
|
|
|
|
93
|
2 |
|
return array( $property->findPropertyTypeID() ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.