2013-12-17 21:20:13 +00:00
|
|
|
<?php
|
|
|
|
|
2014-12-31 23:02:05 +00:00
|
|
|
namespace TextExtracts;
|
|
|
|
|
|
|
|
use ApiBase;
|
|
|
|
use ApiMain;
|
|
|
|
use ApiQueryBase;
|
2020-01-15 09:17:21 +00:00
|
|
|
use ApiUsageException;
|
2014-12-31 23:02:05 +00:00
|
|
|
use Config;
|
|
|
|
use FauxRequest;
|
2017-08-01 21:03:26 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2016-09-23 01:51:12 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2014-12-31 23:02:05 +00:00
|
|
|
use ParserOptions;
|
|
|
|
use Title;
|
|
|
|
use User;
|
2020-02-07 02:51:55 +00:00
|
|
|
use WANObjectCache;
|
2014-12-31 23:02:05 +00:00
|
|
|
use WikiPage;
|
|
|
|
|
2019-04-24 16:26:53 +00:00
|
|
|
/**
|
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
class ApiQueryExtracts extends ApiQueryBase {
|
2017-05-12 18:19:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bump when memcache needs clearing
|
|
|
|
*/
|
2020-05-30 00:35:27 +00:00
|
|
|
private const CACHE_VERSION = 2;
|
2017-05-12 18:19:51 +00:00
|
|
|
|
2020-05-30 00:35:27 +00:00
|
|
|
private const PREFIX = 'ex';
|
2018-03-20 16:28:03 +00:00
|
|
|
|
2020-11-05 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
private $params;
|
2020-11-05 16:16:17 +00:00
|
|
|
|
2014-08-13 06:18:34 +00:00
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
|
|
|
private $config;
|
2020-02-07 02:51:55 +00:00
|
|
|
/**
|
|
|
|
* @var WANObjectCache
|
|
|
|
*/
|
|
|
|
private $cache;
|
2013-12-17 21:20:13 +00:00
|
|
|
|
2015-07-30 04:28:41 +00:00
|
|
|
// TODO: Allow extensions to hook into this to opt-in.
|
|
|
|
// This is partly for security reasons; see T107170.
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-09-23 01:38:27 +00:00
|
|
|
private $supportedContentModels = [ 'wikitext' ];
|
2015-07-30 04:28:41 +00:00
|
|
|
|
2017-11-30 03:52:54 +00:00
|
|
|
/**
|
|
|
|
* @param \ApiQuery $query API query module object
|
|
|
|
* @param string $moduleName Name of this query module
|
|
|
|
* @param Config $conf MediaWiki configuration
|
2020-02-07 02:51:55 +00:00
|
|
|
* @param WANObjectCache $cache
|
2017-11-30 03:52:54 +00:00
|
|
|
*/
|
2020-02-07 02:51:55 +00:00
|
|
|
public function __construct( $query, $moduleName, Config $conf, WANObjectCache $cache ) {
|
2018-03-20 16:28:03 +00:00
|
|
|
parent::__construct( $query, $moduleName, self::PREFIX );
|
2014-08-13 06:18:34 +00:00
|
|
|
$this->config = $conf;
|
2020-02-07 02:51:55 +00:00
|
|
|
$this->cache = $cache;
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 03:52:54 +00:00
|
|
|
/**
|
|
|
|
* Evaluates the parameters, performs the requested extraction of text,
|
|
|
|
* and sets up the result
|
|
|
|
* @return null
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
public function execute() {
|
|
|
|
$titles = $this->getPageSet()->getGoodTitles();
|
2018-06-28 18:45:20 +00:00
|
|
|
if ( $titles === [] ) {
|
2013-12-17 21:20:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-19 16:39:27 +00:00
|
|
|
$isXml = $this->getMain()->isInternalMode()
|
|
|
|
|| $this->getMain()->getPrinter()->getFormat() == 'XML';
|
2013-12-17 21:20:13 +00:00
|
|
|
$result = $this->getResult();
|
|
|
|
$params = $this->params = $this->extractRequestParams();
|
|
|
|
$this->requireMaxOneParameter( $params, 'chars', 'sentences' );
|
|
|
|
$continue = 0;
|
|
|
|
$limit = intval( $params['limit'] );
|
2019-07-01 18:35:13 +00:00
|
|
|
if ( $limit > 1 && !$params['intro'] && count( $titles ) > 1 ) {
|
2013-12-17 21:20:13 +00:00
|
|
|
$limit = 1;
|
2017-08-02 13:23:48 +00:00
|
|
|
$this->addWarning( [ 'apiwarn-textextracts-limit', $limit ] );
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
if ( isset( $params['continue'] ) ) {
|
|
|
|
$continue = intval( $params['continue'] );
|
2016-11-03 19:16:57 +00:00
|
|
|
$this->dieContinueUsageIf( $continue < 0 || $continue > count( $titles ) );
|
2013-12-17 21:20:13 +00:00
|
|
|
$titles = array_slice( $titles, $continue, null, true );
|
|
|
|
}
|
|
|
|
$count = 0;
|
2017-07-07 17:05:07 +00:00
|
|
|
$titleInFileNamespace = false;
|
2013-12-17 21:20:13 +00:00
|
|
|
/** @var Title $t */
|
|
|
|
foreach ( $titles as $id => $t ) {
|
|
|
|
if ( ++$count > $limit ) {
|
|
|
|
$this->setContinueEnumParameter( 'continue', $continue + $count - 1 );
|
|
|
|
break;
|
|
|
|
}
|
2017-07-07 17:05:07 +00:00
|
|
|
|
|
|
|
if ( $t->inNamespace( NS_FILE ) ) {
|
|
|
|
$text = '';
|
|
|
|
$titleInFileNamespace = true;
|
|
|
|
} else {
|
2018-03-20 16:28:03 +00:00
|
|
|
$params = $this->params;
|
2017-07-07 17:05:07 +00:00
|
|
|
$text = $this->getExtract( $t );
|
|
|
|
$text = $this->truncate( $text );
|
2018-03-20 16:28:03 +00:00
|
|
|
if ( $params['plaintext'] ) {
|
2017-07-07 17:05:07 +00:00
|
|
|
$text = $this->doSections( $text );
|
2018-03-20 16:28:03 +00:00
|
|
|
} else {
|
|
|
|
if ( $params['sentences'] ) {
|
|
|
|
$this->addWarning( $this->msg( 'apiwarn-textextracts-sentences-and-html', self::PREFIX ) );
|
|
|
|
}
|
|
|
|
$this->addWarning( 'apiwarn-textextracts-malformed-html' );
|
2017-07-07 17:05:07 +00:00
|
|
|
}
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $isXml ) {
|
2016-09-23 01:38:27 +00:00
|
|
|
$fit = $result->addValue( [ 'query', 'pages', $id ], 'extract', [ '*' => $text ] );
|
2013-12-17 21:20:13 +00:00
|
|
|
} else {
|
2016-09-23 01:38:27 +00:00
|
|
|
$fit = $result->addValue( [ 'query', 'pages', $id ], 'extract', $text );
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
if ( !$fit ) {
|
|
|
|
$this->setContinueEnumParameter( 'continue', $continue + $count - 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-07 17:05:07 +00:00
|
|
|
if ( $titleInFileNamespace ) {
|
|
|
|
$this->addWarning( 'apiwarn-textextracts-title-in-file-namespace' );
|
|
|
|
}
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 03:52:54 +00:00
|
|
|
/**
|
|
|
|
* @param array $params Ignored parameters
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-03-29 11:53:59 +00:00
|
|
|
public function getCacheMode( $params ) {
|
|
|
|
return 'public';
|
|
|
|
}
|
|
|
|
|
2013-12-17 21:20:13 +00:00
|
|
|
/**
|
|
|
|
* Returns a processed, but not trimmed extract
|
|
|
|
* @param Title $title
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getExtract( Title $title ) {
|
2015-07-30 04:28:41 +00:00
|
|
|
$contentModel = $title->getContentModel();
|
|
|
|
if ( !in_array( $contentModel, $this->supportedContentModels, true ) ) {
|
2017-08-02 13:23:48 +00:00
|
|
|
$this->addWarning( [
|
|
|
|
'apiwarn-textextracts-unsupportedmodel',
|
|
|
|
wfEscapeWikiText( $title->getPrefixedText() ),
|
|
|
|
$contentModel
|
|
|
|
] );
|
2015-07-30 04:28:41 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2013-12-17 21:20:13 +00:00
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
$introOnly = $this->params['intro'];
|
|
|
|
$text = $this->getFromCache( $page, $introOnly );
|
|
|
|
// if we need just first section, try retrieving full page and getting first section out of it
|
|
|
|
if ( $text === false && $introOnly ) {
|
|
|
|
$text = $this->getFromCache( $page, false );
|
|
|
|
if ( $text !== false ) {
|
|
|
|
$text = $this->getFirstSection( $text, $this->params['plaintext'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $text === false ) {
|
|
|
|
$text = $this->parse( $page );
|
2016-09-23 01:51:12 +00:00
|
|
|
$text = $this->convertText( $text );
|
2013-12-17 21:20:13 +00:00
|
|
|
$this->setCache( $page, $text );
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2020-11-05 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @param WANObjectCache $cache
|
|
|
|
* @param WikiPage $page
|
|
|
|
* @param bool $introOnly
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-02-07 02:51:55 +00:00
|
|
|
private function cacheKey( WANObjectCache $cache, WikiPage $page, $introOnly ) {
|
2017-05-16 00:13:47 +00:00
|
|
|
return $cache->makeKey( 'textextracts', self::CACHE_VERSION,
|
2017-05-12 18:19:51 +00:00
|
|
|
$page->getId(), $page->getTouched(),
|
2014-06-19 00:57:11 +00:00
|
|
|
$page->getTitle()->getPageLanguage()->getPreferredVariant(),
|
2020-03-13 21:08:54 +00:00
|
|
|
$this->params['plaintext'] ? 'plaintext' : 'html',
|
2019-12-22 07:19:42 +00:00
|
|
|
$introOnly ? 'intro' : 'full'
|
2014-06-19 00:57:11 +00:00
|
|
|
);
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @param WikiPage $page
|
|
|
|
* @param bool $introOnly
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
private function getFromCache( WikiPage $page, $introOnly ) {
|
2020-02-07 02:51:55 +00:00
|
|
|
$cache = $this->cache;
|
|
|
|
// @TODO: replace with getWithSetCallback()
|
|
|
|
$key = $this->cacheKey( $cache, $page, $introOnly );
|
|
|
|
return $cache->get( $key );
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @param WikiPage $page
|
|
|
|
* @param string $text
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
private function setCache( WikiPage $page, $text ) {
|
2020-02-07 02:51:55 +00:00
|
|
|
$cache = $this->cache;
|
|
|
|
// @TODO: replace with getWithSetCallback()
|
2020-03-13 21:08:54 +00:00
|
|
|
$key = $this->cacheKey( $cache, $page, $this->params['intro'] );
|
2020-02-07 02:51:55 +00:00
|
|
|
$cache->set( $key, $text, $this->getConfig()->get( 'ParserCacheExpireTime' ) );
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @param string $text
|
|
|
|
* @param bool $plainText
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
private function getFirstSection( $text, $plainText ) {
|
|
|
|
if ( $plainText ) {
|
|
|
|
$regexp = '/^(.*?)(?=' . ExtractFormatter::SECTION_MARKER_START . ')/s';
|
|
|
|
} else {
|
|
|
|
$regexp = '/^(.*?)(?=<h[1-6]\b)/s';
|
|
|
|
}
|
|
|
|
if ( preg_match( $regexp, $text, $matches ) ) {
|
|
|
|
$text = $matches[0];
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns page HTML
|
|
|
|
* @param WikiPage $page
|
2017-08-01 21:03:26 +00:00
|
|
|
* @return string|null
|
|
|
|
* @throws ApiUsageException
|
2013-12-17 21:20:13 +00:00
|
|
|
*/
|
|
|
|
private function parse( WikiPage $page ) {
|
2017-08-01 21:03:26 +00:00
|
|
|
$apiException = null;
|
2019-03-17 21:03:43 +00:00
|
|
|
$parserOptions = new ParserOptions( new User() );
|
|
|
|
|
2013-12-17 21:20:13 +00:00
|
|
|
// first try finding full page in parser cache
|
2019-03-17 21:03:43 +00:00
|
|
|
if ( $page->shouldCheckParserCache( $parserOptions, 0 ) ) {
|
|
|
|
$pout = MediaWikiServices::getInstance()->getParserCache()->get( $page, $parserOptions );
|
2013-12-17 21:20:13 +00:00
|
|
|
if ( $pout ) {
|
2017-12-22 18:43:44 +00:00
|
|
|
$text = $pout->getText( [ 'unwrap' => true ] );
|
2013-12-17 21:20:13 +00:00
|
|
|
if ( $this->params['intro'] ) {
|
|
|
|
$text = $this->getFirstSection( $text, false );
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
}
|
2016-09-23 01:38:27 +00:00
|
|
|
$request = [
|
2013-12-17 21:20:13 +00:00
|
|
|
'action' => 'parse',
|
|
|
|
'page' => $page->getTitle()->getPrefixedText(),
|
2017-05-12 16:20:38 +00:00
|
|
|
'prop' => 'text',
|
2017-06-28 15:55:00 +00:00
|
|
|
// Invokes special handling when using partial wikitext (T168743)
|
|
|
|
'sectionpreview' => 1,
|
2017-05-12 16:20:38 +00:00
|
|
|
'wrapoutputclass' => '',
|
2016-09-23 01:38:27 +00:00
|
|
|
];
|
2013-12-17 21:20:13 +00:00
|
|
|
if ( $this->params['intro'] ) {
|
|
|
|
$request['section'] = 0;
|
|
|
|
}
|
|
|
|
// in case of cache miss, render just the needed section
|
2016-09-23 01:38:27 +00:00
|
|
|
$api = new ApiMain( new FauxRequest( $request ) );
|
2014-12-17 15:01:06 +00:00
|
|
|
try {
|
|
|
|
$api->execute();
|
2016-09-23 01:38:27 +00:00
|
|
|
$data = $api->getResult()->getResultData( null, [
|
|
|
|
'BC' => [],
|
|
|
|
'Types' => [],
|
|
|
|
] );
|
2016-11-03 19:16:57 +00:00
|
|
|
} catch ( ApiUsageException $e ) {
|
2017-08-01 21:03:26 +00:00
|
|
|
$apiException = $e->__toString();
|
2016-11-03 19:16:57 +00:00
|
|
|
if ( $e->getStatusValue()->hasMessage( 'apierror-nosuchsection' ) ) {
|
|
|
|
// Looks like we tried to get the intro to a page without
|
|
|
|
// sections! Lets just grab what we can get.
|
|
|
|
unset( $request['section'] );
|
|
|
|
$api = new ApiMain( new FauxRequest( $request ) );
|
|
|
|
$api->execute();
|
|
|
|
$data = $api->getResult()->getResultData( null, [
|
|
|
|
'BC' => [],
|
|
|
|
'Types' => [],
|
|
|
|
] );
|
|
|
|
} else {
|
|
|
|
// Some other unexpected error - lets just report it to the user
|
|
|
|
// on the off chance that is the right thing.
|
|
|
|
throw $e;
|
|
|
|
}
|
2014-12-17 15:01:06 +00:00
|
|
|
}
|
2017-08-01 21:03:26 +00:00
|
|
|
if ( !array_key_exists( 'parse', $data ) ) {
|
|
|
|
LoggerFactory::getInstance( 'textextracts' )->warning(
|
|
|
|
'API Parse request failed while generating text extract', [
|
|
|
|
'title' => $page->getTitle()->getFullText(),
|
|
|
|
'url' => $this->getRequest()->getFullRequestURL(),
|
|
|
|
'exception' => $apiException,
|
|
|
|
'request' => $request
|
|
|
|
] );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-17 21:20:13 +00:00
|
|
|
return $data['parse']['text']['*'];
|
|
|
|
}
|
|
|
|
|
2015-12-09 23:33:24 +00:00
|
|
|
/**
|
2017-11-30 02:56:29 +00:00
|
|
|
* @param \ApiQuery $query API query module
|
|
|
|
* @param string $name Name of this query module
|
2015-12-11 23:11:43 +00:00
|
|
|
* @return ApiQueryExtracts
|
2015-12-09 23:33:24 +00:00
|
|
|
*/
|
2017-11-30 02:56:29 +00:00
|
|
|
public static function factory( $query, $name ) {
|
2016-09-23 01:51:12 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
|
2020-02-07 02:51:55 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
|
|
|
return new self( $query, $name, $config, $cache );
|
2015-12-09 23:33:24 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 21:20:13 +00:00
|
|
|
/**
|
|
|
|
* Converts page HTML into an extract
|
|
|
|
* @param string $text
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function convertText( $text ) {
|
2019-03-17 20:58:37 +00:00
|
|
|
$fmt = new ExtractFormatter( $text, $this->params['plaintext'] );
|
|
|
|
$fmt->remove( $this->config->get( 'ExtractsRemoveClasses' ) );
|
2013-12-17 21:20:13 +00:00
|
|
|
$text = $fmt->getText();
|
2019-03-19 11:21:41 +00:00
|
|
|
return $text;
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Truncate the given text to a certain number of characters or sentences
|
|
|
|
* @param string $text The text to truncate
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-04-23 01:12:44 +00:00
|
|
|
private function truncate( $text ) {
|
2021-01-08 08:03:05 +00:00
|
|
|
$useTidy = !$this->params['plaintext'];
|
|
|
|
$truncator = new TextTruncator( $useTidy );
|
2013-12-17 21:20:13 +00:00
|
|
|
|
2019-03-19 11:21:41 +00:00
|
|
|
if ( $this->params['chars'] ) {
|
2021-01-08 08:05:35 +00:00
|
|
|
$truncatedText = $truncator->getFirstChars( $text, $this->params['chars'] );
|
|
|
|
if ( $truncatedText !== $text ) {
|
|
|
|
$text = $truncatedText . $this->msg( 'ellipsis' )->text();
|
|
|
|
}
|
2019-03-19 11:21:41 +00:00
|
|
|
} elseif ( $this->params['sentences'] ) {
|
|
|
|
$text = $truncator->getFirstSentences( $text, $this->params['sentences'] );
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2020-11-05 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @param string $text
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
private function doSections( $text ) {
|
2019-03-19 17:47:45 +00:00
|
|
|
$pattern = '/' .
|
|
|
|
ExtractFormatter::SECTION_MARKER_START . '(\d)' .
|
|
|
|
ExtractFormatter::SECTION_MARKER_END . '(.*)/';
|
2013-12-17 21:20:13 +00:00
|
|
|
|
2019-03-19 17:47:45 +00:00
|
|
|
switch ( $this->params['sectionformat'] ) {
|
|
|
|
case 'raw':
|
|
|
|
return $text;
|
2013-12-17 21:20:13 +00:00
|
|
|
|
2019-03-19 17:47:45 +00:00
|
|
|
case 'wiki':
|
|
|
|
return preg_replace_callback( $pattern, function ( $matches ) {
|
|
|
|
$bars = str_repeat( '=', $matches[1] );
|
|
|
|
return "\n$bars " . trim( $matches[2] ) . " $bars";
|
|
|
|
}, $text );
|
2013-12-17 21:20:13 +00:00
|
|
|
|
2019-03-19 17:47:45 +00:00
|
|
|
case 'plain':
|
|
|
|
return preg_replace_callback( $pattern, function ( $matches ) {
|
|
|
|
return "\n" . trim( $matches[2] );
|
|
|
|
}, $text );
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \LogicException( 'Invalid sectionformat' );
|
|
|
|
}
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 03:52:54 +00:00
|
|
|
/**
|
|
|
|
* Return an array describing all possible parameters to this module
|
|
|
|
* @return array
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
public function getAllowedParams() {
|
2016-09-23 01:38:27 +00:00
|
|
|
return [
|
|
|
|
'chars' => [
|
2013-12-17 21:20:13 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
ApiBase::PARAM_MIN => 1,
|
2017-05-24 22:04:20 +00:00
|
|
|
ApiBase::PARAM_MAX => 1200,
|
2016-09-23 01:38:27 +00:00
|
|
|
],
|
|
|
|
'sentences' => [
|
2013-12-17 21:20:13 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
ApiBase::PARAM_MIN => 1,
|
|
|
|
ApiBase::PARAM_MAX => 10,
|
2016-09-23 01:38:27 +00:00
|
|
|
],
|
|
|
|
'limit' => [
|
2017-05-19 13:37:26 +00:00
|
|
|
ApiBase::PARAM_DFLT => 20,
|
2013-12-17 21:20:13 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'limit',
|
|
|
|
ApiBase::PARAM_MIN => 1,
|
|
|
|
ApiBase::PARAM_MAX => 20,
|
|
|
|
ApiBase::PARAM_MAX2 => 20,
|
2016-09-23 01:38:27 +00:00
|
|
|
],
|
2013-12-17 21:20:13 +00:00
|
|
|
'intro' => false,
|
|
|
|
'plaintext' => false,
|
2016-09-23 01:38:27 +00:00
|
|
|
'sectionformat' => [
|
|
|
|
ApiBase::PARAM_TYPE => [ 'plain', 'wiki', 'raw' ],
|
2013-12-17 21:20:13 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'wiki',
|
2016-09-23 01:38:27 +00:00
|
|
|
],
|
|
|
|
'continue' => [
|
2013-12-17 21:20:13 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2016-09-20 19:23:03 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
|
2016-09-23 01:38:27 +00:00
|
|
|
],
|
|
|
|
];
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 18:50:23 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
2017-10-07 09:24:02 +00:00
|
|
|
* @return array
|
2014-10-29 18:50:23 +00:00
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2016-09-23 01:38:27 +00:00
|
|
|
return [
|
2014-10-29 18:50:23 +00:00
|
|
|
'action=query&prop=extracts&exchars=175&titles=Therion'
|
|
|
|
=> 'apihelp-query+extracts-example-1',
|
2016-09-23 01:38:27 +00:00
|
|
|
];
|
2014-10-29 18:50:23 +00:00
|
|
|
}
|
2013-12-17 21:20:13 +00:00
|
|
|
|
2017-11-30 03:52:54 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getHelpUrls()
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-12-17 21:20:13 +00:00
|
|
|
public function getHelpUrls() {
|
2019-08-27 06:44:34 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:TextExtracts#API';
|
2013-12-17 21:20:13 +00:00
|
|
|
}
|
|
|
|
}
|