2014-08-20 17:32:01 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* API module to handle links table back-queries
|
|
|
|
|
*
|
2017-06-13 16:51:53 +00:00
|
|
|
* Copyright © 2014 Wikimedia Foundation and contributors
|
2014-08-20 17:32:01 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @since 1.24
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This implements prop=redirects, prop=linkshere, prop=catmembers,
|
|
|
|
|
* prop=transcludedin, and prop=fileusage
|
|
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
* @since 1.24
|
|
|
|
|
*/
|
|
|
|
|
class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
|
|
|
|
|
|
|
|
|
|
// Data for the various modules implemented by this class
|
2016-02-17 09:09:32 +00:00
|
|
|
private static $settings = [
|
|
|
|
|
'redirects' => [
|
2014-08-20 17:32:01 +00:00
|
|
|
'code' => 'rd',
|
|
|
|
|
'prefix' => 'rd',
|
|
|
|
|
'linktable' => 'redirect',
|
2016-02-17 09:09:32 +00:00
|
|
|
'props' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
'fragment',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-08-20 17:32:01 +00:00
|
|
|
'showredirects' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'show' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
'fragment',
|
|
|
|
|
'!fragment',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'linkshere' => [
|
2014-08-20 17:32:01 +00:00
|
|
|
'code' => 'lh',
|
|
|
|
|
'prefix' => 'pl',
|
|
|
|
|
'linktable' => 'pagelinks',
|
2016-06-30 17:48:38 +00:00
|
|
|
'indexes' => [ 'pl_namespace', 'pl_backlinks_namespace' ],
|
2014-08-20 17:32:01 +00:00
|
|
|
'from_namespace' => true,
|
|
|
|
|
'showredirects' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'transcludedin' => [
|
2014-08-20 17:32:01 +00:00
|
|
|
'code' => 'ti',
|
|
|
|
|
'prefix' => 'tl',
|
|
|
|
|
'linktable' => 'templatelinks',
|
2016-06-30 17:48:38 +00:00
|
|
|
'indexes' => [ 'tl_namespace', 'tl_backlinks_namespace' ],
|
2014-08-20 17:32:01 +00:00
|
|
|
'from_namespace' => true,
|
|
|
|
|
'showredirects' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'fileusage' => [
|
2014-08-20 17:32:01 +00:00
|
|
|
'code' => 'fu',
|
|
|
|
|
'prefix' => 'il',
|
|
|
|
|
'linktable' => 'imagelinks',
|
2016-06-30 17:48:38 +00:00
|
|
|
'indexes' => [ 'il_to', 'il_backlinks_namespace' ],
|
2014-08-20 17:32:01 +00:00
|
|
|
'from_namespace' => true,
|
|
|
|
|
'to_namespace' => NS_FILE,
|
|
|
|
|
'exampletitle' => 'File:Example.jpg',
|
|
|
|
|
'showredirects' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2014-08-20 17:32:01 +00:00
|
|
|
|
|
|
|
|
public function __construct( ApiQuery $query, $moduleName ) {
|
|
|
|
|
parent::__construct( $query, $moduleName, self::$settings[$moduleName]['code'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$this->run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function executeGenerator( $resultPageSet ) {
|
|
|
|
|
$this->run( $resultPageSet );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param ApiPageSet|null $resultPageSet
|
2014-08-20 17:32:01 +00:00
|
|
|
*/
|
|
|
|
|
private function run( ApiPageSet $resultPageSet = null ) {
|
|
|
|
|
$settings = self::$settings[$this->getModuleName()];
|
|
|
|
|
|
|
|
|
|
$db = $this->getDB();
|
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
$prop = array_flip( $params['prop'] );
|
|
|
|
|
$emptyString = $db->addQuotes( '' );
|
|
|
|
|
|
|
|
|
|
$pageSet = $this->getPageSet();
|
2014-09-26 14:56:00 +00:00
|
|
|
$titles = $pageSet->getGoodAndMissingTitles();
|
|
|
|
|
$map = $pageSet->getGoodAndMissingTitlesByNamespace();
|
2014-08-20 17:32:01 +00:00
|
|
|
|
API: Allow finding log events and links to special pages
Log events are sometimes attributed to a special page; it should be
allowed to use rcnamespace or lenamespace to filter for these.
It's also possible for special pages to be the targets of redirects, so
list=allredirects and prop=redirects should find them.
Maybe someday we'll record links to and transclusions of special pages
too (see T19597), so we may as well make it possible to query for those
as well via list=alllinks, list=alltransclusions, list=backlinks,
list=embeddedin, prop=linkshere, prop=transcludedin, prop=links, and
prop=templates.
NS_MEDIA has similar considerations: although we currently "normalize"
page links to the corresponding File and I don't think anything logs the
Media title rather than the File, transclusions and redirects do show
up in those tables.
Bug: T154319
Change-Id: I00348f83855c6c703b6bd6015f6d3bedc5bfd1c5
2017-01-06 17:49:27 +00:00
|
|
|
// Add in special pages, they can theoretically have backlinks too.
|
|
|
|
|
// (although currently they only do for prop=redirects)
|
|
|
|
|
foreach ( $pageSet->getSpecialTitles() as $id => $title ) {
|
|
|
|
|
$titles[] = $title;
|
|
|
|
|
$map[$title->getNamespace()][$title->getDBkey()] = $id;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 17:32:01 +00:00
|
|
|
// Determine our fields to query on
|
|
|
|
|
$p = $settings['prefix'];
|
|
|
|
|
$hasNS = !isset( $settings['to_namespace'] );
|
|
|
|
|
if ( $hasNS ) {
|
|
|
|
|
$bl_namespace = "{$p}_namespace";
|
|
|
|
|
$bl_title = "{$p}_title";
|
|
|
|
|
} else {
|
|
|
|
|
$bl_namespace = $settings['to_namespace'];
|
|
|
|
|
$bl_title = "{$p}_to";
|
|
|
|
|
|
|
|
|
|
$titles = array_filter( $titles, function ( $t ) use ( $bl_namespace ) {
|
|
|
|
|
return $t->getNamespace() === $bl_namespace;
|
|
|
|
|
} );
|
2016-02-17 09:09:32 +00:00
|
|
|
$map = array_intersect_key( $map, [ $bl_namespace => true ] );
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
$bl_from = "{$p}_from";
|
|
|
|
|
|
|
|
|
|
if ( !$titles ) {
|
|
|
|
|
return; // nothing to do
|
|
|
|
|
}
|
2018-10-01 14:18:40 +00:00
|
|
|
if ( $params['namespace'] !== null && count( $params['namespace'] ) === 0 ) {
|
|
|
|
|
return; // nothing to do
|
|
|
|
|
}
|
2014-08-20 17:32:01 +00:00
|
|
|
|
|
|
|
|
// Figure out what we're sorting by, and add associated WHERE clauses.
|
|
|
|
|
// MySQL's query planner screws up if we include a field in ORDER BY
|
|
|
|
|
// when it's constant in WHERE, so we have to test that for each field.
|
2016-02-17 09:09:32 +00:00
|
|
|
$sortby = [];
|
2014-08-20 17:32:01 +00:00
|
|
|
if ( $hasNS && count( $map ) > 1 ) {
|
|
|
|
|
$sortby[$bl_namespace] = 'ns';
|
|
|
|
|
}
|
|
|
|
|
$theTitle = null;
|
|
|
|
|
foreach ( $map as $nsTitles ) {
|
|
|
|
|
reset( $nsTitles );
|
|
|
|
|
$key = key( $nsTitles );
|
|
|
|
|
if ( $theTitle === null ) {
|
|
|
|
|
$theTitle = $key;
|
|
|
|
|
}
|
|
|
|
|
if ( count( $nsTitles ) > 1 || $key !== $theTitle ) {
|
|
|
|
|
$sortby[$bl_title] = 'title';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$miser_ns = null;
|
|
|
|
|
if ( $params['namespace'] !== null ) {
|
2015-09-23 13:31:39 +00:00
|
|
|
if ( empty( $settings['from_namespace'] ) ) {
|
|
|
|
|
if ( $this->getConfig()->get( 'MiserMode' ) ) {
|
|
|
|
|
$miser_ns = $params['namespace'];
|
|
|
|
|
} else {
|
|
|
|
|
$this->addWhereFld( 'page_namespace', $params['namespace'] );
|
|
|
|
|
}
|
2014-08-20 17:32:01 +00:00
|
|
|
} else {
|
|
|
|
|
$this->addWhereFld( "{$p}_from_namespace", $params['namespace'] );
|
2017-12-04 18:36:48 +00:00
|
|
|
if ( !empty( $settings['from_namespace'] )
|
|
|
|
|
&& $params['namespace'] !== null && count( $params['namespace'] ) > 1
|
|
|
|
|
) {
|
2014-08-20 17:32:01 +00:00
|
|
|
$sortby["{$p}_from_namespace"] = 'int';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$sortby[$bl_from] = 'int';
|
|
|
|
|
|
|
|
|
|
// Now use the $sortby to figure out the continuation
|
|
|
|
|
if ( !is_null( $params['continue'] ) ) {
|
|
|
|
|
$cont = explode( '|', $params['continue'] );
|
|
|
|
|
$this->dieContinueUsageIf( count( $cont ) != count( $sortby ) );
|
|
|
|
|
$where = '';
|
|
|
|
|
$i = count( $sortby ) - 1;
|
|
|
|
|
foreach ( array_reverse( $sortby, true ) as $field => $type ) {
|
|
|
|
|
$v = $cont[$i];
|
|
|
|
|
switch ( $type ) {
|
|
|
|
|
case 'ns':
|
|
|
|
|
case 'int':
|
|
|
|
|
$v = (int)$v;
|
|
|
|
|
$this->dieContinueUsageIf( $v != $cont[$i] );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$v = $db->addQuotes( $v );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $where === '' ) {
|
|
|
|
|
$where = "$field >= $v";
|
|
|
|
|
} else {
|
|
|
|
|
$where = "$field > $v OR ($field = $v AND ($where))";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$i--;
|
|
|
|
|
}
|
|
|
|
|
$this->addWhere( $where );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Populate the rest of the query
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addTables( [ $settings['linktable'], 'page' ] );
|
2014-08-20 17:32:01 +00:00
|
|
|
$this->addWhere( "$bl_from = page_id" );
|
|
|
|
|
|
|
|
|
|
if ( $this->getModuleName() === 'redirects' ) {
|
|
|
|
|
$this->addWhere( "rd_interwiki = $emptyString OR rd_interwiki IS NULL" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addFields( array_keys( $sortby ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addFields( [ 'bl_namespace' => $bl_namespace, 'bl_title' => $bl_title ] );
|
2014-08-20 17:32:01 +00:00
|
|
|
if ( is_null( $resultPageSet ) ) {
|
|
|
|
|
$fld_pageid = isset( $prop['pageid'] );
|
|
|
|
|
$fld_title = isset( $prop['title'] );
|
|
|
|
|
$fld_redirect = isset( $prop['redirect'] );
|
|
|
|
|
|
|
|
|
|
$this->addFieldsIf( 'page_id', $fld_pageid );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addFieldsIf( [ 'page_title', 'page_namespace' ], $fld_title );
|
2014-08-20 17:32:01 +00:00
|
|
|
$this->addFieldsIf( 'page_is_redirect', $fld_redirect );
|
|
|
|
|
|
|
|
|
|
// prop=redirects
|
|
|
|
|
$fld_fragment = isset( $prop['fragment'] );
|
|
|
|
|
$this->addFieldsIf( 'rd_fragment', $fld_fragment );
|
|
|
|
|
} else {
|
|
|
|
|
$this->addFields( $resultPageSet->getPageTableFields() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addFieldsIf( 'page_namespace', $miser_ns !== null );
|
|
|
|
|
|
|
|
|
|
if ( $hasNS ) {
|
API: Allow finding log events and links to special pages
Log events are sometimes attributed to a special page; it should be
allowed to use rcnamespace or lenamespace to filter for these.
It's also possible for special pages to be the targets of redirects, so
list=allredirects and prop=redirects should find them.
Maybe someday we'll record links to and transclusions of special pages
too (see T19597), so we may as well make it possible to query for those
as well via list=alllinks, list=alltransclusions, list=backlinks,
list=embeddedin, prop=linkshere, prop=transcludedin, prop=links, and
prop=templates.
NS_MEDIA has similar considerations: although we currently "normalize"
page links to the corresponding File and I don't think anything logs the
Media title rather than the File, transclusions and redirects do show
up in those tables.
Bug: T154319
Change-Id: I00348f83855c6c703b6bd6015f6d3bedc5bfd1c5
2017-01-06 17:49:27 +00:00
|
|
|
// Can't use LinkBatch because it throws away Special titles.
|
|
|
|
|
// And we already have the needed data structure anyway.
|
|
|
|
|
$this->addWhere( $db->makeWhereFrom2d( $map, $bl_namespace, $bl_title ) );
|
2014-08-20 17:32:01 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$where = [];
|
2014-08-20 17:32:01 +00:00
|
|
|
foreach ( $titles as $t ) {
|
|
|
|
|
if ( $t->getNamespace() == $bl_namespace ) {
|
|
|
|
|
$where[] = "$bl_title = " . $db->addQuotes( $t->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->addWhere( $db->makeList( $where, LIST_OR ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $params['show'] !== null ) {
|
|
|
|
|
// prop=redirects only
|
|
|
|
|
$show = array_flip( $params['show'] );
|
|
|
|
|
if ( isset( $show['fragment'] ) && isset( $show['!fragment'] ) ||
|
|
|
|
|
isset( $show['redirect'] ) && isset( $show['!redirect'] )
|
|
|
|
|
) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-show' );
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
$this->addWhereIf( "rd_fragment != $emptyString", isset( $show['fragment'] ) );
|
|
|
|
|
$this->addWhereIf(
|
|
|
|
|
"rd_fragment = $emptyString OR rd_fragment IS NULL",
|
|
|
|
|
isset( $show['!fragment'] )
|
|
|
|
|
);
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addWhereIf( [ 'page_is_redirect' => 1 ], isset( $show['redirect'] ) );
|
|
|
|
|
$this->addWhereIf( [ 'page_is_redirect' => 0 ], isset( $show['!redirect'] ) );
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override any ORDER BY from above with what we calculated earlier.
|
|
|
|
|
$this->addOption( 'ORDER BY', array_keys( $sortby ) );
|
|
|
|
|
|
2016-06-30 17:48:38 +00:00
|
|
|
// MySQL's optimizer chokes if we have too many values in "$bl_title IN
|
|
|
|
|
// (...)" and chooses the wrong index, so specify the correct index to
|
|
|
|
|
// use for the query. See T139056 for details.
|
|
|
|
|
if ( !empty( $settings['indexes'] ) ) {
|
|
|
|
|
list( $idxNoFromNS, $idxWithFromNS ) = $settings['indexes'];
|
|
|
|
|
if ( $params['namespace'] !== null && !empty( $settings['from_namespace'] ) ) {
|
|
|
|
|
$this->addOption( 'USE INDEX', [ $settings['linktable'] => $idxWithFromNS ] );
|
|
|
|
|
} else {
|
|
|
|
|
$this->addOption( 'USE INDEX', [ $settings['linktable'] => $idxNoFromNS ] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 14:13:10 +00:00
|
|
|
// MySQL (or at least 5.5.5-10.0.23-MariaDB) chooses a really bad query
|
|
|
|
|
// plan if it thinks there will be more matching rows in the linktable
|
|
|
|
|
// than are in page. Use STRAIGHT_JOIN here to force it to use the
|
|
|
|
|
// intended, fast plan. See T145079 for details.
|
|
|
|
|
$this->addOption( 'STRAIGHT_JOIN' );
|
|
|
|
|
|
2014-08-20 17:32:01 +00:00
|
|
|
$this->addOption( 'LIMIT', $params['limit'] + 1 );
|
|
|
|
|
|
|
|
|
|
$res = $this->select( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
if ( is_null( $resultPageSet ) ) {
|
2019-10-12 08:40:22 +00:00
|
|
|
if ( $fld_title ) {
|
|
|
|
|
$this->executeGenderCacheFromResultWrapper( $res, __METHOD__ );
|
|
|
|
|
}
|
2019-09-10 17:42:58 +00:00
|
|
|
|
2014-08-20 17:32:01 +00:00
|
|
|
$count = 0;
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( ++$count > $params['limit'] ) {
|
|
|
|
|
// We've reached the one extra which shows that
|
|
|
|
|
// there are additional pages to be had. Stop here...
|
|
|
|
|
$this->setContinue( $row, $sortby );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $miser_ns !== null && !in_array( $row->page_namespace, $miser_ns ) ) {
|
|
|
|
|
// Miser mode namespace check
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the ID of the current page
|
|
|
|
|
$id = $map[$row->bl_namespace][$row->bl_title];
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$vals = [];
|
2014-08-20 17:32:01 +00:00
|
|
|
if ( $fld_pageid ) {
|
2015-05-06 15:33:08 +00:00
|
|
|
$vals['pageid'] = (int)$row->page_id;
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
if ( $fld_title ) {
|
|
|
|
|
ApiQueryBase::addTitleInfo( $vals,
|
|
|
|
|
Title::makeTitle( $row->page_namespace, $row->page_title )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if ( $fld_fragment && $row->rd_fragment !== null && $row->rd_fragment !== '' ) {
|
|
|
|
|
$vals['fragment'] = $row->rd_fragment;
|
|
|
|
|
}
|
2015-01-16 19:00:07 +00:00
|
|
|
if ( $fld_redirect ) {
|
|
|
|
|
$vals['redirect'] = (bool)$row->page_is_redirect;
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
$fit = $this->addPageSubItem( $id, $vals );
|
|
|
|
|
if ( !$fit ) {
|
|
|
|
|
$this->setContinue( $row, $sortby );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$titles = [];
|
2014-08-20 17:32:01 +00:00
|
|
|
$count = 0;
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
if ( ++$count > $params['limit'] ) {
|
|
|
|
|
// We've reached the one extra which shows that
|
|
|
|
|
// there are additional pages to be had. Stop here...
|
|
|
|
|
$this->setContinue( $row, $sortby );
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-24 13:19:49 +00:00
|
|
|
|
|
|
|
|
if ( $miser_ns !== null && !in_array( $row->page_namespace, $miser_ns ) ) {
|
|
|
|
|
// Miser mode namespace check
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 17:32:01 +00:00
|
|
|
$titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
|
}
|
|
|
|
|
$resultPageSet->populateFromTitles( $titles );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function setContinue( $row, $sortby ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$cont = [];
|
2014-08-20 17:32:01 +00:00
|
|
|
foreach ( $sortby as $field => $v ) {
|
|
|
|
|
$cont[] = $row->$field;
|
|
|
|
|
}
|
2016-03-08 08:13:12 +00:00
|
|
|
$this->setContinueEnumParameter( 'continue', implode( '|', $cont ) );
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCacheMode( $params ) {
|
|
|
|
|
return 'public';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
|
|
|
|
$settings = self::$settings[$this->getModuleName()];
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret = [
|
|
|
|
|
'prop' => [
|
|
|
|
|
ApiBase::PARAM_TYPE => [
|
2014-08-20 17:32:01 +00:00
|
|
|
'pageid',
|
|
|
|
|
'title',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-08-20 17:32:01 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_DFLT => 'pageid|title',
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
|
|
|
|
],
|
|
|
|
|
'namespace' => [
|
2014-08-20 17:32:01 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'namespace',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-09-18 17:38:23 +00:00
|
|
|
'show' => null, // Will be filled/removed below
|
2016-02-17 09:09:32 +00:00
|
|
|
'limit' => [
|
2014-08-20 17:32:01 +00:00
|
|
|
ApiBase::PARAM_DFLT => 10,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'limit',
|
|
|
|
|
ApiBase::PARAM_MIN => 1,
|
|
|
|
|
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
|
|
|
|
|
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'continue' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2014-08-20 17:32:01 +00:00
|
|
|
|
2014-09-18 17:38:23 +00:00
|
|
|
if ( empty( $settings['from_namespace'] ) && $this->getConfig()->get( 'MiserMode' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = [
|
2014-09-18 17:38:23 +00:00
|
|
|
'api-help-param-limited-in-miser-mode',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-09-18 17:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-20 17:32:01 +00:00
|
|
|
if ( !empty( $settings['showredirects'] ) ) {
|
|
|
|
|
$ret['prop'][ApiBase::PARAM_TYPE][] = 'redirect';
|
|
|
|
|
$ret['prop'][ApiBase::PARAM_DFLT] .= '|redirect';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $settings['props'] ) ) {
|
|
|
|
|
$ret['prop'][ApiBase::PARAM_TYPE] = array_merge(
|
2014-09-18 17:38:23 +00:00
|
|
|
$ret['prop'][ApiBase::PARAM_TYPE], $settings['props']
|
2014-08-20 17:32:01 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$show = [];
|
2014-08-20 17:32:01 +00:00
|
|
|
if ( !empty( $settings['showredirects'] ) ) {
|
|
|
|
|
$show[] = 'redirect';
|
|
|
|
|
$show[] = '!redirect';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $settings['show'] ) ) {
|
2014-09-18 17:38:23 +00:00
|
|
|
$show = array_merge( $show, $settings['show'] );
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
if ( $show ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret['show'] = [
|
2014-08-20 17:32:01 +00:00
|
|
|
ApiBase::PARAM_TYPE => $show,
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-09-18 17:38:23 +00:00
|
|
|
} else {
|
|
|
|
|
unset( $ret['show'] );
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2014-08-20 17:32:01 +00:00
|
|
|
$settings = self::$settings[$this->getModuleName()];
|
|
|
|
|
$name = $this->getModuleName();
|
2014-09-18 17:38:23 +00:00
|
|
|
$path = $this->getModulePath();
|
2017-10-06 22:17:58 +00:00
|
|
|
$title = $settings['exampletitle'] ?? 'Main Page';
|
2014-08-20 17:32:01 +00:00
|
|
|
$etitle = rawurlencode( $title );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
"action=query&prop={$name}&titles={$etitle}"
|
|
|
|
|
=> "apihelp-$path-example-simple",
|
|
|
|
|
"action=query&generator={$name}&titles={$etitle}&prop=info"
|
|
|
|
|
=> "apihelp-$path-example-generator",
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getHelpUrls() {
|
2015-04-07 09:55:31 +00:00
|
|
|
$name = ucfirst( $this->getModuleName() );
|
2017-04-04 22:52:57 +00:00
|
|
|
return "https://www.mediawiki.org/wiki/Special:MyLanguage/API:{$name}";
|
2014-08-20 17:32:01 +00:00
|
|
|
}
|
|
|
|
|
}
|