-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoneLinks.hooks.php
66 lines (53 loc) · 1.65 KB
/
PhoneLinks.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Hooks for PhoneLinks extension
*
* @file
* @ingroup Extensions
*/
// These *should not* be used for validation - they are intentionally naive and allow non-existing
// phone numbers, for simplicity's sake!
//@todo special Israeli prefixes: 1-599-\d{6}, 1-700-\d{6}, 1-800-\d{6}, 1-801-\d{6}
//@todo add option to auto-recognize phone numbers
$phonePatterns = array(
'Israel' => '/0(2|3|4|5[0-9]|8|9|7[1-9])-?[2-9]\d{6}',
'USA' => '((\(\d{3}\)?)|(\d{3}))([-./]?)(\d{3})([\s-./]?)(\d{4})'
);
class PhoneLinksHooks {
public static function makeConfig() {
return new GlobalVarConfig( 'wgPhoneLinks' );
}
private static function getConfig() {
return ConfigFactory::getDefaultInstance()->makeConfig( 'wgPhoneLinks' );
}
public static function onLinkerMakeExternalLink( &$url, &$text, &$link, &$attribs ) {
// Don't use parse_url() - as it doesn't correctly detect all tel: links, ffs
if ( substr( $url, 0, 4 ) !== 'tel:' ) {
return true;
}
$attribs['class'] .= ' phonenum';
unset( $attribs['target'] );
$hideOnMobile = self::getConfig()->get( 'HideOnMobile' );
$hideOnDesktop = self::getConfig()->get( 'HideOnDesktop' );
if( !$hideOnMobile && !$hideOnDesktop ) {
return true;
}
$disableLinks = true;
if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileDetect' ) ) {
$isMobile = MobileDetect::isMobile();
} else {
$isMobile = false;
}
if (
( $isMobile && !$hideOnMobile )
|| ( !$isMobile && !$hideOnDesktop )
) {
$disableLinks = false;
}
if( $disableLinks ) {
$link = Html::rawElement( 'span', [ 'class' => 'phonenum phonenum-unlinked' ], $text );
return false;
}
return true;
}
}