31 parent::__construct( $query, $moduleName,
'pi' );
48 $titles = $pageSet->getGoodTitles();
53 $missingTitles = $pageSet->getMissingTitlesByNamespace();
54 $missingFileTitles = $missingTitles[
NS_FILE] ?? [];
58 $missingFileTitles = array_map(
function ( $text ) {
59 return Title::newFromText( $text,
NS_FILE );
60 }, array_flip( $missingFileTitles ) );
64 foreach ( $missingFileTitles as $id =>
$title ) {
78 $prop = array_flip( $params[
'prop'] );
79 if ( !count( $prop ) ) {
87 if ( count( $allTitles ) === 0 ) {
93 if ( isset( $params[
'continue'] ) ) {
96 $pageIds = array_keys( $allTitles );
97 $offset = array_search( intval( $params[
'continue'] ), $pageIds );
102 $limit = $params[
'limit'];
104 $titles = array_slice( $allTitles, $offset, $limit,
true );
107 $nextItemArray = array_slice( $allTitles, $offset + $limit, 1,
true );
108 if ( $nextItemArray ) {
113 $filePageTitles = [];
114 foreach ( $titles as $id =>
$title ) {
116 $filePageTitles[$id] =
$title;
117 unset( $titles[$id] );
121 $size = $params[
'thumbsize'];
123 if ( count( $titles ) > 0 ) {
125 $this->
addFields( [
'pp_page',
'pp_propname',
'pp_value' ] );
126 $this->
addWhere( [
'pp_page' => array_keys( $titles ),
127 'pp_propname' => self::getPropNames( $params[
'license'] ) ] );
132 $propNameAny = PageImages::getPropName(
false );
133 foreach (
$res as $row ) {
134 $pageId = $row->pp_page;
135 if ( !array_key_exists( $pageId, $buffer ) || $row->pp_propname === $propNameAny ) {
136 $buffer[$pageId] = $row;
140 foreach ( $buffer as $pageId => $row ) {
141 $fileName = $row->pp_value;
149 foreach ( $filePageTitles as $pageId =>
$title ) {
150 $fileName =
$title->getDBkey();
167 if ( $license === self::PARAM_LICENSE_FREE ) {
168 return PageImages::getPropName(
true );
170 return [ PageImages::getPropName(
true ), PageImages::getPropName(
false ) ];
193 if ( isset( $prop[
'thumbnail'] ) || isset( $prop[
'original'] ) ) {
196 if ( isset( $prop[
'thumbnail'] ) ) {
197 $thumb =
$file->transform( [
'width' => $size,
'height' => $size ] );
198 if ( $thumb && $thumb->getUrl() ) {
202 $reportedSize = $thumb->fileIsSource() ?
$file : $thumb;
203 $vals[
'thumbnail'] = [
205 'width' => $reportedSize->getWidth(),
206 'height' => $reportedSize->getHeight(),
211 if ( isset( $prop[
'original'] ) ) {
214 $vals[
'original'] = [
215 'source' => $original_url,
216 'width' =>
$file->getWidth(),
217 'height' =>
$file->getHeight()
223 if ( isset( $prop[
'name'] ) ) {
224 $vals[
'pageimage'] = $fileName;
227 $this->
getResult()->addValue( [
'query',
'pages' ], $pageId, $vals );
269 'action=query&prop=pageimages&titles=Albert%20Einstein&pithumbsize=100' =>
270 'apihelp-query+pageimages-example-1',
279 return "https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:PageImages#API";
addTables( $tables, $alias=null)
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfFindFile( $title, $options=[])
Find a file.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
getPageSet()
Get the PageSet object to work on.
Expose image information for a page via a new prop=pageimages API.
__construct(ApiQuery $query, $moduleName)
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
const PARAM_LICENSE_ANY
@const API parameter value for images with any type of license
const PARAM_LICENSE_FREE
@const API parameter value for free images
execute()
Evaluates the parameters, performs the requested retrieval of page images, and sets up the result.
static getPropNames( $license)
Get property names used in page_props table.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
setResultValues(array $prop, $pageId, $fileName, $size)
For a given page, set API return values for thumbnail and pageimage as needed.
getTitles()
Gets the set of titles to get page images for.
getAllowedParams()
Return an array describing all possible parameters to this module.
This is the main query class.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.