33 parent::__construct(
'ThumbnailRender', $title,
$params );
36 public function run() {
37 $uploadThumbnailRenderMethod = MediaWikiServices::getInstance()
38 ->getMainConfig()->get( MainConfigNames::UploadThumbnailRenderMethod );
40 $transformParams = $this->params[
'transformParams'];
42 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
43 ->newFile( $this->title );
44 $file->load( IDBAccessObject::READ_LATEST );
46 if ( $file && $file->exists() ) {
47 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
48 $thumb = $file->transform( $transformParams, File::RENDER_NOW );
50 if ( !$thumb || $thumb->isError() ) {
52 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated:' .
55 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated' );
59 $this->maybeEnqueueNextPage( $transformParams );
61 } elseif ( $uploadThumbnailRenderMethod ===
'http' ) {
62 $res = $this->
hitThumbUrl( $file, $transformParams );
63 $this->maybeEnqueueNextPage( $transformParams );
66 $this->
setLastError( __METHOD__ .
': unknown thumbnail render method ' .
67 $uploadThumbnailRenderMethod );
71 $this->
setLastError( __METHOD__ .
': file doesn\'t exist' );
82 $config = MediaWikiServices::getInstance()->getMainConfig();
83 $uploadThumbnailRenderHttpCustomHost =
84 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomHost );
85 $uploadThumbnailRenderHttpCustomDomain =
86 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomDomain );
89 $this->
setLastError( __METHOD__ .
': could not get handler' );
91 } elseif ( !$handler->normaliseParams( $file, $transformParams ) ) {
92 $this->
setLastError( __METHOD__ .
': failed to normalize' );
95 $thumbName = $file->
thumbName( $transformParams );
98 if ( $thumbUrl ===
null ) {
99 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
103 if ( $uploadThumbnailRenderHttpCustomDomain ) {
106 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
107 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
111 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
114 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
118 $request = MediaWikiServices::getInstance()->getHttpRequestFactory()->create(
120 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
124 if ( $uploadThumbnailRenderHttpCustomHost ) {
125 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
128 $status = $request->execute();
129 $statusCode = $request->getStatus();
130 wfDebug( __METHOD__ .
": received status {$statusCode}" );
134 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
136 } elseif ( $statusCode ) {
137 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
138 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
143 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
144 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );
149 private function maybeEnqueueNextPage( $transformParams ) {
151 ( $this->params[
'enqueueNextPage'] ??
false ) &&
152 ( $transformParams[
'page'] ?? 0 ) < ( $this->params[
'pageLimit'] ?? 0 )
154 $transformParams[
'page'] += 1;
158 'transformParams' => $transformParams,
159 'enqueueNextPage' =>
true,
160 'pageLimit' => $this->params[
'pageLimit']
164 MediaWikiServices::getInstance()->getJobQueueGroup()->lazyPush( [
$job ] );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
array $params
The job parameters.
setLastError( $error)
This is actually implemented in the Job class.
getThumbUrl( $suffix=false)
Get the URL of the thumbnail directory, or a particular file if $suffix is specified.
thumbName( $params, $flags=0)
Return the file name of a thumbnail with the specified parameters.
getHandler()
Get a MediaHandler instance for this file.
Describe and execute a background job.
Local file in the wiki's own database.
A class containing constants representing the names of configuration variables.
Job for asynchronous rendering of thumbnails, e.g.
__construct(Title $title, array $params)
hitThumbUrl(LocalFile $file, $transformParams)
allowRetries()
Whether to retry the job.
if(count( $args)< 1) $job