34 parent::__construct(
'ThumbnailRender', $title,
$params );
37 public function run() {
38 $uploadThumbnailRenderMethod = MediaWikiServices::getInstance()
39 ->getMainConfig()->get( MainConfigNames::UploadThumbnailRenderMethod );
41 $transformParams = $this->params[
'transformParams'];
43 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
44 ->newFile( $this->title );
45 $file->load( IDBAccessObject::READ_LATEST );
47 if ( $file && $file->exists() ) {
48 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
49 $thumb = $file->transform( $transformParams, File::RENDER_NOW );
51 if ( !$thumb || $thumb->isError() ) {
53 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated:' .
56 $this->
setLastError( __METHOD__ .
': thumbnail couldn\'t be generated' );
60 $this->maybeEnqueueNextPage( $transformParams );
62 } elseif ( $uploadThumbnailRenderMethod ===
'http' ) {
63 $res = $this->
hitThumbUrl( $file, $transformParams );
64 $this->maybeEnqueueNextPage( $transformParams );
67 $this->
setLastError( __METHOD__ .
': unknown thumbnail render method ' .
68 $uploadThumbnailRenderMethod );
72 $this->
setLastError( __METHOD__ .
': file doesn\'t exist' );
83 $config = MediaWikiServices::getInstance()->getMainConfig();
84 $uploadThumbnailRenderHttpCustomHost =
85 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomHost );
86 $uploadThumbnailRenderHttpCustomDomain =
87 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomDomain );
90 $this->
setLastError( __METHOD__ .
': could not get handler' );
92 } elseif ( !$handler->normaliseParams( $file, $transformParams ) ) {
93 $this->
setLastError( __METHOD__ .
': failed to normalize' );
96 $thumbName = $file->
thumbName( $transformParams );
99 if ( $thumbUrl ===
null ) {
100 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
104 if ( $uploadThumbnailRenderHttpCustomDomain ) {
107 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
108 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
112 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
115 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
119 $request = MediaWikiServices::getInstance()->getHttpRequestFactory()->create(
121 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
125 if ( $uploadThumbnailRenderHttpCustomHost ) {
126 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
129 $status = $request->execute();
130 $statusCode = $request->getStatus();
131 wfDebug( __METHOD__ .
": received status {$statusCode}" );
135 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
137 } elseif ( $statusCode ) {
138 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
139 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
144 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
145 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );
150 private function maybeEnqueueNextPage( $transformParams ) {
152 ( $this->params[
'enqueueNextPage'] ??
false ) &&
153 ( $transformParams[
'page'] ?? 0 ) < ( $this->params[
'pageLimit'] ?? 0 )
155 $transformParams[
'page']++;
159 'transformParams' => $transformParams,
160 'enqueueNextPage' =>
true,
161 'pageLimit' => $this->params[
'pageLimit']
165 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.
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