MediaWiki  1.23.1
ApiQueryImages.php
Go to the documentation of this file.
1 <?php
34 
35  public function __construct( $query, $moduleName ) {
36  parent::__construct( $query, $moduleName, 'im' );
37  }
38 
39  public function execute() {
40  $this->run();
41  }
42 
43  public function executeGenerator( $resultPageSet ) {
44  $this->run( $resultPageSet );
45  }
46 
50  private function run( $resultPageSet = null ) {
51  if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
52  return; // nothing to do
53  }
54 
55  $params = $this->extractRequestParams();
56  $this->addFields( array(
57  'il_from',
58  'il_to'
59  ) );
60 
61  $this->addTables( 'imagelinks' );
62  $this->addWhereFld( 'il_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
63  if ( !is_null( $params['continue'] ) ) {
64  $cont = explode( '|', $params['continue'] );
65  $this->dieContinueUsageIf( count( $cont ) != 2 );
66  $op = $params['dir'] == 'descending' ? '<' : '>';
67  $ilfrom = intval( $cont[0] );
68  $ilto = $this->getDB()->addQuotes( $cont[1] );
69  $this->addWhere(
70  "il_from $op $ilfrom OR " .
71  "(il_from = $ilfrom AND " .
72  "il_to $op= $ilto)"
73  );
74  }
75 
76  $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
77  // Don't order by il_from if it's constant in the WHERE clause
78  if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
79  $this->addOption( 'ORDER BY', 'il_to' . $sort );
80  } else {
81  $this->addOption( 'ORDER BY', array(
82  'il_from' . $sort,
83  'il_to' . $sort
84  ) );
85  }
86  $this->addOption( 'LIMIT', $params['limit'] + 1 );
87 
88  if ( !is_null( $params['images'] ) ) {
89  $images = array();
90  foreach ( $params['images'] as $img ) {
91  $title = Title::newFromText( $img );
92  if ( !$title || $title->getNamespace() != NS_FILE ) {
93  $this->setWarning( "\"$img\" is not a file" );
94  } else {
95  $images[] = $title->getDBkey();
96  }
97  }
98  $this->addWhereFld( 'il_to', $images );
99  }
100 
101  $res = $this->select( __METHOD__ );
102 
103  if ( is_null( $resultPageSet ) ) {
104  $count = 0;
105  foreach ( $res as $row ) {
106  if ( ++$count > $params['limit'] ) {
107  // We've reached the one extra which shows that
108  // there are additional pages to be had. Stop here...
109  $this->setContinueEnumParameter( 'continue', $row->il_from . '|' . $row->il_to );
110  break;
111  }
112  $vals = array();
113  ApiQueryBase::addTitleInfo( $vals, Title::makeTitle( NS_FILE, $row->il_to ) );
114  $fit = $this->addPageSubItem( $row->il_from, $vals );
115  if ( !$fit ) {
116  $this->setContinueEnumParameter( 'continue', $row->il_from . '|' . $row->il_to );
117  break;
118  }
119  }
120  } else {
121  $titles = array();
122  $count = 0;
123  foreach ( $res as $row ) {
124  if ( ++$count > $params['limit'] ) {
125  // We've reached the one extra which shows that
126  // there are additional pages to be had. Stop here...
127  $this->setContinueEnumParameter( 'continue', $row->il_from . '|' . $row->il_to );
128  break;
129  }
130  $titles[] = Title::makeTitle( NS_FILE, $row->il_to );
131  }
132  $resultPageSet->populateFromTitles( $titles );
133  }
134  }
135 
136  public function getCacheMode( $params ) {
137  return 'public';
138  }
139 
140  public function getAllowedParams() {
141  return array(
142  'limit' => array(
143  ApiBase::PARAM_DFLT => 10,
144  ApiBase::PARAM_TYPE => 'limit',
145  ApiBase::PARAM_MIN => 1,
148  ),
149  'continue' => null,
150  'images' => array(
151  ApiBase::PARAM_ISMULTI => true,
152  ),
153  'dir' => array(
154  ApiBase::PARAM_DFLT => 'ascending',
156  'ascending',
157  'descending'
158  )
159  ),
160  );
161  }
162 
163  public function getParamDescription() {
164  return array(
165  'limit' => 'How many images to return',
166  'continue' => 'When more results are available, use this to continue',
167  'images' => 'Only list these images. Useful for checking whether a ' .
168  'certain page has a certain Image.',
169  'dir' => 'The direction in which to list',
170  );
171  }
172 
173  public function getResultProperties() {
174  return array(
175  '' => array(
176  'ns' => 'namespace',
177  'title' => 'string'
178  )
179  );
180  }
181 
182  public function getDescription() {
183  return 'Returns all images contained on the given page(s).';
184  }
185 
186  public function getExamples() {
187  return array(
188  'api.php?action=query&prop=images&titles=Main%20Page'
189  => 'Get a list of images used in the [[Main Page]]',
190  'api.php?action=query&generator=images&titles=Main%20Page&prop=info'
191  => 'Get information about all images used in the [[Main Page]]',
192  );
193  }
194 
195  public function getHelpUrls() {
196  return 'https://www.mediawiki.org/wiki/API:Properties#images_.2F_im';
197  }
198 }
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:117
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiQueryImages\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiQueryImages.php:182
ApiQueryImages
This query adds an "<images>" subelement to all pages with the list of images embedded into those pag...
Definition: ApiQueryImages.php:33
ApiQueryImages\executeGenerator
executeGenerator( $resultPageSet)
Execute this module as a generator.
Definition: ApiQueryImages.php:43
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiQueryImages\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiQueryImages.php:186
ApiQueryBase\select
select( $method, $extraQuery=array())
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:274
NS_FILE
const NS_FILE
Definition: Defines.php:85
$params
$params
Definition: styleTest.css.php:40
ApiQueryImages\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryImages.php:39
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:252
ApiQueryGeneratorBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Overrides base in case of generator & smart continue to notify ApiQueryMain instead of adding them to...
Definition: ApiQueryBase.php:676
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:56
ApiQueryGeneratorBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:649
$titles
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Definition: ApiBase.php:78
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:417
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:52
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:82
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$sort
$sort
Definition: profileinfo.php:301
ApiQueryImages\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiQueryImages.php:163
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the $prefix.
Definition: ApiBase.php:1965
ApiQueryImages\run
run( $resultPageSet=null)
Definition: ApiQueryImages.php:50
ApiQueryImages\__construct
__construct( $query, $moduleName)
Definition: ApiQueryImages.php:35
ApiQueryImages\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryImages.php:136
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:185
$count
$count
Definition: UtfNormalTest2.php:96
ApiBase\setWarning
setWarning( $warning)
Set warning section for this module.
Definition: ApiBase.php:245
ApiQueryGeneratorBase
Definition: ApiQueryBase.php:626
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Definition: ApiBase.php:79
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiBase\PARAM_MAX2
const PARAM_MAX2
Definition: ApiBase.php:54
ApiQueryImages\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryImages.php:140
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:152
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
$res
$res
Definition: database.txt:21
ApiQueryBase\addPageSubItem
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
Definition: ApiQueryBase.php:383
ApiQueryImages\getHelpUrls
getHelpUrls()
Definition: ApiQueryImages.php:195
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:339
ApiQueryImages\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiQueryImages.php:173