Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.00% |
5 / 10 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
LimitedWidthContentRequirement | |
50.00% |
5 / 10 |
|
25.00% |
1 / 4 |
8.12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
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 | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
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 WebRequest $request; |
38 | private ?Title $title; |
39 | |
40 | /** |
41 | * This constructor accepts all dependencies needed to determine whether |
42 | * the overridable config is enabled for the current user and request. |
43 | * |
44 | * @param Config $config |
45 | * @param WebRequest $request |
46 | * @param Title|null $title can be null in testing environment |
47 | */ |
48 | public function __construct( |
49 | Config $config, |
50 | WebRequest $request, |
51 | Title $title = null |
52 | ) { |
53 | $this->config = $config; |
54 | $this->title = $title; |
55 | $this->request = $request; |
56 | } |
57 | |
58 | /** |
59 | * @inheritDoc |
60 | */ |
61 | public function getName(): string { |
62 | return Constants::REQUIREMENT_LIMITED_WIDTH_CONTENT; |
63 | } |
64 | |
65 | /** |
66 | * Per the $options configuration (for use with $wgVectorMaxWidthOptions) |
67 | * determine whether max-width should be disabled on the page. |
68 | * For the main page: Check the value of $options['exclude']['mainpage'] |
69 | * For all other pages, the following will happen: |
70 | * - the array $options['include'] of canonical page names will be checked |
71 | * against the current page. If a page has been listed there, function will return false |
72 | * (max-width will not be disabled) |
73 | * Max width is disabled if: |
74 | * 1) The current namespace is listed in array $options['exclude']['namespaces'] |
75 | * OR |
76 | * 2) A query string parameter matches one of the regex patterns in $exclusions['querystring']. |
77 | * |
78 | * @internal only for use inside tests. |
79 | * @param array $options |
80 | * @param Title $title |
81 | * @param WebRequest $request |
82 | * @return bool |
83 | */ |
84 | private static function shouldDisableMaxWidth( array $options, Title $title, WebRequest $request ): bool { |
85 | return ConfigHelper::shouldDisable( $options, $request, $title ); |
86 | } |
87 | |
88 | /** |
89 | * Check query parameter to override config or not. |
90 | * Then check for AB test value. |
91 | * Fallback to config value. |
92 | * |
93 | * @inheritDoc |
94 | */ |
95 | public function isMet(): bool { |
96 | return $this->title && !self::shouldDisableMaxWidth( |
97 | $this->config->get( 'VectorMaxWidthOptions' ), |
98 | $this->title, |
99 | $this->request |
100 | ); |
101 | } |
102 | } |