36 switch ( $moduleName ) {
38 $this->table =
'pagelinks';
40 $this->titlesParam =
'titles';
41 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Links';
44 $this->table =
'templatelinks';
46 $this->titlesParam =
'templates';
47 $this->helpUrl =
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Templates';
53 parent::__construct( $query, $moduleName, $this->prefix );
65 $this->
run( $resultPageSet );
71 private function run( $resultPageSet =
null ) {
72 if ( $this->
getPageSet()->getGoodTitleCount() == 0 ) {
79 'pl_from' => $this->prefix .
'_from',
80 'pl_namespace' => $this->prefix .
'_namespace',
81 'pl_title' => $this->prefix .
'_title'
89 if ( $params[$this->titlesParam] ) {
91 $filterNS = $params[
'namespace'] ? array_flip( $params[
'namespace'] ) :
false;
94 foreach ( $params[$this->titlesParam] as
$t ) {
98 } elseif ( !$filterNS || isset( $filterNS[
$title->getNamespace()] ) ) {
102 $cond = $lb->constructSet( $this->prefix, $this->
getDB() );
105 $multiNS = count( $lb->data ) !== 1;
106 $multiTitle = count( array_merge( ...$lb->data ) ) !== 1;
111 } elseif ( $params[
'namespace'] ) {
112 $this->
addWhereFld( $this->prefix .
'_namespace', $params[
'namespace'] );
113 $multiNS = $params[
'namespace'] ===
null || count( $params[
'namespace'] ) !== 1;
116 if ( $params[
'continue'] !==
null ) {
117 $cont = explode(
'|', $params[
'continue'] );
119 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
120 $plfrom = (int)$cont[0];
121 $plns = (int)$cont[1];
122 $pltitle = $this->
getDB()->addQuotes( $cont[2] );
124 "{$this->prefix}_from $op $plfrom OR " .
125 "({$this->prefix}_from = $plfrom AND " .
126 "({$this->prefix}_namespace $op $plns OR " .
127 "({$this->prefix}_namespace = $plns AND " .
128 "{$this->prefix}_title $op= $pltitle)))"
132 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
139 if ( count( $this->
getPageSet()->getGoodTitles() ) != 1 ) {
140 $order[] = $this->prefix .
'_from' . $sort;
143 $order[] = $this->prefix .
'_namespace' . $sort;
146 $order[] = $this->prefix .
'_title' . $sort;
151 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
155 if ( $resultPageSet ===
null ) {
159 foreach (
$res as $row ) {
160 if ( ++$count > $params[
'limit'] ) {
164 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
172 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
179 foreach (
$res as $row ) {
180 if ( ++$count > $params[
'limit'] ) {
184 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
187 $titles[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
189 $resultPageSet->populateFromTitles( $titles );
210 $this->titlesParam => [
228 "action=query&prop={$name}&titles=Main%20Page"
229 =>
"apihelp-{$path}-example-simple",
230 "action=query&generator={$name}&titles=Main%20Page&prop=info"
231 =>
"apihelp-{$path}-example-generator",
232 "action=query&prop={$name}&titles=Main%20Page&{$this->prefix}namespace=2|10"
233 =>
"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) Stable to override.
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)
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.
Class representing a list of titles The execute() method checks them all for existence and adds them ...