37 private const LINKS =
'links';
38 private const TEMPLATES =
'templates';
40 private $table, $prefix, $titlesParam, $helpUrl;
57 switch ( $moduleName ) {
59 $this->table =
'pagelinks';
61 $this->titlesParam =
'titles';
62 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Links';
65 $this->table =
'templatelinks';
67 $this->titlesParam =
'templates';
68 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Templates';
74 parent::__construct( $query, $moduleName, $this->prefix );
75 $this->linkBatchFactory = $linkBatchFactory;
76 $this->linksMigration = $linksMigration;
88 $this->run( $resultPageSet );
94 private function run( $resultPageSet =
null ) {
96 if ( $pages === [] ) {
102 if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
103 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields( $this->table );
104 $queryInfo = $this->linksMigration->getQueryInfo( $this->table );
105 $this->
addTables( $queryInfo[
'tables'] );
109 $nsField = $this->prefix .
'_namespace';
110 $titleField = $this->prefix .
'_title';
114 'pl_from' => $this->prefix .
'_from',
115 'pl_namespace' => $nsField,
116 'pl_title' => $titleField,
119 $this->
addWhereFld( $this->prefix .
'_from', array_keys( $pages ) );
123 if ( $params[$this->titlesParam] ) {
125 $filterNS = $params[
'namespace'] ? array_fill_keys( $params[
'namespace'],
true ) : false;
127 $lb = $this->linkBatchFactory->newLinkBatch();
128 foreach ( $params[$this->titlesParam] as $t ) {
129 $title = Title::newFromText( $t );
130 if ( !$title || $title->isExternal() ) {
132 } elseif ( !$filterNS || isset( $filterNS[$title->getNamespace()] ) ) {
133 $lb->addObj( $title );
136 if ( $lb->isEmpty() ) {
140 $cond = $lb->constructSet( $this->prefix, $this->
getDB() );
142 $multiNS = count( $lb->data ) !== 1;
143 $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
144 } elseif ( $params[
'namespace'] ) {
145 $this->
addWhereFld( $nsField, $params[
'namespace'] );
146 $multiNS = $params[
'namespace'] ===
null || count( $params[
'namespace'] ) !== 1;
149 if ( $params[
'continue'] !==
null ) {
150 $db = $this->
getDB();
152 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
153 $this->
addWhere( $db->buildComparison( $op, [
154 "{$this->prefix}_from" => $cont[0],
155 $nsField => $cont[1],
156 $titleField => $cont[2],
160 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
167 if ( count( $pages ) !== 1 ) {
168 $order[] = $this->prefix .
'_from' . $sort;
171 $order[] = $nsField . $sort;
174 $order[] = $titleField . $sort;
179 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
181 $res = $this->
select( __METHOD__ );
183 if ( $resultPageSet ===
null ) {
187 foreach ( $res as $row ) {
188 if ( ++$count > $params[
'limit'] ) {
192 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
200 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
207 foreach ( $res as $row ) {
208 if ( ++$count > $params[
'limit'] ) {
212 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
215 $titles[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
217 $resultPageSet->populateFromTitles( $titles );
224 ParamValidator::PARAM_TYPE =>
'namespace',
225 ParamValidator::PARAM_ISMULTI =>
true,
229 ParamValidator::PARAM_DEFAULT => 10,
230 ParamValidator::PARAM_TYPE =>
'limit',
231 IntegerDef::PARAM_MIN => 1,
238 $this->titlesParam => [
239 ParamValidator::PARAM_ISMULTI =>
true,
242 ParamValidator::PARAM_DEFAULT =>
'ascending',
243 ParamValidator::PARAM_TYPE => [
254 $title = Title::newMainPage()->getPrefixedText();
255 $mp = rawurlencode( $title );
258 "action=query&prop={$name}&titles={$mp}"
259 =>
"apihelp-{$path}-example-simple",
260 "action=query&generator={$name}&titles={$mp}&prop=info"
261 =>
"apihelp-{$path}-example-generator",
262 "action=query&prop={$name}&titles={$mp}&{$this->prefix}namespace=2|10"
263 =>
"apihelp-{$path}-example-namespaces",
268 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.