1 | <?php |
||
15 | class CachedReferenceListOutputRenderer { |
||
16 | |||
17 | /** |
||
18 | * @var ReferenceListOutputRenderer |
||
19 | */ |
||
20 | private $referenceListOutputRenderer; |
||
21 | |||
22 | /** |
||
23 | * @var MediaWikiContextInteractor |
||
24 | */ |
||
25 | private $contextInteractor; |
||
26 | |||
27 | /** |
||
28 | * @var NamespaceExaminer |
||
29 | */ |
||
30 | private $namespaceExaminer; |
||
31 | |||
32 | /** |
||
33 | * @var Cache |
||
34 | */ |
||
35 | private $cache; |
||
36 | |||
37 | /** |
||
38 | * @var CacheKeyProvider |
||
39 | */ |
||
40 | private $cacheKeyProvider; |
||
41 | |||
42 | /** |
||
43 | * @var DIWikiPage |
||
44 | */ |
||
45 | private $subject; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $defaultOptions = array(); |
||
51 | |||
52 | /** |
||
53 | * @since 1.0 |
||
54 | * |
||
55 | * @param ReferenceListOutputRenderer $referenceListOutputRenderer |
||
56 | * @param MediaWikiContextInteractor $contextInteractor |
||
57 | * @param NamespaceExaminer $namespaceExaminer |
||
58 | * @param Cache $cache |
||
59 | * @param CacheKeyProvider $cacheKeyProvider |
||
60 | */ |
||
61 | 13 | public function __construct( ReferenceListOutputRenderer $referenceListOutputRenderer, MediaWikiContextInteractor $contextInteractor, NamespaceExaminer $namespaceExaminer, Cache $cache, CacheKeyProvider $cacheKeyProvider ) { |
|
62 | 13 | $this->referenceListOutputRenderer = $referenceListOutputRenderer; |
|
63 | 13 | $this->contextInteractor = $contextInteractor; |
|
64 | 13 | $this->namespaceExaminer = $namespaceExaminer; |
|
65 | 13 | $this->cache = $cache; |
|
66 | 13 | $this->cacheKeyProvider = $cacheKeyProvider; |
|
67 | 13 | } |
|
68 | |||
69 | /** |
||
70 | * @since 1.0 |
||
71 | * |
||
72 | * @return DIWikiPage |
||
73 | */ |
||
74 | 11 | public function getSubject() { |
|
75 | |||
76 | 11 | if ( $this->subject === null ) { |
|
77 | 11 | $this->subject = DIWikiPage::newFromTitle( $this->contextInteractor->getTitle() ); |
|
78 | 11 | } |
|
79 | |||
80 | 11 | return $this->subject; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * @since 1.0 |
||
85 | * |
||
86 | * @param string &$text |
||
87 | */ |
||
88 | 12 | public function addReferenceListToText( &$text ) { |
|
100 | |||
101 | 2 | private function removeReferenceListPlaceholder( &$text ) { |
|
102 | |||
113 | |||
114 | 10 | private function addReferenceListToCorrectTextPosition( &$text ) { |
|
115 | |||
116 | // Remember the default options before trying to replace all list |
||
117 | // placeholders to ensure to reset options to the default option |
||
118 | // for when a list doesn't specify an option |
||
119 | 10 | $this->defaultOptions = array( |
|
120 | 10 | 'listtype' => $this->referenceListOutputRenderer->getReferenceListType(), |
|
121 | 10 | 'columns' => $this->referenceListOutputRenderer->getNumberOfReferenceListColumns(), |
|
122 | 10 | 'browse' => $this->referenceListOutputRenderer->getBrowseLinkToCitationResourceState() |
|
123 | 10 | ); |
|
124 | |||
125 | // Find out whether to place the list into a custom position or not |
||
126 | 10 | if ( strpos( $text, 'scite-custom-referencelist' ) !== false ) { |
|
127 | 5 | return $text = preg_replace_callback( |
|
128 | 5 | "/" . "<div id=\"scite-custom-referencelist\"(.*)?>(<h2>|<span>)(.*)?<\/div>" . "/m", |
|
129 | 5 | 'self::getCustomizedRenderedHtmlReferenceList', |
|
130 | $text |
||
131 | 5 | ); |
|
132 | } |
||
133 | |||
134 | 5 | if ( $this->contextInteractor->getTitle()->getNamespace() !== NS_FILE ) { |
|
135 | 4 | $text .= $this->getRenderedHtmlReferenceList(); |
|
136 | 4 | } |
|
137 | 5 | } |
|
138 | |||
139 | 5 | private function getCustomizedRenderedHtmlReferenceList( $customOptions ) { |
|
166 | |||
167 | 5 | private function searchForReferenceListHeaderTocId( array $options ) { |
|
181 | |||
182 | 4 | private function doFilterValidOption( $options, &$references, &$fingerprint ) { |
|
213 | |||
214 | 9 | private function getRenderedHtmlReferenceList( $references = '', $fingerprint = '' ) { |
|
262 | |||
263 | } |
||
264 |