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)
52 * Get filename relative to the repository path
56 public function getFilename()
58 return basename($this->path);
62 * Returns the type of the file, as used by Geshi
66 public function getType()
68 $ext = substr($this->path, strrpos($this->path, '.') + 1);
69 if (isset(static::$arTypeMap[$ext])) {
70 $ext = static::$arTypeMap[$ext];
76 public function getContent()
78 return file_get_contents($this->path);
81 public function getHighlightedContent()
84 * Yes, geshi needs to be in your include path
85 * We use the mediawiki geshi extension package.
87 require 'MediaWiki/geshi/geshi/geshi.php';
88 $geshi = new \GeSHi($this->getContent(), $this->getType());
89 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
90 $geshi->set_header_type(GESHI_HEADER_DIV);
91 return $geshi->parse_code();
94 public function getMimeType()
96 $type = $this->getType();
97 if (!isset(static::$arMimeTypeMap[$type])) {
100 return static::$arMimeTypeMap[$type];
104 * Get a link to the file
106 * @param string $type Link type. Supported are:
112 public function getLink($type)
114 if ($type == 'raw') {
115 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
117 throw new Exception('Unknown type');