/** * Test that we can instantiate and run AllPages plugin without error. */ function testAllPages() { global $request; $lp = new WikiPlugin_AllPages(); $this->assertEquals("AllPages", $lp->getName()); $args = ""; $this->assertType('object', $request->_dbi, 'isa WikiDB'); /* */ $result = $lp->run($request->_dbi, $args, $request, "AllPages"); $this->assertType('object', $result, 'isa PageList'); $this->assertType('object', $request->_dbi, 'isa WikiDB'); if (!isa($request->_dbi, "WikiDB")) { // very very strange bug $request->_dbi = WikiDB::open($GLOBALS['DBParams']); if (!isa($request->_dbi, "WikiDB")) { trigger_error("strange php bug\n", E_USER_WARNING); return; } } $xml = $result->asXml(); $this->assertType('object', $result, 'isa XmlContent'); //$xml->asString(); //$this->assertType('object', $result, 'isa XmlContent'); }
function RatingsDb() { global $request; $this->_dbi =& $request->_dbi; $this->_backend =& $this->_dbi->_backend; $this->dimension = null; if (RATING_STORAGE == 'SQL') { if (isa($this->_backend, 'WikiDB_backend_PearDB')) { $this->_sqlbackend =& $this->_backend; $this->dbtype = "PearDB"; } elseif (isa($this->_backend, 'WikiDB_backend_ADODOB')) { $this->_sqlbackend =& $this->_backend; $this->dbtype = "ADODB"; } else { include_once "lib/WikiDB/backend/ADODB.php"; // It is not possible to decouple a ref from the source again. (4.3.11) // It replaced the main request backend. So we don't initialize _sqlbackend before. //$this->_sqlbackend = clone($this->_backend); $this->_sqlbackend = new WikiDB_backend_ADODB($GLOBALS['DBParams']); $this->dbtype = "ADODB"; } $this->iter_class = "WikiDB_backend_" . $this->dbtype . "_generic_iter"; extract($this->_sqlbackend->_table_names); if (empty($rating_tbl)) { $rating_tbl = (!empty($GLOBALS['DBParams']['prefix']) ? $GLOBALS['DBParams']['prefix'] : '') . 'rating'; $this->_sqlbackend->_table_names['rating_tbl'] = $rating_tbl; } } else { $this->iter_class = "WikiDB_Array_PageIterator"; } }
function RatingsDb() { global $request; $this->_dbi =& $request->_dbi; $this->_backend =& $this->_dbi->_backend; $this->dimension = null; if (RATING_STORAGE == 'SQL') { $this->_sqlbackend =& $this->_backend; if (isa($this->_backend, 'WikiDB_backend_PearDB')) { $this->dbtype = "PearDB"; } elseif (isa($this->_backend, 'WikiDB_backend_ADODOB')) { $this->dbtype = "ADODB"; } else { include_once "lib/WikiDB/backend/ADODB.php"; $this->_sqlbackend = new WikiDB_backend_ADODB($GLOBALS['DBParams']); $this->dbtype = "ADODB"; } $this->iter_class = "WikiDB_backend_" . $this->dbtype . "_generic_iter"; extract($this->_sqlbackend->_table_names); if (empty($rating_tbl)) { $rating_tbl = (!empty($GLOBALS['DBParams']['prefix']) ? $GLOBALS['DBParams']['prefix'] : '') . 'rating'; $this->_sqlbackend->_table_names['rating_tbl'] = $rating_tbl; } } else { $this->iter_class = "WikiDB_Array_PageIterator"; } }
/** * Constructor * * @param mixed $dbh * DB handle, or WikiDB object (from which the DB handle will * be extracted. * * @param string $table * Name of SQL table containing session data. */ function DbSession(&$dbh, $table = 'session') { // Check for existing DbSession handler $db_type = $dbh->getParam('dbtype'); if (isa($dbh, 'WikiDB')) { // will fail with php4 and case-sensitive filesystem //$db_type = substr(get_class($dbh),7); // < 4.1.2 crash on dba sessions at session_write_close(). // (Tested with 4.1.1 and 4.1.2) // Didn't try postgres sessions. if (!check_php_version(4, 1, 2) and $db_type == 'dba') { return false; } @(include_once "lib/DbSession/" . $db_type . ".php"); $class = "DbSession_" . $db_type; if (class_exists($class)) { // dba has no ->_dbh, so this is used for the session link $this->_backend = new $class($dbh->_backend->_dbh, $table); return $this; } } //Fixme: E_USER_WARNING ignored! trigger_error(sprintf(_("Your WikiDB DB backend '%s' cannot be used for DbSession.") . " " . _("Set USE_DB_SESSION to false."), $db_type), E_USER_WARNING); return false; }
function _FilePassUser($UserName = '', $prefs = false, $file = '') { if (!$this->_prefs and isa($this, "_FilePassUser")) { if ($prefs) { $this->_prefs = $prefs; } if (!isset($this->_prefs->_method)) { _PassUser::_PassUser($UserName); } } $this->_userid = $UserName; // read the .htaccess style file. We use our own copy of the standard pear class. $this->_may_change = defined('AUTH_USER_FILE_STORABLE') && AUTH_USER_FILE_STORABLE; if (empty($file) and defined('AUTH_USER_FILE')) { $file = AUTH_USER_FILE; } // same style as in main.php include_once dirname(__FILE__) . "/../pear/File_Passwd.php"; // "__PHP_Incomplete_Class" if (!empty($file) or empty($this->_file) or !isa($this->_file, "File_Passwd")) { $this->_file = new File_Passwd($file, false, $file . '.lock'); } else { return false; } return $this; }
function linkUnknownWikiWord($wikiword, $linktext = '') { global $request; // Get rid of anchors on unknown wikiwords if (isa($wikiword, 'WikiPageName')) { $default_text = $wikiword->shortName; $wikiword = $wikiword->name; } else { $default_text = $wikiword; } $url = WikiURL($wikiword, array('action' => 'create')); //$link = HTML::span(HTML::a(array('href' => $url), '?')); $button = $this->makeButton('?', $url); $button->addTooltip(sprintf(_("Create: %s"), $wikiword)); $link = HTML::span($button); if (!empty($linktext)) { $link->unshiftContent(HTML::u($linktext)); $link->setAttr('class', 'named-wikiunknown'); } else { $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($default_text))); $link->setAttr('class', 'wikiunknown'); } if ($request->getArg('frame')) { $link->setAttr('target', '_top'); } return $link; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); // If the ratings table does not exist, or on dba it will break otherwise. // Check if Theme isa 'wikilens' if ($info == 'pagename' and isa($GLOBALS['WikiTheme'], 'wikilens')) { $info .= ",top3recs"; } if ($info) { $info = split(',', $info); } else { $info = array(); } if (in_array('top3recs', $info)) { require_once 'lib/wikilens/Buddy.php'; require_once 'lib/wikilens/PageListColumns.php'; $active_user = $request->getUser(); $active_userid = $active_user->_userid; // if userids is null or empty, fill it with just the active user if (!isset($userids) || !is_array($userids) || !count($userids)) { // TKL: moved getBuddies call inside if statement because it was // causing the userids[] parameter to be ignored if (is_string($active_userid) and strlen($active_userid) and $active_user->isSignedIn()) { $userids = getBuddies($active_userid, $dbi); } else { $userids = array(); // XXX: this wipes out the category caption... $caption = _("You must be logged in to view ratings."); } } // find out which users we should show ratings for $allowed_users = array(); foreach ($userids as $userid) { $user = new RatingsUser($userid); if ($user->allow_view_ratings($active_user)) { array_push($allowed_users, $user); } // PHP's silly references... (the behavior with this line commented // out is... odd) unset($user); } $options = array('dimension' => $dimension, 'users' => $allowed_users); $args = array_merge($options, $args); } if (empty($pages) and $pages != '0') { return ''; } if (in_array('numbacklinks', $info)) { $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true); } if (in_array('numpagelinks', $info)) { $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#")); } $pagelist = new PageList($info, $exclude, $args); $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array()); $pagelist->addPageList($pages_array); return $pagelist; }
function _print($val) { if (isa($val, 'Template')) { $this->_expandSubtemplate($val); } else { PrintXML($val); } }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); // if (empty($args['s'])) // return ''; $html = HTML(); extract($args); // prevent from dump if ($q and $request->isPost()) { require_once "lib/Google.php"; $google = new Google(); if (!$google) { return ''; } switch ($mode) { case 'search': $result = $google->doGoogleSearch($q); break; case 'cache': $result = $google->doGetCachedPage($q); break; case 'spell': $result = $google->doSpellingSuggestion($q); break; default: trigger_error("Invalid mode"); } if (isa($result, 'HTML')) { $html->pushContent($result); } if (isa($result, 'GoogleSearchResults')) { //TODO: result template if (!empty($result->resultElements)) { $list = HTML::ol(); foreach ($result->resultElements as $res) { $li = HTML::li(LinkURL($res['URL'], $res['directoryTitle']), HTML::br(), $res['directoryTitle'] ? HTML(HTML::raw(' '), HTML::em($res['summary']), ' -- ', LinkURL($res['URL'])) : ''); $list->pushContent($li); } $html->pushContent($list); } else { return _("Nothing found"); } } if (is_string($result)) { // cache content also? $html->pushContent(HTML::blockquote(HTML::raw($result))); } } if ($formsize < 1) { $formsize = 30; } // todo: template $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post', 'accept-charset' => $GLOBALS['charset']), HiddenInputs(array('pagename' => $basepage, 'mode' => $mode))); $form->pushContent(HTML::input(array('type' => 'text', 'value' => $q, 'name' => 'q', 'size' => $formsize))); $form->pushContent(HTML::input(array('type' => 'submit', 'class' => 'button', 'value' => gettext($mode)))); return HTML($html, $form); }
function _testLink($wiki, $expected = null) { if (is_null($expected)) { $ta = $this->_tests(); $expected = $ta[$wiki]; } $xml = TransformInline($wiki); $this->assertTrue(isa($xml, 'XmlContent')); $expectobj = unserialize($expected); /* if (DEBUG & _DEBUG_VERBOSE) echo "\t\"",$wiki,'" => \'',serialize($xml),"',\n"; flush(); */ $this->assertEquals($expectobj, $xml); }
function _EMailConfirmPassUser($UserName = '', $prefs = false, $file = '') { if (!$this->_prefs and isa($this, "_EMailPassUser")) { if ($prefs) { $this->_prefs = $prefs; } if (!isset($this->_prefs->_method)) { _PassUser::_PassUser($UserName); } } $this->_userid = $UserName; return $this; }
/** * Constructor * * @param mixed $dbh * DB handle, or WikiDB object (from which the DB handle will * be extracted. * * @param string $table * Name of SQL table containing session data. */ function DbSession(&$dbh, $table = 'session') { // Check for existing DbSession handler $db_type = $dbh->getParam('dbtype'); if (isa($dbh, 'WikiDB')) { @(include_once "lib/DbSession/" . $db_type . ".php"); $class = "DbSession_" . $db_type; if (class_exists($class)) { // dba has no ->_dbh, so this is used for the session link $this->_backend = new $class($dbh->_backend->_dbh, $table); return $this; } } //Fixme: E_USER_WARNING ignored! trigger_error(sprintf(_("Your WikiDB DB backend '%s' cannot be used for DbSession.") . " " . _("Set USE_DB_SESSION to false."), $db_type), E_USER_WARNING); return false; }
function testLinks() { $uplink = 'http://' . (defined('SERVER_NAME') ? SERVER_NAME : '') . DATA_PATH . '/uploads/image.jpg'; $tests = array("[label|link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | link.jpg ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ image.jpg | link ]" => check_php_version(5) ? 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:1:{i:0;O:11:"HtmlElement":4:{s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:0:{}s:11:"_properties";i:4;}}s:11:"_properties";i:6;}}i:2;s:0:"";}}' : 'o:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;o:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";o:11:"htmlelement":4:{s:8:"_content";a:1:{i:0;o:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:11:"_properties";i:4;}}s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:11:"_properties";i:6;}}i:2;s:0:"";}}', "[ Upload:image.jpg | link ]" => !check_php_version(5) ? 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:' . strlen($uplink) . ':"' . $uplink . '";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}' : 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:' . strlen($uplink) . ':"' . $uplink . '";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}}i:2;s:0:"";}}', "[ http://server/image.jpg | link ]" => !check_php_version(5) ? 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}' : 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}}i:2;s:0:"";}}', "[ label | http://server/link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | Upload:link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | phpwiki:action=link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"Cached_PhpwikiURL":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "Upload:image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}', "http://server/image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}', "http://server/link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}', "[http:/server/~name/]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', "http:/server/~name/" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}'); //$i = 0; foreach ($tests as $wiki => $expected) { //print $i++ . " .. "; $xml = TransformInline($wiki); $this->assertTrue(isa($xml, 'XmlContent')); $actual = serialize($xml); if (!check_php_version(5)) { $expected = strtolower($expected); $actual = strtolower($actual); } $this->assertEquals($expected, $actual); } }
function _PdoDbPassUser($UserName = '', $prefs = false) { if (!$this->_prefs and isa($this, "_PdoDbPassUser")) { if ($prefs) { $this->_prefs = $prefs; } } if (!isset($this->_prefs->_method)) { _PassUser::_PassUser($UserName); } elseif (!$this->isValidName($UserName)) { trigger_error(_("Invalid username."), E_USER_WARNING); return false; } $this->_userid = $UserName; // make use of session data. generally we only initialize this every time, // but do auth checks only once $this->_auth_crypt_method = $GLOBALS['request']->_dbi->getAuthParam('auth_crypt_method'); return $this; }
function _AdoDbPassUser($UserName = '', $prefs = false) { if (!$this->_prefs and isa($this, "_AdoDbPassUser")) { if ($prefs) { $this->_prefs = $prefs; } if (!isset($this->_prefs->_method)) { _PassUser::_PassUser($UserName); } } if (!$this->isValidName($UserName)) { trigger_error(_("Invalid username."), E_USER_WARNING); return false; } $this->_userid = $UserName; $this->getAuthDbh(); $this->_auth_crypt_method = $GLOBALS['request']->_dbi->getAuthParam('auth_crypt_method'); // Don't prepare the configured auth statements anymore return $this; }
function linkUnknownWikiWord($wikiword, $linktext = '') { global $request; if (isa($wikiword, 'WikiPageName')) { $default_text = $wikiword->shortName; $wikiword = $wikiword->name; } else { $default_text = $wikiword; } $url = WikiURL($wikiword, array('action' => 'create')); $link = HTML::span(HTML::a(array('href' => $url, 'rel' => 'nofollow'), '?')); if (!empty($linktext)) { $link->unshiftContent(HTML::u($linktext)); $link->setAttr('class', 'named-wikiunknown'); } else { $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($default_text))); $link->setAttr('class', 'wikiunknown'); } return $link; }
function linkExistingWikiWord($wikiword, $linktext = '', $version = false) { global $request; if ($version !== false and !$this->HTML_DUMP_SUFFIX) { $url = WikiURL($wikiword, array('version' => $version)); } else { $url = WikiURL($wikiword); } // Extra steps for dumping page to an html file. if ($this->HTML_DUMP_SUFFIX) { $url = preg_replace('/^\\./', '%2e', $url); // dot pages } $link = HTML::a(array('href' => $url)); if (isa($wikiword, 'WikiPageName')) { $default_text = $wikiword->shortName; } else { $default_text = $wikiword; } if (!empty($linktext)) { $link->pushContent($linktext); $link->setAttr('class', 'named-wiki'); $link->setAttr('title', $this->maybeSplitWikiWord($default_text)); } else { //TODO: check if wikiblog $link->pushContent($this->maybeSplitWikiWord($default_text)); $link->setAttr('class', 'wiki'); } return $link; }
function handle_plugin_args_cruft($argstr, $args) { $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "radio", "pulldown", "submit", "reset", "combobox"); // no editbox[] = array(...) allowed (space) $arg_array = preg_split("/\n/", $argstr); // for security we should check this better $arg = ''; for ($i = 0; $i < count($arg_array); $i++) { //TODO: we require an name=value pair here, but submit may go without also. if (preg_match("/^\\s*(" . join("|", $allowed) . ")\\[\\](.*)\$/", $arg_array[$i], $m)) { $name = $m[1]; // one of the allowed input types $this->inputbox[][$name] = array(); $j = count($this->inputbox) - 1; $curargs = trim($m[2]); // must match name=NAME and also value=<!plugin-list name !> while (preg_match("/^(\\w+)=((?:\".*\")|(?:\\w+)|(?:\"?<!plugin-list.+!>\"?))\\s*/", $curargs, $m)) { $attr = $m[1]; $value = $m[2]; $curargs = substr($curargs, strlen($m[0])); if (preg_match("/^\"(.*)\"\$/", $value, $m)) { $value = $m[1]; } if (in_array($name, array("pulldown", "checkbox", "radio", "radiobutton", "combobox")) and preg_match('/^<!plugin-list.+!>$/', $value, $m)) { $loader = new WikiPluginLoader(); $markup = null; $basepage = null; $plugin_str = preg_replace(array("/^<!/", "/!>\$/"), array("<?", "?>"), $value); // will return a pagelist object! pulldown,checkbox,radiobutton $value = $loader->expandPI($plugin_str, $GLOBALS['request'], $markup, $basepage); if (isa($value, 'PageList')) { $value = $value->_pages; } elseif (!is_array($value)) { trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])), E_USER_WARNING); } } elseif (defined($value)) { $value = constant($value); } $this->inputbox[$j][$name][$attr] = $value; } //trigger_error("not yet finished"); //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';'); } else { trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])), E_USER_WARNING); } } return; }
function setWidth($ncols) { assert($ncols >= $this->_ncols); if ($ncols <= $this->_ncols) { return; } $rows =& $this->_content; for ($i = 0; $i < count($rows); $i++) { $row =& $rows[$i]; if (isa($row, 'Block_table_dl_defn')) { $row->setWidth($ncols - 1); } else { $n = count($row->_content); $lastcol =& $row->_content[$n - 1]; if (!empty($lastcol)) { $lastcol->setAttr('colspan', $ncols - 1); } } } }
function _tryinsertInterWikiMap($content) { $goback = false; if (strpos($content, "<verbatim>")) { //$error_html = " The newly loaded pgsrc already contains a verbatim block."; $goback = true; } if (!$goback && !defined('INTERWIKI_MAP_FILE')) { $error_html = sprintf(" " . _("%s: not defined"), "INTERWIKI_MAP_FILE"); $goback = true; } $mapfile = FindFile(INTERWIKI_MAP_FILE, 1); if (!$goback && !file_exists($mapfile)) { $error_html = sprintf(" " . _("%s: file not found"), INTERWIKI_MAP_FILE); $goback = true; } if (!empty($error_html)) { trigger_error(_("Default InterWiki map file not loaded.") . $error_html, E_USER_NOTICE); } if ($goback) { return $content; } // if loading from virgin setup do echo, otherwise trigger_error E_USER_NOTICE if (!isa($GLOBALS['request'], 'MockRequest')) { echo sprintf(_("Loading InterWikiMap from external file %s."), $mapfile), "<br />"; } $fd = fopen($mapfile, "rb"); $data = fread($fd, filesize($mapfile)); fclose($fd); $content = $content . "\n<verbatim>\n{$data}</verbatim>\n"; return $content; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); $user =& $request->_user; if (isa($request, 'MockRequest')) { return ''; } if (!$request->isActionPage($request->getArg('pagename')) and (!isset($user->_prefs->_method) or !in_array($user->_prefs->_method, array('ADODB', 'SQL'))) or in_array($request->getArg('action'), array('zip', 'ziphtml', 'dumphtml')) or isa($user, '_ForbiddenUser')) { $no_args = $this->getDefaultArguments(); // ? // foreach ($no_args as $key => $value) { // $no_args[$value] = false; // } $no_args['errmsg'] = HTML(HTML::h2(_("Error: The user HomePage must be a valid WikiWord. Sorry, UserPreferences cannot be saved."), HTML::hr())); $no_args['isForm'] = false; return Template('userprefs', $no_args); } $userid = $user->UserName(); if ($user->isAuthenticated() and !empty($userid)) { $pref =& $request->_prefs; $args['isForm'] = true; //trigger_error("DEBUG: reading prefs from getPreferences".print_r($pref)); if ($request->isPost()) { $errmsg = ''; $delete = $request->getArg('delete'); if ($delete and $request->getArg('verify')) { // deleting prefs, verified $default_prefs = $pref->defaultPreferences(); $default_prefs['userid'] = $user->UserName(); $user->setPreferences($default_prefs); $request->_setUser($user); $request->setArg("verify", false); $request->setArg("delete", false); $alert = new Alert(_("Message"), _("Your UserPreferences have been successfully deleted.")); $alert->show(); return; } elseif ($delete and !$request->getArg('verify')) { return HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), HiddenInputs(array('verify' => 1)), HiddenInputs($request->getArgs()), HTML::p(_("Do you really want to delete all your UserPreferences?")), HTML::p(Button('submit:delete', _("Yes"), 'delete'), HTML::Raw(' '), Button('cancel', _("Cancel")))); } elseif ($rp = $request->getArg('pref')) { // replace only changed prefs in $pref with those from request if (!empty($rp['passwd']) and $rp['passwd2'] != $rp['passwd']) { $errmsg = _("Wrong password. Try again."); } else { //trigger_error("DEBUG: reading prefs from request".print_r($rp)); //trigger_error("DEBUG: writing prefs with setPreferences".print_r($pref)); if (empty($rp['passwd'])) { unset($rp['passwd']); } // fix to set system pulldown's. empty values don't get posted if (empty($rp['theme'])) { $rp['theme'] = ''; } if (empty($rp['lang'])) { $rp['lang'] = ''; } $num = $user->setPreferences($rp); if (!empty($rp['passwd'])) { $passchanged = false; if ($user->mayChangePass()) { if (method_exists($user, 'storePass')) { $passchanged = $user->storePass($rp['passwd']); } if (!$passchanged and method_exists($user, 'changePass')) { $passchanged = $user->changePass($rp['passwd']); } if ($passchanged) { $errmsg = _("Password updated."); } else { $errmsg = _("Password was not changed."); } } else { $errmsg = _("Password cannot be changed."); } } if (!$num) { $errmsg .= " " . _("No changes."); } else { $request->_setUser($user); $pref = $user->_prefs; $errmsg .= sprintf(_("%d UserPreferences fields successfully updated."), $num); } } $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr()); } } $args['available_themes'] = listAvailableThemes(); $args['available_languages'] = listAvailableLanguages(); return Template('userprefs', $args); } else { // wrong or unauthenticated user return $request->_notAuthorized(WIKIAUTH_BOGO); //return $user->PrintLoginForm ($request, $args, false, false); } }
/** * Saves the session data into DB. * * Just a comment: The "write" handler is not * executed until after the output stream is closed. Thus, * output from debugging statements in the "write" handler * will never be seen in the browser. If debugging output * is necessary, it is suggested that the debug output be * written to a file instead. * * @param string $id * @param string $sess_data * @return boolean true if data saved successfully and false * otherwise. * @access private */ function write($id, $sess_data) { if (defined("WIKI_XMLRPC") or defined("WIKI_SOAP")) { return; } $dbh = $this->_connect(); $table = $this->_table; $time = time(); // postgres can't handle binary data in a TEXT field. if (isa($dbh, 'ADODB_postgres64')) { $sess_data = base64_encode($sess_data); } /* AffectedRows with sessions seems to be instable on certain platforms. * Enable the safe and slow USE_SAFE_DBSESSION then. */ if (USE_SAFE_DBSESSION) { $this->_backend->beginTransaction(); $rs = $this->query("DELETE FROM {$table}" . " WHERE sess_id={$qid}"); $sth = $dbh->prepare("INSERT INTO {$table}" . " (sess_id, sess_data, sess_date, sess_ip)" . " VALUES (?, ?, ?, ?)"); $sth->bindParam(1, $id, PDO_PARAM_STR, 32); $sth->bindParam(2, $sess_data, PDO_PARAM_LOB); $sth->bindParam(3, $time, PDO_PARAM_INT); $sth->bindParam(4, $GLOBALS['request']->get('REMOTE_ADDR'), PDO_PARAM_STR, 15); if ($result = $sth->execute()) { $this->_backend->commit(); } else { $this->_backend->rollBack(); } } else { $sth = $dbh->prepare("UPDATE {$table}" . " SET sess_data=?, sess_date=?, sess_ip=?" . " WHERE sess_id=?"); $sth->bindParam(1, $sess_data, PDO_PARAM_LOB); $sth->bindParam(2, $time, PDO_PARAM_INT); $sth->bindParam(3, $GLOBALS['request']->get('REMOTE_ADDR'), PDO_PARAM_STR, 15); $sth->bindParam(4, $id, PDO_PARAM_STR, 32); $result = $sth->execute(); // implicit affected rows if ($result === false or $result < 1) { // false or int > 0 $sth = $dbh->prepare("INSERT INTO {$table}" . " (sess_id, sess_data, sess_date, sess_ip)" . " VALUES (?, ?, ?, ?)"); $sth->bindParam(1, $id, PDO_PARAM_STR, 32); $sth->bindParam(2, $sess_data, PDO_PARAM_LOB); $sth->bindParam(3, $time, PDO_PARAM_INT); $sth->bindParam(4, $GLOBALS['request']->get('REMOTE_ADDR'), PDO_PARAM_STR, 15); $result = $sth->execute(); } } $this->_disconnect(); return $result; }
function _parse_markup_body($markup, $match, &$text, $end_regexps) { if (isa($markup, 'SimpleMarkup')) { return true; } // Done. SimpleMarkup is simple. if (!is_object($markup)) { return false; } // Some error: Should assert array_unshift($end_regexps, $markup->getEndRegexp($match)); // Optimization: if no end pattern in text, we know the // parse will fail. This is an important optimization, // e.g. when text is "*lots *of *start *delims *with // *no *matching *end *delims". $ends_pat = "/(?:" . join(").*(?:", $end_regexps) . ")/xs"; if (!preg_match($ends_pat, $text)) { return false; } return $this->parse($text, $end_regexps); }
function onRenamePage(&$wikidb, $oldpage, $new_pagename) { $result = true; if (!isa($GLOBALS['request'], 'MockRequest')) { $notify = $wikidb->get('notify'); if (!empty($notify) and is_array($notify)) { $this->getPageChangeEmails($notify); if (!empty($this->emails)) { $newpage = $wikidb->getPage($new_pagename); $current = $newpage->getCurrentRevision(); $meta = $current->_data; $this->pagename = $oldpage; $result = $this->sendPageRenameNotification($new_pagename, $meta); } } } }
function _deduceUsername() { global $HTTP_SERVER_VARS, $HTTP_ENV_VARS; if (!empty($this->args['auth']) and !empty($this->args['auth']['userid'])) { return $this->args['auth']['userid']; } // Disable session vars (seems problematic) // if (0 && $user = $this->getSessionVar('wiki_user')) { if (0 && ($user = $this->getSessionVar('wiki_user'))) { // switched auth between sessions. // Note: There's no way to demandload a missing class-definition // afterwards! (Stupid php) if (isa($user, WikiUserClassname())) { $this->_user = $user; $this->_user->_authhow = 'session'; return ENABLE_USER_NEW ? $user->UserName() : $this->_user; } } // Sessions override http auth if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER'])) { return $HTTP_SERVER_VARS['PHP_AUTH_USER']; } // pubcookie et al if (!empty($HTTP_SERVER_VARS['REMOTE_USER'])) { return $HTTP_SERVER_VARS['REMOTE_USER']; } if (!empty($HTTP_ENV_VARS['REMOTE_USER'])) { return $HTTP_ENV_VARS['REMOTE_USER']; } if ($userid = $this->getCookieVar(getCookieName())) { if (!empty($userid) and substr($userid, 0, 2) != 's:') { $this->_user->authhow = 'cookie'; return $userid; } } if ($this->getArg('action') == 'xmlrpc') { // how about SOAP? // wiki.putPage has special otional userid/passwd arguments. check that later. $userid = ''; if (isset($HTTP_SERVER_VARS['REMOTE_USER'])) { $userid = $HTTP_SERVER_VARS['REMOTE_USER']; } elseif (isset($HTTP_SERVER_VARS['REMOTE_ADDR'])) { $userid = $HTTP_SERVER_VARS['REMOTE_ADDR']; } elseif (isset($HTTP_ENV_VARS['REMOTE_ADDR'])) { $userid = $HTTP_ENV_VARS['REMOTE_ADDR']; } elseif (isset($GLOBALS['REMOTE_ADDR'])) { $userid = $GLOBALS['REMOTE_ADDR']; } return $userid; } return false; }
function run($dbi, $argstr, &$request, $basepage) { include_once 'lib/BlockParser.php'; $args = $this->getArgs($argstr, $request, false); extract($args); if (!$page) { return ''; } $this->_pagename = $page; $out = ''; // get rid of this $html = HTML(); if (empty($exclude)) { $exclude = array(); } if (!$include_self) { $exclude[] = $page; } $this->ExcludedPages = empty($exclude) ? "" : "^(?:" . join("|", $exclude) . ")"; $this->_default_limit = str_pad('', 3, '*'); if (is_numeric($reclimit)) { if ($reclimit < 0) { $reclimit = 0; } if ($reclimit > 10) { $reclimit = 10; } $limit = str_pad('', $reclimit + 2, '*'); } else { $limit = '***'; } //Fixme: override given arg $description = $this->getDescription(); if (!$noheader) { $out = $this->getDescription() . " " . sprintf(_("(max. recursion level: %d)"), $reclimit) . ":\n\n"; $html->pushContent(TransformText($out, 1.0, $page)); } $pagelist = new PageList($info, $exclude); $p = $dbi->getPage($page); $pagearr = array(); if ($direction == 'back') { $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*", $limit); } else { $this->dbi = $dbi; $this->initialpage = $page; $this->firstreversed = $firstreversed; $this->excludeunknown = $excludeunknown; $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit); } reset($pagearr); if (!empty($includepages)) { // disallow direct usage, only via child class IncludeSiteMap if (!isa($this, "WikiPlugin_IncludeSiteMap")) { $includepages = ''; } if (!is_string($includepages)) { $includepages = ' '; } // avoid plugin loader problems $loader = new WikiPluginLoader(); $plugin = $loader->getPlugin('IncludePage', false); $nothing = ''; } while (list($key, $link) = each($pagearr)) { if (!empty($includepages)) { $a = substr_count($key, '*'); $indenter = str_pad($nothing, $a); //$request->setArg('IncludePage', 1); // quote linkname, by Stefan Schorn $plugin_args = 'page=\'' . $link->getName() . '\' ' . $includepages; $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage); $html->pushContent($pagehtml); //$html->pushContent( HTML(TransformText($indenter, 1.0, $page), $pagehtml)); //$out .= $indenter . $pagehtml . "\n"; } else { $out .= $key . "\n"; } } if (empty($includepages)) { return TransformText($out, 2.0, $page); } else { return $html; } }
function format_revision($rev) { global $WikiTheme; $args =& $this->_args; $class = 'rc-' . $this->importance($rev); $time = $this->time($rev); if ($rev->get('is_minor_edit')) { $minor_flag = HTML(" ", HTML::span(array('class' => 'pageinfo-minoredit'), "(" . _("minor edit") . ")")); } else { $time = HTML::span(array('class' => 'pageinfo-majoredit'), $time); $minor_flag = ''; } $line = HTML::li(array('class' => $class)); if ($args['difflinks']) { $line->pushContent($this->diffLink($rev), ' '); } if ($args['historylinks']) { $line->pushContent($this->historyLink($rev), ' '); } // Do not display a link for a deleted page, just the page name if ($rev->hasDefaultContents()) { $linkorname = $rev->_pagename; } else { $linkorname = $this->pageLink($rev); } if (isa($WikiTheme, 'WikiTheme_MonoBook') or isa($WikiTheme, 'WikiTheme_fusionforge')) { $line->pushContent($args['historylinks'] ? '' : $this->historyLink($rev), ' . . ', $linkorname, '; ', $time, ' . . ', $this->authorLink($rev), ' ', $this->authorContribs($rev), ' ', $this->summaryAsHTML($rev), ' ', $minor_flag); } else { $line->pushContent($linkorname, ' ', $time, ' ', $this->summaryAsHTML($rev), ' ... ', $this->authorLink($rev)); } return $line; }
function _pagename($page) { if (isa($page, 'WikiDB_Page')) { return $page->getName(); } elseif (isa($page, 'WikiDB_PageRevision')) { return $page->getPageName(); } elseif (isa($page, 'WikiPageName')) { return $page->name; } // '0' or e.g. '1984' should be allowed though if (!is_string($page) and !is_integer($page)) { trigger_error(sprintf("Non-string pagename '%s' (%s)(%s)", $page, gettype($page), get_class($page)), E_USER_NOTICE); } //assert(is_string($page)); return $page; }
/** * use init to avoid update on set */ function updatePrefs($prefs, $init = false) { $count = 0; if ($init) { $this->_init = $init; } if (is_object($prefs)) { $type = 'emailVerified'; $obj =& $this->_prefs['email']; $obj->_init = $init; if ($obj->get($type) !== $prefs->get($type)) { if ($obj->set($type, $prefs->get($type))) { $count++; } } foreach (array_keys($this->_prefs) as $type) { $obj =& $this->_prefs[$type]; $obj->_init = $init; if ($prefs->get($type) !== $obj->get($type)) { // special systemdefault prefs: (probably not needed) if ($type == 'theme' and $prefs->get($type) == '' and $obj->get($type) == THEME) { continue; } if ($type == 'lang' and $prefs->get($type) == '' and $obj->get($type) == DEFAULT_LANGUAGE) { continue; } if ($this->_prefs[$type]->set($type, $prefs->get($type))) { $count++; } } } } elseif (is_array($prefs)) { //unset($this->_prefs['userid']); /* if (isset($this->_method) and ($this->_method == 'SQL' or $this->_method == 'ADODB')) { unset($this->_prefs['passwd']); } */ // emailVerified at first, the rest later $type = 'emailVerified'; $obj =& $this->_prefs['email']; $obj->_init = $init; if (isset($prefs[$type]) and $obj->get($type) !== $prefs[$type]) { if ($obj->set($type, $prefs[$type])) { $count++; } } foreach (array_keys($this->_prefs) as $type) { $obj =& $this->_prefs[$type]; $obj->_init = $init; if (!isset($prefs[$type]) and isa($obj, "_UserPreference_bool")) { $prefs[$type] = false; } if (isset($prefs[$type]) and isa($obj, "_UserPreference_int")) { $prefs[$type] = (int) $prefs[$type]; } if (isset($prefs[$type]) and $obj->get($type) != $prefs[$type]) { // special systemdefault prefs: if ($type == 'theme' and $prefs[$type] == '' and $obj->get($type) == THEME) { continue; } if ($type == 'lang' and $prefs[$type] == '' and $obj->get($type) == DEFAULT_LANGUAGE) { continue; } if ($obj->set($type, $prefs[$type])) { $count++; } } } } return $count; }
/** A higher-level interface to createRevision. * * This takes care of computing the links, and storing * a cached version of the transformed wiki-text. * * @param string $wikitext The page content. * * @param int $version Version number for new revision. * To ensure proper serialization of edits, $version must be * exactly one higher than the current latest version. * (You can defeat this check by setting $version to * {@link WIKIDB_FORCE_CREATE} --- not usually recommended.) * * @param hash $meta Meta-data for new revision. */ function save($wikitext, $version, $meta) { $formatted = new TransformedText($this, $wikitext, $meta); $type = $formatted->getType(); $meta['pagetype'] = $type->getName(); $links = $formatted->getWikiPageLinks(); $backend =& $this->_wikidb->_backend; $newrevision = $this->createRevision($version, $wikitext, $meta, $links); if ($newrevision and !WIKIDB_NOCACHE_MARKUP) { $this->set('_cached_html', $formatted->pack()); } // FIXME: probably should have some global state information // in the backend to control when to optimize. // // We're doing this here rather than in createRevision because // postgres can't optimize while locked. if (DEBUG & _DEBUG_SQL or time() % 5 == 0) { if ($backend->optimize()) { // Codendi: don't show this message... //trigger_error(_("Optimizing database"), E_USER_NOTICE); } } /* Generate notification emails? */ if (ENABLE_EMAIL_NOTIFIFICATION && isa($newrevision, 'WikiDB_PageRevision')) { // Save didn't fail because of concurrent updates. $notify = $this->_wikidb->get('notify'); if (!empty($notify) and is_array($notify) and !isa($GLOBALS['request'], 'MockRequest')) { list($emails, $userids) = $this->getPageChangeEmails($notify); if (!empty($emails)) { $this->sendPageChangeNotification($wikitext, $version, $meta, $emails, $userids); } } $newrevision->_transformedContent = $formatted; } return $newrevision; }