/** * @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; }
/** * @todo doc * @param $fontcode Is the list of parameter gotten from URL. */ protected function statPagesByCode(array &$fontcode) { global $wgOut; global $wgPieceOfCodeConfig; if ($wgPieceOfCodeConfig['stats']) { $out = ""; $code = POCStoredCodes::Instance()->getByCode($fontcode['code']); if ($this->_errors->ok()) { $this->appendTOC($out); $out .= "== " . wfMsg('poc-sinfo-information') . " ==\n"; $out .= "*'''" . wfMsg('poc-sinfo-connection') . "''': {$code['connection']}\n"; $out .= "*'''" . wfMsg('poc-sinfo-path') . "''': {$code['path']}\n"; $out .= "*'''" . wfMsg('poc-sinfo-revision') . "''': {$code['revision']}\n"; $out .= "*'''" . wfMsg('poc-sinfo-lang') . "''': {$code['lang']}\n"; $auxUrl = Title::makeTitle(NS_USER, $code['user'])->getFullURL(); $out .= "*'''" . wfMsg('poc-sinfo-user') . "''': [[User:{$code['user']}|{$code['user']}]]\n"; $auxUrl = Title::makeTitle(NS_SPECIAL, 'PieceOfCode')->escapeFullURL("action=show&connection={$code['connection']}&path={$code['path']}&revision={$code['revision']}"); $out .= "*[{$auxUrl} " . wfMsg('poc-view-source') . "]\n"; $out .= "== " . wfMsg('poc-sinfo-usage') . " ==\n"; $out .= "{|class=\"wikitable sortable\"\n"; $out .= "|-\n"; $out .= "!" . wfMsg('poc-sinfo-page') . "\n"; $out .= "!" . wfMsg('poc-sinfo-stored-codes-count') . "\n"; $out .= "!" . wfMsg('poc-sinfo-stored-codes-user') . "\n"; foreach (POCStats::Instance()->getCodePages($fontcode['code']) as $c) { $out .= "|-\n"; $auxPage = Title::newFromID($c['page_id']); $title = $c['title']; /* * Checking if it isn't the default namesapace. */ if ($auxPage->getNamespace() != NS_MAIN) { $title = $auxPage->getNsText() . $title; } $out .= "|[[{$title}]]\n"; $out .= "|{$c['times']}\n"; $out .= "|[[User:{$c['last_user']}|{$c['last_user']}]]\n"; } $out .= "|}\n"; $out .= "== " . wfMsg('poc-sinfo-history') . " ==\n"; $out .= "{|class=\"wikitable\"\n"; $out .= "|-\n"; $out .= "!" . wfMsg('poc-sinfo-stored-codes-action') . "\n"; $out .= "!" . wfMsg('poc-sinfo-stored-codes-user') . "\n"; $out .= "!" . wfMsg('poc-sinfo-stored-codes-description') . "\n"; $out .= "!" . wfMsg('poc-sinfo-stored-codes-timestamp') . "\n"; foreach ($this->_history->getHistory($fontcode['code']) as $h) { $out .= "|-\n"; $out .= "|" . wfMsg('poc-sinfo-history-' . $h['action']) . "\n"; $out .= "|[[User:{$h['user']}|{$h['user']}]]\n"; $out .= "|{$h['description']}\n"; $out .= "|{$h['timestamp']}\n"; } $out .= "|}\n"; $out .= "== " . wfMsg('poc-sinfo-links') . " ==\n"; $out .= "*[[Special:PieceOfCode|Back]]\n"; } else { $out .= $this->_errors->getLastError(); } $wgOut->addWikiText($out); } else { $wgOut->addHTML($this->_errors->setLastError(wfMsg('poc-errmsg-stats-disabled'))); } }