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( File::READ_LATEST );
48 if ( $uploadThumbnailRenderMethod ===
'jobqueue' ) {
49 $thumb =
$file->transform( $transformParams, File::RENDER_NOW );
51 if ( !$thumb || $thumb->isError() ) {
53 $this->
setLastError( __METHOD__ .
': thumbnail couln\'t be generated:' .
56 $this->
setLastError( __METHOD__ .
': thumbnail couln\'t be generated' );
61 } elseif ( $uploadThumbnailRenderMethod ===
'http' ) {
64 $this->
setLastError( __METHOD__ .
': unknown thumbnail render method ' .
65 $uploadThumbnailRenderMethod );
69 $this->
setLastError( __METHOD__ .
': file doesn\'t exist' );
80 $config = MediaWikiServices::getInstance()->getMainConfig();
81 $uploadThumbnailRenderHttpCustomHost =
82 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomHost );
83 $uploadThumbnailRenderHttpCustomDomain =
84 $config->get( MainConfigNames::UploadThumbnailRenderHttpCustomDomain );
85 $handler =
$file->getHandler();
87 $this->
setLastError( __METHOD__ .
': could not get handler' );
89 } elseif ( !$handler->normaliseParams(
$file, $transformParams ) ) {
90 $this->
setLastError( __METHOD__ .
': failed to normalize' );
93 $thumbName =
$file->thumbName( $transformParams );
94 $thumbUrl =
$file->getThumbUrl( $thumbName );
96 if ( $thumbUrl ===
null ) {
97 $this->
setLastError( __METHOD__ .
': could not get thumb URL' );
101 if ( $uploadThumbnailRenderHttpCustomDomain ) {
104 if ( !isset( $parsedUrl[
'path'] ) || $parsedUrl[
'path'] ===
'' ) {
105 $this->
setLastError( __METHOD__ .
": invalid thumb URL: $thumbUrl" );
109 $thumbUrl =
'//' . $uploadThumbnailRenderHttpCustomDomain . $parsedUrl[
'path'];
112 wfDebug( __METHOD__ .
": hitting url {$thumbUrl}" );
116 $request = MediaWikiServices::getInstance()->getHttpRequestFactory()->create(
118 [
'method' =>
'HEAD',
'followRedirects' =>
true,
'timeout' => 1 ],
122 if ( $uploadThumbnailRenderHttpCustomHost ) {
123 $request->setHeader(
'Host', $uploadThumbnailRenderHttpCustomHost );
126 $status = $request->execute();
127 $statusCode = $request->getStatus();
128 wfDebug( __METHOD__ .
": received status {$statusCode}" );
132 if ( $statusCode === 200 || $statusCode === 301 || $statusCode === 302 || $statusCode === 400 ) {
134 } elseif ( $statusCode ) {
135 $this->
setLastError( __METHOD__ .
": incorrect HTTP status $statusCode when hitting $thumbUrl" );
136 } elseif ( $status->hasMessage(
'http-timed-out' ) ) {
141 $this->
setLastError( __METHOD__ .
': HTTP request failure: '
142 . Status::wrap( $status )->getWikiText(
false,
false,
'en' ) );