Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php |
— | — | @@ -7,9 +7,10 @@ |
8 | 8 | define('SMW_URI_MODE_EMAIL',1); |
9 | 9 | define('SMW_URI_MODE_URI',3); |
10 | 10 | define('SMW_URI_MODE_ANNOURI',4); |
| 11 | +define('SMW_URI_MODE_TEL',5); |
11 | 12 | |
12 | 13 | /** |
13 | | - * This datavalue implements URL/URI/ANNURI/EMAIL-Datavalues suitable for defining |
| 14 | + * This datavalue implements URL/URI/ANNURI/PHONE/EMAIL-Datavalues suitable for defining |
14 | 15 | * the respective types of properties. |
15 | 16 | * |
16 | 17 | * @author Nikolas Iwan |
— | — | @@ -37,6 +38,9 @@ |
38 | 39 | case '_anu': |
39 | 40 | $this->m_mode = SMW_URI_MODE_ANNOURI; |
40 | 41 | break; |
| 42 | + case '_tel': |
| 43 | + $this->m_mode = SMW_URI_MODE_TEL; |
| 44 | + break; |
41 | 45 | case '_uri': case '_url': case '__spu': default: |
42 | 46 | $this->m_mode = SMW_URI_MODE_URI; |
43 | 47 | break; |
— | — | @@ -114,6 +118,24 @@ |
115 | 119 | } |
116 | 120 | } |
117 | 121 | break; |
| 122 | + case SMW_URI_MODE_TEL: |
| 123 | + if (substr($value, 0, 4) === 'tel:') { |
| 124 | + $value = substr($value, 4); |
| 125 | + $this->m_value = $value; |
| 126 | + } |
| 127 | + $value = preg_replace('/(?<=[0-9]) (?=[0-9])/', '\1-\2', $value); |
| 128 | + $value = str_replace(' ', '', $value); |
| 129 | + if (substr($value, 0, 2) == '00') { |
| 130 | + $value = '+' . substr($value, 2); |
| 131 | + } |
| 132 | + $value = 'tel:' . $value; |
| 133 | + if ( (strlen(preg_replace('/[^0-9]/', '', $value)) < 6) || |
| 134 | + (preg_match('<[-+./][-./]>', $value)) || |
| 135 | + (!SMWURIValue::isValidTelURI($value)) ) { ///TODO: introduce error-message for "bad" phone number |
| 136 | + $this->addError(wfMsgForContent('smw_baduri', $this->m_value)); |
| 137 | + } |
| 138 | + $this->m_uri = $value; |
| 139 | + break; |
118 | 140 | case SMW_URI_MODE_EMAIL: |
119 | 141 | if (strpos($value,'mailto:') === 0) { // accept optional "mailto" |
120 | 142 | $value = substr($value, 7); |
— | — | @@ -135,6 +157,17 @@ |
136 | 158 | return true; |
137 | 159 | } |
138 | 160 | |
| 161 | + /** |
| 162 | + * Returns true if the argument is a valid RFC 3966 phone number. |
| 163 | + * Only global phone numbers are supported, and no full validation |
| 164 | + * of parameters (appended via ;param=value) is performed. |
| 165 | + */ |
| 166 | + protected static function isValidTelURI($s) { |
| 167 | + $tel_uri_regex = '<^tel:\+[0-9./-]*[0-9][0-9./-]*(;[0-9a-zA-Z-]+=(%[0-9a-zA-Z][0-9a-zA-Z]|[0-9a-zA-Z._~:/?#[\]@!$&\'()*+,;=-])*)*$>'; |
| 168 | + return (bool) preg_match($tel_uri_regex, $s); |
| 169 | + } |
| 170 | + |
| 171 | + |
139 | 172 | protected function parseDBkeys($args) { |
140 | 173 | $this->m_uri = $args[0]; |
141 | 174 | $this->m_value = $this->m_uri; |
— | — | @@ -148,6 +181,12 @@ |
149 | 182 | $this->m_uri = 'mailto:' . $this->m_value; |
150 | 183 | $this->m_url = $this->m_uri; |
151 | 184 | } |
| 185 | + } elseif ($this->m_mode == SMW_URI_MODE_TEL) { |
| 186 | + $this->m_url = $this->m_value; |
| 187 | + if (strpos($this->m_uri,'tel:') === 0) { // catch inconsistencies in DB, should usually be the case |
| 188 | + $this->m_caption = substr($this->m_value, 4); |
| 189 | + $this->m_value = $this->m_caption; |
| 190 | + } |
152 | 191 | } else { |
153 | 192 | $parts = explode(':', $this->m_uri, 2); // try to split "schema:rest" |
154 | 193 | global $wgUrlProtocols; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -118,6 +118,7 @@ |
119 | 119 | '_ema' => 'SMWURIValue', // Email type |
120 | 120 | '_uri' => 'SMWURIValue', // URL/URI type |
121 | 121 | '_anu' => 'SMWURIValue', // Annotation URI type |
| 122 | + '_tel' => 'SMWURIValue', // Phone number (URI) type |
122 | 123 | '_wpg' => 'SMWWikiPageValue', // Page type |
123 | 124 | '_wpp' => 'SMWWikiPageValue', // Property page type TODO: make available to user space |
124 | 125 | '_wpc' => 'SMWWikiPageValue', // Category page type TODO: make available to user space |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageZh_cn.php |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | '_ema' => 'Email', //'Email', // name of the email type |
39 | 39 | '_uri' => 'URL', //'URL', // name of the URL type |
40 | 40 | '_anu' => 'URI的注解', //'Annotation URI' // name of the annotation URI type (OWL annotation property) |
| 41 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
41 | 42 | ); |
42 | 43 | |
43 | 44 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageAr.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'التاريخ', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'البريد الإلكتروني', // name of the email type |
37 | 37 | '_uri' => 'مسار', // name of the URL type |
38 | | - '_anu' => 'التعليق علي معرف الموارد الموحد' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'التعليق علي معرف الموارد الموحد', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageEn.php |
— | — | @@ -37,14 +37,16 @@ |
38 | 38 | '_dat' => 'Date', // name of the datetime (calendar) type |
39 | 39 | '_ema' => 'Email', // name of the email type |
40 | 40 | '_uri' => 'URL', // name of the URL type |
41 | | - '_anu' => 'Annotation URI' // name of the annotation URI type (OWL annotation property) |
| 41 | + '_anu' => 'Annotation URI', // name of the annotation URI type (OWL annotation property) |
| 42 | + '_tel' => 'Telephone number', // name of the telephone (URI) type |
42 | 43 | ); |
43 | 44 | |
44 | 45 | protected $m_DatatypeAliases = array( |
45 | 46 | 'URI' => '_uri', |
46 | 47 | 'Float' => '_num', |
47 | 48 | 'Integer' => '_num', |
48 | | - 'Enumeration' => '_str' |
| 49 | + 'Enumeration' => '_str', |
| 50 | + 'Phone number'=> '_tel', |
49 | 51 | ); |
50 | 52 | |
51 | 53 | protected $m_SpecialProperties = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageEs.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'Fecha', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'Dirección electrónica', // name of the email type |
37 | 37 | '_uri' => 'URL', // name of the URL type |
38 | | - '_anu' => 'Anotación-URI' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'Anotación-URI', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageFr.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'Date', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'Adresse électronique', // name of the email type |
37 | 37 | '_uri' => 'URL', // name of the URI type |
38 | | - '_anu' => 'Annotation-URI' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'Annotation-URI', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageNl.php |
— | — | @@ -36,7 +36,8 @@ |
37 | 37 | '_dat' => 'Datum', // name of the datetime (calendar) type |
38 | 38 | '_ema' => 'E-mail', // name of the email type |
39 | 39 | '_uri' => 'URL', // name of the URL type |
40 | | - '_anu' => 'Annotatie URI' // name of the annotation URI type (OWL annotation property) |
| 40 | + '_anu' => 'Annotatie URI', // name of the annotation URI type (OWL annotation property) |
| 41 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
41 | 42 | ); |
42 | 43 | |
43 | 44 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguagePl.php |
— | — | @@ -53,7 +53,8 @@ |
54 | 54 | '_dat' => 'Data', // name of the datetime (calendar) type |
55 | 55 | '_ema' => 'Email', // name of the email type |
56 | 56 | '_uri' => 'URL', // name of the URL type |
57 | | - '_anu' => 'URI adnotacji' // name of the annotation URI type (OWL annotation property) |
| 57 | + '_anu' => 'URI adnotacji', // name of the annotation URI type (OWL annotation property) |
| 58 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
58 | 59 | ); |
59 | 60 | |
60 | 61 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageIt.php |
— | — | @@ -35,7 +35,8 @@ |
36 | 36 | '_dat' => 'Data', // name of the datetime (calendar) type |
37 | 37 | '_ema' => 'Email', // name of the email type |
38 | 38 | '_uri' => 'URL', // name of the URL type |
39 | | - '_anu' => 'Annotazione URI' // name of the annotation URI type (OWL annotation property) |
| 39 | + '_anu' => 'Annotazione URI', // name of the annotation URI type (OWL annotation property) |
| 40 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
40 | 41 | ); |
41 | 42 | |
42 | 43 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageNo.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'Dato', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'E-post', // name of the email type |
37 | 37 | '_uri' => 'URL', // name of the URL type |
38 | | - '_anu' => 'URI-merknad' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'URI-merknad', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageSk.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'Dátum', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'Email', // name of the email type |
37 | 37 | '_uri' => 'URL', // name of the URL type |
38 | | - '_anu' => 'URI anotácie' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'URI anotácie', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguagePt.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'Data', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'Email', // name of the email type (Portuguese does not have another word for this) |
37 | 37 | '_uri' => 'URL', // name of the URI type |
38 | | - '_anu' => 'Anotação-URI' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'Anotação-URI', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageRu.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'Дата', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'Почта', // name of the email type |
37 | 37 | '_uri' => 'URL', // name of the URL type |
38 | | - '_anu' => 'URI аннотации' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'URI аннотации', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageDe.php |
— | — | @@ -42,7 +42,8 @@ |
43 | 43 | '_dat' => 'Datum', // name of the datetime (calendar) type |
44 | 44 | '_ema' => 'Email', // name of the email type |
45 | 45 | '_uri' => 'URL', // name of the URL type |
46 | | - '_anu' => 'URI-Annotation' // name of the annotation URI type (OWL annotation property) |
| 46 | + '_anu' => 'URI-Annotation', // name of the annotation URI type (OWL annotation property) |
| 47 | + '_tel' => 'Telefonnummer', // name of the telephone number URI datatype |
47 | 48 | ); |
48 | 49 | |
49 | 50 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageZh_tw.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | '_ema' => 'Email', //'Email', // name of the email type |
37 | 37 | '_uri' => 'URL', //'URL', // name of the URL type |
38 | 38 | '_anu' => 'URI的註解', //'Annotation URI' // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageHe.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'תאריך', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'דואל', // name of the email (URI) type |
37 | 37 | '_uri' => 'כתובת כללית', // name of the URL type |
38 | | - '_anu' => 'מזהה יחודי לפירוש' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'מזהה יחודי לפירוש', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_LanguageArz.php |
— | — | @@ -34,7 +34,8 @@ |
35 | 35 | '_dat' => 'التاريخ', // name of the datetime (calendar) type |
36 | 36 | '_ema' => 'البريد الإلكترونى', // name of the email type |
37 | 37 | '_uri' => 'مسار', // name of the URL type |
38 | | - '_anu' => 'التعليق علي معرف الموارد الموحد' // name of the annotation URI type (OWL annotation property) |
| 38 | + '_anu' => 'التعليق علي معرف الموارد الموحد', // name of the annotation URI type (OWL annotation property) |
| 39 | + '_tel' => 'Telephone number', // name of the telephone (URI) type //TODO: translate |
39 | 40 | ); |
40 | 41 | |
41 | 42 | protected $m_DatatypeAliases = array( |