/**
  * This method retrieves a value from the data base.
  * @param $code Identifier for the flag to retieve.
  * @param $reload This flag force to reload from database. This is
  * needed because POCFlags holds a cache.
  * @return Returns the value found.
  */
 public function get($code, $reload = false)
 {
     $out = false;
     if (!isset($this->_flags[$code]) || $reload) {
         global $wgPieceOfCodeConfig;
         $this->_errors->clearError();
         if ($this->_dbtype == 'mysql') {
             global $wgPieceOfCodeConfig;
             $dbr =& wfGetDB(DB_SLAVE);
             $res = $dbr->select($wgPieceOfCodeConfig['db-tablename-flags'], array('flg_code', 'flg_type', 'flg_bvalue', 'flg_ivalue', 'flg_float', 'flg_svalue'), "flg_code = '{$code}'");
             if ($row = $dbr->fetchRow($res)) {
                 /*
                  * @fixme cast values.
                  */
                 switch ($row['flg_type']) {
                     case 'B':
                         $this->_flags[$code] = $row['flg_bvalue'];
                         break;
                     case 'I':
                         $this->_flags[$code] = $row['flg_ivalue'];
                         break;
                     case 'F':
                         $this->_flags[$code] = $row['flg_fvalue'];
                         break;
                     case 'S':
                         $this->_flags[$code] = $row['flg_svalue'];
                         break;
                 }
                 $out = $this->_flags[$code];
             }
         } else {
             $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype));
         }
     } else {
         $out = $this->_flags[$code];
     }
     return $out;
 }
 /**
  * @todo doc
  * @param $code @todo doc
  * @return @todo doc
  */
 public function removeByCode($code)
 {
     $out = false;
     global $wgPieceOfCodeConfig;
     $this->_errors->clearError();
     $fileInfo = $this->selectByCode($code);
     if ($this->_errors->ok()) {
         global $wgPieceOfCodeConfig;
         $upload_path = $wgPieceOfCodeConfig['uploaddirectory'] . DIRECTORY_SEPARATOR . $fileInfo['upload_path'];
         unlink($upload_path);
         if (!is_readable($upload_path)) {
             $this->_history->deleteSVNCode($fileInfo['code'], "Removing file {$fileInfo['path']}:{$fileInfo['revision']} from disk.");
             $this->deleteByCode($code);
             if ($out = $this->_errors->ok()) {
                 $this->_history->deleteDBCode($fileInfo['code'], "Removing file {$fileInfo['path']}:{$fileInfo['revision']} from disk.");
             }
         } else {
             $this->_errors->setLastError(wfMsg('poc-errmsg-remove-file', $upload_path));
         }
     }
     return $out;
 }
 /**
  * @todo doc
  * @param $fontcode Is the list of parameter gotten from URL.
  */
 protected function showFontCode(array &$fontcode)
 {
     $out = "";
     global $wgOut;
     global $wgPieceOfCodeConfig;
     $this->_errors->clearError();
     $fileInfo = $this->_storedCodes->getFile($fontcode['connection'], $fontcode['path'], $fontcode['revision']);
     $this->appendTOC($out);
     if ($fileInfo) {
         $tag = '';
         if (!PieceOfCode::CheckSyntaxHighlightExtension($tag)) {
             $out .= "<br/>" . $this->_errors->getLastError();
         }
         $filepath = $wgPieceOfCodeConfig['uploaddirectory'] . DIRECTORY_SEPARATOR . $fileInfo['upload_path'];
         $st = stat($filepath);
         $lang = $fileInfo['lang'];
         if ($st['size'] > $wgPieceOfCodeConfig['maxsize']['highlighting']) {
             $out .= "*" . $this->_errors->setLastError(wfMsg('poc-errmsg-large-highlight', $wgPieceOfCodeConfig['maxsize']['highlighting']));
             $lang = "text";
         }
         if ($st['size'] > $wgPieceOfCodeConfig['maxsize']['showing']) {
             $out .= "*" . $this->_errors->setLastError(wfMsg('poc-errmsg-large-show', $wgPieceOfCodeConfig['maxsize']['showing']));
             $lang = "text";
         }
         $out .= "<h2>{$fileInfo['connection']}: {$fileInfo['path']}:{$fontcode['revision']} </h2>";
         $out .= "<div class=\"PieceOfCode_code\"><{$tag} lang=\"{$lang}\" line=\"GESHI_NORMAL_LINE_NUMBERS\" start=\"1\">";
         $out .= file_get_contents($filepath, false, null, -1, $wgPieceOfCodeConfig['maxsize']['showing']);
         $out .= "</{$tag}></div>";
     } else {
         if ($this->_errors->ok()) {
             $this->_errors->setLastError(wfMsg('poc-errmsg-no-fileinfo', $fontcode['connection'], $fontcode['path'], $fontcode['revision']));
         }
         $out .= $this->_errors->getLastError();
     }
     $out .= "<h2>" . wfMsg('poc-sinfo-links') . "</h2>\n";
     $out .= "*[[Special:PieceOfCode|Back]]\n";
     $wgOut->addWikiText($out);
 }