[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/api/ -> ApiQueryImageInfo.php (source)

   1  <?php
   2  /**
   3   *
   4   *
   5   * Created on July 6, 2007
   6   *
   7   * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
   8   *
   9   * This program is free software; you can redistribute it and/or modify
  10   * it under the terms of the GNU General Public License as published by
  11   * the Free Software Foundation; either version 2 of the License, or
  12   * (at your option) any later version.
  13   *
  14   * This program is distributed in the hope that it will be useful,
  15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17   * GNU General Public License for more details.
  18   *
  19   * You should have received a copy of the GNU General Public License along
  20   * with this program; if not, write to the Free Software Foundation, Inc.,
  21   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22   * http://www.gnu.org/copyleft/gpl.html
  23   *
  24   * @file
  25   */
  26  
  27  /**
  28   * A query action to get image information and upload history.
  29   *
  30   * @ingroup API
  31   */
  32  class ApiQueryImageInfo extends ApiQueryBase {
  33      const TRANSFORM_LIMIT = 50;
  34      private static $transformCount = 0;
  35  
  36  	public function __construct( ApiQuery $query, $moduleName, $prefix = 'ii' ) {
  37          // We allow a subclass to override the prefix, to create a related API
  38          // module. Some other parts of MediaWiki construct this with a null
  39          // $prefix, which used to be ignored when this only took two arguments
  40          if ( is_null( $prefix ) ) {
  41              $prefix = 'ii';
  42          }
  43          parent::__construct( $query, $moduleName, $prefix );
  44      }
  45  
  46  	public function execute() {
  47          $params = $this->extractRequestParams();
  48  
  49          $prop = array_flip( $params['prop'] );
  50  
  51          $scale = $this->getScale( $params );
  52  
  53          $opts = array(
  54              'version' => $params['metadataversion'],
  55              'language' => $params['extmetadatalanguage'],
  56              'multilang' => $params['extmetadatamultilang'],
  57              'extmetadatafilter' => $params['extmetadatafilter'],
  58              'revdelUser' => $this->getUser(),
  59          );
  60  
  61          $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
  62          if ( !empty( $pageIds[NS_FILE] ) ) {
  63              $titles = array_keys( $pageIds[NS_FILE] );
  64              asort( $titles ); // Ensure the order is always the same
  65  
  66              $fromTitle = null;
  67              if ( !is_null( $params['continue'] ) ) {
  68                  $cont = explode( '|', $params['continue'] );
  69                  $this->dieContinueUsageIf( count( $cont ) != 2 );
  70                  $fromTitle = strval( $cont[0] );
  71                  $fromTimestamp = $cont[1];
  72                  // Filter out any titles before $fromTitle
  73                  foreach ( $titles as $key => $title ) {
  74                      if ( $title < $fromTitle ) {
  75                          unset( $titles[$key] );
  76                      } else {
  77                          break;
  78                      }
  79                  }
  80              }
  81  
  82              $user = $this->getUser();
  83              $findTitles = array_map( function ( $title ) use ( $user ) {
  84                  return array(
  85                      'title' => $title,
  86                      'private' => $user,
  87                  );
  88              }, $titles );
  89  
  90              if ( $params['localonly'] ) {
  91                  $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
  92              } else {
  93                  $images = RepoGroup::singleton()->findFiles( $findTitles );
  94              }
  95  
  96              $result = $this->getResult();
  97              foreach ( $titles as $title ) {
  98                  $pageId = $pageIds[NS_FILE][$title];
  99                  $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
 100  
 101                  if ( !isset( $images[$title] ) ) {
 102                      if ( isset( $prop['uploadwarning'] ) ) {
 103                          // Uploadwarning needs info about non-existing files
 104                          $images[$title] = wfLocalFile( $title );
 105                      } else {
 106                          $result->addValue(
 107                              array( 'query', 'pages', intval( $pageId ) ),
 108                              'imagerepository', ''
 109                          );
 110                          // The above can't fail because it doesn't increase the result size
 111                          continue;
 112                      }
 113                  }
 114  
 115                  /** @var $img File */
 116                  $img = $images[$title];
 117  
 118                  if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
 119                      if ( count( $pageIds[NS_FILE] ) == 1 ) {
 120                          // See the 'the user is screwed' comment below
 121                          $this->setContinueEnumParameter( 'start',
 122                              $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
 123                          );
 124                      } else {
 125                          $this->setContinueEnumParameter( 'continue',
 126                              $this->getContinueStr( $img, $start ) );
 127                      }
 128                      break;
 129                  }
 130  
 131                  $fit = $result->addValue(
 132                      array( 'query', 'pages', intval( $pageId ) ),
 133                      'imagerepository', $img->getRepoName()
 134                  );
 135                  if ( !$fit ) {
 136                      if ( count( $pageIds[NS_FILE] ) == 1 ) {
 137                          // The user is screwed. imageinfo can't be solely
 138                          // responsible for exceeding the limit in this case,
 139                          // so set a query-continue that just returns the same
 140                          // thing again. When the violating queries have been
 141                          // out-continued, the result will get through
 142                          $this->setContinueEnumParameter( 'start',
 143                              $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
 144                          );
 145                      } else {
 146                          $this->setContinueEnumParameter( 'continue',
 147                              $this->getContinueStr( $img, $start ) );
 148                      }
 149                      break;
 150                  }
 151  
 152                  // Check if we can make the requested thumbnail, and get transform parameters.
 153                  $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
 154  
 155                  // Get information about the current version first
 156                  // Check that the current version is within the start-end boundaries
 157                  $gotOne = false;
 158                  if (
 159                      ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
 160                      ( is_null( $params['end'] ) || $img->getTimestamp() >= $params['end'] )
 161                  ) {
 162                      $gotOne = true;
 163  
 164                      $fit = $this->addPageSubItem( $pageId,
 165                          self::getInfo( $img, $prop, $result,
 166                              $finalThumbParams, $opts
 167                          )
 168                      );
 169                      if ( !$fit ) {
 170                          if ( count( $pageIds[NS_FILE] ) == 1 ) {
 171                              // See the 'the user is screwed' comment above
 172                              $this->setContinueEnumParameter( 'start',
 173                                  wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
 174                          } else {
 175                              $this->setContinueEnumParameter( 'continue',
 176                                  $this->getContinueStr( $img ) );
 177                          }
 178                          break;
 179                      }
 180                  }
 181  
 182                  // Now get the old revisions
 183                  // Get one more to facilitate query-continue functionality
 184                  $count = ( $gotOne ? 1 : 0 );
 185                  $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
 186                  /** @var $oldie File */
 187                  foreach ( $oldies as $oldie ) {
 188                      if ( ++$count > $params['limit'] ) {
 189                          // We've reached the extra one which shows that there are
 190                          // additional pages to be had. Stop here...
 191                          // Only set a query-continue if there was only one title
 192                          if ( count( $pageIds[NS_FILE] ) == 1 ) {
 193                              $this->setContinueEnumParameter( 'start',
 194                                  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
 195                          }
 196                          break;
 197                      }
 198                      $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
 199                          $this->addPageSubItem( $pageId,
 200                              self::getInfo( $oldie, $prop, $result,
 201                                  $finalThumbParams, $opts
 202                              )
 203                          );
 204                      if ( !$fit ) {
 205                          if ( count( $pageIds[NS_FILE] ) == 1 ) {
 206                              $this->setContinueEnumParameter( 'start',
 207                                  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
 208                          } else {
 209                              $this->setContinueEnumParameter( 'continue',
 210                                  $this->getContinueStr( $oldie ) );
 211                          }
 212                          break;
 213                      }
 214                  }
 215                  if ( !$fit ) {
 216                      break;
 217                  }
 218              }
 219          }
 220      }
 221  
 222      /**
 223       * From parameters, construct a 'scale' array
 224       * @param array $params Parameters passed to api.
 225       * @return array|null Key-val array of 'width' and 'height', or null
 226       */
 227  	public function getScale( $params ) {
 228          $p = $this->getModulePrefix();
 229  
 230          if ( $params['urlwidth'] != -1 ) {
 231              $scale = array();
 232              $scale['width'] = $params['urlwidth'];
 233              $scale['height'] = $params['urlheight'];
 234          } elseif ( $params['urlheight'] != -1 ) {
 235              // Height is specified but width isn't
 236              // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
 237              $scale = array();
 238              $scale['height'] = $params['urlheight'];
 239          } else {
 240              if ( $params['urlparam'] ) {
 241                  // Audio files might not have a width/height.
 242                  $scale = array();
 243              } else {
 244                  $scale = null;
 245              }
 246          }
 247  
 248          return $scale;
 249      }
 250  
 251      /** Validate and merge scale parameters with handler thumb parameters, give error if invalid.
 252       *
 253       * We do this later than getScale, since we need the image
 254       * to know which handler, since handlers can make their own parameters.
 255       * @param File $image Image that params are for.
 256       * @param array $thumbParams Thumbnail parameters from getScale
 257       * @param string $otherParams String of otherParams (iiurlparam).
 258       * @return array Array of parameters for transform.
 259       */
 260  	protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
 261          if ( $thumbParams === null ) {
 262              // No scaling requested
 263              return null;
 264          }
 265          if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
 266              // We want to limit only by height in this situation, so pass the
 267              // image's full width as the limiting width. But some file types
 268              // don't have a width of their own, so pick something arbitrary so
 269              // thumbnailing the default icon works.
 270              if ( $image->getWidth() <= 0 ) {
 271                  $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
 272              } else {
 273                  $thumbParams['width'] = $image->getWidth();
 274              }
 275          }
 276  
 277          if ( !$otherParams ) {
 278              $this->checkParameterNormalise( $image, $thumbParams );
 279              return $thumbParams;
 280          }
 281          $p = $this->getModulePrefix();
 282  
 283          $h = $image->getHandler();
 284          if ( !$h ) {
 285              $this->setWarning( 'Could not create thumbnail because ' .
 286                  $image->getName() . ' does not have an associated image handler' );
 287  
 288              return $thumbParams;
 289          }
 290  
 291          $paramList = $h->parseParamString( $otherParams );
 292          if ( !$paramList ) {
 293              // Just set a warning (instead of dieUsage), as in many cases
 294              // we could still render the image using width and height parameters,
 295              // and this type of thing could happen between different versions of
 296              // handlers.
 297              $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
 298                  . '. Using only width and height' );
 299              $this->checkParameterNormalise( $image, $thumbParams );
 300              return $thumbParams;
 301          }
 302  
 303          if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
 304              if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
 305                  $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
 306                      . "in favor of width value derived from {$p}urlwidth/{$p}urlheight "
 307                      . "({$thumbParams['width']})" );
 308              }
 309          }
 310  
 311          foreach ( $paramList as $name => $value ) {
 312              if ( !$h->validateParam( $name, $value ) ) {
 313                  $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", "urlparam" );
 314              }
 315          }
 316  
 317          $finalParams = $thumbParams + $paramList;
 318          $this->checkParameterNormalise( $image, $finalParams );
 319          return $finalParams;
 320      }
 321  
 322      /**
 323       * Verify that the final image parameters can be normalised.
 324       *
 325       * This doesn't use the normalised parameters, since $file->transform
 326       * expects the pre-normalised parameters, but doing the normalisation
 327       * allows us to catch certain error conditions early (such as missing
 328       * required parameter).
 329       *
 330       * @param $image File
 331       * @param $finalParams array List of parameters to transform image with
 332       */
 333  	protected function checkParameterNormalise( $image, $finalParams ) {
 334          $h = $image->getHandler();
 335          if ( !$h ) {
 336              return;
 337          }
 338          // Note: normaliseParams modifies the array in place, but we aren't interested
 339          // in the actual normalised version, only if we can actually normalise them,
 340          // so we use the functions scope to throw away the normalisations.
 341          if ( !$h->normaliseParams( $image, $finalParams ) ) {
 342              $this->dieUsage( "Could not normalise image parameters for " . $image->getName(), "urlparamnormal" );
 343          }
 344      }
 345  
 346      /**
 347       * Get result information for an image revision
 348       *
 349       * @param File $file
 350       * @param array $prop Array of properties to get (in the keys)
 351       * @param ApiResult $result
 352       * @param array $thumbParams Containing 'width' and 'height' items, or null
 353       * @param array|bool|string $opts Options for data fetching.
 354       *   This is an array consisting of the keys:
 355       *    'version': The metadata version for the metadata option
 356       *    'language': The language for extmetadata property
 357       *    'multilang': Return all translations in extmetadata property
 358       *    'revdelUser': User to use when checking whether to show revision-deleted fields.
 359       * @return array Result array
 360       */
 361  	static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
 362          global $wgContLang;
 363  
 364          $anyHidden = false;
 365  
 366          if ( !$opts || is_string( $opts ) ) {
 367              $opts = array(
 368                  'version' => $opts ?: 'latest',
 369                  'language' => $wgContLang,
 370                  'multilang' => false,
 371                  'extmetadatafilter' => array(),
 372                  'revdelUser' => null,
 373              );
 374          }
 375          $version = $opts['version'];
 376          $vals = array();
 377          // Timestamp is shown even if the file is revdelete'd in interface
 378          // so do same here.
 379          if ( isset( $prop['timestamp'] ) ) {
 380              $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
 381          }
 382  
 383          // Handle external callers who don't pass revdelUser
 384          if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
 385              $revdelUser = $opts['revdelUser'];
 386              $canShowField = function ( $field ) use ( $file, $revdelUser ) {
 387                  return $file->userCan( $field, $revdelUser );
 388              };
 389          } else {
 390              $canShowField = function ( $field ) use ( $file ) {
 391                  return !$file->isDeleted( $field );
 392              };
 393          }
 394  
 395          $user = isset( $prop['user'] );
 396          $userid = isset( $prop['userid'] );
 397  
 398          if ( $user || $userid ) {
 399              if ( $file->isDeleted( File::DELETED_USER ) ) {
 400                  $vals['userhidden'] = '';
 401                  $anyHidden = true;
 402              }
 403              if ( $canShowField( File::DELETED_USER ) ) {
 404                  if ( $user ) {
 405                      $vals['user'] = $file->getUser();
 406                  }
 407                  if ( $userid ) {
 408                      $vals['userid'] = $file->getUser( 'id' );
 409                  }
 410                  if ( !$file->getUser( 'id' ) ) {
 411                      $vals['anon'] = '';
 412                  }
 413              }
 414          }
 415  
 416          // This is shown even if the file is revdelete'd in interface
 417          // so do same here.
 418          if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
 419              $vals['size'] = intval( $file->getSize() );
 420              $vals['width'] = intval( $file->getWidth() );
 421              $vals['height'] = intval( $file->getHeight() );
 422  
 423              $pageCount = $file->pageCount();
 424              if ( $pageCount !== false ) {
 425                  $vals['pagecount'] = $pageCount;
 426              }
 427  
 428              // length as in how many seconds long a video is.
 429              $length = $file->getLength();
 430              if ( $length ) {
 431                  // Call it duration, because "length" can be ambiguous.
 432                  $vals['duration'] = (float)$length;
 433              }
 434          }
 435  
 436          $pcomment = isset( $prop['parsedcomment'] );
 437          $comment = isset( $prop['comment'] );
 438  
 439          if ( $pcomment || $comment ) {
 440              if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
 441                  $vals['commenthidden'] = '';
 442                  $anyHidden = true;
 443              }
 444              if ( $canShowField( File::DELETED_COMMENT ) ) {
 445                  if ( $pcomment ) {
 446                      $vals['parsedcomment'] = Linker::formatComment(
 447                          $file->getDescription( File::RAW ), $file->getTitle() );
 448                  }
 449                  if ( $comment ) {
 450                      $vals['comment'] = $file->getDescription( File::RAW );
 451                  }
 452              }
 453          }
 454  
 455          $canonicaltitle = isset( $prop['canonicaltitle'] );
 456          $url = isset( $prop['url'] );
 457          $sha1 = isset( $prop['sha1'] );
 458          $meta = isset( $prop['metadata'] );
 459          $extmetadata = isset( $prop['extmetadata'] );
 460          $commonmeta = isset( $prop['commonmetadata'] );
 461          $mime = isset( $prop['mime'] );
 462          $mediatype = isset( $prop['mediatype'] );
 463          $archive = isset( $prop['archivename'] );
 464          $bitdepth = isset( $prop['bitdepth'] );
 465          $uploadwarning = isset( $prop['uploadwarning'] );
 466  
 467          if ( $uploadwarning ) {
 468              $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
 469          }
 470  
 471          if ( $file->isDeleted( File::DELETED_FILE ) ) {
 472              $vals['filehidden'] = '';
 473              $anyHidden = true;
 474          }
 475  
 476          if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
 477              $vals['suppressed'] = true;
 478          }
 479  
 480          if ( !$canShowField( File::DELETED_FILE ) ) {
 481              //Early return, tidier than indenting all following things one level
 482              return $vals;
 483          }
 484  
 485          if ( $canonicaltitle ) {
 486              $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
 487          }
 488  
 489          if ( $url ) {
 490              if ( !is_null( $thumbParams ) ) {
 491                  $mto = $file->transform( $thumbParams );
 492                  self::$transformCount++;
 493                  if ( $mto && !$mto->isError() ) {
 494                      $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
 495  
 496                      // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
 497                      // thumbnail sizes for the thumbnail actual size
 498                      if ( $mto->getUrl() !== $file->getUrl() ) {
 499                          $vals['thumbwidth'] = intval( $mto->getWidth() );
 500                          $vals['thumbheight'] = intval( $mto->getHeight() );
 501                      } else {
 502                          $vals['thumbwidth'] = intval( $file->getWidth() );
 503                          $vals['thumbheight'] = intval( $file->getHeight() );
 504                      }
 505  
 506                      if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
 507                          list( , $mime ) = $file->getHandler()->getThumbType(
 508                              $mto->getExtension(), $file->getMimeType(), $thumbParams );
 509                          $vals['thumbmime'] = $mime;
 510                      }
 511                  } elseif ( $mto && $mto->isError() ) {
 512                      $vals['thumberror'] = $mto->toText();
 513                  }
 514              }
 515              $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
 516              $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
 517          }
 518  
 519          if ( $sha1 ) {
 520              $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
 521          }
 522  
 523          if ( $meta ) {
 524              wfSuppressWarnings();
 525              $metadata = unserialize( $file->getMetadata() );
 526              wfRestoreWarnings();
 527              if ( $metadata && $version !== 'latest' ) {
 528                  $metadata = $file->convertMetadataVersion( $metadata, $version );
 529              }
 530              $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
 531          }
 532          if ( $commonmeta ) {
 533              $metaArray = $file->getCommonMetaArray();
 534              $vals['commonmetadata'] = $metaArray ? self::processMetaData( $metaArray, $result ) : array();
 535          }
 536  
 537          if ( $extmetadata ) {
 538              // Note, this should return an array where all the keys
 539              // start with a letter, and all the values are strings.
 540              // Thus there should be no issue with format=xml.
 541              $format = new FormatMetadata;
 542              $format->setSingleLanguage( !$opts['multilang'] );
 543              $format->getContext()->setLanguage( $opts['language'] );
 544              $extmetaArray = $format->fetchExtendedMetadata( $file );
 545              if ( $opts['extmetadatafilter'] ) {
 546                  $extmetaArray = array_intersect_key(
 547                      $extmetaArray, array_flip( $opts['extmetadatafilter'] )
 548                  );
 549              }
 550              $vals['extmetadata'] = $extmetaArray;
 551          }
 552  
 553          if ( $mime ) {
 554              $vals['mime'] = $file->getMimeType();
 555          }
 556  
 557          if ( $mediatype ) {
 558              $vals['mediatype'] = $file->getMediaType();
 559          }
 560  
 561          if ( $archive && $file->isOld() ) {
 562              $vals['archivename'] = $file->getArchiveName();
 563          }
 564  
 565          if ( $bitdepth ) {
 566              $vals['bitdepth'] = $file->getBitDepth();
 567          }
 568  
 569          return $vals;
 570      }
 571  
 572      /**
 573       * Get the count of image transformations performed
 574       *
 575       * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
 576       *
 577       * @return int Count
 578       */
 579  	static function getTransformCount() {
 580          return self::$transformCount;
 581      }
 582  
 583      /**
 584       *
 585       * @param array $metadata
 586       * @param ApiResult $result
 587       * @return array
 588       */
 589  	public static function processMetaData( $metadata, $result ) {
 590          $retval = array();
 591          if ( is_array( $metadata ) ) {
 592              foreach ( $metadata as $key => $value ) {
 593                  $r = array( 'name' => $key );
 594                  if ( is_array( $value ) ) {
 595                      $r['value'] = self::processMetaData( $value, $result );
 596                  } else {
 597                      $r['value'] = $value;
 598                  }
 599                  $retval[] = $r;
 600              }
 601          }
 602          $result->setIndexedTagName( $retval, 'metadata' );
 603  
 604          return $retval;
 605      }
 606  
 607  	public function getCacheMode( $params ) {
 608          if ( $this->userCanSeeRevDel() ) {
 609              return 'private';
 610          }
 611  
 612          return 'public';
 613      }
 614  
 615      /**
 616       * @param File $img
 617       * @param null|string $start
 618       * @return string
 619       */
 620  	protected function getContinueStr( $img, $start = null ) {
 621          if ( $start === null ) {
 622              $start = $img->getTimestamp();
 623          }
 624  
 625          return $img->getOriginalTitle()->getDBkey() . '|' . $start;
 626      }
 627  
 628  	public function getAllowedParams() {
 629          global $wgContLang;
 630  
 631          return array(
 632              'prop' => array(
 633                  ApiBase::PARAM_ISMULTI => true,
 634                  ApiBase::PARAM_DFLT => 'timestamp|user',
 635                  ApiBase::PARAM_TYPE => self::getPropertyNames()
 636              ),
 637              'limit' => array(
 638                  ApiBase::PARAM_TYPE => 'limit',
 639                  ApiBase::PARAM_DFLT => 1,
 640                  ApiBase::PARAM_MIN => 1,
 641                  ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
 642                  ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
 643              ),
 644              'start' => array(
 645                  ApiBase::PARAM_TYPE => 'timestamp'
 646              ),
 647              'end' => array(
 648                  ApiBase::PARAM_TYPE => 'timestamp'
 649              ),
 650              'urlwidth' => array(
 651                  ApiBase::PARAM_TYPE => 'integer',
 652                  ApiBase::PARAM_DFLT => -1
 653              ),
 654              'urlheight' => array(
 655                  ApiBase::PARAM_TYPE => 'integer',
 656                  ApiBase::PARAM_DFLT => -1
 657              ),
 658              'metadataversion' => array(
 659                  ApiBase::PARAM_TYPE => 'string',
 660                  ApiBase::PARAM_DFLT => '1',
 661              ),
 662              'extmetadatalanguage' => array(
 663                  ApiBase::PARAM_TYPE => 'string',
 664                  ApiBase::PARAM_DFLT => $wgContLang->getCode(),
 665              ),
 666              'extmetadatamultilang' => array(
 667                  ApiBase::PARAM_TYPE => 'boolean',
 668                  ApiBase::PARAM_DFLT => false,
 669              ),
 670              'extmetadatafilter' => array(
 671                  ApiBase::PARAM_TYPE => 'string',
 672                  ApiBase::PARAM_ISMULTI => true,
 673              ),
 674              'urlparam' => array(
 675                  ApiBase::PARAM_DFLT => '',
 676                  ApiBase::PARAM_TYPE => 'string',
 677              ),
 678              'continue' => null,
 679              'localonly' => false,
 680          );
 681      }
 682  
 683      /**
 684       * Returns all possible parameters to iiprop
 685       *
 686       * @param array $filter List of properties to filter out
 687       *
 688       * @return array
 689       */
 690  	public static function getPropertyNames( $filter = array() ) {
 691          return array_diff( array_keys( self::getProperties() ), $filter );
 692      }
 693  
 694      /**
 695       * Returns array key value pairs of properties and their descriptions
 696       *
 697       * @param string $modulePrefix
 698       * @return array
 699       */
 700  	private static function getProperties( $modulePrefix = '' ) {
 701          return array(
 702              'timestamp' =>      ' timestamp     - Adds timestamp for the uploaded version',
 703              'user' =>           ' user          - Adds the user who uploaded the image version',
 704              'userid' =>         ' userid        - Add the user ID that uploaded the image version',
 705              'comment' =>        ' comment       - Comment on the version',
 706              'parsedcomment' =>  ' parsedcomment - Parse the comment on the version',
 707              'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
 708              'url' =>            ' url           - Gives URL to the image and the description page',
 709              'size' =>           ' size          - Adds the size of the image in bytes, ' .
 710                  'its height and its width. Page count and duration are added if applicable',
 711              'dimensions' =>     ' dimensions    - Alias for size', // B/C with Allimages
 712              'sha1' =>           ' sha1          - Adds SHA-1 hash for the image',
 713              'mime' =>           ' mime          - Adds MIME type of the image',
 714              'thumbmime' =>      ' thumbmime     - Adds MIME type of the image thumbnail' .
 715                  ' (requires url and param ' . $modulePrefix . 'urlwidth)',
 716              'mediatype' =>      ' mediatype     - Adds the media type of the image',
 717              'metadata' =>       ' metadata      - Lists Exif metadata for the version of the image',
 718              'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
 719                  'for the version of the image',
 720              'extmetadata' =>    ' extmetadata   - Lists formatted metadata combined ' .
 721                  'from multiple sources. Results are HTML formatted.',
 722              'archivename' =>    ' archivename   - Adds the file name of the archive ' .
 723                  'version for non-latest versions',
 724              'bitdepth' =>       ' bitdepth      - Adds the bit depth of the version',
 725              'uploadwarning' =>  ' uploadwarning - Used by the Special:Upload page to ' .
 726                  'get information about an existing file. Not intended for use outside MediaWiki core',
 727          );
 728      }
 729  
 730      /**
 731       * Returns the descriptions for the properties provided by getPropertyNames()
 732       *
 733       * @param array $filter List of properties to filter out
 734       * @param string $modulePrefix
 735       * @return array
 736       */
 737  	public static function getPropertyDescriptions( $filter = array(), $modulePrefix = '' ) {
 738          return array_merge(
 739              array( 'What image information to get:' ),
 740              array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
 741          );
 742      }
 743  
 744      /**
 745       * Return the API documentation for the parameters.
 746       * @return array Parameter documentation.
 747       */
 748  	public function getParamDescription() {
 749          $p = $this->getModulePrefix();
 750  
 751          return array(
 752              'prop' => self::getPropertyDescriptions( array(), $p ),
 753              'urlwidth' => array(
 754                  "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
 755                  'For performance reasons if this option is used, ' .
 756                      'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.'
 757              ),
 758              'urlheight' => "Similar to {$p}urlwidth.",
 759              'urlparam' => array(
 760                  "A handler specific parameter string. For example, pdf's ",
 761                  "might use 'page15-100px'."
 762              ),
 763              'limit' => 'How many image revisions to return per image',
 764              'start' => 'Timestamp to start listing from',
 765              'end' => 'Timestamp to stop listing at',
 766              'metadataversion'
 767                  => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
 768                  "Defaults to '1' for backwards compatibility" ),
 769              'extmetadatalanguage' => array(
 770                  'What language to fetch extmetadata in. This affects both which',
 771                  'translation to fetch, if multiple are available, as well as how things',
 772                  'like numbers and various values are formatted.'
 773              ),
 774              'extmetadatamultilang'
 775                  =>'If translations for extmetadata property are available, fetch all of them.',
 776              'extmetadatafilter'
 777                  => "If specified and non-empty, only these keys will be returned for {$p}prop=extmetadata",
 778              'continue' => 'If the query response includes a continue value, ' .
 779                  'use it here to get another page of results',
 780              'localonly' => 'Look only for files in the local repository',
 781          );
 782      }
 783  
 784  	public function getDescription() {
 785          return 'Returns image information and upload history.';
 786      }
 787  
 788  	public function getExamples() {
 789          return array(
 790              'api.php?action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo',
 791              'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
 792                  'iiend=20071231235959&iiprop=timestamp|user|url',
 793          );
 794      }
 795  
 796  	public function getHelpUrls() {
 797          return 'https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii';
 798      }
 799  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1