35 public function run() {
36 $uploadThumbnailRenderMethod = MediaWikiServices::getInstance()
37 ->getMainConfig()->get( MainConfigNames::UploadThumbnailRenderMethod );
39 $transformParams = $this->params[
'transformParams'];
41 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
42 ->newFile( $this->title );
43 $file->load( File::READ_LATEST );
46 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
47 $thumb =
$file->transform( $transformParams, File::RENDER_NOW );
49 if ( !$thumb || $thumb->isError() ) {
51 $this->
setLastError( __METHOD__ .
': thumbnail couln\'t be generated:' .
54 $this->
setLastError( __METHOD__ .
': thumbnail couln\'t be generated' );
59 } elseif ( $uploadThumbnailRenderMethod ===
'http' ) {
62 $this->
setLastError( __METHOD__ .
': unknown thumbnail render method ' .
63 $uploadThumbnailRenderMethod );
67 $this->
setLastError( __METHOD__ .
': file doesn\'t exist' );
78 $config = MediaWikiServices::getInstance()->getMainConfig();
79 $uploadThumbnailRenderHttpCustomHost =
80 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomHost );
81 $uploadThumbnailRenderHttpCustomDomain =
82 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomDomain );
83 $handler =
$file->getHandler();
85 $this->
setLastError( __METHOD__ .
': could not get handler' );
87 } elseif ( !$handler->normaliseParams(
$file, $transformParams ) ) {
88 $this->
setLastError( __METHOD__ .
': failed to normalize' );
91 $thumbName =
$file->thumbName( $transformParams );
92 $thumbUrl =
$file->getThumbUrl( $thumbName );
94 if ( $thumbUrl ===
null ) {
95 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
99 if ( $uploadThumbnailRenderHttpCustomDomain ) {
102 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
103 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
107 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
110 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
114 $request = MediaWikiServices::getInstance()->getHttpRequestFactory()->create(
116 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
120 if ( $uploadThumbnailRenderHttpCustomHost ) {
121 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
124 $status = $request->execute();
125 $statusCode = $request->getStatus();
126 wfDebug( __METHOD__ .
": received status {$statusCode}" );
130 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
132 } elseif ( $statusCode ) {
133 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
134 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
139 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
140 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );