Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
25.71% |
9 / 35 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
MobileFrontendSkinHooks | |
25.71% |
9 / 35 |
|
33.33% |
1 / 3 |
20.76 | |
0.00% |
0 / 1 |
getTermsLink | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
getDesktopViewLink | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
getMobileViewLink | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | use MediaWiki\Html\Html; |
4 | |
5 | class MobileFrontendSkinHooks { |
6 | /** |
7 | * Returns HTML of terms of use link or null if it shouldn't be displayed |
8 | * Note: This is called by a hook in the WikimediaMessages extension. |
9 | * |
10 | * @param MessageLocalizer $localizer |
11 | * @return null|string |
12 | */ |
13 | public static function getTermsLink( MessageLocalizer $localizer ) { |
14 | $urlMsg = $localizer->msg( 'mobile-frontend-terms-url' )->inContentLanguage(); |
15 | if ( $urlMsg->isDisabled() ) { |
16 | return null; |
17 | } |
18 | $url = $urlMsg->plain(); |
19 | |
20 | return Html::element( |
21 | 'a', |
22 | [ 'href' => Skin::makeInternalOrExternalUrl( $url ) ], |
23 | $localizer->msg( 'mobile-frontend-terms-text' )->text() |
24 | ); |
25 | } |
26 | |
27 | /** |
28 | * @param Skin $skin |
29 | * @param MobileContext $context |
30 | * @return string representing the desktop link. |
31 | */ |
32 | public static function getDesktopViewLink( Skin $skin, MobileContext $context ) { |
33 | $url = $skin->getOutput()->getProperty( 'desktopUrl' ); |
34 | $req = $skin->getRequest(); |
35 | if ( $url ) { |
36 | $url = wfAppendQuery( $url, 'mobileaction=toggle_view_desktop' ); |
37 | } else { |
38 | $title = $skin->getTitle(); |
39 | $url = $title->getLocalURL( |
40 | $req->appendQueryValue( 'mobileaction', 'toggle_view_desktop' ) |
41 | ); |
42 | } |
43 | $desktopUrl = $context->getDesktopUrl( wfExpandUrl( $url, PROTO_RELATIVE ) ); |
44 | |
45 | $desktop = $context->msg( 'mobile-frontend-view-desktop' )->text(); |
46 | return Html::element( 'a', |
47 | [ 'id' => 'mw-mf-display-toggle', 'href' => $desktopUrl, |
48 | 'data-event-name' => 'switch_to_desktop' ], $desktop ); |
49 | } |
50 | |
51 | /** |
52 | * @param Skin $skin |
53 | * @param MobileContext $context |
54 | * @return string representing the mobile link. |
55 | */ |
56 | public static function getMobileViewLink( Skin $skin, MobileContext $context ) { |
57 | $req = $skin->getRequest(); |
58 | $args = $req->getQueryValues(); |
59 | // avoid title being set twice |
60 | unset( $args['title'], $args['useformat'] ); |
61 | $args['mobileaction'] = 'toggle_view_mobile'; |
62 | $title = $skin->getTitle(); |
63 | // Title could be null |
64 | // If no title, there is a problem with context. Possibly inside a test. |
65 | if ( !$title ) { |
66 | return ''; |
67 | } |
68 | $mobileViewUrl = $title->getFullURL( $args ); |
69 | $mobileViewUrl = $context->getMobileUrl( $mobileViewUrl ); |
70 | |
71 | return Html::element( 'a', |
72 | [ 'href' => $mobileViewUrl, 'class' => 'noprint stopMobileRedirectToggle' ], |
73 | $context->msg( 'mobile-frontend-view' )->text() |
74 | ); |
75 | } |
76 | } |