Indefero

Indefero Commit Details

Date:2008-11-11 21:21:21 (5 years 5 months ago)
Author:Loic d'Anterroches
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:297d7290df3745da610f62183e4b0ff1f15daa23
Parents: cf01b5f3dfcd835d2b8ae6665c36464baa480df6
Message:Fixed partially issue 37, text files are displayed as text.

The display is not done with a nice layout, the file is pushed directly
with the text/plain mime type. This is working better than expected.
Changes:
Msrc/IDF/Views/Source.php (4 diffs)

File differences

src/IDF/Views/Source.php
124124
125125
126126
127
128
129
127
128
129
130
131
132
133
134
135
130136
131137
132138
......
241247
242248
243249
244
250
245251
246252
247253
......
252258
253259
254260
255
261
256262
257263
258264
......
260266
261267
262268
263
269
264270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
265287
266
288
289
267290
268291
269292
}
if ($request_file_info->type != 'tree') {
$info = self::getMimeType($request_file_info->file);
$rep = new Pluf_HTTP_Response($scm->getBlob($request_file_info, $commit),
$info[0]);
$rep->headers['Content-Disposition'] = 'attachment; filename="'.$info[1].'"';
if (!self::isText($info)) {
$rep = new Pluf_HTTP_Response($scm->getBlob($request_file_info, $commit),
$info[0]);
$rep->headers['Content-Disposition'] = 'attachment; filename="'.$info[1].'"';
} else {
// We want to display the content of the file as text
$rep = new Pluf_HTTP_Response($scm->getBlob($request_file_info, $commit),
'text/plain');
}
return $rep;
}
$bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->file);
*
* @param string Filename/Filepath
* @param string Path to the mime types database ('/etc/mime.types')
* @param array Mime type found or 'application/octet-stream' and basename
* @param array Mime type found or 'application/octet-stream', basename, extension
*/
public static function getMimeType($file, $src='/etc/mime.types')
{
if ('#' != substr($mime, 0, 1)) {
$elts = preg_split('/ |\t/', $mime, -1, PREG_SPLIT_NO_EMPTY);
if (in_array($info['extension'], $elts)) {
return array($elts[0], $info['basename']);
return array($elts[0], $info['basename'], $info['extension']);
}
}
}
// we consider that if no extension and base name is all
// uppercase, then we have a text file.
if ($info['basename'] == strtoupper($info['basename'])) {
return array('text/plain', $info['basename']);
return array('text/plain', $info['basename'], 'txt');
}
$info['extension'] = 'bin';
}
return array('application/octet-stream', $info['basename'], $info['extension']);
}
/**
* Find if a given mime type is a text file.
* This uses the output of the self::getMimeType function.
*
* @param array (Mime type, file name, extension)
* @return bool Is text
*/
public static function isText($fileinfo)
{
if (0 === strpos($fileinfo[0], 'text/')) {
return true;
}
return array('application/octet-stream', $info['basename']);
$ext = 'mdtext php js';
return (in_array($fileinfo[2], explode(' ', $ext)));
}
/**

Archive Download the corresponding diff file