Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
10 / 12 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| SpecialPageHtmlFragment | |
83.33% |
10 / 12 |
|
85.71% |
6 / 7 |
9.37 | |
0.00% |
0 / 1 |
| __construct | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
3.33 | |||
| 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\Message\Message; |
| 9 | use MediaWiki\Output\OutputPage; |
| 10 | use MediaWiki\SpecialPage\SpecialPage; |
| 11 | use MediaWiki\Title\Title; |
| 12 | use MediaWiki\User\User; |
| 13 | use MessageLocalizer; |
| 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 | * @param SpecialPage|self $specialPage |
| 34 | */ |
| 35 | final public function __construct( $specialPage ) { |
| 36 | if ( $specialPage instanceof self ) { |
| 37 | $specialPage = $specialPage->specialPage; |
| 38 | } elseif ( !( $specialPage instanceof SpecialPage ) ) { |
| 39 | throw new \InvalidArgumentException( |
| 40 | '$specialPage must be a SpecialPage or SpecialPageHtmlFragment' ); |
| 41 | } |
| 42 | |
| 43 | $this->specialPage = $specialPage; |
| 44 | } |
| 45 | |
| 46 | protected function getPageTitle(): Title { |
| 47 | return $this->specialPage->getPageTitle(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @return IContextSource|MutableContext |
| 52 | */ |
| 53 | protected function getContext() { |
| 54 | return $this->specialPage->getContext(); |
| 55 | } |
| 56 | |
| 57 | protected function getOutput(): OutputPage { |
| 58 | return $this->getContext()->getOutput(); |
| 59 | } |
| 60 | |
| 61 | protected function getUser(): User { |
| 62 | return $this->getContext()->getUser(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return Language |
| 67 | */ |
| 68 | protected function getLanguage() { |
| 69 | return $this->getContext()->getLanguage(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @see MessageLocalizer::msg |
| 74 | * |
| 75 | * @param string|string[]|MessageSpecifier $key |
| 76 | * @param mixed ...$params Any number of message parameters |
| 77 | */ |
| 78 | public function msg( $key, ...$params ): Message { |
| 79 | return $this->getContext()->msg( $key, ...$params ); |
| 80 | } |
| 81 | |
| 82 | } |