37 private const LINKS =
'links';
38 private const TEMPLATES =
'templates';
40 private $table, $prefix, $titlesParam, $helpUrl;
43 private $linkBatchFactory;
46 private $linksMigration;
60 switch ( $moduleName ) {
62 $this->table =
'pagelinks';
64 $this->titlesParam =
'titles';
65 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Links';
68 $this->table =
'templatelinks';
70 $this->titlesParam =
'templates';
71 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Templates';
77 parent::__construct( $query, $moduleName, $this->prefix );
78 $this->linkBatchFactory = $linkBatchFactory;
79 $this->linksMigration = $linksMigration;
91 $this->run( $resultPageSet );
97 private function run( $resultPageSet =
null ) {
99 if ( $pages === [] ) {
105 if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
106 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields( $this->table );
107 $queryInfo = $this->linksMigration->getQueryInfo( $this->table );
108 $this->
addTables( $queryInfo[
'tables'] );
112 $nsField = $this->prefix .
'_namespace';
113 $titleField = $this->prefix .
'_title';
117 'pl_from' => $this->prefix .
'_from',
118 'pl_namespace' => $nsField,
119 'pl_title' => $titleField,
122 $this->
addWhereFld( $this->prefix .
'_from', array_keys( $pages ) );
126 if ( $params[$this->titlesParam] ) {
128 $filterNS = $params[
'namespace'] ? array_fill_keys( $params[
'namespace'],
true ) : false;
130 $lb = $this->linkBatchFactory->newLinkBatch();
131 foreach ( $params[$this->titlesParam] as
$t ) {
135 } elseif ( !$filterNS || isset( $filterNS[
$title->getNamespace()] ) ) {
139 $cond = $lb->constructSet( $this->prefix, $this->
getDB() );
142 $multiNS = count( $lb->data ) !== 1;
143 $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
148 } elseif ( $params[
'namespace'] ) {
149 $this->
addWhereFld( $nsField, $params[
'namespace'] );
150 $multiNS = $params[
'namespace'] ===
null || count( $params[
'namespace'] ) !== 1;
153 if ( $params[
'continue'] !==
null ) {
154 $db = $this->
getDB();
156 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
157 $this->
addWhere( $db->buildComparison( $op, [
158 "{$this->prefix}_from" => $cont[0],
159 $nsField => $cont[1],
160 $titleField => $cont[2],
164 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
171 if ( count( $pages ) !== 1 ) {
172 $order[] = $this->prefix .
'_from' . $sort;
175 $order[] = $nsField . $sort;
178 $order[] = $titleField . $sort;
183 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
187 if ( $resultPageSet ===
null ) {
191 foreach (
$res as $row ) {
192 if ( ++$count > $params[
'limit'] ) {
196 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
204 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
211 foreach (
$res as $row ) {
212 if ( ++$count > $params[
'limit'] ) {
216 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
219 $titles[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
221 $resultPageSet->populateFromTitles( $titles );
228 ParamValidator::PARAM_TYPE =>
'namespace',
229 ParamValidator::PARAM_ISMULTI =>
true,
233 ParamValidator::PARAM_DEFAULT => 10,
234 ParamValidator::PARAM_TYPE =>
'limit',
235 IntegerDef::PARAM_MIN => 1,
242 $this->titlesParam => [
243 ParamValidator::PARAM_ISMULTI =>
true,
246 ParamValidator::PARAM_DEFAULT =>
'ascending',
247 ParamValidator::PARAM_TYPE => [
258 $title = Title::newMainPage()->getPrefixedText();
259 $mp = rawurlencode(
$title );
262 "action=query&prop={$name}&titles={$mp}"
263 =>
"apihelp-{$path}-example-simple",
264 "action=query&generator={$name}&titles={$mp}&prop=info"
265 =>
"apihelp-{$path}-example-generator",
266 "action=query&prop={$name}&titles={$mp}&{$this->prefix}namespace=2|10"
267 =>
"apihelp-{$path}-example-namespaces",
272 return $this->helpUrl;
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
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,...
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.