Index: branches/wmf/1.17wmf1/includes/GlobalFunctions.php |
— | — | @@ -1462,11 +1462,12 @@ |
1463 | 1463 | * @return string Fully-qualified URL |
1464 | 1464 | */ |
1465 | 1465 | function wfExpandUrl( $url ) { |
| 1466 | + global $wgServer; |
1466 | 1467 | if( substr( $url, 0, 2 ) == '//' ) { |
1467 | | - global $wgProto; |
1468 | | - return $wgProto . ':' . $url; |
| 1468 | + $bits = wfParseUrl( $wgServer ); |
| 1469 | + $scheme = $bits && $bits['scheme'] !== '' ? $bits['scheme'] : 'http'; |
| 1470 | + return $scheme . ':' . $url; |
1469 | 1471 | } elseif( substr( $url, 0, 1 ) == '/' ) { |
1470 | | - global $wgServer; |
1471 | 1472 | return $wgServer . $url; |
1472 | 1473 | } else { |
1473 | 1474 | return $url; |
— | — | @@ -2792,14 +2793,21 @@ |
2793 | 2794 | * parse_url() work-alike, but non-broken. Differences: |
2794 | 2795 | * |
2795 | 2796 | * 1) Does not raise warnings on bad URLs (just returns false) |
2796 | | - * 2) Handles protocols that don't use :// (e.g., mailto: and news:) correctly |
2797 | | - * 3) Adds a "delimiter" element to the array, either '://' or ':' (see (2)) |
| 2797 | + * 2) Handles protocols that don't use :// (e.g., mailto: and news: , as well as protocol-relative URLs) correctly |
| 2798 | + * 3) Adds a "delimiter" element to the array, either '://', ':' or '//' (see (2)) |
2798 | 2799 | * |
2799 | 2800 | * @param $url String: a URL to parse |
2800 | 2801 | * @return Array: bits of the URL in an associative array, per PHP docs |
2801 | 2802 | */ |
2802 | 2803 | function wfParseUrl( $url ) { |
2803 | 2804 | global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php |
| 2805 | + |
| 2806 | + // Protocol-relative URLs are handled really badly by parse_url(). It's so bad that the easiest |
| 2807 | + // way to handle them is to just prepend 'http:' and strip the protocol out later |
| 2808 | + $wasRelative = substr( $url, 0, 2 ) == '//'; |
| 2809 | + if ( $wasRelative ) { |
| 2810 | + $url = "http:$url"; |
| 2811 | + } |
2804 | 2812 | wfSuppressWarnings(); |
2805 | 2813 | $bits = parse_url( $url ); |
2806 | 2814 | wfRestoreWarnings(); |
— | — | @@ -2822,6 +2830,11 @@ |
2823 | 2831 | return false; |
2824 | 2832 | } |
2825 | 2833 | |
| 2834 | + // If the URL was protocol-relative, fix scheme and delimiter |
| 2835 | + if ( $wasRelative ) { |
| 2836 | + $bits['scheme'] = ''; |
| 2837 | + $bits['delimiter'] = '//'; |
| 2838 | + } |
2826 | 2839 | return $bits; |
2827 | 2840 | } |
2828 | 2841 | |
Property changes on: branches/wmf/1.17wmf1/includes/GlobalFunctions.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
2829 | 2842 | Merged /trunk/phase3/includes/GlobalFunctions.php:r92036,92044 |
Index: branches/wmf/1.17wmf1/includes/parser/Parser.php |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); |
130 | 130 | $this->mDefaultStripList = $this->mStripList = array(); |
131 | 131 | $this->mUrlProtocols = wfUrlProtocols(); |
132 | | - $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'. |
| 132 | + $this->mExtLinkBracketedRegex = '/\[((' . wfUrlProtocols() . ')'. |
133 | 133 | '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S'; |
134 | 134 | $this->mVarCache = array(); |
135 | 135 | if ( isset( $conf['preprocessorClass'] ) ) { |
Property changes on: branches/wmf/1.17wmf1/includes/parser/Parser.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
136 | 136 | Merged /trunk/phase3/includes/parser/Parser.php:r92036,92044 |
Index: branches/wmf/1.17wmf1/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | $data = array(); |
107 | 107 | $mainPage = Title::newMainPage(); |
108 | 108 | $data['mainpage'] = $mainPage->getPrefixedText(); |
109 | | - $data['base'] = $mainPage->getFullUrl(); |
| 109 | + $data['base'] = wfExpandUrl( $mainPage->getFullUrl() ); |
110 | 110 | $data['sitename'] = $GLOBALS['wgSitename']; |
111 | 111 | $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}"; |
112 | 112 | $data['phpversion'] = phpversion(); |
— | — | @@ -267,7 +267,7 @@ |
268 | 268 | if ( isset( $langNames[$row->iw_prefix] ) ) { |
269 | 269 | $val['language'] = $langNames[$row->iw_prefix]; |
270 | 270 | } |
271 | | - $val['url'] = $row->iw_url; |
| 271 | + $val['url'] = wfExpandUrl( $row->iw_url ); |
272 | 272 | |
273 | 273 | $data[] = $val; |
274 | 274 | } |
— | — | @@ -427,7 +427,7 @@ |
428 | 428 | protected function appendRightsInfo( $property ) { |
429 | 429 | global $wgRightsPage, $wgRightsUrl, $wgRightsText; |
430 | 430 | $title = Title::newFromText( $wgRightsPage ); |
431 | | - $url = $title ? $title->getFullURL() : $wgRightsUrl; |
| 431 | + $url = $title ? wfExpandUrl( $title->getFullURL() ) : $wgRightsUrl; |
432 | 432 | $text = $wgRightsText; |
433 | 433 | if ( !$text && $title ) { |
434 | 434 | $text = $title->getPrefixedText(); |
Index: branches/wmf/1.17wmf1/includes/api/ApiParse.php |
— | — | @@ -349,7 +349,7 @@ |
350 | 350 | |
351 | 351 | $entry['lang'] = $bits[0]; |
352 | 352 | if ( $title ) { |
353 | | - $entry['url'] = $title->getFullURL(); |
| 353 | + $entry['url'] = wfExpandUrl( $title->getFullURL() ); |
354 | 354 | } |
355 | 355 | $this->getResult()->setContent( $entry, $bits[1] ); |
356 | 356 | $result[] = $entry; |
— | — | @@ -407,7 +407,7 @@ |
408 | 408 | |
409 | 409 | $title = Title::newFromText( "{$prefix}:{$title}" ); |
410 | 410 | if ( $title ) { |
411 | | - $entry['url'] = $title->getFullURL(); |
| 411 | + $entry['url'] = wfExpandUrl( $title->getFullURL() ); |
412 | 412 | } |
413 | 413 | |
414 | 414 | $this->getResult()->setContent( $entry, $title->getFullText() ); |
Property changes on: branches/wmf/1.17wmf1/includes/api/ApiParse.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
415 | 415 | Merged /trunk/phase3/includes/api/ApiParse.php:r92036,92044 |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryExtLinksUsage.php |
— | — | @@ -135,6 +135,7 @@ |
136 | 136 | ApiQueryBase::addTitleInfo( $vals, $title ); |
137 | 137 | } |
138 | 138 | if ( $fld_url ) { |
| 139 | + // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan |
139 | 140 | $vals['url'] = $row->el_to; |
140 | 141 | } |
141 | 142 | $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
Index: branches/wmf/1.17wmf1/includes/api/ApiFormatBase.php |
— | — | @@ -265,7 +265,7 @@ |
266 | 266 | // encode all comments or tags as safe blue strings |
267 | 267 | $text = preg_replace( '/\<(!--.*?--|.*?)\>/', '<span style="color:blue;"><\1></span>', $text ); |
268 | 268 | // identify URLs |
269 | | - $protos = implode( "|", $wgUrlProtocols ); |
| 269 | + $protos = wfUrlProtocols(); |
270 | 270 | // This regex hacks around bug 13218 (" included in the URL) |
271 | 271 | $text = preg_replace( "#(($protos).*?)(")?([ \\'\"<>\n]|<|>|")#", '<a href="\\1">\\1</a>\\3\\4', $text ); |
272 | 272 | // identify requests to api.php |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryIWLinks.php |
— | — | @@ -96,7 +96,7 @@ |
97 | 97 | if ( !is_null( $params['url'] ) ) { |
98 | 98 | $title = Title::newFromText( "{$row->iwl_prefix}:{$row->iwl_title}" ); |
99 | 99 | if ( $title ) { |
100 | | - $entry['url'] = $title->getFullURL(); |
| 100 | + $entry['url'] = wfExpandUrl( $title->getFullURL() ); |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryLangLinks.php |
— | — | @@ -90,7 +90,7 @@ |
91 | 91 | if ( $params['url'] ) { |
92 | 92 | $title = Title::newFromText( "{$row->ll_lang}:{$row->ll_title}" ); |
93 | 93 | if ( $title ) { |
94 | | - $entry['url'] = $title->getFullURL(); |
| 94 | + $entry['url'] = wfExpandUrl( $title->getFullURL() ); |
95 | 95 | } |
96 | 96 | } |
97 | 97 | ApiResult::setContent( $entry, $row->ll_title ); |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryImageInfo.php |
— | — | @@ -308,7 +308,7 @@ |
309 | 309 | $vals['thumberror'] = $mto->toText(); |
310 | 310 | } |
311 | 311 | } |
312 | | - $vals['url'] = $file->getFullURL(); |
| 312 | + $vals['url'] = wfExpandUrl( $file->getFullURL() ); |
313 | 313 | $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl() ); |
314 | 314 | } |
315 | 315 | |
Property changes on: branches/wmf/1.17wmf1/includes/api/ApiQueryImageInfo.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
316 | 316 | Merged /trunk/phase3/includes/api/ApiQueryImageInfo.php:r92036,92044 |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryExternalLinks.php |
— | — | @@ -75,6 +75,7 @@ |
76 | 76 | break; |
77 | 77 | } |
78 | 78 | $entry = array(); |
| 79 | + // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan |
79 | 80 | ApiResult::setContent( $entry, $row->el_to ); |
80 | 81 | $fit = $this->addPageSubItem( $row->el_from, $entry ); |
81 | 82 | if ( !$fit ) { |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryInfo.php |
— | — | @@ -353,8 +353,8 @@ |
354 | 354 | } |
355 | 355 | |
356 | 356 | if ( $this->fld_url ) { |
357 | | - $pageInfo['fullurl'] = $title->getFullURL(); |
358 | | - $pageInfo['editurl'] = $title->getFullURL( 'action=edit' ); |
| 357 | + $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL() ); |
| 358 | + $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ) ); |
359 | 359 | } |
360 | 360 | if ( $this->fld_readable && $title->userCanRead() ) { |
361 | 361 | $pageInfo['readable'] = ''; |
Index: branches/wmf/1.17wmf1/includes/DefaultSettings.php |
— | — | @@ -2742,6 +2742,7 @@ |
2743 | 2743 | 'svn://', |
2744 | 2744 | 'git://', |
2745 | 2745 | 'mms://', |
| 2746 | + '//', // for protocol-relative URLs |
2746 | 2747 | ); |
2747 | 2748 | |
2748 | 2749 | /** |
Property changes on: branches/wmf/1.17wmf1/includes/DefaultSettings.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
2749 | 2750 | Merged /trunk/phase3/includes/DefaultSettings.php:r92036,92044 |