Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| HelpBanner | |
0.00% |
0 / 40 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| shouldHelpBannerBeShown | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getHtml | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace FileImporter\Html; |
| 4 | |
| 5 | use FileImporter\FileImporterUtils; |
| 6 | use MediaWiki\Html\Html; |
| 7 | use MediaWiki\MediaWikiServices; |
| 8 | use MediaWiki\User\Options\UserOptionsLookup; |
| 9 | use OOUI\HtmlSnippet; |
| 10 | use OOUI\IconWidget; |
| 11 | use OOUI\MessageWidget; |
| 12 | |
| 13 | /** |
| 14 | * @license GPL-2.0-or-later |
| 15 | * @author Andrew Kostka <andrew.kostka@wikimedia.de> |
| 16 | */ |
| 17 | class HelpBanner extends SpecialPageHtmlFragment { |
| 18 | |
| 19 | public const HIDE_HELP_BANNER_PREFERENCE = 'userjs-fileimporter-hide-help-banner'; |
| 20 | public const HIDE_HELP_BANNER_CHECK_BOX = 'mw-importfile-disable-help-banner'; |
| 21 | |
| 22 | /** |
| 23 | * @return bool |
| 24 | */ |
| 25 | private function shouldHelpBannerBeShown() { |
| 26 | // TODO: Inject |
| 27 | /** @var UserOptionsLookup $userOptionsLookup */ |
| 28 | $userOptionsLookup = MediaWikiServices::getInstance()->getService( 'UserOptionsLookup' ); |
| 29 | return !$userOptionsLookup->getBoolOption( $this->getUser(), self::HIDE_HELP_BANNER_PREFERENCE ); |
| 30 | } |
| 31 | |
| 32 | public function getHtml(): string { |
| 33 | if ( !$this->shouldHelpBannerBeShown() ) { |
| 34 | return ''; |
| 35 | } |
| 36 | |
| 37 | $textSection = Html::rawElement( |
| 38 | 'div', |
| 39 | [ 'class' => 'mw-importfile-help-banner-text' ], |
| 40 | FileImporterUtils::addTargetBlankToLinks( |
| 41 | $this->msg( 'fileimporter-help-banner-text' )->parse() |
| 42 | ) |
| 43 | ); |
| 44 | |
| 45 | $imageSection = Html::element( |
| 46 | 'div', |
| 47 | [ 'class' => 'mw-importfile-image-help-banner' ], |
| 48 | '' |
| 49 | ); |
| 50 | |
| 51 | $closeSection = Html::rawElement( |
| 52 | 'label', |
| 53 | [ 'for' => self::HIDE_HELP_BANNER_CHECK_BOX ], |
| 54 | new IconWidget( [ |
| 55 | 'icon' => 'close', |
| 56 | 'title' => $this->msg( 'fileimporter-help-banner-close-tooltip' )->text() |
| 57 | ] ) |
| 58 | ); |
| 59 | |
| 60 | return Html::rawElement( |
| 61 | 'div', |
| 62 | [ 'class' => 'mw-importfile-help-banner' ], |
| 63 | Html::check( |
| 64 | 'mw-importfile-disable-help-banner', |
| 65 | false, |
| 66 | [ 'id' => self::HIDE_HELP_BANNER_CHECK_BOX ] |
| 67 | ) . |
| 68 | new MessageWidget( [ |
| 69 | 'label' => new HtmlSnippet( |
| 70 | $textSection . |
| 71 | $imageSection . |
| 72 | $closeSection |
| 73 | ) |
| 74 | ] ) |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | } |