|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WikibaseQuality\ExternalValidation\Specials; |
|
4
|
|
|
|
|
5
|
|
|
use Html; |
|
6
|
|
|
use Language; |
|
7
|
|
|
use Linker; |
|
8
|
|
|
use SpecialPage; |
|
9
|
|
|
use Wikibase\DataModel\Services\Lookup\LanguageLabelDescriptionLookup; |
|
10
|
|
|
use Wikibase\DataModel\Services\Lookup\TermLookup; |
|
11
|
|
|
use Wikibase\Repo\EntityIdHtmlLinkFormatterFactory; |
|
12
|
|
|
use Wikibase\Repo\WikibaseRepo; |
|
13
|
|
|
use WikibaseQuality\ExternalValidation\DumpMetaInformation\DumpMetaInformation; |
|
14
|
|
|
use WikibaseQuality\ExternalValidation\DumpMetaInformation\DumpMetaInformationLookup; |
|
15
|
|
|
use WikibaseQuality\ExternalValidation\DumpMetaInformation\SqlDumpMetaInformationRepo; |
|
16
|
|
|
use WikibaseQuality\ExternalValidation\ExternalValidationServices; |
|
17
|
|
|
use WikibaseQuality\Html\HtmlTableBuilder; |
|
18
|
|
|
use WikibaseQuality\Html\HtmlTableCellBuilder; |
|
19
|
|
|
|
|
20
|
|
|
class SpecialExternalDatabases extends SpecialPage { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var EntityIdHtmlLinkFormatterFactory |
|
24
|
|
|
*/ |
|
25
|
|
|
private $entityIdLinkFormatter; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var SqlDumpMetaInformationRepo |
|
29
|
|
|
*/ |
|
30
|
|
|
private $dumpMetaInformationRepo; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Creates new instance from global state. |
|
34
|
|
|
* |
|
35
|
|
|
* @return self |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function newFromGlobalState() { |
|
38
|
|
|
$repo = WikibaseRepo::getDefaultInstance(); |
|
39
|
|
|
$externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
|
40
|
|
|
|
|
41
|
|
|
return new self( |
|
42
|
|
|
$repo->getTermLookup(), |
|
43
|
|
|
$repo->getEntityIdHtmlLinkFormatterFactory(), |
|
44
|
|
|
$externalValidationServices->getDumpMetaInformationLookup() |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param TermLookup $termLookup |
|
50
|
|
|
* @param EntityIdHtmlLinkFormatterFactory $entityIdHtmlLinkFormatterFactory |
|
51
|
|
|
* @param DumpMetaInformationLookup $dumpMetaInformationRepo |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct( |
|
54
|
|
|
TermLookup $termLookup, |
|
55
|
|
|
EntityIdHtmlLinkFormatterFactory $entityIdHtmlLinkFormatterFactory, |
|
56
|
|
|
DumpMetaInformationLookup $dumpMetaInformationRepo ) { |
|
57
|
|
|
parent::__construct( 'ExternalDatabases' ); |
|
58
|
|
|
|
|
59
|
|
|
$this->entityIdLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( |
|
60
|
|
|
new LanguageLabelDescriptionLookup( $termLookup, $this->getLanguage()->getCode() ) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$this->dumpMetaInformationRepo = $dumpMetaInformationRepo; |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @see SpecialPage::getGroupName |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
function getGroupName() { |
|
|
|
|
|
|
72
|
|
|
return 'wikibasequality'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @see SpecialPage::getDescription |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getDescription() { |
|
81
|
|
|
return $this->msg( 'wbqev-externaldbs' )->text(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @see SpecialPage::execute |
|
86
|
|
|
* |
|
87
|
|
|
* @param string|null $subPage |
|
88
|
|
|
*/ |
|
89
|
|
|
public function execute( $subPage ) { |
|
90
|
|
|
$out = $this->getOutput(); |
|
91
|
|
|
|
|
92
|
|
|
$this->setHeaders(); |
|
93
|
|
|
|
|
94
|
|
|
$out->addHTML( |
|
95
|
|
|
Html::openElement( 'p' ) |
|
96
|
|
|
. $this->msg( 'wbqev-externaldbs-instructions' )->parse() |
|
97
|
|
|
. Html::closeElement( 'p' ) |
|
98
|
|
|
. Html::openElement( 'h3' ) |
|
99
|
|
|
. $this->msg( 'wbqev-externaldbs-overview-headline' )->parse() |
|
100
|
|
|
. Html::closeElement( 'h3' ) |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$dumps = $this->dumpMetaInformationRepo->getAll(); |
|
104
|
|
|
if ( count( $dumps ) > 0 ) { |
|
105
|
|
|
$groupedDumpMetaInformation = array(); |
|
106
|
|
|
foreach ( $dumps as $dump ) { |
|
|
|
|
|
|
107
|
|
|
$sourceItemId = $dump->getSourceItemId()->getSerialization(); |
|
108
|
|
|
$groupedDumpMetaInformation[$sourceItemId][] = $dump; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$table = new HtmlTableBuilder( |
|
112
|
|
|
array( |
|
113
|
|
|
$this->msg( 'wbqev-externaldbs-name' )->escaped(), |
|
114
|
|
|
$this->msg( 'wbqev-externaldbs-id' )->escaped(), |
|
115
|
|
|
$this->msg( 'wbqev-externaldbs-import-date' )->escaped(), |
|
116
|
|
|
$this->msg( 'wbqev-externaldbs-language' )->escaped(), |
|
117
|
|
|
$this->msg( 'wbqev-externaldbs-source-urls' )->escaped(), |
|
118
|
|
|
$this->msg( 'wbqev-externaldbs-size' )->escaped(), |
|
119
|
|
|
$this->msg( 'wbqev-externaldbs-license' )->escaped() |
|
120
|
|
|
), |
|
121
|
|
|
true |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
|
|
foreach ( $groupedDumpMetaInformation as $dumpMetaInformation ) { |
|
125
|
|
|
$table->appendRows( $this->getRowGroup( $dumpMetaInformation ) ); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$out->addHTML( $table->toHtml() ); |
|
129
|
|
|
} else { |
|
130
|
|
|
$out->addHTML( |
|
131
|
|
|
Html::openElement( 'p' ) |
|
132
|
|
|
. $this->msg( 'wbqev-externaldbs-no-databases' )->escaped() |
|
133
|
|
|
. Html::closeElement( 'p' ) |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Build grouped rows for dump meta information with same source item id |
|
140
|
|
|
* |
|
141
|
|
|
* @param DumpMetaInformation[] $dumpMetaInformationGroup |
|
142
|
|
|
* |
|
143
|
|
|
* @return array |
|
144
|
|
|
*/ |
|
145
|
|
|
private function getRowGroup( array $dumpMetaInformationGroup ) { |
|
146
|
|
|
$rows = array(); |
|
147
|
|
|
|
|
148
|
|
|
foreach ( $dumpMetaInformationGroup as $dumpMetaInformation ) { |
|
149
|
|
|
$dumpId = $dumpMetaInformation->getDumpId(); |
|
150
|
|
|
$importDate = $this->getLanguage()->timeanddate( $dumpMetaInformation->getImportDate() ); |
|
151
|
|
|
$language = Language::fetchLanguageName( |
|
152
|
|
|
$dumpMetaInformation->getLanguageCode(), |
|
153
|
|
|
$this->getLanguage()->getCode() |
|
154
|
|
|
); |
|
155
|
|
|
$sourceUrl = Linker::makeExternalLink( |
|
156
|
|
|
$dumpMetaInformation->getSourceUrl(), |
|
157
|
|
|
$dumpMetaInformation->getSourceUrl() |
|
158
|
|
|
); |
|
159
|
|
|
$size = $this->getLanguage()->formatSize( $dumpMetaInformation->getSize() ); |
|
160
|
|
|
$license = $this->entityIdLinkFormatter->formatEntityId( $dumpMetaInformation->getLicenseItemId() ); |
|
161
|
|
|
$rows[] = array( |
|
162
|
|
|
new HtmlTableCellBuilder( $dumpId ), |
|
163
|
|
|
new HtmlTableCellBuilder( $importDate ), |
|
164
|
|
|
new HtmlTableCellBuilder( $language ), |
|
165
|
|
|
new HtmlTableCellBuilder( $sourceUrl, array(), true ), |
|
166
|
|
|
new HtmlTableCellBuilder( $size ), |
|
167
|
|
|
new HtmlTableCellBuilder( $license, array(), true ) |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
array_unshift( |
|
172
|
|
|
$rows[0], |
|
173
|
|
|
new HtmlTableCellBuilder( |
|
174
|
|
|
$this->entityIdLinkFormatter->formatEntityId( $dumpMetaInformationGroup[0]->getSourceItemId() ), |
|
175
|
|
|
array( 'rowspan' => (string)count( $dumpMetaInformationGroup ) ), |
|
176
|
|
|
true |
|
177
|
|
|
) |
|
178
|
|
|
); |
|
179
|
|
|
|
|
180
|
|
|
return $rows; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.