Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| LimitedWidthContentRequirement | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| shouldDisableMaxWidth | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isMet | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * http://www.gnu.org/copyleft/gpl.html |
| 18 | * |
| 19 | * @file |
| 20 | */ |
| 21 | |
| 22 | namespace MediaWiki\Skins\Vector\FeatureManagement\Requirements; |
| 23 | |
| 24 | use MediaWiki\Config\Config; |
| 25 | use MediaWiki\Request\WebRequest; |
| 26 | use MediaWiki\Skins\Vector\ConfigHelper; |
| 27 | use MediaWiki\Skins\Vector\Constants; |
| 28 | use MediaWiki\Skins\Vector\FeatureManagement\Requirement; |
| 29 | use MediaWiki\Title\Title; |
| 30 | |
| 31 | /** |
| 32 | * The `MaxWidthRequirement` for content. |
| 33 | * @package MediaWiki\Skins\Vector\FeatureManagement\Requirements |
| 34 | */ |
| 35 | final class LimitedWidthContentRequirement implements Requirement { |
| 36 | private Config $config; |
| 37 | private ConfigHelper $configHelper; |
| 38 | private WebRequest $request; |
| 39 | private ?Title $title; |
| 40 | |
| 41 | /** |
| 42 | * This constructor accepts all dependencies needed to determine whether |
| 43 | * the overridable config is enabled for the current user and request. |
| 44 | * |
| 45 | * @param Config $config |
| 46 | * @param ConfigHelper $configHelper |
| 47 | * @param WebRequest $request |
| 48 | * @param Title|null $title can be null in testing environment |
| 49 | */ |
| 50 | public function __construct( |
| 51 | Config $config, |
| 52 | ConfigHelper $configHelper, |
| 53 | WebRequest $request, |
| 54 | ?Title $title = null |
| 55 | ) { |
| 56 | $this->config = $config; |
| 57 | $this->configHelper = $configHelper; |
| 58 | $this->title = $title; |
| 59 | $this->request = $request; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @inheritDoc |
| 64 | */ |
| 65 | public function getName(): string { |
| 66 | return Constants::REQUIREMENT_LIMITED_WIDTH_CONTENT; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Per the $options configuration (for use with $wgVectorMaxWidthOptions) |
| 71 | * determine whether max-width should be disabled on the page. |
| 72 | * For the main page: Check the value of $options['exclude']['mainpage'] |
| 73 | * For all other pages, the following will happen: |
| 74 | * - the array $options['include'] of canonical page names will be checked |
| 75 | * against the current page. If a page has been listed there, function will return false |
| 76 | * (max-width will not be disabled) |
| 77 | * Max width is disabled if: |
| 78 | * 1) The current namespace is listed in array $options['exclude']['namespaces'] |
| 79 | * OR |
| 80 | * 2) A query string parameter matches one of the regex patterns in $exclusions['querystring']. |
| 81 | * |
| 82 | * @internal only for use inside tests. |
| 83 | * @param array $options |
| 84 | * @param Title $title |
| 85 | * @param WebRequest $request |
| 86 | * @return bool |
| 87 | */ |
| 88 | private function shouldDisableMaxWidth( array $options, Title $title, WebRequest $request ): bool { |
| 89 | return $this->configHelper->shouldDisable( $options, $request, $title ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Check query parameter to override config or not. |
| 94 | * Then check for AB test value. |
| 95 | * Fallback to config value. |
| 96 | * |
| 97 | * @inheritDoc |
| 98 | */ |
| 99 | public function isMet(): bool { |
| 100 | return $this->title && !$this->shouldDisableMaxWidth( |
| 101 | $this->config->get( 'VectorMaxWidthOptions' ), |
| 102 | $this->title, |
| 103 | $this->request |
| 104 | ); |
| 105 | } |
| 106 | } |