+
+ $res = self::prepareForStream( $fname, $stat, $headers, $sendErrors );
+ if ( $res == self::NOT_MODIFIED ) {
+ $ok = true; // use client cache
+ } elseif ( $res == self::READY_STREAM ) {
+ wfProfileIn( __METHOD__ . '-send' );
+ $ok = readfile( $fname );
+ wfProfileOut( __METHOD__ . '-send' );
+ } else {
+ $ok = false; // failed
+ }
+
+ wfProfileOut( __METHOD__ );
+ return $ok;
+ }
+
+ /**
+ * Call this function used in preparation before streaming a file.
+ * This function does the following:
+ * (a) sends Last-Modified, Content-type, and Content-Disposition headers
+ * (b) cancels any PHP output buffering and automatic gzipping of output
+ * (c) sends Content-Length header based on HTTP_IF_MODIFIED_SINCE check
+ *
+ * @param $path string Storage path or file system path
+ * @param $info Array|bool File stat info with 'mtime' and 'size' fields
+ * @param $headers Array Additional headers to send
+ * @param $sendErrors bool Send error messages if errors occur (like 404)
+ * @return int|bool READY_STREAM, NOT_MODIFIED, or false on failure
+ */
+ public static function prepareForStream(
+ $path, $info, $headers = array(), $sendErrors = true
+ ) {
+ global $wgLanguageCode;
+
+ if ( !is_array( $info ) ) {