44 parent::__construct( $query, $moduleName,
'el' );
46 $this->urlUtils = $urlUtils;
51 if ( $pages === [] ) {
58 $query = $params[
'query'];
59 $protocol = LinkFilter::getProtocolPrefix( $params[
'protocol'] );
61 $fields = [
'el_from' ];
62 $fields[] =
'el_to_domain_index';
63 $fields[] =
'el_to_path';
64 $continueField =
'el_to_domain_index';
68 $this->
addWhereFld(
'el_from', array_keys( $pages ) );
70 if ( $query !==
null && $query !==
'' ) {
74 $conds = LinkFilter::getQueryConditions( $query, [
75 'protocol' => $protocol,
76 'oneWildcard' =>
true,
84 if ( $protocol !==
null ) {
85 $this->
addWhere( $continueField . $db->buildLike(
"$protocol", $db->anyString() ) );
89 $orderBy = [
'el_id' ];
94 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
96 if ( $params[
'continue'] !==
null ) {
98 array_fill( 0, count( $orderBy ),
'string' ) );
99 $conds = array_combine( $orderBy, array_map(
'rawurldecode', $cont ) );
100 $this->
addWhere( $db->buildComparison(
'>=', $conds ) );
103 $res = $this->
select( __METHOD__ );
106 foreach ( $res as $row ) {
107 if ( ++$count > $params[
'limit'] ) {
110 $this->setContinue( $orderBy, $row );
114 $to = LinkFilter::reverseIndexes( $row->el_to_domain_index ) . $row->el_to_path;
116 if ( $params[
'expandurl'] ) {
119 ApiResult::setContentValue( $entry,
'url', $to );
122 $this->setContinue( $orderBy, $row );
128 private function setContinue( $orderBy, $row ) {
130 foreach ( $orderBy as $field ) {
131 $fields[] = strtr( $row->$field, [
'%' =>
'%25',
'|' =>
'%7C' ] );
143 ParamValidator::PARAM_DEFAULT => 10,
144 ParamValidator::PARAM_TYPE =>
'limit',
145 IntegerDef::PARAM_MIN => 1,
153 ParamValidator::PARAM_TYPE => LinkFilter::prepareProtocols(),
154 ParamValidator::PARAM_DEFAULT =>
'',
158 ParamValidator::PARAM_TYPE =>
'boolean',
159 ParamValidator::PARAM_DEFAULT =>
false,
160 ParamValidator::PARAM_DEPRECATED =>
true,
166 $title = Title::newMainPage()->getPrefixedText();
167 $mp = rawurlencode( $title );
170 "action=query&prop=extlinks&titles={$mp}"
171 =>
'apihelp-query+extlinks-example-simple',
176 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Extlinks';
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const LIMIT_BIG1
Fast query, standard limit.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addFields( $value)
Add a set of fields to select to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getPageSet()
Get the PageSet object to work on.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
A query module to list all external URLs found on a given set of pages.
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, UrlUtils $urlUtils)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
This is the main query class.
static normalizeLinkUrl( $url)
Replace unusual escape codes in a URL with their equivalent characters.