These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use ParamProcessor\ParamDefinition; |
||
4 | |||
5 | /** |
||
6 | * API module to retrieve formatted results for a given page, printouts and template. |
||
7 | * |
||
8 | * @author Stephan Gambke |
||
9 | * @ingroup SemanticResultFormats |
||
10 | */ |
||
11 | class SRFSlideShowApi extends ApiBase { |
||
12 | |||
13 | /** |
||
14 | * Evaluates the parameters, performs the query, and sets up the result. |
||
15 | * |
||
16 | * The result data is stored in the ApiResult object available through getResult(). |
||
17 | */ |
||
18 | public function execute() { |
||
19 | |||
20 | // get request parameters |
||
21 | $requestParams = $this->extractRequestParams(); |
||
22 | |||
23 | $title = Title::newFromID( $requestParams[ 'pageid' ] )->getPrefixedText(); |
||
24 | |||
25 | $rp = new SMWListResultPrinter( 'template', true ); |
||
26 | |||
27 | // get defaults of parameters for the 'template' result format as array of ParamDefinition |
||
28 | $paramDefinitions = ParamDefinition::getCleanDefinitions( $rp->getParamDefinitions( [] ) ); |
||
0 ignored issues
–
show
|
|||
29 | |||
30 | // transform into normal key-value array |
||
31 | $queryParams = []; |
||
32 | |||
33 | foreach ( $paramDefinitions as $def ) { |
||
34 | $queryParams[ $def->getName() ] = $def->getDefault(); |
||
35 | } |
||
36 | |||
37 | // add/set specific parameters for this call |
||
38 | $queryParams = array_merge( $queryParams, [ |
||
39 | 'format' => 'template', |
||
40 | 'template' => $requestParams[ 'template' ], |
||
41 | 'mainlabel' => '', |
||
42 | 'sort' => '', |
||
43 | 'order' => '', |
||
44 | 'intro' => null, |
||
45 | 'outro' => null, |
||
46 | 'searchlabel' => null, |
||
47 | 'link' => null, |
||
48 | 'default' => null, |
||
49 | 'headers' => null, |
||
50 | 'introtemplate' => '', |
||
51 | 'outrotemplate' => '', |
||
52 | ] ); |
||
53 | |||
54 | // A bit of a hack since the parser isn't run, avoids [[SMW::off]]/[[SMW::on]] |
||
55 | $queryParams['import-annotation'] = 'true'; |
||
56 | |||
57 | // transform query parameters into format suitable for SMWQueryProcessor |
||
58 | $queryParams = SMWQueryProcessor::getProcessedParams( $queryParams, [] ); |
||
59 | |||
60 | // build array of printouts |
||
61 | |||
62 | $printoutsRaw = json_decode( $requestParams[ 'printouts' ], true ); |
||
63 | $printouts = []; |
||
64 | |||
65 | foreach ( $printoutsRaw as $printoutData ) { |
||
66 | |||
67 | // if printout mode is PRINT_PROP |
||
68 | if ( $printoutData[0] == SMWPrintRequest::PRINT_PROP ) { |
||
69 | // create property from property key |
||
70 | $data = SMWPropertyValue::makeUserProperty( $printoutData[2] ); |
||
71 | } else { |
||
72 | $data = null; |
||
73 | } |
||
74 | |||
75 | // create printrequest from request mode, label, property name, output format, parameters |
||
76 | $printouts[] = new SMWPrintRequest( $printoutData[0], $printoutData[1], $data, $printoutData[3], $printoutData[4] ); |
||
77 | } |
||
78 | |||
79 | // query SMWQueryProcessor and set query result as API call result |
||
80 | $this->getResult()->addValue( |
||
81 | null, |
||
82 | $requestParams[ 'pageid' ], |
||
83 | SMWQueryProcessor::getResultFromQueryString( '[[' . $title . ']]', $queryParams, $printouts, SMW_OUTPUT_HTML, SMWQueryProcessor::INLINE_QUERY ) |
||
84 | ); |
||
85 | |||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Returns the description string for this module |
||
90 | * @return mixed string or array of strings |
||
91 | */ |
||
92 | protected function getDescription() { |
||
93 | return [ |
||
94 | 'API module used by the SlideShow result printer to retrieve formatted results.', |
||
95 | 'This module is should not be called directly.' |
||
96 | ]; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Returns usage examples for this module. Return false if no examples are available. |
||
101 | * @return bool|string|array |
||
102 | */ |
||
103 | protected function getExamples() { |
||
104 | return false; |
||
105 | } |
||
106 | |||
107 | public function getHelpUrls() { |
||
108 | return 'http://semantic-mediawiki.org/wiki/Help:Slideshow_format'; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Returns an array of allowed parameters |
||
113 | * |
||
114 | * @return array|bool |
||
115 | */ |
||
116 | protected function getAllowedParams() { |
||
117 | return [ |
||
118 | 'pageid' => [ |
||
119 | ApiBase::PARAM_TYPE => 'integer', |
||
120 | ApiBase::PARAM_ISMULTI => false, |
||
121 | ApiBase::PARAM_REQUIRED => true, |
||
122 | ], |
||
123 | 'template' => [ |
||
124 | ApiBase::PARAM_TYPE => 'string', |
||
125 | ApiBase::PARAM_ISMULTI => false, |
||
126 | ApiBase::PARAM_REQUIRED => true, |
||
127 | ], |
||
128 | 'printouts' => [ |
||
129 | ApiBase::PARAM_TYPE => 'string', |
||
130 | ApiBase::PARAM_ISMULTI => false, |
||
131 | ApiBase::PARAM_REQUIRED => false, |
||
132 | ApiBase::PARAM_DFLT => '[]', |
||
133 | ], |
||
134 | ]; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Returns an array of parameter descriptions. |
||
139 | * Don't call this functon directly: use getFinalParamDescription() to |
||
140 | * allow hooks to modify descriptions as needed. |
||
141 | * @return array|bool False on no parameter descriptions |
||
142 | */ |
||
143 | protected function getParamDescription() { |
||
144 | return [ |
||
145 | 'pageid' => 'Id of the page (subject) to be displayed', |
||
146 | 'template' => 'Template to use for formatting', |
||
147 | 'printouts' => 'Printouts to send to the template', |
||
148 | ]; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Returns a string that identifies the version of the extending class. |
||
153 | * Typically includes the class name, the svn revision, timestamp, and |
||
154 | * last author. Usually done with SVN's Id keyword |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getVersion() { |
||
158 | global $srfgIP; |
||
159 | $gitSha1 = SpecialVersion::getGitHeadSha1( $srfgIP ); |
||
160 | return __CLASS__ . '-' . SRF_VERSION . ($gitSha1 !== false) ? ' (' . substr( $gitSha1, 0, 7 ) . ')' : ''; |
||
161 | } |
||
162 | |||
163 | } |
||
164 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: