1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Specials\Admin; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
use SMW\MediaWiki\Renderer\HtmlFormRenderer; |
7
|
|
|
use SMW\Store; |
8
|
|
|
use SMW\Message; |
9
|
|
|
use SMW\NamespaceManager; |
10
|
|
|
use Html; |
11
|
|
|
use WebRequest; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 2.5 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class IdTaskHandler extends TaskHandler { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Store |
23
|
|
|
*/ |
24
|
|
|
private $store; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var HtmlFormRenderer |
28
|
|
|
*/ |
29
|
|
|
private $htmlFormRenderer; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var OutputFormatter |
33
|
|
|
*/ |
34
|
|
|
private $outputFormatter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var User|null |
38
|
|
|
*/ |
39
|
|
|
private $user; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @since 2.5 |
43
|
|
|
* |
44
|
|
|
* @param Store $store |
45
|
|
|
* @param HtmlFormRenderer $htmlFormRenderer |
46
|
|
|
* @param OutputFormatter $outputFormatter |
47
|
|
|
*/ |
48
|
|
|
public function __construct( Store $store, HtmlFormRenderer $htmlFormRenderer, OutputFormatter $outputFormatter ) { |
49
|
|
|
$this->store = $store; |
50
|
|
|
$this->htmlFormRenderer = $htmlFormRenderer; |
51
|
|
|
$this->outputFormatter = $outputFormatter; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @since 2.5 |
56
|
|
|
* |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
*/ |
59
|
|
|
public function isTaskFor( $task ) { |
60
|
|
|
return $task === 'idlookup'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @since 2.5 |
65
|
|
|
* |
66
|
|
|
* {@inheritDoc} |
67
|
|
|
*/ |
68
|
|
|
public function setUser( $user = null ) { |
69
|
|
|
$this->user = $user; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @since 2.5 |
74
|
|
|
* |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
|
|
public function getHtml() { |
78
|
|
|
return Html::rawElement( |
79
|
|
|
'li', |
80
|
|
|
array(), |
81
|
|
|
$this->getMessageAsString( |
82
|
|
|
array( |
83
|
|
|
'smw-admin-supplementary-idlookup-intro', |
84
|
|
|
$this->outputFormatter->getSpecialPageLinkWith( $this->getMessageAsString( 'smw-admin-supplementary-idlookup-title' ), array( 'action' => 'idlookup' ) ) |
85
|
|
|
) |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @since 2.5 |
92
|
|
|
* |
93
|
|
|
* {@inheritDoc} |
94
|
|
|
*/ |
95
|
|
|
public function handleRequest( WebRequest $webRequest ) { |
96
|
|
|
|
97
|
|
|
$this->outputFormatter->setPageTitle( $this->getMessageAsString( 'smw-admin-supplementary-idlookup-title' ) ); |
98
|
|
|
$this->outputFormatter->addParentLink(); |
99
|
|
|
|
100
|
|
|
$id = $webRequest->getText( 'id' ); |
101
|
|
|
|
102
|
|
|
if ( $this->isEnabledFeature( SMW_ADM_DISPOSAL ) && $id > 0 && $webRequest->getText( 'dispose' ) === 'yes' ) { |
103
|
|
|
$this->doDispose( $id ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->outputFormatter->addHtml( $this->getForm( $webRequest, $id ) ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param integer $id |
111
|
|
|
* @param User|null $use |
|
|
|
|
112
|
|
|
*/ |
113
|
|
|
private function doDispose( $id ) { |
114
|
|
|
|
115
|
|
|
$entityIdDisposerJob = ApplicationFactory::getInstance()->newJobFactory()->newEntityIdDisposerJob( |
116
|
|
|
\Title::newFromText( __METHOD__ ) |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$entityIdDisposerJob->dispose( $id ); |
120
|
|
|
|
121
|
|
|
$manualEntryLogger = ApplicationFactory::getInstance()->create( 'ManualEntryLogger' ); |
122
|
|
|
$manualEntryLogger->registerLoggableEventType( 'admin' ); |
123
|
|
|
$manualEntryLogger->log( 'admin', $this->user, 'Special:SMWAdmin', 'Forced removal of ID '. $id ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
private function getForm( $webRequest, $id ) { |
127
|
|
|
|
128
|
|
|
$message = $this->createInfoMessageById( $webRequest, $id ); |
129
|
|
|
|
130
|
|
|
if ( $id < 1 ) { |
131
|
|
|
$id = null; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$html = $this->htmlFormRenderer |
135
|
|
|
->setName( 'idlookup' ) |
136
|
|
|
->setMethod( 'get' ) |
137
|
|
|
->addHiddenField( 'action', 'idlookup' ) |
138
|
|
|
->addHiddenField( 'id', $id ) |
139
|
|
|
->addParagraph( $this->getMessageAsString( 'smw-admin-idlookup-docu' ) ) |
140
|
|
|
->addInputField( |
141
|
|
|
$this->getMessageAsString( 'smw-admin-objectid' ), |
142
|
|
|
'id', |
143
|
|
|
$id |
144
|
|
|
) |
145
|
|
|
->addNonBreakingSpace() |
146
|
|
|
->addSubmitButton( $this->getMessageAsString( 'allpagessubmit' ) ) |
147
|
|
|
->addParagraph( $message ) |
148
|
|
|
->getForm(); |
149
|
|
|
|
150
|
|
|
$html .= Html::element( 'p', array(), '' ); |
151
|
|
|
|
152
|
|
|
if ( $id > 0 && $webRequest->getText( 'dispose' ) == 'yes' ) { |
153
|
|
|
$message = $this->getMessageAsString( array ('smw-admin-iddispose-done', $id ) ); |
|
|
|
|
154
|
|
|
$id = null; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if ( !$this->isEnabledFeature( SMW_ADM_DISPOSAL ) ) { |
158
|
|
|
return $html; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$html .= $this->htmlFormRenderer |
162
|
|
|
->setName( 'iddispose' ) |
163
|
|
|
->setMethod( 'get' ) |
164
|
|
|
->addHiddenField( 'action', 'idlookup' ) |
165
|
|
|
->addHiddenField( 'id', $id ) |
166
|
|
|
->addHeader( 'h2', $this->getMessageAsString( 'smw-admin-iddispose-title' ) ) |
167
|
|
|
->addParagraph( $this->getMessageAsString( 'smw-admin-iddispose-docu', Message::PARSE ) ) |
168
|
|
|
->addInputField( |
169
|
|
|
$this->getMessageAsString( 'smw-admin-objectid' ), |
170
|
|
|
'id', |
171
|
|
|
$id, |
172
|
|
|
null, |
173
|
|
|
20, |
174
|
|
|
'', |
175
|
|
|
true |
176
|
|
|
) |
177
|
|
|
->addNonBreakingSpace() |
178
|
|
|
->addSubmitButton( $this->getMessageAsString( 'allpagessubmit' ) ) |
179
|
|
|
->addCheckbox( |
180
|
|
|
$this->getMessageAsString( 'smw_smwadmin_datarefreshstopconfirm', Message::ESCAPED ), |
181
|
|
|
'dispose', |
182
|
|
|
'yes' |
183
|
|
|
) |
184
|
|
|
->getForm(); |
185
|
|
|
|
186
|
|
|
return $html . Html::element( 'p', array(), '' ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
private function createInfoMessageById( $webRequest, &$id ) { |
190
|
|
|
|
191
|
|
|
if ( $webRequest->getText( 'action' ) !== 'idlookup' || $id === '' ) { |
192
|
|
|
return ''; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
$connection = $this->store->getConnection( 'mw.db' ); |
196
|
|
|
|
197
|
|
|
if ( intval( $id ) ) { |
198
|
|
|
$condition = 'smw_id=' . intval( $id ); |
199
|
|
|
} else { |
200
|
|
|
$condition = 'smw_sortkey=' . $connection->addQuotes( $id ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
$rows = $connection->select( |
204
|
|
|
\SMWSql3SmwIds::TABLE_NAME, |
205
|
|
|
array( |
206
|
|
|
'smw_id', |
207
|
|
|
'smw_title', |
208
|
|
|
'smw_namespace', |
209
|
|
|
'smw_iw', |
210
|
|
|
'smw_subobject', |
211
|
|
|
'smw_sortkey' |
212
|
|
|
), |
213
|
|
|
$condition, |
214
|
|
|
__METHOD__ |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
return $this->createMessageFromRows( $id, $rows ); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
private function createMessageFromRows( &$id, $rows ) { |
221
|
|
|
|
222
|
|
|
$references = array(); |
223
|
|
|
$formattedRows = array(); |
224
|
|
|
$output = ''; |
225
|
|
|
|
226
|
|
|
if ( $rows !== array() ) { |
227
|
|
|
foreach ( $rows as $row ) { |
228
|
|
|
$id = $row->smw_id; |
229
|
|
|
|
230
|
|
|
$references[$id] = $this->store->getPropertyTableIdReferenceFinder()->searchAllTablesToFindAtLeastOneReferenceById( |
|
|
|
|
231
|
|
|
$id |
232
|
|
|
); |
233
|
|
|
|
234
|
|
|
$formattedRows[$id] = (array)$row; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
// ID is not unique |
239
|
|
|
if ( count( $formattedRows ) > 1 ) { |
240
|
|
|
$id = ''; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
if ( $formattedRows !== array() ) { |
244
|
|
|
$output = '<pre>' . $this->outputFormatter->encodeAsJson( $formattedRows ) . '</pre>'; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
if ( $references !== array() ) { |
248
|
|
|
$output .= Html::element( |
249
|
|
|
'p', |
250
|
|
|
array(), |
251
|
|
|
$this->getMessageAsString( array( 'smw-admin-iddispose-references', $id, count( $references ) ) ) |
252
|
|
|
); |
253
|
|
|
$output .= '<pre>' . $this->outputFormatter->encodeAsJson( $references ) . '</pre>'; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
return $output; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
} |
260
|
|
|
|
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.