From 7b8b23e8b4efbcdd2f799c12ae9e66576a7c6678 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 13 Jul 2011 01:27:07 +0000 Subject: [PATCH] Per wikitech-l, run a bunch of URLs in the API output through wfExpandUrl(), so they become fully-qualified even if they were originally protocol-relative --- includes/api/ApiParse.php | 4 ++-- includes/api/ApiQuery.php | 2 +- includes/api/ApiQueryExtLinksUsage.php | 3 ++- includes/api/ApiQueryExternalLinks.php | 1 + includes/api/ApiQueryIWLinks.php | 2 +- includes/api/ApiQueryImageInfo.php | 2 +- includes/api/ApiQueryInfo.php | 4 ++-- includes/api/ApiQueryLangLinks.php | 2 +- includes/api/ApiQuerySiteinfo.php | 6 +++--- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 1b0e94076a..9d2d95a5a1 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -353,7 +353,7 @@ class ApiParse extends ApiBase { $entry['lang'] = $bits[0]; if ( $title ) { - $entry['url'] = $title->getFullURL(); + $entry['url'] = wfExpandUrl( $title->getFullURL() ); } $this->getResult()->setContent( $entry, $bits[1] ); $result[] = $entry; @@ -435,7 +435,7 @@ class ApiParse extends ApiBase { $title = Title::newFromText( "{$prefix}:{$title}" ); if ( $title ) { - $entry['url'] = $title->getFullURL(); + $entry['url'] = wfExpandUrl( $title->getFullURL() ); } $this->getResult()->setContent( $entry, $title->getFullText() ); diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 844b66e61e..810fba1e6d 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -374,7 +374,7 @@ class ApiQuery extends ApiBase { ); if ( $this->iwUrl ) { $title = Title::newFromText( $rawTitleStr ); - $item['url'] = $title->getFullURL(); + $item['url'] = wfExpandUrl( $title->getFullURL() ); } $intrwValues[] = $item; } diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index 1a7439424e..3aec88ff44 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -126,6 +126,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { ApiQueryBase::addTitleInfo( $vals, $title ); } if ( $fld_url ) { + // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan $vals['url'] = $row->el_to; } $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); @@ -183,7 +184,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { foreach ( $wgUrlProtocols as $p ) { $protocols[] = substr( $p, 0, strpos( $p, ':' ) ); } - return $protocols; + return $protocols; } public static function getProtocolPrefix( $protocol ) { diff --git a/includes/api/ApiQueryExternalLinks.php b/includes/api/ApiQueryExternalLinks.php index 88d3258305..85a1bcc7d9 100644 --- a/includes/api/ApiQueryExternalLinks.php +++ b/includes/api/ApiQueryExternalLinks.php @@ -86,6 +86,7 @@ class ApiQueryExternalLinks extends ApiQueryBase { break; } $entry = array(); + // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan ApiResult::setContent( $entry, $row->el_to ); $fit = $this->addPageSubItem( $row->el_from, $entry ); if ( !$fit ) { diff --git a/includes/api/ApiQueryIWLinks.php b/includes/api/ApiQueryIWLinks.php index 6244793201..9addf36757 100644 --- a/includes/api/ApiQueryIWLinks.php +++ b/includes/api/ApiQueryIWLinks.php @@ -112,7 +112,7 @@ class ApiQueryIWLinks extends ApiQueryBase { if ( !is_null( $params['url'] ) ) { $title = Title::newFromText( "{$row->iwl_prefix}:{$row->iwl_title}" ); if ( $title ) { - $entry['url'] = $title->getFullURL(); + $entry['url'] = wfExpandUrl( $title->getFullURL() ); } } diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 8114e8d6a2..a1fa7ac3ff 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -370,7 +370,7 @@ class ApiQueryImageInfo extends ApiQueryBase { $vals['thumberror'] = $mto->toText(); } } - $vals['url'] = $file->getFullURL(); + $vals['url'] = wfExpandUrl( $file->getFullURL() ); $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl() ); } diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 707a24c207..23ef920ee3 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -380,8 +380,8 @@ class ApiQueryInfo extends ApiQueryBase { } if ( $this->fld_url ) { - $pageInfo['fullurl'] = $title->getFullURL(); - $pageInfo['editurl'] = $title->getFullURL( 'action=edit' ); + $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL() ); + $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ) ); } if ( $this->fld_readable && $title->userCanRead() ) { $pageInfo['readable'] = ''; diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index 4dd34957a9..66e151ef65 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -106,7 +106,7 @@ class ApiQueryLangLinks extends ApiQueryBase { if ( $params['url'] ) { $title = Title::newFromText( "{$row->ll_lang}:{$row->ll_title}" ); if ( $title ) { - $entry['url'] = $title->getFullURL(); + $entry['url'] = wfExpandUrl( $title->getFullURL() ); } } ApiResult::setContent( $entry, $row->ll_title ); diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 6ace1641bb..2cd4825b1b 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -117,7 +117,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data = array(); $mainPage = Title::newMainPage(); $data['mainpage'] = $mainPage->getPrefixedText(); - $data['base'] = $mainPage->getFullUrl(); + $data['base'] = wfExpandUrl( $mainPage->getFullUrl() ); $data['sitename'] = $GLOBALS['wgSitename']; $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}"; $data['phpversion'] = phpversion(); @@ -284,7 +284,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { if ( isset( $langNames[$row->iw_prefix] ) ) { $val['language'] = $langNames[$row->iw_prefix]; } - $val['url'] = $row->iw_url; + $val['url'] = wfExpandUrl( $row->iw_url ); $val['wikiid'] = $row->iw_wikiid; $val['api'] = $row->iw_api; @@ -448,7 +448,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { protected function appendRightsInfo( $property ) { global $wgRightsPage, $wgRightsUrl, $wgRightsText; $title = Title::newFromText( $wgRightsPage ); - $url = $title ? $title->getFullURL() : $wgRightsUrl; + $url = $title ? wfExpandUrl( $title->getFullURL() ) : $wgRightsUrl; $text = $wgRightsText; if ( !$text && $title ) { $text = $title->getPrefixedText(); -- 2.20.1