r92172 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92171‎ | r92172 | r92173 >
Date:17:48, 14 July 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT protocol-relative URL fixes: r91663, r92024, r92028, r92036, r92044. Also kill $wgProto in wfExpandUrl() as has been done on trunk
Modified paths:
  • /branches/wmf/1.17wmf1/includes/DefaultSettings.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/GlobalFunctions.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiFormatBase.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiParse.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQueryExtLinksUsage.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQueryExternalLinks.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQueryIWLinks.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQueryImageInfo.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQueryInfo.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQueryLangLinks.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/GlobalFunctions.php
@@ -1462,11 +1462,12 @@
14631463 * @return string Fully-qualified URL
14641464 */
14651465 function wfExpandUrl( $url ) {
 1466+ global $wgServer;
14661467 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;
14691471 } elseif( substr( $url, 0, 1 ) == '/' ) {
1470 - global $wgServer;
14711472 return $wgServer . $url;
14721473 } else {
14731474 return $url;
@@ -2792,14 +2793,21 @@
27932794 * parse_url() work-alike, but non-broken. Differences:
27942795 *
27952796 * 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))
27982799 *
27992800 * @param $url String: a URL to parse
28002801 * @return Array: bits of the URL in an associative array, per PHP docs
28012802 */
28022803 function wfParseUrl( $url ) {
28032804 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+ }
28042812 wfSuppressWarnings();
28052813 $bits = parse_url( $url );
28062814 wfRestoreWarnings();
@@ -2822,6 +2830,11 @@
28232831 return false;
28242832 }
28252833
 2834+ // If the URL was protocol-relative, fix scheme and delimiter
 2835+ if ( $wasRelative ) {
 2836+ $bits['scheme'] = '';
 2837+ $bits['delimiter'] = '//';
 2838+ }
28262839 return $bits;
28272840 }
28282841
Property changes on: branches/wmf/1.17wmf1/includes/GlobalFunctions.php
___________________________________________________________________
Modified: svn:mergeinfo
28292842 Merged /trunk/phase3/includes/GlobalFunctions.php:r92036,92044
Index: branches/wmf/1.17wmf1/includes/parser/Parser.php
@@ -128,7 +128,7 @@
129129 $this->mFunctionSynonyms = array( 0 => array(), 1 => array() );
130130 $this->mDefaultStripList = $this->mStripList = array();
131131 $this->mUrlProtocols = wfUrlProtocols();
132 - $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'.
 132+ $this->mExtLinkBracketedRegex = '/\[((' . wfUrlProtocols() . ')'.
133133 '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x00-\\x08\\x0a-\\x1F]*?)\]/S';
134134 $this->mVarCache = array();
135135 if ( isset( $conf['preprocessorClass'] ) ) {
Property changes on: branches/wmf/1.17wmf1/includes/parser/Parser.php
___________________________________________________________________
Modified: svn:mergeinfo
136136 Merged /trunk/phase3/includes/parser/Parser.php:r92036,92044
Index: branches/wmf/1.17wmf1/includes/api/ApiQuerySiteinfo.php
@@ -105,7 +105,7 @@
106106 $data = array();
107107 $mainPage = Title::newMainPage();
108108 $data['mainpage'] = $mainPage->getPrefixedText();
109 - $data['base'] = $mainPage->getFullUrl();
 109+ $data['base'] = wfExpandUrl( $mainPage->getFullUrl() );
110110 $data['sitename'] = $GLOBALS['wgSitename'];
111111 $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}";
112112 $data['phpversion'] = phpversion();
@@ -267,7 +267,7 @@
268268 if ( isset( $langNames[$row->iw_prefix] ) ) {
269269 $val['language'] = $langNames[$row->iw_prefix];
270270 }
271 - $val['url'] = $row->iw_url;
 271+ $val['url'] = wfExpandUrl( $row->iw_url );
272272
273273 $data[] = $val;
274274 }
@@ -427,7 +427,7 @@
428428 protected function appendRightsInfo( $property ) {
429429 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
430430 $title = Title::newFromText( $wgRightsPage );
431 - $url = $title ? $title->getFullURL() : $wgRightsUrl;
 431+ $url = $title ? wfExpandUrl( $title->getFullURL() ) : $wgRightsUrl;
432432 $text = $wgRightsText;
433433 if ( !$text && $title ) {
434434 $text = $title->getPrefixedText();
Index: branches/wmf/1.17wmf1/includes/api/ApiParse.php
@@ -349,7 +349,7 @@
350350
351351 $entry['lang'] = $bits[0];
352352 if ( $title ) {
353 - $entry['url'] = $title->getFullURL();
 353+ $entry['url'] = wfExpandUrl( $title->getFullURL() );
354354 }
355355 $this->getResult()->setContent( $entry, $bits[1] );
356356 $result[] = $entry;
@@ -407,7 +407,7 @@
408408
409409 $title = Title::newFromText( "{$prefix}:{$title}" );
410410 if ( $title ) {
411 - $entry['url'] = $title->getFullURL();
 411+ $entry['url'] = wfExpandUrl( $title->getFullURL() );
412412 }
413413
414414 $this->getResult()->setContent( $entry, $title->getFullText() );
Property changes on: branches/wmf/1.17wmf1/includes/api/ApiParse.php
___________________________________________________________________
Modified: svn:mergeinfo
415415 Merged /trunk/phase3/includes/api/ApiParse.php:r92036,92044
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryExtLinksUsage.php
@@ -135,6 +135,7 @@
136136 ApiQueryBase::addTitleInfo( $vals, $title );
137137 }
138138 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
139140 $vals['url'] = $row->el_to;
140141 }
141142 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
Index: branches/wmf/1.17wmf1/includes/api/ApiFormatBase.php
@@ -265,7 +265,7 @@
266266 // encode all comments or tags as safe blue strings
267267 $text = preg_replace( '/\&lt;(!--.*?--|.*?)\&gt;/', '<span style="color:blue;">&lt;\1&gt;</span>', $text );
268268 // identify URLs
269 - $protos = implode( "|", $wgUrlProtocols );
 269+ $protos = wfUrlProtocols();
270270 // This regex hacks around bug 13218 (&quot; included in the URL)
271271 $text = preg_replace( "#(($protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
272272 // identify requests to api.php
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryIWLinks.php
@@ -96,7 +96,7 @@
9797 if ( !is_null( $params['url'] ) ) {
9898 $title = Title::newFromText( "{$row->iwl_prefix}:{$row->iwl_title}" );
9999 if ( $title ) {
100 - $entry['url'] = $title->getFullURL();
 100+ $entry['url'] = wfExpandUrl( $title->getFullURL() );
101101 }
102102 }
103103
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryLangLinks.php
@@ -90,7 +90,7 @@
9191 if ( $params['url'] ) {
9292 $title = Title::newFromText( "{$row->ll_lang}:{$row->ll_title}" );
9393 if ( $title ) {
94 - $entry['url'] = $title->getFullURL();
 94+ $entry['url'] = wfExpandUrl( $title->getFullURL() );
9595 }
9696 }
9797 ApiResult::setContent( $entry, $row->ll_title );
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryImageInfo.php
@@ -308,7 +308,7 @@
309309 $vals['thumberror'] = $mto->toText();
310310 }
311311 }
312 - $vals['url'] = $file->getFullURL();
 312+ $vals['url'] = wfExpandUrl( $file->getFullURL() );
313313 $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl() );
314314 }
315315
Property changes on: branches/wmf/1.17wmf1/includes/api/ApiQueryImageInfo.php
___________________________________________________________________
Modified: svn:mergeinfo
316316 Merged /trunk/phase3/includes/api/ApiQueryImageInfo.php:r92036,92044
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryExternalLinks.php
@@ -75,6 +75,7 @@
7676 break;
7777 }
7878 $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
7980 ApiResult::setContent( $entry, $row->el_to );
8081 $fit = $this->addPageSubItem( $row->el_from, $entry );
8182 if ( !$fit ) {
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryInfo.php
@@ -353,8 +353,8 @@
354354 }
355355
356356 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' ) );
359359 }
360360 if ( $this->fld_readable && $title->userCanRead() ) {
361361 $pageInfo['readable'] = '';
Index: branches/wmf/1.17wmf1/includes/DefaultSettings.php
@@ -2742,6 +2742,7 @@
27432743 'svn://',
27442744 'git://',
27452745 'mms://',
 2746+ '//', // for protocol-relative URLs
27462747 );
27472748
27482749 /**
Property changes on: branches/wmf/1.17wmf1/includes/DefaultSettings.php
___________________________________________________________________
Modified: svn:mergeinfo
27492750 Merged /trunk/phase3/includes/DefaultSettings.php:r92036,92044

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91663(bug 29497) To support protocol-relative URLs in external links, add '//' to ...catrope18:26, 7 July 2011
r92024Extend wfParseUrl() to handle protocol-relative URLs. parse_url() doesn't han...catrope23:52, 12 July 2011
r92028Now that wfParseUrl() can handle protocol-relative URLs, make wfExpandUrl() w...catrope00:03, 13 July 2011
r92036Use wfUrlProtocols() in ApiFormatBase instead of simply imploding $wgUrlProto...catrope00:27, 13 July 2011
r92044Per wikitech-l, run a bunch of URLs in the API output through wfExpandUrl(), ...catrope01:27, 13 July 2011

Status & tagging log