Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Hooks | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
onOutputPageBodyAttributes | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
onSkinTemplateNavigation__Universal | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | /** |
3 | * MonoBook hooks |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | */ |
22 | |
23 | namespace MonoBook; |
24 | |
25 | use MediaWiki\Hook\SkinTemplateNavigation__UniversalHook; |
26 | use MediaWiki\Output\Hook\OutputPageBodyAttributesHook; |
27 | use MediaWiki\Output\OutputPage; |
28 | use Skin; |
29 | use SkinTemplate; |
30 | |
31 | /** |
32 | * @phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName |
33 | */ |
34 | class Hooks implements |
35 | OutputPageBodyAttributesHook, |
36 | SkinTemplateNavigation__UniversalHook |
37 | { |
38 | /** |
39 | * Add the "monobook-capitalize-all-nouns" CSS class to the <body> element for German |
40 | * (de) and various languages which have German set as a fallback language, such |
41 | * as Colognian (ksh) and others. |
42 | * |
43 | * @see https://phabricator.wikimedia.org/T97892 |
44 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageBodyAttributes |
45 | * @param OutputPage $out |
46 | * @param Skin $skin |
47 | * @param array &$bodyAttrs Pre-existing attributes for the <body> element |
48 | */ |
49 | public function onOutputPageBodyAttributes( $out, $skin, &$bodyAttrs ): void { |
50 | $lang = $skin->getLanguage(); |
51 | if ( |
52 | $skin->getSkinName() === 'monobook' && ( |
53 | $lang->getCode() === 'de' || |
54 | in_array( 'de', $lang->getFallbackLanguages() ) |
55 | ) |
56 | ) { |
57 | $bodyAttrs['class'] .= ' monobook-capitalize-all-nouns'; |
58 | } |
59 | } |
60 | |
61 | /** |
62 | * SkinTemplateNavigationUniversal hook handler |
63 | * |
64 | * @param SkinTemplate $skin |
65 | * @param array &$content_navigation |
66 | */ |
67 | public function onSkinTemplateNavigation__Universal( $skin, &$content_navigation ): void { |
68 | $title = $skin->getTitle(); |
69 | if ( $skin->getSkinName() === 'monobook' ) { |
70 | $tabs = []; |
71 | $namespaces = $content_navigation['namespaces']; |
72 | foreach ( $namespaces as $nsid => $attribs ) { |
73 | $id = $nsid . '-mobile'; |
74 | $tabs[$id] = [] + $attribs; |
75 | $tabs[$id]['title'] = $attribs['text']; |
76 | $tabs[$id]['id'] = $id; |
77 | } |
78 | |
79 | if ( !$title->isSpecialPage() ) { |
80 | $tabs['more'] = [ |
81 | 'text' => $skin->msg( 'monobook-more-actions' )->text(), |
82 | 'href' => '#p-cactions', |
83 | 'id' => 'ca-more' |
84 | ]; |
85 | } |
86 | |
87 | $tabs['toolbox'] = [ |
88 | 'text' => $skin->msg( 'toolbox' )->text(), |
89 | 'href' => '#p-tb', |
90 | 'id' => 'ca-tools', |
91 | 'title' => $skin->msg( 'toolbox' )->text() |
92 | ]; |
93 | |
94 | $languages = $skin->getLanguages(); |
95 | if ( count( $languages ) > 0 ) { |
96 | $tabs['languages'] = [ |
97 | 'text' => $skin->msg( 'otherlanguages' )->text(), |
98 | 'href' => '#p-lang', |
99 | 'id' => 'ca-languages', |
100 | 'title' => $skin->msg( 'otherlanguages' )->text() |
101 | ]; |
102 | } |
103 | |
104 | $content_navigation['cactions-mobile'] = $tabs; |
105 | } |
106 | } |
107 | } |