Index: trunk/extensions/CodeBrowse/CodeBrowse.i18n.php |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | 'codebrowse-revision' => 'Revision', |
15 | 15 | 'codebrowse-lastchange' => 'Last modified date', |
16 | 16 | 'codebrowse-size' => 'Size', |
| 17 | + 'codebrowse-binary-file' => 'Binary files will not be shown.' |
17 | 18 | ); |
18 | 19 | |
19 | 20 | |
\ No newline at end of file |
Index: trunk/extensions/CodeBrowse/CodeBrowseItemView.php |
— | — | @@ -80,13 +80,25 @@ |
81 | 81 | } |
82 | 82 | |
83 | 83 | function showFile() { |
| 84 | + $i = strpos( $this->mBasePath, '/' ); |
| 85 | + $i = $i === false ? 0 : $i + 1; |
| 86 | + $filename = substr( $this->mBasePath, $i ); |
| 87 | + $i = strpos( $filename, '.' ); |
| 88 | + if ( $i !== false ) { |
| 89 | + $ext = substr( $filename, $i + 1 ); |
| 90 | + $mime = MimeMagic::singleton(); |
| 91 | + $ctype = $mime->guessTypesForExtension( $ext ); |
| 92 | + } else { |
| 93 | + $ctype = 'application/octet-stream'; |
| 94 | + } |
| 95 | + |
84 | 96 | $contents = $this->svn->getFile( $this->mBasePath, $this->mRev == 'HEAD' ? null : $this->mRev ); |
85 | 97 | if ( $this->mAction == 'raw' || $this->mAction == 'download' ) { |
86 | 98 | global $wgOut; |
87 | 99 | $wgOut->disable(); |
88 | 100 | |
89 | 101 | if ( $this->mAction == 'raw' ) |
90 | | - header( 'Content-Type: text/plain' ); |
| 102 | + header( 'Content-Type: '.$ctype ); |
91 | 103 | else |
92 | 104 | header( 'Content-Type: application/octet-stream' ); |
93 | 105 | header( 'Content-Length: '.strlen( $contents ) ); |
— | — | @@ -94,6 +106,9 @@ |
95 | 107 | return; |
96 | 108 | } |
97 | 109 | |
98 | | - return Xml::element( 'pre', array( 'style' => 'overflow: auto;' ), $contents ); |
| 110 | + if ( substr( $ctype, 0, 5 ) == 'text/' ) |
| 111 | + return Xml::element( 'pre', array( 'style' => 'overflow: auto;' ), $contents ); |
| 112 | + else |
| 113 | + return wfMsgHTML( 'codebrowse-binary-file' ); |
99 | 114 | } |
100 | 115 | } |