From 88639151ccc97729333a8f773ee3a20183040fa2 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Fri, 7 Sep 2012 20:29:22 +0200 Subject: [PATCH] Add 'expandurl' to prop=extlinks/list=exturlusage Allow prop=extlinks and list=exturlusage to expand protocol-relative urls See also bug 40052 Change-Id: I3fd661b51c44020dad9e95ac2fe6994c6e22aabb --- includes/api/ApiQueryExtLinksUsage.php | 14 ++++++++++---- includes/api/ApiQueryExternalLinks.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index 42b398ba92..6081601bba 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -121,8 +121,12 @@ 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; + $to = $row->el_to; + // expand protocol-relative urls + if( $params['expandurl'] ) { + $to = wfExpandUrl( $to, PROTO_CANONICAL ); + } + $vals['url'] = $to; } $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); if ( !$fit ) { @@ -169,7 +173,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 - ) + ), + 'expandurl' => false, ); } @@ -218,7 +223,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { ), 'query' => 'Search string without protocol. See [[Special:LinkSearch]]. Leave empty to list all external links', 'namespace' => 'The page namespace(s) to enumerate.', - 'limit' => 'How many pages to return.' + 'limit' => 'How many pages to return.', + 'expandurl' => 'Expand protocol-relative urls with the canonical protocol', ); if ( $wgMiserMode ) { diff --git a/includes/api/ApiQueryExternalLinks.php b/includes/api/ApiQueryExternalLinks.php index 9365a9b845..1449a96784 100644 --- a/includes/api/ApiQueryExternalLinks.php +++ b/includes/api/ApiQueryExternalLinks.php @@ -86,8 +86,12 @@ 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 ); + $to = $row->el_to; + // expand protocol-relative urls + if( $params['expandurl'] ) { + $to = wfExpandUrl( $to, PROTO_CANONICAL ); + } + ApiResult::setContent( $entry, $to ); $fit = $this->addPageSubItem( $row->el_from, $entry ); if ( !$fit ) { $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); @@ -117,6 +121,7 @@ class ApiQueryExternalLinks extends ApiQueryBase { ApiBase::PARAM_DFLT => '', ), 'query' => null, + 'expandurl' => false, ); } @@ -130,6 +135,7 @@ class ApiQueryExternalLinks extends ApiQueryBase { "Leave both this and {$p}query empty to list all external links" ), 'query' => 'Search string without protocol. Useful for checking whether a certain page contains a certain external url', + 'expandurl' => 'Expand protocol-relative urls with the canonical protocol', ); } -- 2.20.1