Файловый менеджер - Редактировать - /var/www/html/Output.zip
Ðазад
PK ! G~n n StreamFile.phpnu �Iw�� <?php /** * Functions related to the output of file content. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ namespace MediaWiki\Output; use InvalidArgumentException; use MediaWiki\Context\RequestContext; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; use UploadBase; use Wikimedia\FileBackend\FileBackend; use Wikimedia\FileBackend\HTTPFileStreamer; /** * Functions related to the output of file content */ class StreamFile { private const UNKNOWN_CONTENT_TYPE = 'unknown/unknown'; /** * Stream a file to the browser, adding all the headings and fun stuff. * Headers sent include: Content-type, Content-Length, Last-Modified, * and Content-Disposition. * * @param string $fname Full name and path of the file to stream * @param array $headers Any additional headers to send if the file exists * @param bool $sendErrors Send error messages if errors occur (like 404) * @param array $optHeaders HTTP request header map (e.g. "range") (use lowercase keys) * @param int $flags Bitfield of STREAM_* constants * @return bool Success */ public static function stream( $fname, $headers = [], $sendErrors = true, $optHeaders = [], $flags = 0 ) { if ( FileBackend::isStoragePath( $fname ) ) { throw new InvalidArgumentException( __FUNCTION__ . " given storage path '$fname'." ); } $streamer = new HTTPFileStreamer( $fname, [ 'obResetFunc' => 'wfResetOutputBuffers', 'streamMimeFunc' => [ __CLASS__, 'contentTypeFromPath' ], 'headerFunc' => [ __CLASS__, 'setHeader' ], ] ); return $streamer->stream( $headers, $sendErrors, $optHeaders, $flags ); } /** * @param string $header * * @internal */ public static function setHeader( $header ) { RequestContext::getMain()->getRequest()->response()->header( $header ); } /** * Determine the file type of a file based on the path * * @param string $filename Storage path or file system path * @param bool $safe Whether to do retroactive upload prevention checks * @return null|string */ public static function contentTypeFromPath( $filename, $safe = true ) { // NOTE: TrivialMimeDetection is forced by ThumbnailEntryPoint. When this // code is moved to a non-static method in a service object, we can no // longer rely on that. $trivialMimeDetection = MediaWikiServices::getInstance()->getMainConfig() ->get( MainConfigNames::TrivialMimeDetection ); $ext = strrchr( $filename, '.' ); $ext = $ext ? strtolower( substr( $ext, 1 ) ) : ''; # trivial detection by file extension, # used for thumbnails (thumb.php) if ( $trivialMimeDetection ) { switch ( $ext ) { case 'gif': return 'image/gif'; case 'png': return 'image/png'; case 'jpg': case 'jpeg': return 'image/jpeg'; case 'webp': return 'image/webp'; } return self::UNKNOWN_CONTENT_TYPE; } $magic = MediaWikiServices::getInstance()->getMimeAnalyzer(); // Use the extension only, rather than magic numbers, to avoid opening // up vulnerabilities due to uploads of files with allowed extensions // but disallowed types. $type = $magic->getMimeTypeFromExtensionOrNull( $ext ); /** * Double-check some security settings that were done on upload but might * have changed since. */ if ( $safe ) { $mainConfig = MediaWikiServices::getInstance()->getMainConfig(); $prohibitedFileExtensions = $mainConfig->get( MainConfigNames::ProhibitedFileExtensions ); $checkFileExtensions = $mainConfig->get( MainConfigNames::CheckFileExtensions ); $strictFileExtensions = $mainConfig->get( MainConfigNames::StrictFileExtensions ); $fileExtensions = $mainConfig->get( MainConfigNames::FileExtensions ); $verifyMimeType = $mainConfig->get( MainConfigNames::VerifyMimeType ); $mimeTypeExclusions = $mainConfig->get( MainConfigNames::MimeTypeExclusions ); [ , $extList ] = UploadBase::splitExtensions( $filename ); if ( UploadBase::checkFileExtensionList( $extList, $prohibitedFileExtensions ) ) { return self::UNKNOWN_CONTENT_TYPE; } if ( $checkFileExtensions && $strictFileExtensions && !UploadBase::checkFileExtensionList( $extList, $fileExtensions ) ) { return self::UNKNOWN_CONTENT_TYPE; } if ( $verifyMimeType && $type !== null && in_array( strtolower( $type ), $mimeTypeExclusions ) ) { return self::UNKNOWN_CONTENT_TYPE; } } return $type; } } /** @deprecated class alias since 1.41 */ class_alias( StreamFile::class, 'StreamFile' ); PK ! K�Hk k OutputHandler.phpnu �Iw�� <?php /** * Functions to be used with PHP's output buffer. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ namespace MediaWiki\Output; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; /** * @since 1.31 */ class OutputHandler { /** * Standard output handler for use with ob_start. * * Output buffers using this method should only be started from MW_SETUP_CALLBACK, * and only if there are no parent output buffers. * * @param string $s Web response output * @param int $phase Flags indicating the reason for the call * @return string */ public static function handle( $s, $phase ) { $config = MediaWikiServices::getInstance()->getMainConfig(); $disableOutputCompression = $config->get( MainConfigNames::DisableOutputCompression ); // Don't send headers if output is being discarded (T278579) if ( ( $phase & PHP_OUTPUT_HANDLER_CLEAN ) === PHP_OUTPUT_HANDLER_CLEAN ) { $logger = LoggerFactory::getInstance( 'output' ); $logger->debug( __METHOD__ . " entrypoint={entry}; size={size}; phase=$phase", [ 'entry' => MW_ENTRY_POINT, 'size' => strlen( $s ), ] ); return $s; } // Check if a compression output buffer is already enabled via php.ini. Such // buffers exists at the start of the request and are reflected by ob_get_level(). $phpHandlesCompression = ( ini_get( 'output_handler' ) === 'ob_gzhandler' || ini_get( 'zlib.output_handler' ) === 'ob_gzhandler' || !in_array( strtolower( ini_get( 'zlib.output_compression' ) ), [ '', 'off', '0' ] ) ); if ( // Compression is not already handled by an internal PHP buffer !$phpHandlesCompression && // Compression is not disabled by the application entry point !defined( 'MW_NO_OUTPUT_COMPRESSION' ) && // Compression is not disabled by site configuration !$disableOutputCompression ) { $s = self::handleGzip( $s ); } if ( // Response body length does not depend on internal PHP compression buffer !$phpHandlesCompression && // Response body length does not depend on mangling by a custom buffer !ini_get( 'output_handler' ) && !ini_get( 'zlib.output_handler' ) ) { self::emitContentLength( strlen( $s ) ); } return $s; } /** * Get the "file extension" that some client apps will estimate from * the currently-requested URL. * * This isn't a WebRequest method, because we need it before the class loads. * @todo As of 2018, this actually runs after autoloader in Setup.php, so * WebRequest seems like a good place for this. * * @return string */ private static function findUriExtension() { // @todo FIXME: this sort of dupes some code in WebRequest::getRequestUrl() if ( isset( $_SERVER['REQUEST_URI'] ) ) { // Strip the query string... $path = explode( '?', $_SERVER['REQUEST_URI'], 2 )[0]; } elseif ( isset( $_SERVER['SCRIPT_NAME'] ) ) { // Probably IIS. QUERY_STRING appears separately. $path = $_SERVER['SCRIPT_NAME']; } else { // Can't get the path from the server? :( return ''; } $period = strrpos( $path, '.' ); if ( $period !== false ) { return strtolower( substr( $path, $period ) ); } return ''; } /** * Handler that compresses data with gzip if allowed by the Accept header. * * Unlike ob_gzhandler, it works for HEAD requests too. This assumes that the application * processes them as normal GET request and that the webserver is tasked with stripping out * the response body before sending the response the client. * * @param string $s Web response output * @return string */ private static function handleGzip( $s ) { if ( !function_exists( 'gzencode' ) ) { wfDebug( __METHOD__ . "() skipping compression (gzencode unavailable)" ); return $s; } if ( headers_sent() ) { wfDebug( __METHOD__ . "() skipping compression (headers already sent)" ); return $s; } $ext = self::findUriExtension(); if ( $ext == '.gz' || $ext == '.tgz' ) { // Don't do gzip compression if the URL path ends in .gz or .tgz // This confuses Safari and triggers a download of the page, // even though it's pretty clearly labeled as viewable HTML. // Bad Safari! Bad! return $s; } if ( $s === '' ) { // Do not gzip empty HTTP responses since that would not only bloat the body // length, but it would result in invalid HTTP responses when the HTTP status code // is one that must not be accompanied by a body (e.g. "204 No Content"). return $s; } if ( wfClientAcceptsGzip() ) { wfDebug( __METHOD__ . "() is compressing output" ); header( 'Content-Encoding: gzip' ); $s = gzencode( $s, 6 ); } // Set vary header if it hasn't been set already $headers = headers_list(); $foundVary = false; foreach ( $headers as $header ) { $headerName = strtolower( substr( $header, 0, 5 ) ); if ( $headerName == 'vary:' ) { $foundVary = true; break; } } if ( !$foundVary ) { header( 'Vary: Accept-Encoding' ); } return $s; } /** * Set the Content-Length header if possible * * This sets Content-Length for the following cases: * - When the response body is meaningful (HTTP 200/404). * - On any HTTP 1.0 request response. This improves cooperation with certain CDNs. * * This assumes that HEAD requests are processed as GET requests by MediaWiki and that * the webserver is tasked with stripping out the body. * * Setting Content-Length can prevent clients from getting stuck waiting on PHP to finish * while deferred updates are running. * * @param int $length */ private static function emitContentLength( $length ) { if ( headers_sent() ) { wfDebug( __METHOD__ . "() headers already sent" ); return; } if ( in_array( http_response_code(), [ 200, 404 ], true ) || ( $_SERVER['SERVER_PROTOCOL'] ?? null ) === 'HTTP/1.0' ) { header( "Content-Length: $length" ); } } } /** @deprecated class alias since 1.41 */ class_alias( OutputHandler::class, 'MediaWiki\\OutputHandler' ); PK ! }�u�� � Hook/BeforePageRedirectHook.phpnu �Iw�� <?php namespace MediaWiki\Output\Hook; use MediaWiki\Output\OutputPage; /** * This is a hook handler interface, see docs/Hooks.md. * Use the hook name "BeforePageRedirect" to register handlers implementing this interface. * * @stable to implement * @ingroup Hooks */ interface BeforePageRedirectHook { /** * This hook is called prior to sending an HTTP redirect. Gives a chance to * override how the redirect is output by modifying, or by returning false and * taking over the output. * * @since 1.35 * * @param OutputPage $out * @param string &$redirect Absolute or path-relative URL, modifiable * @param string &$code HTTP code (eg '301' or '302'), modifiable * @return bool|void True or no return value to continue or false to abort */ public function onBeforePageRedirect( $out, &$redirect, &$code ); } /** @deprecated class alias since 1.42 */ class_alias( BeforePageRedirectHook::class, 'MediaWiki\Hook\BeforePageRedirectHook' ); PK ! @�Z�� � ( Hook/OutputPageMakeCategoryLinksHook.phpnu �Iw�� <?php namespace MediaWiki\Output\Hook; use MediaWiki\Output\OutputPage; /** * This is a hook handler interface, see docs/Hooks.md. * Use the hook name "OutputPageMakeCategoryLinks" to register handlers implementing this interface. * * @deprecated since 1.43, use OutputPageRenderCategoryLinkHook instead. * @ingroup Hooks */ interface OutputPageMakeCategoryLinksHook { /** * This hook is called when links are about to be generated for the page's categories. * * @since 1.35 * * @param OutputPage $out * @param string[] $categories Associative array in which keys are category names and * values are category types ("normal" or "hidden") * @param array &$links Intended to hold the result. Associative array with * category types as keys and arrays of HTML links as values. * @return bool|void True or no return value to continue. Implementations should return * false if they generate the category links, so the default link generation is skipped. */ public function onOutputPageMakeCategoryLinks( $out, $categories, &$links ); } /** @deprecated class alias since 1.42 */ class_alias( OutputPageMakeCategoryLinksHook::class, 'MediaWiki\Hook\OutputPageMakeCategoryLinksHook' ); PK ! [�9ZZ Z # Hook/OutputPageParserOutputHook.phpnu �Iw�� <?php namespace MediaWiki\Output\Hook; use MediaWiki\Output\OutputPage; use MediaWiki\Parser\ParserOutput; /** * This is a hook handler interface, see docs/Hooks.md. * Use the hook name "OutputPageParserOutput" to register handlers implementing this interface. * * @stable to implement * @ingroup Hooks */ interface OutputPageParserOutputHook { /** * This hook is called after adding a parserOutput to $wgOut. * * @since 1.35 * * @param OutputPage $outputPage * @param ParserOutput $parserOutput ParserOutput instance being added in $outputPage * @return void This hook must not abort, it must return no value */ public function onOutputPageParserOutput( $outputPage, $parserOutput ): void; } /** @deprecated class alias since 1.42 */ class_alias( OutputPageParserOutputHook::class, 'MediaWiki\Hook\OutputPageParserOutputHook' ); PK ! i���� � ! Hook/AfterFinalPageOutputHook.phpnu �Iw�� <?php namespace MediaWiki\Output\Hook; use MediaWiki\Output\OutputPage; /** * This is a hook handler interface, see docs/Hooks.md. * Use the hook name "AfterFinalPageOutput" to register handlers implementing this interface. * * @stable to implement * @ingroup Hooks */ interface AfterFinalPageOutputHook { /** * This hook is called nearly at the end of OutputPage::output() but * before OutputPage::sendCacheControl() and final ob_end_flush() which * will send the buffered output to the client. This allows for last-minute * modification of the output within the buffer by using ob_get_clean(). * * @since 1.35 * * @param OutputPage $output The OutputPage object where output() was called * @return void This hook must not abort, it must return no value */ public function onAfterFinalPageOutput( $output ): void; } /** @deprecated class alias since 1.42 */ class_alias( AfterFinalPageOutputHook::class, 'MediaWiki\Hook\AfterFinalPageOutputHook' ); PK ! ũ<LV V &