27 private const LINKS =
'links';
28 private const TEMPLATES =
'templates';
30 private string $table;
31 private string $prefix;
32 private string $titlesParam;
33 private string $helpUrl;
34 private ?
string $virtualdomain;
42 switch ( $moduleName ) {
44 $this->table =
'pagelinks';
46 $this->titlesParam =
'titles';
47 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Links';
48 $this->virtualdomain = PageLinksTable::VIRTUAL_DOMAIN;
51 $this->table =
'templatelinks';
53 $this->titlesParam =
'templates';
54 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Templates';
55 $this->virtualdomain = TemplateLinksTable::VIRTUAL_DOMAIN;
61 parent::__construct( $query, $moduleName, $this->prefix );
75 $this->run( $resultPageSet );
81 private function run( $resultPageSet =
null ) {
83 if ( $pages === [] ) {
91 if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
92 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields( $this->table );
93 $queryInfo = $this->linksMigration->getQueryInfo( $this->table );
98 $nsField = $this->prefix .
'_namespace';
99 $titleField = $this->prefix .
'_title';
103 'pl_from' => $this->prefix .
'_from',
104 'pl_namespace' => $nsField,
105 'pl_title' => $titleField,
108 $this->
addWhereFld( $this->prefix .
'_from', array_keys( $pages ) );
112 if ( $params[$this->titlesParam] ) {
114 $filterNS =
$params[
'namespace'] ? array_fill_keys( $params[
'namespace'],
true ) : false;
116 $lb = $this->linkBatchFactory->newLinkBatch();
117 foreach ( $params[$this->titlesParam] as $t ) {
118 $title = Title::newFromText( $t );
119 if ( !$title || $title->isExternal() ) {
121 } elseif ( !$filterNS || isset( $filterNS[$title->getNamespace()] ) ) {
122 $lb->addObj( $title );
125 if ( $lb->isEmpty() ) {
129 $cond = $lb->constructSet( $this->prefix, $this->
getDB() );
131 $multiNS = count( $lb->data ) !== 1;
132 $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
133 } elseif ( $params[
'namespace'] ) {
134 $this->
addWhereFld( $nsField, $params[
'namespace'] );
135 $multiNS =
$params[
'namespace'] ===
null || count( $params[
'namespace'] ) !== 1;
138 if ( $params[
'continue'] !==
null ) {
140 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
142 "{$this->prefix}_from" => $cont[0],
143 $nsField => $cont[1],
144 $titleField => $cont[2],
148 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
155 if ( count( $pages ) !== 1 ) {
156 $order[] = $this->prefix .
'_from' . $sort;
159 $order[] = $nsField . $sort;
162 $order[] = $titleField . $sort;
167 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
169 $res = $this->
select( __METHOD__ );
171 if ( $resultPageSet ===
null ) {
175 foreach ( $res as $row ) {
176 if ( ++$count > $params[
'limit'] ) {
180 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
188 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
195 foreach ( $res as $row ) {
196 if ( ++$count > $params[
'limit'] ) {
200 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
205 $resultPageSet->populateFromTitles( $titles );
213 ParamValidator::PARAM_TYPE =>
'namespace',
214 ParamValidator::PARAM_ISMULTI =>
true,
218 ParamValidator::PARAM_DEFAULT => 10,
219 ParamValidator::PARAM_TYPE =>
'limit',
220 IntegerDef::PARAM_MIN => 1,
227 $this->titlesParam => [
228 ParamValidator::PARAM_ISMULTI =>
true,
231 ParamValidator::PARAM_DEFAULT =>
'ascending',
232 ParamValidator::PARAM_TYPE => [
244 $title = Title::newMainPage()->getPrefixedText();
245 $mp = rawurlencode( $title );
248 "action=query&prop={$name}&titles={$mp}"
249 =>
"apihelp-{$path}-example-simple",
250 "action=query&generator={$name}&titles={$mp}&prop=info"
251 =>
"apihelp-{$path}-example-generator",
252 "action=query&prop={$name}&titles={$mp}&{$this->prefix}namespace=2|10"
253 =>
"apihelp-{$path}-example-namespaces",
259 return $this->helpUrl;
264class_alias( ApiQueryLinks::class,
'ApiQueryLinks' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Factory for LinkBatch objects to batch query page metadata.