43 public function run() {
47 $transformParams = $this->params[
'transformParams'];
50 ->newFile( $this->title );
51 $file->load( IDBAccessObject::READ_LATEST );
53 if ( $file && $file->exists() ) {
54 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
55 $thumb = $file->transform( $transformParams, File::RENDER_NOW );
57 if ( !$thumb || $thumb->isError() ) {
59 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated:' .
62 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated' );
66 $this->maybeEnqueueNextPage( $transformParams );
68 } elseif ( $uploadThumbnailRenderMethod ===
'http' ) {
69 $res = $this->
hitThumbUrl( $file, $transformParams );
70 $this->maybeEnqueueNextPage( $transformParams );
73 $this->
setLastError( __METHOD__ .
': unknown thumbnail render method ' .
74 $uploadThumbnailRenderMethod );
78 $this->
setLastError( __METHOD__ .
': file doesn\'t exist' );
90 $uploadThumbnailRenderHttpCustomHost =
92 $uploadThumbnailRenderHttpCustomDomain =
96 $this->
setLastError( __METHOD__ .
': could not get handler' );
98 } elseif ( !$handler->normaliseParams( $file, $transformParams ) ) {
99 $this->
setLastError( __METHOD__ .
': failed to normalize' );
102 $thumbName = $file->
thumbName( $transformParams );
105 if ( $thumbUrl ===
null ) {
106 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
110 if ( $uploadThumbnailRenderHttpCustomDomain ) {
113 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
114 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
118 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
121 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
127 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
131 if ( $uploadThumbnailRenderHttpCustomHost ) {
132 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
135 $status = $request->execute();
136 $statusCode = $request->getStatus();
137 wfDebug( __METHOD__ .
": received status {$statusCode}" );
141 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
143 } elseif ( $statusCode ) {
144 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
145 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
150 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
151 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );
156 private function maybeEnqueueNextPage( array $transformParams ) {
158 ( $this->params[
'enqueueNextPage'] ??
false ) &&
159 ( $transformParams[
'page'] ?? 0 ) < ( $this->params[
'pageLimit'] ?? 0 )
161 $transformParams[
'page']++;
165 'transformParams' => $transformParams,
166 'enqueueNextPage' =>
true,
167 'pageLimit' => $this->params[
'pageLimit']
189class_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