1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Specials; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
use SMW\DataValueFactory; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
use SMW\Localizer; |
9
|
|
|
use SMW\SemanticData; |
10
|
|
|
use SMW\UrlEncoder; |
11
|
|
|
use SMW\MediaWiki\Specials\Browse\ContentsBuilder; |
12
|
|
|
use SMW\MediaWiki\Specials\Browse\FormHelper; |
13
|
|
|
use SMW\Message; |
14
|
|
|
use SpecialPage; |
15
|
|
|
use Html; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* A factbox view on one specific article, showing all the Semantic data about it |
19
|
|
|
* |
20
|
|
|
* @license GNU GPL v2+ |
21
|
|
|
* @since 1.6 |
22
|
|
|
* |
23
|
|
|
* @author mwjames |
24
|
|
|
*/ |
25
|
|
|
class SpecialBrowse extends SpecialPage { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var DataValue |
29
|
|
|
*/ |
30
|
|
|
private $subjectDV = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ApplicationFactory |
34
|
|
|
*/ |
35
|
|
|
private $applicationFactory = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @see SpecialPage::__construct |
39
|
4 |
|
*/ |
40
|
4 |
|
public function __construct() { |
41
|
4 |
|
parent::__construct( 'Browse', '', true, false, 'default', true ); |
42
|
4 |
|
$this->applicationFactory = ApplicationFactory::getInstance(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @see SpecialPage::execute |
47
|
|
|
* |
48
|
|
|
* @param string $query string |
49
|
11 |
|
*/ |
50
|
|
|
public function execute( $query ) { |
51
|
11 |
|
|
52
|
11 |
|
$this->setHeaders(); |
53
|
|
|
$webRequest = $this->getRequest(); |
54
|
|
|
|
55
|
11 |
|
// get the GET parameters |
56
|
11 |
|
$articletext = $webRequest->getVal( 'article' ); |
57
|
|
|
$isEmptyRequest = $query === null && ( $webRequest->getVal( 'article' ) === '' || $webRequest->getVal( 'article' ) === null ); |
58
|
|
|
|
59
|
11 |
|
// @see SMWInfolink::encodeParameters |
60
|
|
|
if ( $query === null && $this->getRequest()->getCheck( 'x' ) ) { |
61
|
|
|
$query = $this->getRequest()->getVal( 'x' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
11 |
|
// Auto-generated link is marked with a leading : |
65
|
3 |
|
if ( $query !== '' && $query{0} === ':' ) { |
66
|
9 |
|
$articletext = UrlEncoder::unescape( $query ); |
67
|
9 |
|
} elseif ( $articletext === null ) { |
68
|
|
|
$articletext = $query; |
69
|
|
|
} |
70
|
|
|
|
71
|
11 |
|
// no GET parameters? Then try the URL |
72
|
|
|
if ( $articletext === null ) { |
|
|
|
|
73
|
|
|
} |
74
|
11 |
|
|
75
|
11 |
|
$this->subjectDV = DataValueFactory::getInstance()->newTypeIDValue( |
|
|
|
|
76
|
|
|
'_wpg', |
77
|
|
|
$articletext |
78
|
|
|
); |
79
|
11 |
|
|
80
|
11 |
|
$out = $this->getOutput(); |
81
|
|
|
$out->setHTMLTitle( $this->subjectDV->getTitle() ); |
|
|
|
|
82
|
11 |
|
|
83
|
11 |
|
$out->addModuleStyles( array( |
84
|
|
|
'mediawiki.ui', |
85
|
|
|
'mediawiki.ui.button', |
86
|
|
|
'mediawiki.ui.input' |
87
|
|
|
) ); |
88
|
11 |
|
|
89
|
11 |
|
$out->addModules( array( |
90
|
|
|
'ext.smw.browse', |
91
|
|
|
'ext.smw.tooltip' |
92
|
|
|
) ); |
93
|
11 |
|
|
94
|
11 |
|
$out->addHTML( |
95
|
|
|
$this->getHtml( $webRequest, $isEmptyRequest ) |
96
|
|
|
); |
97
|
11 |
|
|
98
|
11 |
|
$this->addExternalHelpLinks(); |
99
|
|
|
} |
100
|
11 |
|
|
101
|
|
|
private function getHtml( $webRequest, $isEmptyRequest ) { |
102
|
11 |
|
|
103
|
|
|
if ( $isEmptyRequest && !$this->including() ) { |
104
|
|
|
return Message::get( 'smw-browse-intro', Message::TEXT, Message::USER_LANGUAGE ) . FormHelper::getQueryForm(); |
105
|
|
|
} |
106
|
11 |
|
|
107
|
|
|
if ( !$this->subjectDV->isValid() ) { |
108
|
4 |
|
|
109
|
4 |
|
foreach ( $this->subjectDV->getErrors() as $error ) { |
110
|
|
|
$error = Message::decode( $error, Message::TEXT ); |
111
|
|
|
} |
112
|
4 |
|
|
113
|
4 |
|
$html = Html::rawElement( |
114
|
|
|
'div', |
115
|
|
|
array( |
116
|
4 |
|
'class' => 'smw-callout smw-callout-error' |
117
|
4 |
|
), |
118
|
|
|
Message::get( array( 'smw-browse-invalid-subject', $error ), Message::TEXT ) |
|
|
|
|
119
|
|
|
); |
120
|
4 |
|
|
121
|
4 |
|
if ( !$this->including() ) { |
122
|
|
|
$html .= FormHelper::getQueryForm( $webRequest->getVal( 'article' ) ); |
123
|
|
|
} |
124
|
4 |
|
|
125
|
|
|
return $html; |
126
|
|
|
} |
127
|
7 |
|
|
128
|
|
|
$contentsBuilder = $this->newContentsBuilder( |
129
|
7 |
|
$webRequest, |
130
|
|
|
$this->applicationFactory->getSettings() |
131
|
|
|
); |
132
|
7 |
|
|
133
|
5 |
|
if ( $webRequest->getVal( 'output' ) === 'legacy' || !$contentsBuilder->getOption( 'byApi' ) ) { |
134
|
|
|
return $contentsBuilder->getHtml(); |
135
|
|
|
} |
136
|
|
|
|
137
|
2 |
|
$options = array( |
138
|
2 |
|
'dir' => $contentsBuilder->getOption( 'dir' ), |
139
|
2 |
|
'offset' => $contentsBuilder->getOption( 'offset' ), |
140
|
2 |
|
'printable' => $contentsBuilder->getOption( 'printable' ), |
141
|
2 |
|
'showInverse' => $contentsBuilder->getOption( 'showInverse' ), |
142
|
2 |
|
'showAll' => $contentsBuilder->getOption( 'showAll' ), |
143
|
|
|
'including' => $contentsBuilder->getOption( 'including' ) |
144
|
|
|
); |
145
|
|
|
|
146
|
2 |
|
// Ajax/API is doing the data fetch |
147
|
2 |
|
$html = Html::rawElement( |
148
|
|
|
'div', |
149
|
2 |
|
array( |
150
|
2 |
|
'class' => 'smwb-container', |
151
|
2 |
|
'data-subject' => $this->subjectDV->getDataItem()->getHash(), |
152
|
|
|
'data-options' => json_encode( $options ) |
153
|
2 |
|
), |
154
|
2 |
|
Html::rawElement( |
155
|
|
|
'div', |
156
|
|
|
array( |
157
|
2 |
|
'class' => 'smwb-status' |
158
|
2 |
|
), |
159
|
2 |
|
Html::rawElement( |
160
|
2 |
|
'noscript', |
161
|
2 |
|
array(), |
162
|
2 |
|
Html::rawElement( |
163
|
|
|
'div', |
164
|
2 |
|
array( |
165
|
|
|
'class' => 'smw-callout smw-callout-error', |
166
|
2 |
|
), |
167
|
|
|
Message::get( 'smw-browse-js-disabled', Message::PARSE ) |
168
|
|
|
) |
169
|
2 |
|
) |
170
|
2 |
|
) . Html::rawElement( |
171
|
|
|
'div', |
172
|
|
|
array( |
173
|
2 |
|
'class' => 'smwb-content is-disabled' |
174
|
2 |
|
), |
175
|
2 |
|
Html::rawElement( |
176
|
|
|
'span', |
177
|
|
|
array( |
178
|
2 |
|
'class' => 'smw-overlay-spinner large inline' |
179
|
2 |
|
) |
180
|
|
|
) . $contentsBuilder->getEmptyHtml() |
181
|
|
|
) |
182
|
|
|
); |
183
|
2 |
|
|
184
|
|
|
return $html; |
185
|
|
|
} |
186
|
7 |
|
|
187
|
|
|
private function newContentsBuilder( $webRequest, $settings ) { |
188
|
7 |
|
|
189
|
7 |
|
$contentsBuilder = new ContentsBuilder( |
190
|
7 |
|
$this->applicationFactory->getStore(), |
191
|
|
|
$this->subjectDV->getDataItem() |
192
|
|
|
); |
193
|
7 |
|
|
194
|
7 |
|
$contentsBuilder->setOption( |
195
|
7 |
|
'dir', |
196
|
|
|
$webRequest->getVal( 'dir' ) |
197
|
|
|
); |
198
|
7 |
|
|
199
|
7 |
|
$contentsBuilder->setOption( |
200
|
7 |
|
'printable', |
201
|
|
|
$webRequest->getVal( 'printable' ) |
202
|
|
|
); |
203
|
7 |
|
|
204
|
7 |
|
$contentsBuilder->setOption( |
205
|
7 |
|
'offset', |
206
|
|
|
$webRequest->getVal( 'offset' ) |
207
|
|
|
); |
208
|
7 |
|
|
209
|
7 |
|
$contentsBuilder->setOption( |
210
|
7 |
|
'including', |
211
|
|
|
$this->including() |
212
|
|
|
); |
213
|
7 |
|
|
214
|
7 |
|
$contentsBuilder->setOption( |
215
|
7 |
|
'showInverse', |
216
|
|
|
$settings->get( 'smwgBrowseShowInverse' ) |
217
|
|
|
); |
218
|
7 |
|
|
219
|
7 |
|
$contentsBuilder->setOption( |
220
|
7 |
|
'showAll', |
221
|
|
|
$settings->get( 'smwgBrowseShowAll' ) |
222
|
|
|
); |
223
|
7 |
|
|
224
|
7 |
|
$contentsBuilder->setOption( |
225
|
7 |
|
'byApi', |
226
|
|
|
$settings->get( 'smwgBrowseByApi' ) |
227
|
|
|
); |
228
|
7 |
|
|
229
|
|
|
return $contentsBuilder; |
230
|
|
|
} |
231
|
11 |
|
|
232
|
|
|
private function addExternalHelpLinks() { |
233
|
11 |
|
|
234
|
|
|
if ( $this->getRequest()->getVal( 'printable' ) === 'yes' ) { |
235
|
|
|
return null; |
236
|
|
|
} |
237
|
|
|
|
238
|
11 |
|
// FIXME with SMW 3.0, allow to be used with MW 1.25- |
239
|
|
|
if ( !method_exists( $this, 'addHelpLink' ) ) { |
240
|
|
|
return null; |
241
|
|
|
} |
242
|
11 |
|
|
243
|
7 |
|
if ( $this->subjectDV->isValid() ) { |
244
|
|
|
$link = SpecialPage::getTitleFor( 'ExportRDF', $this->subjectDV->getTitle()->getPrefixedText() ); |
245
|
7 |
|
|
246
|
7 |
|
$this->getOutput()->setIndicators( array( |
247
|
7 |
|
'browse' => Html::rawElement( |
248
|
|
|
'div', |
249
|
|
|
array( |
250
|
7 |
|
'class' => 'smw-page-indicator-rdflink' |
251
|
7 |
|
), |
252
|
7 |
|
Html::rawElement( |
253
|
|
|
'a', |
254
|
7 |
|
array( |
255
|
|
|
'href' => $link->getLocalUrl( 'syntax=rdf' ) |
256
|
7 |
|
), |
257
|
|
|
'RDF' |
258
|
|
|
) |
259
|
|
|
) |
260
|
|
|
) ); |
261
|
|
|
} |
262
|
11 |
|
|
263
|
11 |
|
$this->addHelpLink( wfMessage( 'smw-specials-browse-helplink' )->escaped(), true ); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
protected function getGroupName() { |
267
|
|
|
return 'smw_group'; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
} |
271
|
|
|
|
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.