Go to the documentation of this file.
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 ( !is_null( $params[
'continue'] ) ) {
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 ( is_null( $resultPageSet ) ) {
157 foreach (
$res as $row ) {
158 if ( ++$count > $params[
'limit'] ) {
162 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
170 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
177 foreach (
$res as $row ) {
178 if ( ++$count > $params[
'limit'] ) {
182 "{$row->pl_from}|{$row->pl_namespace}|{$row->pl_title}" );
187 $resultPageSet->populateFromTitles( $titles );
208 $this->titlesParam => [
226 "action=query&prop={$name}&titles=Main%20Page"
227 =>
"apihelp-{$path}-example-simple",
228 "action=query&generator={$name}&titles=Main%20Page&prop=info"
229 =>
"apihelp-{$path}-example-generator",
230 "action=query&prop={$name}&titles=Main%20Page&{$this->prefix}namespace=2|10"
231 =>
"apihelp-{$path}-example-namespaces",
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
addFields( $value)
Add a set of fields to select to the internal array.
This is the main query class.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
A query module to list all wiki links on a given set of pages.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
getPageSet()
Get the PageSet object to work on.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getModulePath()
Get the path to this module.
const LIMIT_BIG1
Fast query, standard limit.
getDB()
Get the Query database connection (read-only)
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
getExamplesMessages()
Returns usage examples for this module.
executeGenerator( $resultPageSet)
Execute this module as a generator.
__construct(ApiQuery $query, $moduleName)
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getCacheMode( $params)
Get the cache mode for the data generated by this module.
const LIMIT_BIG2
Fast query, apihighlimits limit.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
getHelpUrls()
Return links to more detailed help pages about the module.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
addWhere( $value)
Add a set of WHERE clauses to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
run( $resultPageSet=null)
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.