1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Contains the class creating the OutputPageParserOutput hook callback. |
4
|
|
|
* |
5
|
|
|
* @copyright (C) 2018, Tobias Oetterer, Paderborn University |
6
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3 (or later) |
7
|
|
|
* |
8
|
|
|
* This file is part of the MediaWiki extension BootstrapComponents. |
9
|
|
|
* The BootstrapComponents extension is free software: you can redistribute it |
10
|
|
|
* and/or modify it under the terms of the GNU General Public License as published |
11
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* The BootstrapComponents extension is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
* @file |
23
|
|
|
* @ingroup BootstrapComponents |
24
|
|
|
* @author Tobias Oetterer |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace BootstrapComponents\Hooks; |
28
|
|
|
|
29
|
|
|
use \BootstrapComponents\ApplicationFactory; |
30
|
|
|
use \BootstrapComponents\ParserOutputHelper; |
31
|
|
|
use \OutputPage; |
32
|
|
|
use \ParserOutput; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class OutputPageParserOutput |
36
|
|
|
* |
37
|
|
|
* Called after parse, before the HTML is added to the output. |
38
|
|
|
* |
39
|
|
|
* Method delegated to separate class to fix missing (deferred) content in |
40
|
|
|
* {@see \BootstrapComponents\Tests\Integration\BootstrapComponentsJsonTestCaseScriptRunnerTest::assertParserOutputForCase} |
41
|
|
|
* |
42
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageParserOutput |
43
|
|
|
* |
44
|
|
|
* @since 1.2 |
45
|
|
|
*/ |
46
|
|
|
class OutputPageParserOutput { |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var OutputPage $outputPage |
50
|
|
|
*/ |
51
|
|
|
private $outputPage; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var ParserOutput $parserOutput |
55
|
|
|
*/ |
56
|
|
|
private $parserOutput; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var ParserOutputHelper $parserOutputHelper |
60
|
|
|
*/ |
61
|
|
|
private $parserOutputHelper; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* OutputPageParserOutput constructor. |
65
|
|
|
* |
66
|
|
|
* @param OutputPage $outputPage |
67
|
|
|
* @param ParserOutput $parserOutput |
68
|
|
|
* @param ParserOutputHelper $parserOutputHelper |
69
|
|
|
*/ |
70
|
22 |
|
public function __construct( &$outputPage, $parserOutput, &$parserOutputHelper = null ) { |
71
|
22 |
|
$this->outputPage = $outputPage; |
72
|
22 |
|
$this->parserOutput = $parserOutput; |
73
|
22 |
|
if ( is_null( $parserOutputHelper ) ) { |
74
|
20 |
|
$parserOutputHelper = ApplicationFactory::getInstance()->getParserOutputHelper(); |
75
|
20 |
|
} |
76
|
|
|
|
77
|
22 |
|
$this->parserOutputHelper = $parserOutputHelper; |
78
|
22 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
21 |
|
public function process() { |
84
|
21 |
|
$text = $this->getParserOutput()->getText(); |
85
|
21 |
|
$text .= $this->getParserOutputHelper()->getContentForLaterInjection( |
86
|
21 |
|
$this->getParserOutput() |
87
|
21 |
|
); |
88
|
21 |
|
$this->getParserOutput()->setText( $text ); |
89
|
|
|
|
90
|
21 |
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return \OutputPage |
95
|
|
|
*/ |
96
|
|
|
protected function getOutputPage() { |
97
|
|
|
return $this->outputPage; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return \ParserOutput |
102
|
|
|
*/ |
103
|
21 |
|
protected function getParserOutput() { |
104
|
21 |
|
return $this->parserOutput; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return ParserOutputHelper |
109
|
|
|
*/ |
110
|
21 |
|
protected function getParserOutputHelper() { |
111
|
21 |
|
return $this->parserOutputHelper; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|