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( File::READ_LATEST );
47 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
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' ) {
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 );
87 $handler =
$file->getHandler();
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 );
96 $thumbUrl =
$file->getThumbUrl( $thumbName );
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.
const RENDER_NOW
Force rendering in the current process.
Class to both describe a background job and handle jobs.
array $params
Array of job parameters.
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
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.