Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| SpecialPageHtmlFragment | |
100.00% |
7 / 7 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| getPageTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getContext | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOutput | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLanguage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| msg | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace FileImporter\Html; |
| 4 | |
| 5 | use MediaWiki\Context\IContextSource; |
| 6 | use MediaWiki\Context\MutableContext; |
| 7 | use MediaWiki\Language\Language; |
| 8 | use MediaWiki\Language\MessageLocalizer; |
| 9 | use MediaWiki\Message\Message; |
| 10 | use MediaWiki\Output\OutputPage; |
| 11 | use MediaWiki\SpecialPage\SpecialPage; |
| 12 | use MediaWiki\Title\Title; |
| 13 | use MediaWiki\User\User; |
| 14 | use Wikimedia\Message\MessageSpecifier; |
| 15 | |
| 16 | /** |
| 17 | * Common framework for classes providing HTML fragments (similar to |
| 18 | * {@see https://developer.mozilla.org/de/docs/Web/API/Document/createDocumentFragment}) that are |
| 19 | * meant to be shown on a special page. Implementations should have a `getHtml` method with as many |
| 20 | * arguments as needed. |
| 21 | * |
| 22 | * @license GPL-2.0-or-later |
| 23 | * @author Thiemo Kreuz |
| 24 | */ |
| 25 | abstract class SpecialPageHtmlFragment implements MessageLocalizer { |
| 26 | |
| 27 | private SpecialPage $specialPage; |
| 28 | |
| 29 | /** |
| 30 | * Implementations should not have a constructor, but provide whatever is needed as arguments to |
| 31 | * their `getHtml` method. |
| 32 | */ |
| 33 | public function __construct( |
| 34 | SpecialPage|self $specialPage, |
| 35 | ) { |
| 36 | $this->specialPage = $specialPage instanceof self ? $specialPage->specialPage : $specialPage; |
| 37 | } |
| 38 | |
| 39 | protected function getPageTitle(): Title { |
| 40 | return $this->specialPage->getPageTitle(); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @return IContextSource|MutableContext |
| 45 | */ |
| 46 | protected function getContext() { |
| 47 | return $this->specialPage->getContext(); |
| 48 | } |
| 49 | |
| 50 | protected function getOutput(): OutputPage { |
| 51 | return $this->getContext()->getOutput(); |
| 52 | } |
| 53 | |
| 54 | protected function getUser(): User { |
| 55 | return $this->getContext()->getUser(); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return Language |
| 60 | */ |
| 61 | protected function getLanguage() { |
| 62 | return $this->getContext()->getLanguage(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @see MessageLocalizer::msg |
| 67 | * |
| 68 | * @param string|string[]|MessageSpecifier $key |
| 69 | * @param mixed ...$params Any number of message parameters |
| 70 | */ |
| 71 | public function msg( $key, ...$params ): Message { |
| 72 | return $this->getContext()->msg( $key, ...$params ); |
| 73 | } |
| 74 | |
| 75 | } |