/** * 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 getAuthDbh() { global $request; //, $DBParams, $DBAuthParams; $dbh = $request->getDbh(); // session restauration doesn't re-connect to the database automatically, // so dirty it here, to force a reconnect. if (isset($this->_auth_dbi)) { if ($dbh->getParam('dbtype') == 'SQL' and empty($this->_auth_dbi->connection)) { unset($this->_auth_dbi); } if ($dbh->getParam('dbtype') == 'ADODB' and empty($this->_auth_dbi->_connectionID)) { unset($this->_auth_dbi); } } if (empty($this->_auth_dbi)) { if ($dbh->getParam('dbtype') != 'SQL' and $dbh->getParam('dbtype') != 'ADODB' and $dbh->getParam('dbtype') != 'PDO') { return false; } if (empty($GLOBALS['DBAuthParams'])) { return false; } if (!$dbh->getAuthParam('auth_dsn')) { $dbh = $request->getDbh(); // use phpwiki database } elseif ($dbh->getAuthParam('auth_dsn') == $dbh->getParam('dsn')) { $dbh = $request->getDbh(); // same phpwiki database } else { // use another external database handle. needs PHP >= 4.1 $local_params = array_merge($GLOBALS['DBParams'], $GLOBALS['DBAuthParams']); $local_params['dsn'] = $local_params['auth_dsn']; $dbh = WikiDB::open($local_params); } $this->_auth_dbi =& $dbh->_backend->_dbh; } return $this->_auth_dbi; }
function WikiRequest() { $this->_dbi = WikiDB::open($GLOBALS['DBParams']); // first mysql request costs [958ms]! [670ms] is mysql_connect() if (in_array('File', $this->_dbi->getAuthParam('USER_AUTH_ORDER'))) { // force our local copy, until the pear version is fixed. include_once dirname(__FILE__) . "/pear/File_Passwd.php"; } if (ENABLE_USER_NEW) { // Preload all necessary userclasses. Otherwise session => __PHP_Incomplete_Class_Name // There's no way to demand-load it later. This way it's much slower, but needs slightly // less memory than loading all. if (ALLOW_BOGO_LOGIN) { include_once "lib/WikiUser/BogoLogin.php"; } // UserPreferences POST Update doesn't reach this. foreach ($GLOBALS['USER_AUTH_ORDER'] as $method) { include_once "lib/WikiUser/{$method}.php"; if ($method == 'Db') { switch (DATABASE_TYPE) { case 'SQL': include_once "lib/WikiUser/PearDb.php"; break; case 'ADODB': include_once "lib/WikiUser/AdoDb.php"; break; case 'PDO': include_once "lib/WikiUser/PdoDb.php"; break; } } } unset($method); } if (USE_DB_SESSION) { include_once 'lib/DbSession.php'; $dbi =& $this->_dbi; $this->_dbsession = new DbSession($dbi, $dbi->getParam('prefix') . $dbi->getParam('db_session_table')); } // Fixme: Does pear reset the error mask to 1? We have to find the culprit //$x = error_reporting(); $this->version = phpwiki_version(); $this->Request(); // [90ms] // Normalize args... $this->setArg('pagename', $this->_deducePagename()); $this->setArg('action', $this->_deduceAction()); if (DEBUG & _DEBUG_SQL or DATABASE_OPTIMISE_FREQUENCY > 0 and time() % DATABASE_OPTIMISE_FREQUENCY == 0) { if ($this->_dbi->_backend->optimize()) { trigger_error(_("Optimizing database"), E_USER_NOTICE); } } // Restore auth state. This doesn't check for proper authorization! $userid = $this->_deduceUsername(); if (ENABLE_USER_NEW) { if (isset($this->_user) and !empty($this->_user->_authhow) and $this->_user->_authhow == 'session') { // users might switch in a session between the two objects. // restore old auth level here or in updateAuthAndPrefs? //$user = $this->getSessionVar('wiki_user'); // revive db handle, because these don't survive sessions if (isset($this->_user) and (!isa($this->_user, WikiUserClassname()) or strtolower(get_class($this->_user)) == '_passuser')) { $this->_user = WikiUser($userid, $this->_user->_prefs); } // revive other db handle if (isset($this->_user->_prefs->_method) and ($this->_user->_prefs->_method == 'SQL' or $this->_user->_prefs->_method == 'ADODB' or $this->_user->_prefs->_method == 'PDO' or $this->_user->_prefs->_method == 'HomePage')) { $this->_user->_HomePagehandle = $this->getPage($userid); } // need to update the lockfile filehandle if (isa($this->_user, '_FilePassUser') and $this->_user->_file->lockfile and !$this->_user->_file->fplock) { //$level = $this->_user->_level; $this->_user = UpgradeUser($this->_user, new _FilePassUser($userid, $this->_user->_prefs, $this->_user->_file->filename)); //$this->_user->_level = $level; } $this->_prefs =& $this->_user->_prefs; } else { $user = WikiUser($userid); $this->_user =& $user; $this->_prefs =& $this->_user->_prefs; } } else { $this->_user = new WikiUser($this, $userid); $this->_prefs = $this->_user->getPreferences(); } }
function linkSearch($linktype, $search, $pages = "*", $relation = "*", $credentials = false) { global $server; checkCredentials($server, $credentials, 'view', _("HomePage")); $dbi = WikiDB::open($GLOBALS['DBParams']); require_once "lib/TextSearchQuery.php"; $pagequery = new TextSearchQuery($pages); $linkquery = new TextSearchQuery($search); if ($linktype == 'relation') { $relquery = new TextSearchQuery($relation); $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype, $relquery); } elseif ($linktype == 'attribute') { // only numeric search withh attributes! $relquery = new TextSearchQuery($relation); require_once "lib/SemanticWeb.php"; // search: "population > 1 million and area < 200 km^2" relation="*" pages="*" $linkquery = new SemanticAttributeSearchQuery($search, $relation); $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype, $relquery); } else { // we already do have forward and backlinks as SOAP $links = $dbi->_backend->link_search($pagequery, $linkquery, $linktype); } return $links->asArray(); }
function _upgrade_db_init(&$dbh) { global $request, $DBParams, $DBAuthParams; if (!in_array($DBParams['dbtype'], array('SQL', 'ADODB', 'PDO'))) { return; } if (DBADMIN_USER) { // if need to connect as the root user, for CREATE and ALTER privileges $AdminParams = $DBParams; if ($DBParams['dbtype'] == 'SQL') { $dsn = DB::parseDSN($AdminParams['dsn']); } else { // ADODB or PDO $dsn = parseDSN($AdminParams['dsn']); } $AdminParams['dsn'] = sprintf("%s://%s:%s@%s/%s", $dsn['phptype'], DBADMIN_USER, DBADMIN_PASSWD, $dsn['hostspec'], $dsn['database']); if (DEBUG & _DEBUG_SQL and $DBParams['dbtype'] == 'PDO') { echo "<br>\nDBParams['dsn']: '", $DBParams['dsn'], "'"; echo "<br>\ndsn: '", print_r($dsn), "'"; echo "<br>\nAdminParams['dsn']: '", $AdminParams['dsn'], "'"; } $dbh = WikiDB::open($AdminParams); } elseif ($dbadmin = $request->getArg('dbadmin')) { if (empty($dbadmin['user']) or isset($dbadmin['cancel'])) { $dbh =& $request->_dbi; } else { $AdminParams = $DBParams; if ($DBParams['dbtype'] == 'SQL') { $dsn = DB::parseDSN($AdminParams['dsn']); } else { $dsn = parseDSN($AdminParams['dsn']); } $AdminParams['dsn'] = sprintf("%s://%s:%s@%s/%s", $dsn['phptype'], $dbadmin['user'], $dbadmin['passwd'], $dsn['hostspec'], $dsn['database']); $dbh = WikiDB::open($AdminParams); } } else { // Check if the privileges are enough. Need CREATE and ALTER perms. // And on windows: SELECT FROM mysql, possibly: UPDATE mysql. $form = HTML::form(array("method" => "post", "action" => $request->getPostURL(), "accept-charset" => $GLOBALS['charset']), HTML::p(_("Upgrade requires database privileges to CREATE and ALTER the phpwiki database."), HTML::br(), _("And on windows at least the privilege to SELECT FROM mysql, and possibly UPDATE mysql")), HiddenInputs(array('action' => 'upgrade')), HTML::table(array("cellspacing" => 4), HTML::tr(HTML::td(array('align' => 'right'), _("DB admin user:"******"dbadmin[user]", 'size' => 12, 'maxlength' => 256, 'value' => 'root')))), HTML::tr(HTML::td(array('align' => 'right'), _("DB admin password:"******"dbadmin[passwd]", 'type' => 'password', 'size' => 12, 'maxlength' => 256)))), HTML::tr(HTML::td(array('align' => 'center', 'colspan' => 2), Button("submit:", _("Submit"), 'wikiaction'), HTML::raw(' '), Button("submit:dbadmin[cancel]", _("Cancel"), 'button'))))); $form->printXml(); echo "</div><!-- content -->\n"; echo asXML(Template("bottom")); echo "</body></html>\n"; $request->finish(); exit; } }
/** * Initializes PhpWiki and calls the plugin specified in the url to * produce an image. Furthermore, allow the usage of Apache's * ErrorDocument mechanism in order to make this file only called when * image could not be found in the cache. * (see doc/README.phpwiki-cache for further information). */ function mainImageCache() { $request = new Request(); // normalize pagename $request->setArg('pagename', deducePagename($request)); $pagename = $request->getArg('pagename'); $request->_dbi = WikiDB::open($GLOBALS['DBParams']); if (ENABLE_USER_NEW) { $request->_user = new _AnonUser(); $request->_prefs =& $request->_user->_prefs; } else { $request->_user = new WikiUser($request); $request->_prefs = new UserPreferences(); } // Enable the output of most of the warning messages. // The warnings will screw up zip files and setpref though. // They will also screw up my images... But I think // we should keep them. global $ErrorManager; $ErrorManager->setPostponedErrorMask(E_NOTICE | E_USER_NOTICE); $id = $request->getArg('id'); $args = $request->getArg('args'); $request->setArg('action', 'imagecache'); $cache = new WikiPluginCached(); if ($id) { // this indicates a direct call (script wasn't called as // 404 ErrorDocument) } else { // deduce image id or image args (plugincall) from // refering URL $uri = $request->get('REDIRECT_URL'); $query = $request->get('REDIRECT_QUERY_STRING'); $uri .= $query ? '?' . $query : ''; if (!$uri) { $uri = $request->get('REQUEST_URI'); } if (!$uri) { $cache->printError('png', 'Could not deduce image identifier or creation' . ' parameters. (Neither REQUEST nor REDIRECT' . ' obtained.)'); return; } //$cacheparams = $GLOBALS['CacheParams']; if (!preg_match(':^(.*/)?' . PLUGIN_CACHED_FILENAME_PREFIX . '([^\\?/]+)\\.img(\\?args=([^\\?&]*))?$:', $uri, $matches)) { $cache->printError('png', "I do not understand this URL: {$uri}"); return; } $request->setArg('id', $matches[2]); if ($matches[4]) { // md5 args? $request->setArg('args', rawurldecode($matches[4])); } $request->setStatus(200); // No, we do _not_ have an Error 404 :-> } $cache->fetchImageFromCache($request->_dbi, $request, 'png'); }
function doFullTextSearch($s, $credentials = false) { global $server; checkCredentials($server, $credentials, 'view', _("FullTextSearch")); $dbi = WikiDB::open($GLOBALS['DBParams']); $query = new TextSearchQuery($s); $page_iter = $dbi->fullSearch($query); $pages = array(); while ($page = $page_iter->next()) { $pages[] = array('pagename' => $page->getName()); } return $pages; }
function _try_dbadmin_user($user, $passwd) { global $DBParams, $DBAuthParams; $AdminParams = $DBParams; if (DATABASE_TYPE == 'SQL') { $dsn = DB::parseDSN($AdminParams['dsn']); } else { $dsn = parseDSN($AdminParams['dsn']); } $AdminParams['dsn'] = sprintf("%s://%s:%s@%s/%s", $dsn['phptype'], $user, $passwd, $dsn['hostspec'], $dsn['database']); $AdminParams['_tryroot_from_upgrade'] = 1; // add error handler to warn about missing permissions for DBADMIN_USER global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_dbpermission_filter')); $this->error_caught = 0; $this->dbi = WikiDB::open($AdminParams); if (!$this->error_caught) { return true; } // FAILED: redo our connection with the wikiuser $this->dbi = WikiDB::open($DBParams); $ErrorManager->flushPostponedErrors(); $ErrorManager->popErrorHandler(); return false; }