23 private const MAX_NUM_LINKS = 100;
37 private $page =
false;
49 $this->lbFactory = $lbFactory;
50 $this->repoGroup = $repoGroup;
51 $this->pageLookup = $pageLookup;
58 if ( $this->page === false ) {
59 $this->page = $this->pageLookup->getExistingPageByText(
72 $page = $this->getPage();
75 MessageValue::new(
'rest-nonexistent-title' )->plaintextParams(
$title ),
80 if ( !$this->
getAuthority()->authorizeRead(
'read', $page ) ) {
82 MessageValue::new(
'rest-permission-denied-title' )->plaintextParams(
$title ),
88 $results = $this->getDbResults( $page->getId() );
89 if ( count( $results ) > self::MAX_NUM_LINKS ) {
91 MessageValue::new(
'rest-media-too-many-links' )
92 ->plaintextParams(
$title )
93 ->numParams( self::MAX_NUM_LINKS ),
97 $response = $this->processDbResults( $results );
105 private function getDbResults(
int $pageId ) {
106 return $this->lbFactory->getReplicaDatabase()->newSelectQueryBuilder()
108 ->from(
'imagelinks' )
109 ->where( [
'il_from' => $pageId ] )
111 ->limit( self::MAX_NUM_LINKS + 1 )
112 ->caller( __METHOD__ )->fetchFieldValues();
119 private function processDbResults( $results ) {
123 $findTitles = array_map(
static function (
$title ) use ( $performer ) {
126 'private' => $performer,
130 $files = $this->repoGroup->findFiles( $findTitles );
131 [ $maxWidth, $maxHeight ] = self::getImageLimitsFromOption(
137 'maxWidth' => $maxWidth,
138 'maxHeight' => $maxHeight,
142 foreach ( $files as
$file ) {
143 $response[] = $this->getFileInfo(
$file, $performer, $transforms );
160 self::PARAM_SOURCE =>
'path',
161 ParamValidator::PARAM_TYPE =>
'string',
162 ParamValidator::PARAM_REQUIRED =>
true,
172 $page = $this->getPage();
178 return '"' . $page->getLatest() .
'@' .
wfTimestamp( TS_MW, $page->getTouched() ) .
'"';
186 $page = $this->getPage();
187 return $page ? $page->getTouched() :
null;
194 return (
bool)$this->getPage();
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Prioritized list of file repositories.
Service for looking up information about wiki pages.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.