From: Aaron Schulz Date: Thu, 27 Oct 2011 22:42:53 +0000 (+0000) Subject: FU r100535: renamed thumb-handler.php to match the other files here X-Git-Tag: 1.31.0-rc.0~26863 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin//%22%24path/%7B%24disabledImages%5B%24type%5D%7D/%22?a=commitdiff_plain;h=3dbb621c5895f229dfcfdef1206ee6ba569419df;p=lhc%2Fweb%2Fwiklou.git FU r100535: renamed thumb-handler.php to match the other files here --- diff --git a/thumb-handler.php b/thumb-handler.php deleted file mode 100644 index 6d18bab3e0..0000000000 --- a/thumb-handler.php +++ /dev/null @@ -1,252 +0,0 @@ - $filename, 'width' => $size ); - if ( $pagenum ) { - $params['page'] = $pagenum; - } - if ( $archOrTemp == '/archive' ) { - $params['archived'] = 1; - } elseif ( $archOrTemp == '/temp' ) { - $params['temp'] = 1; - } - } else { - $params = null; // not a valid thumbnail URL - } - - return $params; -} - -/** - * cURL to thumb.php and stream back the resulting file or give an error message. - * - * @param $params Array Parameters to thumb.php - * @param $uri String Thumbnail request URI - * @return void - */ -function wfStreamThumbViaCurl( array $params, $uri ) { - global $thgThumbCallbacks, $thgThumbScriptPath, $thgThumbCurlProxy, $thgThumbCurlTimeout; - - # Build up the request URL to use with CURL... - $reqURL = "{$thgThumbScriptPath}?"; - $first = true; - foreach ( $params as $name => $value ) { - if ( $first ) { - $first = false; - } else { - $reqURL .= '&'; - } - $reqURL .= "$name=$value"; // Note: value is already urlencoded - } - - # Set relevant HTTP headers... - $headers = array(); - $headers[] = "X-Original-URI: " . str_replace( "\n", '', $uri ); - if ( isset( $thgThumbCallbacks['curlHeaders'] ) - && is_callable( $thgThumbCallbacks['curlHeaders'] ) ) - { - # Add on any custom headers (like XFF) - call_user_func_array( $thgThumbCallbacks['curlHeaders'], array( &$headers ) ); - } - - # Pass through some other headers... - $passThrough = array( 'If-Modified-Since', 'Referer', 'User-Agent' ); - foreach ( $passThrough as $headerName ) { - $serverVarName = 'HTTP_' . str_replace( '-', '_', strtoupper( $headerName ) ); - if ( !empty( $_SERVER[$serverVarName] ) ) { - $headers[] = $headerName . ': ' . - str_replace( "\n", '', $_SERVER[$serverVarName] ); - } - } - - $ch = curl_init( $reqURL ); - if ( $thgThumbCurlProxy ) { - curl_setopt( $ch, CURLOPT_PROXY, $thgThumbCurlProxy ); - } - - curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); - curl_setopt( $ch, CURLOPT_TIMEOUT, $thgThumbCurlTimeout ); - - # Actually make the request - $text = curl_exec( $ch ); - - # Send it on to the client... - $errno = curl_errno( $ch ); - $contentType = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE ); - $httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); - if ( $errno ) { - header( 'HTTP/1.1 500 Internal server error' ); - header( 'Cache-Control: no-cache' ); - $contentType = 'text/html'; - $text = wfCurlErrorText( $ch ); - } elseif ( $httpCode == 304 ) { // OK - header( 'HTTP/1.1 304 Not modified' ); - $contentType = ''; - $text = ''; - } elseif ( strval( $text ) == '' ) { - header( 'HTTP/1.1 500 Internal server error' ); - header( 'Cache-Control: no-cache' ); - $contentType = 'text/html'; - $text = wfCurlEmptyText( $ch ); - } elseif ( $httpCode == 404 ) { - header( 'HTTP/1.1 404 Not found' ); - header( 'Cache-Control: s-maxage=300, must-revalidate, max-age=0' ); - } elseif ( $httpCode != 200 || substr( $contentType, 0, 9 ) == 'text/html' ) { - # Error message, suppress cache - header( 'HTTP/1.1 500 Internal server error' ); - header( 'Cache-Control: no-cache' ); - } else { - # OK thumbnail; save to any backend caches... - if ( isset( $thgThumbCallbacks['fillCache'] ) - && is_callable( $thgThumbCallbacks['fillCache'] ) ) - { - call_user_func_array( $thgThumbCallbacks['fillCache'], array( $uri, $text ) ); - } - } - - if ( !$contentType ) { - header( 'Content-Type:' ); - } else { - header( "Content-Type: $contentType" ); - } - - print $text; // thumb data or error text - - curl_close( $ch ); -} - -/** - * Get error message HTML for when the cURL response is an error. - * - * @param $ch cURL handle - * @return string - */ -function wfCurlErrorText( $ch ) { - $error = htmlspecialchars( curl_error( $ch ) ); - return << -Thumbnail error -Error retrieving thumbnail from scaling server: $error - -EOT; -} - -/** - * Get error message HTML for when the cURL response is empty. - * - * @param $ch cURL handle - * @return string - */ -function wfCurlEmptyText( $ch ) { - return << -Thumbnail error -Error retrieving thumbnail from scaling server: empty response - -EOT; -} - -/** - * Print out a generic 404 error message. - * - * @return void - */ -function wfDisplay404Error() { - header( 'HTTP/1.1 404 Not Found' ); - header( 'Content-Type: text/html;charset=utf-8' ); - - $prot = isset( $_SERVER['HTTPS'] ) ? "https://" : "http://"; - $serv = strlen( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; - $loc = $_SERVER["REQUEST_URI"]; - - $encUrl = htmlspecialchars( $prot . $serv . $loc ); - - // Looks like a typical apache2 error - $standard_404 = << - -404 Not Found - -

Not Found

-

The requested URL $encUrl was not found on this server.

- -ENDTEXT; - - print $standard_404; -} diff --git a/thumb-handler.php5 b/thumb-handler.php5 deleted file mode 100644 index cb8eb611ea..0000000000 --- a/thumb-handler.php5 +++ /dev/null @@ -1 +0,0 @@ - $filename, 'width' => $size ); + if ( $pagenum ) { + $params['page'] = $pagenum; + } + if ( $archOrTemp == '/archive' ) { + $params['archived'] = 1; + } elseif ( $archOrTemp == '/temp' ) { + $params['temp'] = 1; + } + } else { + $params = null; // not a valid thumbnail URL + } + + return $params; +} + +/** + * cURL to thumb.php and stream back the resulting file or give an error message. + * + * @param $params Array Parameters to thumb.php + * @param $uri String Thumbnail request URI + * @return void + */ +function wfStreamThumbViaCurl( array $params, $uri ) { + global $thgThumbCallbacks, $thgThumbScriptPath, $thgThumbCurlProxy, $thgThumbCurlTimeout; + + # Build up the request URL to use with CURL... + $reqURL = "{$thgThumbScriptPath}?"; + $first = true; + foreach ( $params as $name => $value ) { + if ( $first ) { + $first = false; + } else { + $reqURL .= '&'; + } + $reqURL .= "$name=$value"; // Note: value is already urlencoded + } + + # Set relevant HTTP headers... + $headers = array(); + $headers[] = "X-Original-URI: " . str_replace( "\n", '', $uri ); + if ( isset( $thgThumbCallbacks['curlHeaders'] ) + && is_callable( $thgThumbCallbacks['curlHeaders'] ) ) + { + # Add on any custom headers (like XFF) + call_user_func_array( $thgThumbCallbacks['curlHeaders'], array( &$headers ) ); + } + + # Pass through some other headers... + $passThrough = array( 'If-Modified-Since', 'Referer', 'User-Agent' ); + foreach ( $passThrough as $headerName ) { + $serverVarName = 'HTTP_' . str_replace( '-', '_', strtoupper( $headerName ) ); + if ( !empty( $_SERVER[$serverVarName] ) ) { + $headers[] = $headerName . ': ' . + str_replace( "\n", '', $_SERVER[$serverVarName] ); + } + } + + $ch = curl_init( $reqURL ); + if ( $thgThumbCurlProxy ) { + curl_setopt( $ch, CURLOPT_PROXY, $thgThumbCurlProxy ); + } + + curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_TIMEOUT, $thgThumbCurlTimeout ); + + # Actually make the request + $text = curl_exec( $ch ); + + # Send it on to the client... + $errno = curl_errno( $ch ); + $contentType = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE ); + $httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); + if ( $errno ) { + header( 'HTTP/1.1 500 Internal server error' ); + header( 'Cache-Control: no-cache' ); + $contentType = 'text/html'; + $text = wfCurlErrorText( $ch ); + } elseif ( $httpCode == 304 ) { // OK + header( 'HTTP/1.1 304 Not modified' ); + $contentType = ''; + $text = ''; + } elseif ( strval( $text ) == '' ) { + header( 'HTTP/1.1 500 Internal server error' ); + header( 'Cache-Control: no-cache' ); + $contentType = 'text/html'; + $text = wfCurlEmptyText( $ch ); + } elseif ( $httpCode == 404 ) { + header( 'HTTP/1.1 404 Not found' ); + header( 'Cache-Control: s-maxage=300, must-revalidate, max-age=0' ); + } elseif ( $httpCode != 200 || substr( $contentType, 0, 9 ) == 'text/html' ) { + # Error message, suppress cache + header( 'HTTP/1.1 500 Internal server error' ); + header( 'Cache-Control: no-cache' ); + } else { + # OK thumbnail; save to any backend caches... + if ( isset( $thgThumbCallbacks['fillCache'] ) + && is_callable( $thgThumbCallbacks['fillCache'] ) ) + { + call_user_func_array( $thgThumbCallbacks['fillCache'], array( $uri, $text ) ); + } + } + + if ( !$contentType ) { + header( 'Content-Type:' ); + } else { + header( "Content-Type: $contentType" ); + } + + print $text; // thumb data or error text + + curl_close( $ch ); +} + +/** + * Get error message HTML for when the cURL response is an error. + * + * @param $ch cURL handle + * @return string + */ +function wfCurlErrorText( $ch ) { + $error = htmlspecialchars( curl_error( $ch ) ); + return << +Thumbnail error +Error retrieving thumbnail from scaling server: $error + +EOT; +} + +/** + * Get error message HTML for when the cURL response is empty. + * + * @param $ch cURL handle + * @return string + */ +function wfCurlEmptyText( $ch ) { + return << +Thumbnail error +Error retrieving thumbnail from scaling server: empty response + +EOT; +} + +/** + * Print out a generic 404 error message. + * + * @return void + */ +function wfDisplay404Error() { + header( 'HTTP/1.1 404 Not Found' ); + header( 'Content-Type: text/html;charset=utf-8' ); + + $prot = isset( $_SERVER['HTTPS'] ) ? "https://" : "http://"; + $serv = strlen( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; + $loc = $_SERVER["REQUEST_URI"]; + + $encUrl = htmlspecialchars( $prot . $serv . $loc ); + + // Looks like a typical apache2 error + $standard_404 = << + +404 Not Found + +

Not Found

+

The requested URL $encUrl was not found on this server.

+ +ENDTEXT; + + print $standard_404; +} diff --git a/thumb_handler.php5 b/thumb_handler.php5 new file mode 100644 index 0000000000..5092931003 --- /dev/null +++ b/thumb_handler.php5 @@ -0,0 +1 @@ +