28 private $page =
false;
33 private $file =
false;
39 $this->repoGroup = $repoGroup;
40 $this->pageLookup = $pageLookup;
47 if ( $this->page === false ) {
48 $this->page = $this->pageLookup->getExistingPageByText(
58 private function getFile(): ?File {
59 if ( $this->file === false ) {
60 $page = $this->getPage();
63 $this->repoGroup->findFile( $page, [
'private' => $this->getAuthority() ] ) ?:
null;
73 public function run( $title ) {
74 $page = $this->getPage();
78 MessageValue::new(
'rest-nonexistent-title' )->plaintextParams( $title ),
83 if ( !$this->getAuthority()->authorizeRead(
'read', $page ) ) {
85 MessageValue::new(
'rest-permission-denied-title' )->plaintextParams( $title ),
91 if ( !$fileObj || !$fileObj->exists() ) {
93 MessageValue::new(
'rest-cannot-load-file' )->plaintextParams( $title ),
98 $response = $this->getResponse( $fileObj );
99 return $this->getResponseFactory()->createJson( $response );
106 private function getResponse(
File $file ): array {
107 [ $maxWidth, $maxHeight ] = self::getImageLimitsFromOption(
108 $this->getAuthority()->getUser(),
'imagesize'
110 [ $maxThumbWidth, $maxThumbHeight ] = self::getImageLimitsFromOption(
111 $this->getAuthority()->getUser(),
'thumbsize'
115 'maxWidth' => $maxWidth,
116 'maxHeight' => $maxHeight
119 'maxWidth' => $maxThumbWidth,
120 'maxHeight' => $maxThumbHeight
124 return $this->getFileInfo( $file, $this->getAuthority(), $transforms );
134 self::PARAM_SOURCE =>
'path',
135 ParamValidator::PARAM_TYPE =>
'string',
136 ParamValidator::PARAM_REQUIRED =>
true,
147 if ( !$file || !$file->
exists() ) {
151 return '"' . $file->
getSha1() .
'"';
160 if ( !$file || !$file->
exists() ) {
172 return $file && $file->
exists();