|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SCI\Specials; |
|
4
|
|
|
|
|
5
|
|
|
use MediaWiki\MediaWikiServices; |
|
|
|
|
|
|
6
|
|
|
use SpecialPage; |
|
|
|
|
|
|
7
|
|
|
use SMW\Services\ServicesFactory as ApplicationFactory; |
|
|
|
|
|
|
8
|
|
|
use Onoi\HttpRequest\HttpRequestFactory; |
|
9
|
|
|
use SCI\FilteredMetadata\HttpResponseParserFactory; |
|
10
|
|
|
use SCI\CitationResourceMatchFinder; |
|
11
|
|
|
use SCI\Specials\CitableMetadata\PageBuilder; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
* |
|
17
|
|
|
* @author mwjames |
|
18
|
|
|
*/ |
|
19
|
|
|
class SpecialFindCitableMetadata extends SpecialPage { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @codeCoverageIgnore |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct() { |
|
25
|
|
|
parent::__construct( 'FindCitableMetadata', 'sci-metadatasearch' ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @see SpecialPage::getGroupName |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function getGroupName() { |
|
32
|
|
|
return 'wiki'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @see SpecialPage::execute |
|
37
|
2 |
|
*/ |
|
38
|
|
|
public function execute( $query ) { |
|
39
|
2 |
|
|
|
40
|
|
|
if ( !$this->userCanExecute( $this->getUser() ) ) { |
|
41
|
|
|
$this->displayRestrictionError(); |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
2 |
|
|
|
45
|
2 |
|
$output = $this->getOutput(); |
|
46
|
2 |
|
$output->setPageTitle( $this->msg( 'findmetadatabyid' )->text() ); |
|
47
|
|
|
$this->setHeaders(); |
|
48
|
2 |
|
|
|
49
|
|
|
$output->addModuleStyles( 'ext.scite.styles' ); |
|
50
|
2 |
|
|
|
51
|
|
|
$output->addModules( |
|
52
|
2 |
|
[ |
|
53
|
|
|
'ext.scite.metadata' |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
2 |
|
|
|
57
|
2 |
|
list( $type, $id, $format ) = $this->getRequestParameters( |
|
58
|
|
|
$query |
|
59
|
|
|
); |
|
60
|
2 |
|
|
|
61
|
|
|
if ( $type === 'pmid' ) { |
|
62
|
|
|
$type = 'pubmed'; |
|
63
|
|
|
} |
|
64
|
2 |
|
|
|
65
|
2 |
|
$this->callPageBuilderFor( $type, $id, $format ); |
|
66
|
|
|
} |
|
67
|
2 |
|
|
|
68
|
|
|
private function callPageBuilderFor( $type, $id, $format ) { |
|
69
|
2 |
|
|
|
70
|
|
|
$pageBuilder = $this->newPageBuilder(); |
|
71
|
2 |
|
|
|
72
|
|
|
if ( $format === 'raw' ) { |
|
73
|
|
|
$this->getOutput()->disable(); |
|
74
|
|
|
header( "Content-type: text/plain; charset=utf-8" ); |
|
75
|
|
|
header( 'Cache-Control: private, no-cache, must-revalidate' ); |
|
76
|
|
|
|
|
77
|
|
|
$html = $pageBuilder->getRawResponseFor( |
|
78
|
|
|
$type, $id |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
return print $html; |
|
82
|
|
|
} |
|
83
|
2 |
|
|
|
84
|
2 |
|
$html = $pageBuilder->getHtmlFor( |
|
85
|
|
|
$type, $id |
|
86
|
|
|
); |
|
87
|
2 |
|
|
|
88
|
2 |
|
$this->getOutput()->addHTML( $html ); |
|
89
|
2 |
|
$this->addExternalHelpLinkFor( 'sci-specials-citablemetadata-helplink' ); |
|
90
|
|
|
} |
|
91
|
2 |
|
|
|
92
|
|
|
private function getRequestParameters( $query ) { |
|
93
|
2 |
|
|
|
94
|
|
|
$request = $this->getRequest()->getValues(); |
|
95
|
2 |
|
|
|
96
|
1 |
|
if ( strpos( $query, '/' ) !== false ) { |
|
97
|
1 |
|
list( $type, $id ) = explode( '/', $query, 2 ); |
|
98
|
1 |
|
$request['type'] = $type; |
|
99
|
|
|
$request['id'] = $id; |
|
100
|
|
|
} |
|
101
|
2 |
|
|
|
102
|
2 |
|
$id = isset( $request['id'] ) ? trim( $request['id'] ) : ''; |
|
103
|
2 |
|
$type = isset( $request['type'] ) ? strtolower( $request['type'] ) : ''; |
|
104
|
|
|
$format = isset( $request['format'] ) ? strtolower( $request['format'] ) : ''; |
|
105
|
2 |
|
|
|
106
|
|
|
return [ $type, $id, $format ]; |
|
107
|
|
|
} |
|
108
|
2 |
|
|
|
109
|
|
|
private function newPageBuilder() { |
|
110
|
2 |
|
|
|
111
|
2 |
|
$applicationFactory = ApplicationFactory::getInstance(); |
|
112
|
|
|
$mwCollaboratorFactory = $applicationFactory->newMwCollaboratorFactory(); |
|
113
|
2 |
|
|
|
114
|
2 |
|
$htmlFormRenderer = $mwCollaboratorFactory->newHtmlFormRenderer( |
|
115
|
2 |
|
$this->getContext()->getTitle(), |
|
116
|
|
|
$this->getLanguage() |
|
117
|
|
|
); |
|
118
|
2 |
|
|
|
119
|
2 |
|
$httpRequestFactory = new HttpRequestFactory( |
|
120
|
|
|
$applicationFactory->newCacheFactory()->newMediaWikiCompositeCache( $GLOBALS['scigMetadataResponseCacheType'] ) |
|
121
|
|
|
); |
|
122
|
2 |
|
|
|
123
|
2 |
|
$httpRequest = $httpRequestFactory->newCachedCurlRequest(); |
|
124
|
2 |
|
$httpRequest->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, $GLOBALS['scigMetadataResponseCacheLifetime'] ); |
|
125
|
|
|
$httpRequest->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, $GLOBALS['scigCachePrefix'] . ':sci:meta:' ); |
|
126
|
2 |
|
|
|
127
|
2 |
|
$pageBuilder = new PageBuilder( |
|
128
|
2 |
|
$htmlFormRenderer, |
|
129
|
2 |
|
$mwCollaboratorFactory->newHtmlColumnListRenderer(), |
|
130
|
2 |
|
new CitationResourceMatchFinder( $applicationFactory->getStore() ), |
|
131
|
|
|
new HttpResponseParserFactory( $httpRequest ) |
|
132
|
|
|
); |
|
133
|
2 |
|
|
|
134
|
|
|
$pageBuilder->isReadOnly( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ); |
|
135
|
2 |
|
|
|
136
|
|
|
return $pageBuilder; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* FIXME MW 1.25 |
|
141
|
2 |
|
*/ |
|
142
|
|
|
private function addExternalHelpLinkFor( $key ) { |
|
143
|
2 |
|
|
|
144
|
|
|
if ( !method_exists( $this, 'addHelpLink' ) ) { |
|
145
|
|
|
return null; |
|
146
|
|
|
} |
|
147
|
2 |
|
|
|
148
|
2 |
|
$this->getOutput()->addHelpLink( wfMessage( $key )->escaped(), true ); |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
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