44 parent::__construct( $query, $moduleName,
'eu' );
46 $this->urlUtils = $urlUtils;
58 $this->run( $resultPageSet );
65 private function run( $resultPageSet =
null ) {
69 $query = $params[
'query'];
70 $protocol = LinkFilter::getProtocolPrefix( $params[
'protocol'] );
72 $this->
addTables( [
'externallinks',
'page' ] );
73 $this->
addJoinConds( [
'page' => [
'JOIN',
'page_id=el_from' ] ] );
74 $fields = [
'el_to_domain_index',
'el_to_path' ];
78 $miser_ns = $params[
'namespace'] ?: [];
80 $this->
addWhereFld(
'page_namespace', $params[
'namespace'] );
82 if ( $query !==
null && $query !==
'' ) {
84 $query = Parser::normalizeLinkUrl( $query );
85 $conds = LinkFilter::getQueryConditions( $query, [
86 'protocol' => $protocol,
87 'oneWildcard' =>
true,
95 if ( $protocol !==
null ) {
97 $db->expr(
'el_to_domain_index', IExpression::LIKE,
new LikeValue(
"$protocol", $db->anyString() ) )
101 $orderBy = [
'el_id' ];
103 $this->
addOption(
'ORDER BY', $orderBy );
106 $prop = array_fill_keys( $params[
'prop'],
true );
107 $fld_ids = isset( $prop[
'ids'] );
108 $fld_title = isset( $prop[
'title'] );
109 $fld_url = isset( $prop[
'url'] );
111 if ( $resultPageSet ===
null ) {
117 foreach ( $fields as $field ) {
121 $this->
addFields( $resultPageSet->getPageTableFields() );
130 if ( $params[
'continue'] !==
null ) {
132 array_fill( 0, count( $orderBy ),
'string' ) );
133 $conds = array_combine( $orderBy, array_map(
'rawurldecode', $cont ) );
134 $this->
addWhere( $db->buildComparison(
'>=', $conds ) );
137 $res = $this->
select( __METHOD__ );
141 if ( $resultPageSet ===
null ) {
146 foreach ( $res as $row ) {
147 if ( ++$count > $limit ) {
150 $this->setContinue( $orderBy, $row );
154 if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
158 if ( $resultPageSet ===
null ) {
163 $vals[
'pageid'] = (int)$row->page_id;
166 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
170 $to = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path;
172 if ( $params[
'expandurl'] ) {
177 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
179 $this->setContinue( $orderBy, $row );
183 $resultPageSet->processDbRow( $row );
187 if ( $resultPageSet ===
null ) {
188 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
193 private function setContinue( $orderBy, $row ) {
195 foreach ( $orderBy as $field ) {
196 $fields[] = strtr( $row->$field, [
'%' =>
'%25',
'|' =>
'%7C' ] );
204 ParamValidator::PARAM_ISMULTI =>
true,
205 ParamValidator::PARAM_DEFAULT =>
'ids|title|url',
206 ParamValidator::PARAM_TYPE => [
217 ParamValidator::PARAM_TYPE => LinkFilter::prepareProtocols(),
218 ParamValidator::PARAM_DEFAULT =>
'',
222 ParamValidator::PARAM_ISMULTI =>
true,
223 ParamValidator::PARAM_TYPE =>
'namespace'
226 ParamValidator::PARAM_DEFAULT => 10,
227 ParamValidator::PARAM_TYPE =>
'limit',
228 IntegerDef::PARAM_MIN => 1,
233 ParamValidator::PARAM_TYPE =>
'boolean',
234 ParamValidator::PARAM_DEFAULT =>
false,
235 ParamValidator::PARAM_DEPRECATED =>
true,
241 'api-help-param-limited-in-miser-mode',
250 'action=query&list=exturlusage&euquery=www.mediawiki.org'
251 =>
'apihelp-query+exturlusage-example-simple',
256 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Exturlusage';
261class_alias( ApiQueryExtLinksUsage::class,
'ApiQueryExtLinksUsage' );
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()