protected function __construct()
 {
     $this->_errors = POCErrorsHolder::Instance();
     $this->_connections = array();
     $this->_isLoaded = false;
     $this->load();
 }
 /**
  * @todo doc
  */
 protected function upToVersion0_2_rev()
 {
     if ($this->_dbtype == 'mysql') {
         global $wgDBprefix;
         global $wgPieceOfCodeConfig;
         $dbr =& wfGetDB(DB_SLAVE);
         if ($dbr->tableExists($wgPieceOfCodeConfig['db-tablename-texts'])) {
             if (!$dbr->fieldExists($wgPieceOfCodeConfig['db-tablename-texts'], 'plst_scanned')) {
                 $sql = "alter table {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename-texts']}\n" . "        add (plst_scanned boolean not null default false)";
                 $error = $dbr->query($sql);
                 if ($error !== true) {
                     die(__FILE__ . ":" . __LINE__);
                 }
             }
             if (!$dbr->fieldExists($wgPieceOfCodeConfig['db-tablename-texts'], 'plst_use_poc')) {
                 $sql = "alter table {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename-texts']}\n" . "        add (plst_use_poc boolean not null default true)";
                 $error = $dbr->query($sql);
                 if ($error !== true) {
                     die(__FILE__ . ":" . __LINE__);
                 }
             }
         }
     } else {
         $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype));
     }
 }
 /**
  * @todo doc
  * @return @todo doc
  */
 public function show()
 {
     $out = "";
     if ($this->_fileInfo) {
         global $wgPieceOfCodeConfig;
         global $wgParser;
         $tag = '';
         if (!PieceOfCode::CheckSyntaxHighlightExtension($tag)) {
             $out .= $this->_errors->getLastError();
         }
         $upload_path = $wgPieceOfCodeConfig['uploaddirectory'] . DIRECTORY_SEPARATOR . $this->_fileInfo['upload_path'];
         $out .= "<div class=\"PieceOfCode_code\">\n";
         if ($this->_showTitle) {
             $auxUrl = Title::makeTitle(NS_SPECIAL, 'PieceOfCode')->escapeFullURL("action=show&connection={$this->_connection}&path={$this->_filename}&revision={$this->_revision}");
             $out .= "<span class=\"PieceOfCode_title\"><a href=\"{$auxUrl}\"><strong>{$this->_connection}></strong>{$this->_filename}:{$this->_revision}</a></span>";
         }
         $auxCount = count($this->_lines);
         if ($auxCount) {
             foreach ($this->_lines as $l) {
                 $auxCount--;
                 $auxOut = "<{$tag} lang=\"{$this->_fileInfo['lang']}\" line=\"GESHI_NORMAL_LINE_NUMBERS\" start=\"{$l[0]}\"" . ($this->_highlightLines ? " highlight=\"{$this->_highlightLines}\"" : "") . ">";
                 $file = file($upload_path);
                 for ($i = $l[0] - 1; $i < $l[1]; $i++) {
                     if (isset($file[$i])) {
                         $auxOut .= $file[$i];
                     }
                 }
                 $auxOut .= "</{$tag}>";
                 $out .= $wgParser->recursiveTagParse($auxOut);
                 if ($this->_separator && $auxCount > 0) {
                     $out .= html_entity_decode($this->_separator);
                 }
             }
         } else {
             $st = stat($upload_path);
             if ($st['size'] > $wgPieceOfCodeConfig['maxsize']['showing']) {
                 $out .= $this->_errors->setLastError(wfMsg('poc-errmsg-large-showall', $wgPieceOfCodeConfig['maxsize']['showing']));
                 $out .= "<pre>";
                 $out .= htmlentities(file_get_contents($upload_path));
                 $out .= "</pre>";
             } else {
                 $lang = $this->_fileInfo['lang'];
                 if ($st['size'] > $wgPieceOfCodeConfig['maxsize']['highlighting']) {
                     $out .= $this->_errors->setLastError(wfMsg('poc-errmsg-large-highlight', $wgPieceOfCodeConfig['maxsize']['highlighting']));
                     $lang = "text";
                 }
                 $auxOut = "<{$tag} lang=\"{$lang}\" line=\"GESHI_NORMAL_LINE_NUMBERS\" start=\"1\">";
                 $auxOut .= file_get_contents($upload_path);
                 $auxOut .= "</{$tag}>";
                 $out .= $wgParser->recursiveTagParse($auxOut);
             }
         }
         $out .= "</div>\n";
     }
     return $out;
 }
 /**
  * @todo doc
  * @param $code @todo doc
  * @return @todo doc
  */
 protected function deleteByCode($code)
 {
     $out = null;
     if ($this->_dbtype == 'mysql') {
         global $wgPieceOfCodeConfig;
         $dbr =& wfGetDB(DB_SLAVE);
         $res = $dbr->delete($wgPieceOfCodeConfig['db-tablename'], array('cod_code' => $code));
         if ($res !== true) {
             $this->_errors->setLastError(wfMsg('poc-errmsg-query-no-delete'));
         }
     } else {
         $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype));
     }
     return $out;
 }
 /**
  * @todo doc
  * @return @todo doc
  */
 protected function updateZeroCounts()
 {
     $out = false;
     if ($this->_dbtype == 'mysql') {
         global $wgDBprefix;
         global $wgPieceOfCodeConfig;
         $dbr =& wfGetDB(DB_SLAVE);
         $sql = "select  cod_code\n" . "from    {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename']}\n" . "where   cod_code not in (\n" . "                select  cod_code\n" . "                from    {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename']}\n" . "                                inner join {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename-ccounts']}\n" . "                                        on (cod_code = cps_code))\n";
         if ($wgPieceOfCodeConfig['db-stats-limited']) {
             $sql .= "limit 0, {$wgPieceOfCodeConfig['db-stats-per-try']}\n";
         }
         $res = $dbr->query($sql);
         while ($row = $dbr->fetchRow($res)) {
             $sql = "update  {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename']}\n" . "set     cod_count = '0'\n" . "where   cod_code  = '{$row['cod_code']}'";
             $err = $dbr->query($sql);
         }
     } else {
         $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype));
     }
     return $out;
 }
 /**
  * This method checks existens for table of flags. 
  * @return Returns true if there where no errors. Otherwise, false.
  */
 protected function createTable()
 {
     $out = false;
     if ($this->_dbtype == 'mysql') {
         global $wgDBprefix;
         global $wgPieceOfCodeConfig;
         $dbr =& wfGetDB(DB_SLAVE);
         if (!$dbr->tableExists($wgPieceOfCodeConfig['db-tablename-flags'])) {
             $sql = "create table " . $wgDBprefix . $wgPieceOfCodeConfig['db-tablename-flags'] . "(\n" . "        flg_code           varchar(20)               not null primary key,\n" . "        flg_type\t    enum ('B', 'I', 'S', 'F') not null default 'S',\n" . "        flg_bvalue         boolean                   not null default false,\n" . "        flg_ivalue         integer                   not null default '0',\n" . "        flg_float          float                     not null default '0',\n" . "        flg_svalue         varchar(255)              not null default '',\n" . "        flg_timestamp      timestamp default current_timestamp\n" . ")";
             $error = $dbr->query($sql);
             if ($error === true) {
                 $out = true;
             } else {
                 die(__FILE__ . ":" . __LINE__);
             }
         } else {
             $out = true;
         }
     } else {
         $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype));
     }
     return $out;
 }
 /**
  * This method checks existens for table of history storage.
  * @return Returns true if there where no errors. Otherwise, false.
  */
 protected function createTable()
 {
     $out = false;
     if ($this->_dbtype == 'mysql') {
         global $wgDBprefix;
         global $wgPieceOfCodeConfig;
         $dbr =& wfGetDB(DB_SLAVE);
         if (!$dbr->tableExists($wgPieceOfCodeConfig['db-tablename-history'])) {
             $sql = "create table " . $wgDBprefix . $wgPieceOfCodeConfig['db-tablename-history'] . "(\n" . "        hty_code           varchar(40)  not null,\n" . "        hty_action\t    varchar(20)  not null,\n" . "        hty_description    varchar(255) not null default '',\n" . "        hty_user           varchar(40)  not null default '',\n" . "        hty_timestamp      timestamp default current_timestamp,\n" . "        index(hty_code)\n" . ")";
             $error = $dbr->query($sql);
             if ($error === true) {
                 $out = true;
             } else {
                 die(__FILE__ . ":" . __LINE__);
             }
         } else {
             $out = true;
         }
     } else {
         $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype));
     }
     return $out;
 }
 /**
  * This class method looks for a hook for tag &lt;syntaxhighlight&gt; or
  * &lt;source%gt;. When one of these tags is present, it means, the
  * extension SyntaxHighlight is loaded.
  * @param $tag When this method finishes, this parameter contains the
  * tag. Or a null string when it's not found.
  * @return Returns true when a tag is found. Otherwise, false.
  */
 public static function CheckSyntaxHighlightExtension(&$tag)
 {
     $tag = '';
     global $wgParser;
     $tags = $wgParser->getTags();
     if (in_array('syntaxhighlight', $tags)) {
         $tag = 'syntaxhighlight';
     } elseif (in_array('source', $tags)) {
         $tag = 'source';
     }
     if (!$tag) {
         POCErrorsHolder::Instance()->setLastError(wfMsg('poc-errmsg-stylecode-extension'));
         return false;
     } else {
         return true;
     }
 }
 /**
  * @return Returns the singleton instance of this class POCErrorsHolder.
  */
 public static function Instance()
 {
     if (!isset(self::$_Instance)) {
         $c = __CLASS__;
         self::$_Instance = new $c();
     }
     return self::$_Instance;
 }