/** * @todo doc * @param $input @todo doc * @param $params @todo doc * @param $parser @todo doc * @return @todo doc */ public function load($input, &$params, $parser) { $out = ""; /* * Clearing status. */ $this->clear(); /* * Loading configuration from tags. */ $out .= $this->loadParams($params); if ($this->_errors->ok()) { if ($this->_parseInput) { $input = $parser->recursiveTagParse($input); } $out .= $this->loadVariables($input); } /* * Loading file information */ if ($this->_errors->ok()) { $this->_fileInfo = $this->_storeCodes->getFile($this->_connection, $this->_filename, $this->_revision); if (!$this->_fileInfo) { $out .= $this->_errors->setLastError(wfMsg('poc-errmsg-no-fileinfo', $this->_connection, $this->_filename, $this->_revision)); } } return $out; }
/** * This method set a flag on database. It it doesn't exists, it creates * it. * @param $code Flag identification code. * @param $value Value to be set. * @param $type Type of value. When it's false, it tries to auto-detect * type of value. */ public function set($code, $value, $type = false) { if ($this->_dbtype == 'mysql') { global $wgPieceOfCodeConfig; $row = array(); $fType = 'flg_ivalue'; /* * Type auto-detection. */ if ($type === false) { if (is_string($value)) { $type = 'S'; } elseif (is_bool($value)) { $type = 'B'; } elseif (is_int($value)) { $type = 'I'; } else { $type = 'F'; } } /* * Selecting field to store values. */ switch ($type) { case 'B': $row['flg_bvalue'] = $value; $fType = 'flg_bvalue'; break; case 'I': $row['flg_ivalue'] = $value; $fType = 'flg_ivalue'; break; case 'F': $row['flg_fvalue'] = $value; $fType = 'flg_fvalue'; break; case 'S': $row['flg_svalue'] = $value; $fType = 'flg_svalue'; break; } $row['flg_code'] = $code; $row['flg_type'] = $type; if ($this->_errors->ok()) { global $wgDBprefix; $dbr =& wfGetDB(DB_SLAVE); $sql = "insert\n" . " into {$wgDBprefix}{$wgPieceOfCodeConfig['db-tablename-flags']} (\n" . " flg_code, flg_type, {$fType})\n" . " values ('{$row['flg_code']}', '{$row['flg_type']}', '{$row[$fType]}')\n" . " on duplicate key\n" . " update {$fType} = '{$row[$fType]}'"; $res = $dbr->query($sql); if ($res === true) { $out = true; } else { $this->_errors->setLastError(wfMsg('poc-errmsg-no-insert')); } } } else { $this->_errors->setLastError(wfMsg('poc-errmsg-unknown-dbtype', $this->_dbtype)); } }
/** * @todo doc * @param $fileInfo @todo doc * @return @todo doc */ protected function insertFile(&$fileInfo) { $out = false; if ($this->_dbtype == 'mysql') { global $wgPieceOfCodeConfig; if ($this->_errors->ok()) { $dbr =& wfGetDB(DB_SLAVE); $res = $dbr->insert($wgPieceOfCodeConfig['db-tablename'], array('cod_connection' => $fileInfo['connection'], 'cod_code' => $fileInfo['code'], 'cod_path' => $fileInfo['path'], 'cod_lang' => $fileInfo['lang'], 'cod_revision' => $fileInfo['revision'], 'cod_upload_path' => $fileInfo['upload_path'], 'cod_user' => $fileInfo['user'])); if ($res === true) { $out = true; } else { $this->_errors->setLastError(wfMsg('poc-errmsg-no-insert')); } } } 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'))); } }