Add 'expandurl' to prop=extlinks/list=exturlusage
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 7 Sep 2012 18:29:22 +0000 (20:29 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Oct 2012 02:04:11 +0000 (02:04 +0000)
Allow prop=extlinks and list=exturlusage to expand protocol-relative
urls

See also bug 40052

Change-Id: I3fd661b51c44020dad9e95ac2fe6994c6e22aabb

includes/api/ApiQueryExtLinksUsage.php
includes/api/ApiQueryExternalLinks.php

index 42b398b..6081601 100644 (file)
@@ -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 ) {
index 9365a9b..1449a96 100644 (file)
@@ -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',
                );
        }