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' );
77 $uploadThumbnailRenderHttpCustomHost =
79 $uploadThumbnailRenderHttpCustomDomain =
83 $this->
setLastError( __METHOD__ .
': could not get handler' );
85 } elseif ( !$handler->normaliseParams( $file, $transformParams ) ) {
86 $this->
setLastError( __METHOD__ .
': failed to normalize' );
89 $thumbName = $file->
thumbName( $transformParams );
92 if ( $thumbUrl ===
null ) {
93 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
97 if ( $uploadThumbnailRenderHttpCustomDomain ) {
100 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
101 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
105 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
108 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
114 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
118 if ( $uploadThumbnailRenderHttpCustomHost ) {
119 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
122 $status = $request->execute();
123 $statusCode = $request->getStatus();
124 wfDebug( __METHOD__ .
": received status {$statusCode}" );
128 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
130 } elseif ( $statusCode ) {
131 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
132 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
137 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
138 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );
143 private function maybeEnqueueNextPage( array $transformParams ) {
145 ( $this->params[
'enqueueNextPage'] ??
false ) &&
146 ( $transformParams[
'page'] ?? 0 ) < ( $this->params[
'pageLimit'] ?? 0 )
148 $transformParams[
'page']++;
152 'transformParams' => $transformParams,
153 'enqueueNextPage' =>
true,
154 'pageLimit' => $this->params[
'pageLimit']
176class_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