summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryExtLinksUsage.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryExtLinksUsage.php')
-rw-r--r--includes/api/ApiQueryExtLinksUsage.php109
1 files changed, 69 insertions, 40 deletions
diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php
index ecd9e699..89928372 100644
--- a/includes/api/ApiQueryExtLinksUsage.php
+++ b/includes/api/ApiQueryExtLinksUsage.php
@@ -1,6 +1,6 @@
<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on July 7, 2007
*
@@ -50,45 +50,32 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
$this->run( $resultPageSet );
}
+ /**
+ * @param $resultPageSet ApiPageSet
+ * @return void
+ */
private function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
- $protocol = $params['protocol'];
$query = $params['query'];
+ $protocol = self::getProtocolPrefix( $params['protocol'] );
- // Find the right prefix
- global $wgUrlProtocols;
- if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) {
- foreach ( $wgUrlProtocols as $p ) {
- if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
- $protocol = $p;
- break;
- }
- }
- } else {
- $protocol = null;
- }
-
- $db = $this->getDB();
$this->addTables( array( 'page', 'externallinks' ) ); // must be in this order for 'USE INDEX'
$this->addOption( 'USE INDEX', 'el_index' );
$this->addWhere( 'page_id=el_from' );
- $this->addWhereFld( 'page_namespace', $params['namespace'] );
- if ( !is_null( $query ) || $query != '' ) {
- if ( is_null( $protocol ) ) {
- $protocol = 'http://';
- }
+ global $wgMiserMode;
+ $miser_ns = array();
+ if ( $wgMiserMode ) {
+ $miser_ns = $params['namespace'];
+ } else {
+ $this->addWhereFld( 'page_namespace', $params['namespace'] );
+ }
- $likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
- if ( !$likeQuery ) {
- $this->dieUsage( 'Invalid query', 'bad_query' );
- }
+ $whereQuery = $this->prepareUrlQuerySearchString( $query, $protocol );
- $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
- $this->addWhere( 'el_index ' . $db->buildLike( $likeQuery ) );
- } elseif ( !is_null( $protocol ) ) {
- $this->addWhere( 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ) );
+ if ( $whereQuery !== null ) {
+ $this->addWhere( $whereQuery );
}
$prop = array_flip( $params['prop'] );
@@ -125,6 +112,10 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
break;
}
+ if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
+ continue;
+ }
+
if ( is_null( $resultPageSet ) ) {
$vals = array();
if ( $fld_ids ) {
@@ -135,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 );
@@ -154,12 +146,6 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
}
public function getAllowedParams() {
- global $wgUrlProtocols;
- $protocols = array( '' );
- foreach ( $wgUrlProtocols as $p ) {
- $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
- }
-
return array(
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
@@ -174,7 +160,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
ApiBase::PARAM_TYPE => 'integer'
),
'protocol' => array(
- ApiBase::PARAM_TYPE => $protocols,
+ ApiBase::PARAM_TYPE => self::prepareProtocols(),
ApiBase::PARAM_DFLT => '',
),
'query' => null,
@@ -192,13 +178,42 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
);
}
+ public static function prepareProtocols() {
+ global $wgUrlProtocols;
+ $protocols = array( '' );
+ foreach ( $wgUrlProtocols as $p ) {
+ if ( $p !== '//' ) {
+ $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
+ }
+ }
+ return $protocols;
+ }
+
+ public static function getProtocolPrefix( $protocol ) {
+ // Find the right prefix
+ global $wgUrlProtocols;
+ if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) {
+ foreach ( $wgUrlProtocols as $p ) {
+ if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
+ $protocol = $p;
+ break;
+ }
+ }
+
+ return $protocol;
+ } else {
+ return null;
+ }
+ }
+
public function getParamDescription() {
+ global $wgMiserMode;
$p = $this->getModulePrefix();
- return array(
+ $desc = array(
'prop' => array(
'What pieces of information to include',
- ' ids - Adds the id of page',
- ' title - Adds the title and namespace id of the page',
+ ' ids - Adds the ID of page',
+ ' title - Adds the title and namespace ID of the page',
' url - Adds the URL used in the page',
),
'offset' => 'Used for paging. Use the value returned for "continue"',
@@ -210,6 +225,16 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
'namespace' => 'The page namespace(s) to enumerate.',
'limit' => 'How many pages to return.'
);
+
+ if ( $wgMiserMode ) {
+ $desc['namespace'] = array(
+ $desc['namespace'],
+ "NOTE: Due to \$wgMiserMode, using this may result in fewer than \"{$p}limit\" results",
+ 'returned before continuing; in extreme cases, zero results may be returned',
+ );
+ }
+
+ return $desc;
}
public function getDescription() {
@@ -228,7 +253,11 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Exturlusage';
+ }
+
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQueryExtLinksUsage.php 70647 2010-08-07 19:59:42Z ialex $';
+ return __CLASS__ . ': $Id: ApiQueryExtLinksUsage.php 104449 2011-11-28 15:52:04Z reedy $';
}
}