7 * Full path to the file
14 * Repository this file belongs to
21 * Maps file extensions to MIME Types
25 public static $arMimeTypeMap = array(
28 'html' => 'text/html',
29 'js' => 'application/javascript',
30 'php' => 'text/x-php',
31 'txt' => 'text/plain',
36 * Maps file extensions to geshi types
40 public static $arTypeMap = array(
45 public function __construct($path, Repository $repo = null)
52 * Get filename relative to the repository path
56 public function getFilename()
58 return basename($this->path);
62 * Get file extension without dot
66 public function getExt()
68 return substr($this->path, strrpos($this->path, '.') + 1);
72 * Returns the type of the file, as used by Geshi
76 public function getType()
78 $ext = $this->getExt();
79 if (isset(static::$arTypeMap[$ext])) {
80 $ext = static::$arTypeMap[$ext];
86 public function getContent()
88 return file_get_contents($this->path);
91 public function getHighlightedContent()
94 * Yes, geshi needs to be in your include path
95 * We use the mediawiki geshi extension package.
97 require 'MediaWiki/geshi/geshi/geshi.php';
98 $geshi = new \GeSHi($this->getContent(), $this->getType());
99 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
100 $geshi->set_header_type(GESHI_HEADER_DIV);
101 return $geshi->parse_code();
104 public function getMimeType()
106 $ext = $this->getExt();
107 if (!isset(static::$arMimeTypeMap[$ext])) {
110 return static::$arMimeTypeMap[$ext];
114 * Get a link to the file
116 * @param string $type Link type. Supported are:
122 public function getLink($type)
124 if ($type == 'raw') {
125 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
127 throw new Exception('Unknown type');