|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SCI; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\Query\Language\SomeProperty; |
|
|
|
|
|
|
6
|
|
|
use SMW\Query\Language\ValueDescription; |
|
|
|
|
|
|
7
|
|
|
use SMW\Query\PrintRequest; |
|
|
|
|
|
|
8
|
|
|
use SMW\Store; |
|
|
|
|
|
|
9
|
|
|
use SMW\DIProperty; |
|
|
|
|
|
|
10
|
|
|
use SMW\DataValues\PropertyValue; |
|
|
|
|
|
|
11
|
|
|
use SMWQuery as Query; |
|
|
|
|
|
|
12
|
|
|
use SMWDIBlob as DIBlob; |
|
|
|
|
|
|
13
|
|
|
use SMW\DataValueFactory; |
|
|
|
|
|
|
14
|
|
|
use SMW\Query\QueryResult; |
|
|
|
|
|
|
15
|
|
|
use SMWInfolink; |
|
|
|
|
|
|
16
|
|
|
use SCI\DataValues\ResourceIdentifierFactory; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @license GNU GPL v2+ |
|
20
|
|
|
* @since 2.2 |
|
21
|
|
|
* |
|
22
|
|
|
* @author mwjames |
|
23
|
|
|
*/ |
|
24
|
|
|
class CitationResourceMatchFinder { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Store |
|
28
|
|
|
*/ |
|
29
|
|
|
private $store; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var DataValueFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
private $dataValueFactory; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @since 1.0 |
|
38
|
|
|
* |
|
39
|
16 |
|
* @param Store $store |
|
40
|
16 |
|
*/ |
|
41
|
16 |
|
public function __construct( Store $store ) { |
|
42
|
16 |
|
$this->store = $store; |
|
43
|
|
|
$this->dataValueFactory = DataValueFactory::getInstance(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @since 1.0 |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $subjects |
|
50
|
|
|
* @param string $linkClass |
|
51
|
|
|
* |
|
52
|
1 |
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function findCitationResourceLinks( array $subjects, $linkClass = '', $caption = '' ) { |
|
55
|
|
|
|
|
56
|
1 |
|
$citationResourceLinks = []; |
|
57
|
|
|
|
|
58
|
1 |
|
foreach ( $subjects as $subject ) { |
|
59
|
1 |
|
|
|
60
|
1 |
|
$dataValue = $this->dataValueFactory->newDataItemValue( |
|
61
|
|
|
$subject, |
|
62
|
|
|
null |
|
63
|
1 |
|
); |
|
64
|
1 |
|
|
|
65
|
1 |
|
$browselink = SMWInfolink::newBrowsingLink( |
|
66
|
1 |
|
$caption, |
|
67
|
|
|
$dataValue->getWikiValue(), |
|
68
|
|
|
$linkClass |
|
69
|
1 |
|
); |
|
70
|
|
|
|
|
71
|
|
|
$citationResourceLinks[] = $browselink->getHTML(); |
|
72
|
1 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $citationResourceLinks; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Find match for [[OCLC::SomeOclcKey]] |
|
79
|
|
|
* |
|
80
|
|
|
* @since 1.0 |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $type |
|
83
|
|
|
* @param string|null $id |
|
84
|
|
|
* |
|
85
|
6 |
|
* @return array |
|
86
|
|
|
*/ |
|
87
|
6 |
|
public function findMatchForResourceIdentifierTypeToValue( $type, $id = null ) { |
|
88
|
|
|
|
|
89
|
|
|
if ( $id === null || $id === '' ) { |
|
90
|
|
|
return []; |
|
91
|
6 |
|
} |
|
92
|
|
|
|
|
93
|
6 |
|
$resourceIdentifierFactory = new ResourceIdentifierFactory(); |
|
94
|
6 |
|
|
|
95
|
6 |
|
$resourceIdentifierStringValue = $resourceIdentifierFactory->newResourceIdentifierStringValueForType( $type ); |
|
96
|
|
|
$resourceIdentifierStringValue->setUserValue( $id ); |
|
97
|
6 |
|
$id = $resourceIdentifierStringValue->getWikiValue(); |
|
98
|
6 |
|
|
|
99
|
6 |
|
$description = new SomeProperty( |
|
100
|
|
|
$resourceIdentifierStringValue->getProperty(), |
|
101
|
|
|
new ValueDescription( new DIBlob( $id ) ) |
|
102
|
6 |
|
); |
|
103
|
6 |
|
|
|
104
|
6 |
|
$query = new Query( |
|
105
|
6 |
|
$description, |
|
106
|
|
|
false, |
|
107
|
|
|
false |
|
108
|
6 |
|
); |
|
109
|
6 |
|
|
|
110
|
|
|
$query->querymode = Query::MODE_INSTANCES; |
|
111
|
6 |
|
$query->setLimit( 10 ); |
|
112
|
6 |
|
|
|
113
|
|
|
if ( defined( 'SMWQuery::NO_CACHE' ) ) { |
|
114
|
|
|
$query->setOption( Query::NO_CACHE, true ); |
|
115
|
6 |
|
} |
|
116
|
6 |
|
|
|
117
|
|
|
if ( defined( 'SMWQuery::PROC_CONTEXT' ) ) { |
|
118
|
|
|
$query->setOption( Query::PROC_CONTEXT, 'SCI.CitationResourceMatchFinder' ); |
|
119
|
6 |
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $this->store->getQueryResult( $query )->getResults(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @since 1.0 |
|
126
|
|
|
* |
|
127
|
|
|
* @param string $citationReference |
|
128
|
|
|
* |
|
129
|
8 |
|
* @return array |
|
130
|
|
|
*/ |
|
131
|
8 |
|
public function findCitationTextFor( $citationReference ) { |
|
132
|
8 |
|
|
|
133
|
|
|
$text = ''; |
|
134
|
8 |
|
$subjects = []; |
|
135
|
8 |
|
|
|
136
|
|
|
$queryResult = $this->findMatchForCitationReference( |
|
137
|
|
|
$citationReference |
|
138
|
8 |
|
); |
|
139
|
|
|
|
|
140
|
|
|
if ( !$queryResult instanceof QueryResult ) { |
|
141
|
|
|
return [ $subjects, $text ]; |
|
142
|
8 |
|
} |
|
143
|
8 |
|
|
|
144
|
|
|
while ( $resultArray = $queryResult->getNext() ) { |
|
145
|
|
|
foreach ( $resultArray as $result ) { |
|
146
|
|
|
|
|
147
|
|
|
// Collect all subjects for the same reference because it can happen |
|
148
|
|
|
// that the same reference key is used for different citation |
|
149
|
8 |
|
// resources therefore only return one (the last) valid citation |
|
150
|
|
|
// text but return all subjects to make it easier to find them later |
|
151
|
8 |
|
$subjects[] = $result->getResultSubject(); |
|
152
|
8 |
|
|
|
153
|
|
|
while ( ( $dataValue = $result->getNextDataValue() ) !== false ) { |
|
154
|
|
|
$text = $dataValue->getShortWikiText(); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
8 |
|
} |
|
158
|
|
|
|
|
159
|
|
|
return [ $subjects, $text ]; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Find match for [[Citation key::SomeKey]]|?Citation text |
|
164
|
|
|
* |
|
165
|
|
|
* @since 1.0 |
|
166
|
|
|
* |
|
167
|
|
|
* @param string $citationReference |
|
168
|
|
|
* |
|
169
|
8 |
|
* @return QueryResult |
|
170
|
|
|
*/ |
|
171
|
8 |
|
public function findMatchForCitationReference( $citationReference ) { |
|
172
|
8 |
|
|
|
173
|
8 |
|
$description = new SomeProperty( |
|
174
|
|
|
new DIProperty( PropertyRegistry::SCI_CITE_KEY ), |
|
175
|
|
|
new ValueDescription( new DIBlob( $citationReference ) ) |
|
176
|
8 |
|
); |
|
177
|
8 |
|
|
|
178
|
8 |
|
$propertyValue = $this->dataValueFactory->newDataValueByType( '__pro' ); |
|
179
|
|
|
$propertyValue->setDataItem( |
|
180
|
|
|
new DIProperty( PropertyRegistry::SCI_CITE_TEXT ) |
|
181
|
8 |
|
); |
|
182
|
8 |
|
|
|
183
|
|
|
$description->addPrintRequest( |
|
184
|
|
|
new PrintRequest( PrintRequest::PRINT_PROP, null, $propertyValue ) |
|
185
|
8 |
|
); |
|
186
|
8 |
|
|
|
187
|
8 |
|
$query = new Query( |
|
188
|
8 |
|
$description, |
|
189
|
|
|
false, |
|
190
|
|
|
false |
|
191
|
8 |
|
); |
|
192
|
8 |
|
|
|
193
|
|
|
$query->querymode = Query::MODE_INSTANCES; |
|
194
|
8 |
|
$query->setLimit( 10 ); |
|
195
|
8 |
|
|
|
196
|
|
|
if ( defined( 'SMWQuery::PROC_CONTEXT' ) ) { |
|
197
|
|
|
$query->setOption( Query::PROC_CONTEXT, 'SCI.CitationResourceMatchFinder' ); |
|
198
|
8 |
|
} |
|
199
|
|
|
|
|
200
|
|
|
return $this->store->getQueryResult( $query ); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
} |
|
204
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths