r43094 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43093‎ | r43094 | r43095 >
Date:21:07, 2 November 2008
Author:btongminh
Status:old
Tags:
Comment:
Don't show binary files.
Modified paths:
  • /trunk/extensions/CodeBrowse/CodeBrowse.i18n.php (modified) (history)
  • /trunk/extensions/CodeBrowse/CodeBrowseItemView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeBrowse/CodeBrowse.i18n.php
@@ -13,6 +13,7 @@
1414 'codebrowse-revision' => 'Revision',
1515 'codebrowse-lastchange' => 'Last modified date',
1616 'codebrowse-size' => 'Size',
 17+ 'codebrowse-binary-file' => 'Binary files will not be shown.'
1718 );
1819
1920
\ No newline at end of file
Index: trunk/extensions/CodeBrowse/CodeBrowseItemView.php
@@ -80,13 +80,25 @@
8181 }
8282
8383 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+
8496 $contents = $this->svn->getFile( $this->mBasePath, $this->mRev == 'HEAD' ? null : $this->mRev );
8597 if ( $this->mAction == 'raw' || $this->mAction == 'download' ) {
8698 global $wgOut;
8799 $wgOut->disable();
88100
89101 if ( $this->mAction == 'raw' )
90 - header( 'Content-Type: text/plain' );
 102+ header( 'Content-Type: '.$ctype );
91103 else
92104 header( 'Content-Type: application/octet-stream' );
93105 header( 'Content-Length: '.strlen( $contents ) );
@@ -94,6 +106,9 @@
95107 return;
96108 }
97109
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' );
99114 }
100115 }

Status & tagging log