public function __construct() { parent::__construct('PieceOfCode'); /* * Checking and updating version. */ $this->_versionManager = POCVersionManager::Instance(); /* * Setting tag-kooks. */ if (defined('MEDIAWIKI')) { global $wgParser; $wgParser->setHook('pieceofcode', array(&$this, 'parse')); } $this->_errors = POCErrorsHolder::Instance(); $this->_flags = POCFlags::Instance(); $this->_history = POCHistoryManager::Instance(); $this->_svnConnections = POCSVNConnections::Instance(); $this->_storedCodes = POCStoredCodes::Instance(); $this->_stats = POCStats::Instance(); $this->_errors->clearError(); }
/** * @todo doc * @param $connection @todo doc * @param $filepath @todo doc * @param $revision @todo doc * @return @todo doc */ public function getFile($connection, $filepath, $revision) { $out = false; $conn = POCSVNConnections::Instance()->getConnection($connection); if ($conn) { global $wgPieceOfCodeConfig; $this->_errors->clearError(); $fileInfo = $this->selectFiles($connection, $filepath, $revision); /* * If the code doesn't exists, it tries to download and * stored it. */ if (!$fileInfo && $this->_errors->ok()) { global $wgUser; /* * Checking if there are enough permission to * upload a new file. */ if ($wgPieceOfCodeConfig['enableuploads'] && in_array('upload', $wgUser->getRights())) { /* * Calculating unique code. */ $code = md5("{$connection}{$revision}{$filepath}"); //@fixme this must be centralized. /* * Calculating upload path and creating * every directory that is needed and * doesn't exist. */ $auxDir = $code[0] . DIRECTORY_SEPARATOR . $code[0] . $code[1] . DIRECTORY_SEPARATOR; if (!is_dir($wgPieceOfCodeConfig['uploaddirectory'] . DIRECTORY_SEPARATOR . $auxDir)) { mkdir($wgPieceOfCodeConfig['uploaddirectory'] . DIRECTORY_SEPARATOR . $auxDir, 0755, true); } $uploadPath = $auxDir . $code . "_" . $revision . "_" . basename($filepath); /* * Calculationg downloading path. */ $svnPath = $conn['url'] . $filepath; /* * Build font-code information. */ $auxFileInfo = array('connection' => $connection, 'code' => $code, 'path' => $filepath, 'revision' => $revision, 'lang' => $this->getLangFromExtension($filepath), 'upload_path' => $uploadPath, 'user' => $wgUser->getName()); /* * Getting file from SVN. */ if ($this->_errors->ok() && $this->getSVNFile($conn, $auxFileInfo)) { $this->insertFile($auxFileInfo); if ($this->_errors->ok()) { if ($out = $this->selectFiles($connection, $filepath, $revision)) { $this->_history->newDBCode($auxFileInfo['code'], "Adding file {$auxFileInfo['path']}:{$auxFileInfo['revision']} to database."); } } } else { if ($this->_errors->ok()) { $this->_errors->setLastError(wfMsg('poc-errmsg-no-svn-file', $connection, $filepath, $revision)); } } } else { $this->_errors->setLastError(wfMsg('poc-errmsg-no-upload-rights')); } } else { $out = $fileInfo; } } else { $this->_errors->setLastError(wfMsg('poc-errmsg-invalid-connection')); } return $out; }