7 * Full path to the file
14 * Repository this file belongs to
20 public function __construct($path, Repository $repo = null)
27 * Get filename relative to the repository path
31 public function getFilename()
33 return basename($this->path);
37 * Return the full path to the file
41 public function getPath()
47 * Get file extension without dot
51 public function getExt()
53 return substr($this->path, strrpos($this->path, '.') + 1);
56 public function getContent()
58 return file_get_contents($this->path);
61 public function getHighlightedContent()
64 * Yes, geshi needs to be in your include path
65 * We use the mediawiki geshi extension package.
67 require_once 'MediaWiki/geshi/geshi/geshi.php';
68 $geshi = new \GeSHi($this->getContent(), $this->getGeshiType());
69 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
70 $geshi->set_header_type(GESHI_HEADER_DIV);
71 return $geshi->parse_code();
75 * Get a link to the file
77 * @param string $type Link type. Supported are:
83 public function getLink($type)
86 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
88 throw new Exception('Unknown type');
92 * Returns the type of the file, as used by Geshi
96 public function getGeshiType()
98 $ext = $this->getExt();
99 if (isset($GLOBALS['phorkie']['languages'][$ext]['geshi'])) {
100 $ext = $GLOBALS['phorkie']['languages'][$ext]['geshi'];
106 public function getMimeType()
108 $ext = $this->getExt();
109 if (!isset($GLOBALS['phorkie']['languages'][$ext])) {
112 return $GLOBALS['phorkie']['languages'][$ext]['mime'];