1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Specials\Admin; |
4
|
|
|
|
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
use SMW\MediaWiki\Renderer\HtmlFormRenderer; |
7
|
|
|
use SMW\MediaWiki\ManualEntryLogger; |
8
|
|
|
use SMW\MediaWiki\Database; |
9
|
|
|
use SMW\Message; |
10
|
|
|
use SMW\Store; |
11
|
|
|
use Html; |
12
|
|
|
use WebRequest; |
13
|
|
|
use User; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @license GNU GPL v2+ |
17
|
|
|
* @since 2.5 |
18
|
|
|
* |
19
|
|
|
* @author mwjames |
20
|
|
|
*/ |
21
|
|
|
class IdHandlerSection { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Database |
25
|
|
|
*/ |
26
|
|
|
private $connection; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var HtmlFormRenderer |
30
|
|
|
*/ |
31
|
|
|
private $htmlFormRenderer; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var OutputFormatter |
35
|
|
|
*/ |
36
|
|
|
private $outputFormatter; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var boolean |
40
|
|
|
*/ |
41
|
|
|
private $enabledIdDisposal = false; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @since 2.5 |
45
|
3 |
|
* |
46
|
3 |
|
* @param Database $connection |
47
|
3 |
|
* @param HtmlFormRenderer $htmlFormRenderer |
48
|
3 |
|
* @param OutputFormatter $outputFormatter |
49
|
3 |
|
*/ |
50
|
|
|
public function __construct( Database $connection, HtmlFormRenderer $htmlFormRenderer, OutputFormatter $outputFormatter ) { |
51
|
|
|
$this->connection = $connection; |
52
|
|
|
$this->htmlFormRenderer = $htmlFormRenderer; |
53
|
|
|
$this->outputFormatter = $outputFormatter; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
2 |
|
* @since 2.5 |
58
|
|
|
* |
59
|
2 |
|
* @param boolean $enabledIdDisposal |
60
|
2 |
|
*/ |
61
|
|
|
public function enabledIdDisposal( $enabledIdDisposal ) { |
62
|
2 |
|
$this->enabledIdDisposal = (bool)$enabledIdDisposal; |
63
|
|
|
} |
64
|
2 |
|
|
65
|
1 |
|
/** |
66
|
|
|
* @since 2.5 |
67
|
|
|
* |
68
|
2 |
|
* @param WebRequest $webRequest |
69
|
2 |
|
* @param User|null $user |
70
|
|
|
*/ |
71
|
|
|
public function outputActionForm( WebRequest $webRequest, User $user = null ) { |
72
|
|
|
|
73
|
|
|
$this->outputFormatter->setPageTitle( $this->getMessage( 'smw-smwadmin-idlookup-title' ) ); |
74
|
|
|
$this->outputFormatter->addParentLink(); |
75
|
1 |
|
|
76
|
|
|
$id = (int)$webRequest->getText( 'id' ); |
77
|
1 |
|
|
78
|
1 |
|
if ( $this->enabledIdDisposal && $id > 0 && $webRequest->getText( 'dispose' ) === 'yes' ) { |
79
|
|
|
$this->doDispose( $id, $user ); |
80
|
|
|
} |
81
|
1 |
|
|
82
|
|
|
$this->outputFormatter->addHtml( $this->getForm( $webRequest, $id ) ); |
83
|
1 |
|
} |
84
|
1 |
|
|
85
|
1 |
|
/** |
86
|
1 |
|
* @param integer $id |
87
|
|
|
* @param User|null $use |
|
|
|
|
88
|
2 |
|
*/ |
89
|
|
|
private function doDispose( $id, $user = null ) { |
90
|
2 |
|
|
91
|
|
|
$entityIdDisposerJob = ApplicationFactory::getInstance()->newJobFactory()->newEntityIdDisposerJob( |
92
|
2 |
|
\Title::newFromText( __METHOD__ ) |
93
|
1 |
|
); |
94
|
|
|
|
95
|
|
|
$entityIdDisposerJob->executeWith( $id ); |
96
|
2 |
|
|
97
|
2 |
|
$manualEntryLogger = ApplicationFactory::getInstance()->create( 'ManualEntryLogger' ); |
98
|
2 |
|
$manualEntryLogger->registerLoggableEventType( 'admin' ); |
99
|
2 |
|
$manualEntryLogger->log( 'admin', $user, 'Special:SMWAdmin', 'Forced removal of ID '. $id ); |
100
|
2 |
|
} |
101
|
2 |
|
|
102
|
2 |
|
private function getForm( $webRequest, $id ) { |
103
|
2 |
|
|
104
|
2 |
|
$message = $this->getIdInfoAsJson( $webRequest, $id ); |
105
|
|
|
|
106
|
|
|
if ( $id < 1 ) { |
107
|
2 |
|
$id = null; |
108
|
2 |
|
} |
109
|
2 |
|
|
110
|
2 |
|
$html = $this->htmlFormRenderer |
111
|
|
|
->setName( 'idlookup' ) |
112
|
2 |
|
->setMethod( 'get' ) |
113
|
|
|
->addHiddenField( 'action', 'idlookup' ) |
114
|
2 |
|
->addHiddenField( 'id', $id ) |
115
|
|
|
->addParagraph( $this->getMessage( 'smw-sp-admin-idlookup-docu' ) ) |
116
|
|
|
->addInputField( |
117
|
|
|
$this->getMessage( 'smw-sp-admin-objectid' ), |
118
|
|
|
'id', |
119
|
2 |
|
$id |
120
|
2 |
|
) |
121
|
2 |
|
->addNonBreakingSpace() |
122
|
2 |
|
->addSubmitButton( $this->getMessage( 'allpagessubmit' ) ) |
123
|
2 |
|
->addParagraph( $message ) |
124
|
2 |
|
->getForm(); |
125
|
2 |
|
|
126
|
2 |
|
$html .= Html::element( 'p', array(), '' ); |
127
|
2 |
|
|
128
|
2 |
|
if ( $id > 0 && $webRequest->getText( 'dispose' ) == 'yes' ) { |
129
|
|
|
$message = $this->getMessage( array ('smw-sp-admin-iddispose-done', $id ) ); |
|
|
|
|
130
|
2 |
|
$id = null; |
131
|
2 |
|
} |
132
|
2 |
|
|
133
|
2 |
|
if ( !$this->enabledIdDisposal ) { |
134
|
|
|
return $html; |
135
|
2 |
|
} |
136
|
2 |
|
|
137
|
2 |
|
$html .= $this->htmlFormRenderer |
138
|
2 |
|
->setName( 'iddispose' ) |
139
|
2 |
|
->setMethod( 'get' ) |
140
|
2 |
|
->addHiddenField( 'action', 'idlookup' ) |
141
|
|
|
->addHiddenField( 'id', $id ) |
142
|
2 |
|
->addHeader( 'h3', $this->getMessage( 'smw-sp-admin-iddispose-title' ) ) |
143
|
|
|
->addParagraph( $this->getMessage( 'smw-sp-admin-iddispose-docu', Message::PARSE ) ) |
144
|
2 |
|
->addInputField( |
145
|
|
|
$this->getMessage( 'smw-sp-admin-objectid' ), |
146
|
|
|
'id', |
147
|
2 |
|
$id, |
148
|
|
|
null, |
149
|
2 |
|
20, |
150
|
1 |
|
'', |
151
|
|
|
true |
152
|
|
|
) |
153
|
1 |
|
->addNonBreakingSpace() |
154
|
1 |
|
->addSubmitButton( $this->getMessage( 'allpagessubmit' ) ) |
155
|
|
|
->addCheckbox( |
156
|
1 |
|
$this->getMessage( 'smw_smwadmin_datarefreshstopconfirm', Message::ESCAPED ), |
157
|
|
|
'dispose', |
158
|
|
|
'yes' |
159
|
|
|
) |
160
|
|
|
->getForm(); |
161
|
|
|
|
162
|
1 |
|
return $html . Html::element( 'p', array(), '' ); |
163
|
1 |
|
} |
164
|
|
|
|
165
|
|
|
private function getIdInfoAsJson( $webRequest, $id ) { |
166
|
1 |
|
|
167
|
|
|
if ( $id < 1 || $webRequest->getText( 'action' ) !== 'idlookup' ) { |
168
|
|
|
return ''; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$row = $this->connection->selectRow( |
172
|
|
|
\SMWSql3SmwIds::TABLE_NAME, |
173
|
|
|
array( |
174
|
|
|
'smw_title', |
175
|
|
|
'smw_namespace', |
176
|
|
|
'smw_iw', |
177
|
|
|
'smw_subobject', |
178
|
|
|
'smw_sortkey' |
179
|
|
|
), |
180
|
|
|
'smw_id=' . $id, |
181
|
|
|
__METHOD__ |
182
|
|
|
); |
183
|
|
|
|
184
|
|
|
return '<pre>' . $this->outputFormatter->encodeAsJson( array( $id, $row ) ) . '</pre>'; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
private function getMessage( $key, $type = Message::TEXT ) { |
188
|
|
|
return Message::get( $key, $type, Message::USER_LANGUAGE ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
} |
192
|
|
|
|
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.