Go to the documentation of this file.
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 ) {
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'] ) ] );
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 ) {
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";
setResultValues(array $prop, $pageId, $fileName, $size)
For a given page, set API return values for thumbnail and pageimage as needed.
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.
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
getAllowedParams()
Return an array describing all possible parameters to this module.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
__construct(ApiQuery $query, $moduleName)
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
const PARAM_LICENSE_ANY
@const API parameter value for images with any type of license
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Expose image information for a page via a new prop=pageimages API.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
This is a base class for all Query modules.
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,...
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
getPageSet()
Get the PageSet object to work on.
getTitles()
Gets the set of titles to get page images for.
wfFindFile( $title, $options=[])
Find a file.
static getPropName( $isFree)
Get property name used in page_props table.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
static getPropNames( $license)
Get property names used in page_props table.
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.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.