36 private const LINKS =
'links';
37 private const TEMPLATES =
'templates';
39 private $table, $prefix, $titlesParam, $helpUrl;
42 private $linkBatchFactory;
45 private $linksMigration;
59 switch ( $moduleName ) {
61 $this->table =
'pagelinks';
63 $this->titlesParam =
'titles';
64 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Links';
67 $this->table =
'templatelinks';
69 $this->titlesParam =
'templates';
70 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Templates';
76 parent::__construct( $query, $moduleName, $this->prefix );
77 $this->linkBatchFactory = $linkBatchFactory;
78 $this->linksMigration = $linksMigration;
90 $this->run( $resultPageSet );
96 private function run( $resultPageSet =
null ) {
98 if ( $pages === [] ) {
104 if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
105 list( $nsField, $titleField ) = $this->linksMigration->getTitleFields( $this->table );
106 $queryInfo = $this->linksMigration->getQueryInfo( $this->table );
107 $this->
addTables( $queryInfo[
'tables'] );
111 $nsField = $this->prefix .
'_namespace';
112 $titleField = $this->prefix .
'_title';
116 'pl_from' => $this->prefix .
'_from',
117 'pl_namespace' => $nsField,
118 'pl_title' => $titleField,
121 $this->
addWhereFld( $this->prefix .
'_from', array_keys( $pages ) );
125 if ( $params[$this->titlesParam] ) {
127 $filterNS = $params[
'namespace'] ? array_fill_keys( $params[
'namespace'],
true ) : false;
129 $lb = $this->linkBatchFactory->newLinkBatch();
130 foreach ( $params[$this->titlesParam] as
$t ) {
134 } elseif ( !$filterNS || isset( $filterNS[
$title->getNamespace()] ) ) {
138 $cond = $lb->constructSet( $this->prefix, $this->
getDB() );
141 $multiNS = count( $lb->data ) !== 1;
142 $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
147 } elseif ( $params[
'namespace'] ) {
148 $this->
addWhereFld( $nsField, $params[
'namespace'] );
149 $multiNS = $params[
'namespace'] ===
null || count( $params[
'namespace'] ) !== 1;
152 if ( $params[
'continue'] !==
null ) {
153 $cont = explode(
'|', $params[
'continue'] );
155 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
156 $plfrom = (int)$cont[0];
157 $plns = (int)$cont[1];
158 $pltitle = $this->
getDB()->addQuotes( $cont[2] );
160 "{$this->prefix}_from $op $plfrom OR " .
161 "({$this->prefix}_from = $plfrom AND " .
162 "($nsField $op $plns OR " .
163 "($nsField = $plns AND " .
164 "$titleField $op= $pltitle)))"
168 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
175 if ( count( $pages ) !== 1 ) {
176 $order[] = $this->prefix .
'_from' . $sort;
179 $order[] = $nsField . $sort;
182 $order[] = $titleField . $sort;
187 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
191 if ( $resultPageSet ===
null ) {
195 foreach (
$res as $row ) {
196 if ( ++$count > $params[
'limit'] ) {
200 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
208 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
215 foreach (
$res as $row ) {
216 if ( ++$count > $params[
'limit'] ) {
220 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
225 $resultPageSet->populateFromTitles( $titles );
232 ParamValidator::PARAM_TYPE =>
'namespace',
233 ParamValidator::PARAM_ISMULTI =>
true,
237 ParamValidator::PARAM_DEFAULT => 10,
238 ParamValidator::PARAM_TYPE =>
'limit',
239 IntegerDef::PARAM_MIN => 1,
246 $this->titlesParam => [
247 ParamValidator::PARAM_ISMULTI =>
true,
250 ParamValidator::PARAM_DEFAULT =>
'ascending',
251 ParamValidator::PARAM_TYPE => [
262 $title = Title::newMainPage()->getPrefixedText();
263 $mp = rawurlencode(
$title );
266 "action=query&prop={$name}&titles={$mp}"
267 =>
"apihelp-{$path}-example-simple",
268 "action=query&generator={$name}&titles={$mp}&prop=info"
269 =>
"apihelp-{$path}-example-generator",
270 "action=query&prop={$name}&titles={$mp}&{$this->prefix}namespace=2|10"
271 =>
"apihelp-{$path}-example-namespaces",
276 return $this->helpUrl;
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
const LIMIT_BIG1
Fast query, standard limit.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModulePath()
Get the path to this module.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
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)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
getPageSet()
Get the PageSet object to work on.
A query module to list all wiki links on a given set of pages.
getHelpUrls()
Return links to more detailed help pages about the module.
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
executeGenerator( $resultPageSet)
Execute this module as a generator.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, LinkBatchFactory $linkBatchFactory, LinksMigration $linksMigration)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
This is the main query class.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.