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