30 public function run() {
34 $transformParams = $this->params[
'transformParams'];
37 ->newFile( $this->title );
38 $file->load( IDBAccessObject::READ_LATEST );
40 if ( $file && $file->exists() ) {
41 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
42 $thumb = $file->transform( $transformParams, File::RENDER_NOW );
44 if ( !$thumb || $thumb->isError() ) {
46 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated:' .
49 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated' );
53 $this->maybeEnqueueNextPage( $transformParams );
55 } elseif ( $uploadThumbnailRenderMethod ===
'http' ) {
56 $res = $this->
hitThumbUrl( $file, $transformParams );
57 $this->maybeEnqueueNextPage( $transformParams );
60 $this->
setLastError( __METHOD__ .
': unknown thumbnail render method ' .
61 $uploadThumbnailRenderMethod );
65 $this->
setLastError( __METHOD__ .
': file doesn\'t exist' );
78 $uploadThumbnailRenderHttpCustomHost =
80 $uploadThumbnailRenderHttpCustomDomain =
84 $this->
setLastError( __METHOD__ .
': could not get handler' );
86 } elseif ( !$handler->normaliseParams( $file, $transformParams ) ) {
87 $this->
setLastError( __METHOD__ .
': failed to normalize' );
90 $thumbName = $file->
thumbName( $transformParams );
93 if ( $thumbUrl ===
null ) {
94 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
98 if ( $uploadThumbnailRenderHttpCustomDomain ) {
99 $parsedUrl = $urlUtils->parse( $thumbUrl );
101 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
102 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
106 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
109 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
115 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
119 if ( $uploadThumbnailRenderHttpCustomHost ) {
120 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
124 $statusCode =
$request->getStatus();
125 wfDebug( __METHOD__ .
": received status {$statusCode}" );
129 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
131 } elseif ( $statusCode ) {
132 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
133 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
138 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
139 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );
144 private function maybeEnqueueNextPage( array $transformParams ) {
146 ( $this->params[
'enqueueNextPage'] ??
false ) &&
147 ( $transformParams[
'page'] ?? 0 ) < ( $this->params[
'pageLimit'] ?? 0 )
149 $transformParams[
'page']++;
153 'transformParams' => $transformParams,
154 'enqueueNextPage' =>
true,
155 'pageLimit' => $this->params[
'pageLimit']
177class_alias( ThumbnailRenderJob::class,
'ThumbnailRenderJob' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
A class containing constants representing the names of configuration variables.
const UploadThumbnailRenderMethod
Name constant for the UploadThumbnailRenderMethod setting, for use with Config::get()
const UploadThumbnailRenderHttpCustomDomain
Name constant for the UploadThumbnailRenderHttpCustomDomain setting, for use with Config::get()
const UploadThumbnailRenderHttpCustomHost
Name constant for the UploadThumbnailRenderHttpCustomHost setting, for use with Config::get()
if(count( $args)< 1) $job