50 switch ( $moduleName ) {
52 $this->table =
'pagelinks';
54 $this->titlesParam =
'titles';
55 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Links';
58 $this->table =
'templatelinks';
60 $this->titlesParam =
'templates';
61 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Templates';
67 parent::__construct( $query, $moduleName, $this->prefix );
80 $this->
run( $resultPageSet );
86 private function run( $resultPageSet =
null ) {
87 if ( $this->
getPageSet()->getGoodTitleCount() == 0 ) {
94 'pl_from' => $this->prefix .
'_from',
95 'pl_namespace' => $this->prefix .
'_namespace',
96 'pl_title' => $this->prefix .
'_title'
104 if ( $params[$this->titlesParam] ) {
106 $filterNS = $params[
'namespace'] ? array_fill_keys( $params[
'namespace'],
true ) :
false;
108 $lb = $this->linkBatchFactory->newLinkBatch();
109 foreach ( $params[$this->titlesParam] as
$t ) {
113 } elseif ( !$filterNS || isset( $filterNS[
$title->getNamespace()] ) ) {
117 $cond = $lb->constructSet( $this->prefix, $this->
getDB() );
120 $multiNS = count( $lb->data ) !== 1;
121 $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
126 } elseif ( $params[
'namespace'] ) {
127 $this->
addWhereFld( $this->prefix .
'_namespace', $params[
'namespace'] );
128 $multiNS = $params[
'namespace'] ===
null || count( $params[
'namespace'] ) !== 1;
131 if ( $params[
'continue'] !==
null ) {
132 $cont = explode(
'|', $params[
'continue'] );
134 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
135 $plfrom = (int)$cont[0];
136 $plns = (int)$cont[1];
137 $pltitle = $this->
getDB()->addQuotes( $cont[2] );
139 "{$this->prefix}_from $op $plfrom OR " .
140 "({$this->prefix}_from = $plfrom AND " .
141 "({$this->prefix}_namespace $op $plns OR " .
142 "({$this->prefix}_namespace = $plns AND " .
143 "{$this->prefix}_title $op= $pltitle)))"
147 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
154 if ( count( $this->
getPageSet()->getGoodTitles() ) != 1 ) {
155 $order[] = $this->prefix .
'_from' . $sort;
158 $order[] = $this->prefix .
'_namespace' . $sort;
161 $order[] = $this->prefix .
'_title' . $sort;
166 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
170 if ( $resultPageSet ===
null ) {
174 foreach (
$res as $row ) {
175 if ( ++$count > $params[
'limit'] ) {
179 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
187 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
194 foreach (
$res as $row ) {
195 if ( ++$count > $params[
'limit'] ) {
199 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
202 $titles[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
204 $resultPageSet->populateFromTitles( $titles );
225 $this->titlesParam => [
243 "action=query&prop={$name}&titles=Main%20Page"
244 =>
"apihelp-{$path}-example-simple",
245 "action=query&generator={$name}&titles=Main%20Page&prop=info"
246 =>
"apihelp-{$path}-example-generator",
247 "action=query&prop={$name}&titles=Main%20Page&{$this->prefix}namespace=2|10"
248 =>
"apihelp-{$path}-example-namespaces",
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_EXTRA_NAMESPACES
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.
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.
__construct(ApiQuery $query, $moduleName, LinkBatchFactory $linkBatchFactory)
LinkBatchFactory $linkBatchFactory
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.
run( $resultPageSet=null)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
This is the main query class.