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 * Return the full path to the file
66 public function getPath()
72 * Get file extension without dot
76 public function getExt()
78 return substr($this->path, strrpos($this->path, '.') + 1);
82 * Returns the type of the file, as used by Geshi
86 public function getType()
88 $ext = $this->getExt();
89 if (isset(static::$arTypeMap[$ext])) {
90 $ext = static::$arTypeMap[$ext];
96 public function getContent()
98 return file_get_contents($this->path);
101 public function getHighlightedContent()
104 * Yes, geshi needs to be in your include path
105 * We use the mediawiki geshi extension package.
107 require 'MediaWiki/geshi/geshi/geshi.php';
108 $geshi = new \GeSHi($this->getContent(), $this->getType());
109 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
110 $geshi->set_header_type(GESHI_HEADER_DIV);
111 return $geshi->parse_code();
114 public function getMimeType()
116 $ext = $this->getExt();
117 if (!isset(static::$arMimeTypeMap[$ext])) {
120 return static::$arMimeTypeMap[$ext];
124 * Get a link to the file
126 * @param string $type Link type. Supported are:
132 public function getLink($type)
134 if ($type == 'raw') {
135 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
137 throw new Exception('Unknown type');