<?php
-
/**
- * Created on July 7, 2007
*
- * API for MediaWiki 1.8+
*
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Created on July 7, 2007
+ *
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( 'ApiQueryBase.php' );
-}
-
/**
* @ingroup API
*/
$this->run();
}
+ public function getCacheMode( $params ) {
+ return 'public';
+ }
+
public function executeGenerator( $resultPageSet ) {
$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'] );
break;
}
+ if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
+ continue;
+ }
+
if ( is_null( $resultPageSet ) ) {
$vals = array();
if ( $fld_ids ) {
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 );
}
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,
ApiBase::PARAM_TYPE => 'integer'
),
'protocol' => array(
- ApiBase::PARAM_TYPE => $protocols,
+ ApiBase::PARAM_TYPE => self::prepareProtocols(),
ApiBase::PARAM_DFLT => '',
),
'query' => null,
);
}
+ 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(
- 'prop' => 'What pieces of information to include',
+ $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',
+ ' url - Adds the URL used in the page',
+ ),
'offset' => 'Used for paging. Use the value returned for "continue"',
'protocol' => array(
"Protocol of the url. If empty and {$p}query set, the protocol is http.",
'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 getResultProperties() {
+ return array(
+ 'ids' => array(
+ 'pageid' => 'integer'
+ ),
+ 'title' => array(
+ 'ns' => 'namespace',
+ 'title' => 'string'
+ ),
+ 'url' => array(
+ 'url' => 'string'
+ )
+ );
}
public function getDescription() {
) );
}
- protected function getExamples() {
+ public function getExamples() {
return array(
'api.php?action=query&list=exturlusage&euquery=www.mediawiki.org'
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Exturlusage';
+ }
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}
-}
\ No newline at end of file
+}