Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| SpecialCommunityConfigurationExample | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| showStringConfig | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| showMultiselectEnumConfig | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| showNumbersFromObject | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| showLinks | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace MediaWiki\Extension\CommunityConfigurationExample\Specials; |
| 6 | |
| 7 | use MediaWiki\Config\Config; |
| 8 | use SpecialPage; |
| 9 | |
| 10 | class SpecialCommunityConfigurationExample extends SpecialPage { |
| 11 | |
| 12 | private Config $wikiConfig; |
| 13 | |
| 14 | public function __construct( |
| 15 | Config $wikiConfig |
| 16 | ) { |
| 17 | parent::__construct( 'CommunityConfigurationExample' ); |
| 18 | |
| 19 | $this->wikiConfig = $wikiConfig; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @inheritDoc |
| 24 | */ |
| 25 | public function execute( $subPage ): void { |
| 26 | parent::execute( $subPage ); |
| 27 | |
| 28 | $stringConfigNames = [ 'CCExample_String' ]; |
| 29 | $this->getOutput()->addWikiTextAsInterface( |
| 30 | <<<'STRING_INTRO' |
| 31 | (Note that string-length is calculated in a multi-byte way. |
| 32 | For English copy that usually means that each character is counted as "1". |
| 33 | But this may be less true for other scripts and it is not true for emoji. |
| 34 | Try "🏴": it is counted as having a length of 7.) |
| 35 | STRING_INTRO |
| 36 | ); |
| 37 | foreach ( $stringConfigNames as $configName ) { |
| 38 | $this->showStringConfig( $configName ); |
| 39 | } |
| 40 | $this->showNumbersFromObject( 'CCExample_Numbers' ); |
| 41 | $this->showMultiselectEnumConfig(); |
| 42 | $this->showLinks(); |
| 43 | } |
| 44 | |
| 45 | private function showStringConfig( string $configName ): void { |
| 46 | $exampleString = $this->wikiConfig->get( $configName ); |
| 47 | $this->getOutput()->addWikiTextAsInterface( $configName . ': "' . $exampleString . '"' ); |
| 48 | $this->getOutput()->addWikiTextAsInterface( 'Length: ' . mb_strlen( $exampleString ) ); |
| 49 | } |
| 50 | |
| 51 | private function showMultiselectEnumConfig(): void { |
| 52 | $colorConfigValues = $this->wikiConfig->get( 'CCExample_FavoriteColors' ); |
| 53 | $this->getOutput()->addWikiTextAsInterface( '==== Favorite colors: ====' ); |
| 54 | foreach ( $colorConfigValues as $color ) { |
| 55 | $this->getOutput()->addHTML( '<div style="background-color: ' . $color . ';"> </div>' ); |
| 56 | $this->getOutput()->addWikiTextAsInterface( 'Color: ' . $color ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private function showNumbersFromObject( string $configName ): void { |
| 61 | $this->getOutput()->addWikiTextAsInterface( '==== Numbers: ====' ); |
| 62 | $this->getOutput()->addWikiTextAsInterface( |
| 63 | 'Note that each values has a default, so there will always be a number here.' |
| 64 | ); |
| 65 | $exampleNumberObject = $this->wikiConfig->get( $configName ); |
| 66 | $fieldNames = [ 'IntegerNumber', 'DecimalNumber' ]; |
| 67 | foreach ( $fieldNames as $fieldName ) { |
| 68 | $this->getOutput()->addWikiTextAsInterface( |
| 69 | $configName . ' ' . $fieldName . ': ' . $exampleNumberObject->{$fieldName} |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | private function showLinks(): void { |
| 75 | $configuredPages = $this->wikiConfig->get( 'CCExample_RelevantPages' ); |
| 76 | if ( count( $configuredPages ) === 0 ) { |
| 77 | $this->getOutput()->addWikiTextAsInterface( 'No relevant pages configured.' ); |
| 78 | return; |
| 79 | } |
| 80 | $this->getOutput()->addWikiTextAsInterface( '==== Relevant pages: ====' ); |
| 81 | foreach ( $configuredPages as $page ) { |
| 82 | $this->getOutput()->addWikiTextAsInterface( '# [[' . $page->title . '|' . $page->text . ']]' ); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | } |