4 * Copyright 2005 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * @author: Reini Urban
27 require_once 'lib/WikiDB/backend.php';
29 class WikiDB_backend_PDO
30 extends WikiDB_backend
33 function __construct($dbparams)
35 $this->_dbparams = $dbparams;
36 if (strstr($dbparams['dsn'], "://")) { // pear DB syntax
37 $parsed = parseDSN($dbparams['dsn']);
38 $this->_parsedDSN = $parsed;
39 /* Need to convert the DSN
40 * dbtype(dbsyntax)://username:password@protocol+hostspec/database?option=value&option2=value2
41 * to dbtype:option1=value1;option2=value2
42 * PDO passes the DSN verbatim to the driver. But we need to extract the username + password
43 * and cannot rely that the parseDSN keys have the same name as needed by the driver.
44 * e.g: odbc:DSN=SAMPLE;UID=db2inst1;PWD=ibmdb2, mysql:host=127.0.0.1;dbname=testdb
46 $driver = $parsed['phptype'];
47 unset($parsed['phptype']);
48 unset($parsed['dbsyntax']);
49 $dbparams['dsn'] = $driver . ":";
50 $this->_dbh->database = $parsed['database'];
51 // mysql needs to map database=>dbname, hostspec=>host. TODO for the others.
52 $dsnmap = array('mysql' => array('database' => 'dbname', 'hostspec' => 'host')
54 foreach (array('protocol', 'hostspec', 'port', 'socket', 'database') as $option) {
55 if (!empty($parsed[$option])) {
56 $optionname = (isset($dsnmap[$driver][$option]) and !isset($parsed[$optionname]))
57 ? $dsnmap[$driver][$option]
59 $dbparams['dsn'] .= ($optionname . "=" . $parsed[$option] . ";");
60 unset($parsed[$optionname]);
62 unset($parsed[$option]);
64 unset($parsed['username']);
65 unset($parsed['password']);
66 // pass the rest verbatim to the driver.
67 foreach ($parsed as $option => $value) {
68 $dbparams['dsn'] .= ($option . "=" . $value . ";");
71 list($driver, $dsn) = explode(":", $dbparams['dsn'], 2);
72 foreach (explode(";", trim($dsn)) as $pair) {
74 list($option, $value) = explode("=", $pair, 2);
75 $this->_parsedDSN[$option] = $value;
78 $this->_dbh->database = isset($this->_parsedDSN['database'])
79 ? $this->_parsedDSN['database']
80 : $this->_parsedDSN['dbname'];
82 if (empty($this->_parsedDSN['password'])) $this->_parsedDSN['password'] = '';
85 // try to load it dynamically (unix only)
86 if (!loadPhpExtension("pdo_$driver")) {
87 echo $GLOBALS['php_errormsg'], "<br>\n";
88 trigger_error(sprintf("dl() problem: Required extension '%s' could not be loaded!",
93 // persistent is defined as DSN option, or with a config value.
94 // phptype://username:password@hostspec/database?persistent=false
95 $this->_dbh = new PDO($dbparams['dsn'],
96 $this->_parsedDSN['username'],
97 $this->_parsedDSN['password'],
98 array(PDO::ATTR_AUTOCOMMIT => true,
99 PDO::ATTR_TIMEOUT => DATABASE_TIMEOUT,
100 PDO::ATTR_PERSISTENT => !empty($parsed['persistent'])
101 or DATABASE_PERSISTENT
103 } catch (PDOException $e) {
104 echo "<br>\nCan't connect to database: %s" . $e->getMessage();
105 if (DEBUG & _DEBUG_VERBOSE or DEBUG & _DEBUG_SQL) {
106 echo "<br>\nDSN: '", $dbparams['dsn'], "'";
107 echo "<br>\n_parsedDSN: '", print_r($this->_parsedDSN), "'";
108 echo "<br>\nparsed: '", print_r($parsed), "'";
110 if (isset($dbparams['_tryroot_from_upgrade']))
111 trigger_error(sprintf("Can't connect to database: %s", $e->getMessage()),
116 if (DEBUG & _DEBUG_SQL) { // not yet implemented
117 $this->_dbh->debug = true;
119 $this->_dsn = $dbparams['dsn'];
120 $this->_dbh->databaseType = $driver;
121 $this->_dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
122 // Use the faster FETCH_NUM, with some special ASSOC based exceptions.
124 $this->_hasTransactions = true;
126 $this->_dbh->beginTransaction();
127 } catch (PDOException $e) {
128 $this->_hasTransactions = false;
130 $sth = $this->_dbh->prepare("SELECT version()");
132 $this->_serverinfo['version'] = $sth->fetchColumn();
133 $this->commit(); // required to match the try catch block above!
135 $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
137 = array('page_tbl' => $prefix . 'page',
138 'version_tbl' => $prefix . 'version',
139 'link_tbl' => $prefix . 'link',
140 'recent_tbl' => $prefix . 'recent',
141 'nonempty_tbl' => $prefix . 'nonempty');
142 $page_tbl = $this->_table_names['page_tbl'];
143 $version_tbl = $this->_table_names['version_tbl'];
144 $this->page_tbl_fields = "$page_tbl.id AS id, $page_tbl.pagename AS pagename, "
145 . "$page_tbl.hits hits";
146 $this->page_tbl_field_list = array('id', 'pagename', 'hits');
147 $this->version_tbl_fields = "$version_tbl.version AS version, "
148 . "$version_tbl.mtime AS mtime, "
149 . "$version_tbl.minor_edit AS minor_edit, $version_tbl.content AS content, "
150 . "$version_tbl.versiondata AS versiondata";
151 $this->version_tbl_field_list = array('version', 'mtime', 'minor_edit', 'content',
155 = array('maxmajor' => "MAX(CASE WHEN minor_edit=0 THEN version END)",
156 'maxminor' => "MAX(CASE WHEN minor_edit<>0 THEN version END)",
157 'maxversion' => "MAX(version)",
158 'notempty' => "<>''",
159 'iscontent' => "$version_tbl.content<>''");
160 $this->_lock_count = 0;
163 function beginTransaction()
165 if ($this->_hasTransactions)
166 $this->_dbh->beginTransaction();
171 if ($this->_hasTransactions)
172 $this->_dbh->commit();
177 if ($this->_hasTransactions)
178 $this->_dbh->rollback();
184 $sth = $this->_dbh->prepare($sql);
185 return $sth->execute();
188 /* with one result row */
189 function getRow($sql)
191 $sth = $this->_dbh->prepare($sql);
193 return $sth->fetch(PDO::FETCH_BOTH);
199 * Close database connection.
205 if ($this->_lock_count) {
206 trigger_error("WARNING: database still locked " .
207 '(lock_count = $this->_lock_count)' . "\n<br />",
210 $this->unlock(false, 'force');
216 * Fast test for wikipage.
218 function is_wiki_page($pagename)
221 extract($this->_table_names);
222 $sth = $dbh->prepare("SELECT $page_tbl.id AS id"
223 . " FROM $nonempty_tbl, $page_tbl"
224 . " WHERE $nonempty_tbl.id=$page_tbl.id"
225 . " AND pagename=?");
226 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
228 return $sth->fetchColumn();
233 function get_all_pagenames()
236 extract($this->_table_names);
237 $sth = $dbh->exec("SELECT pagename"
238 . " FROM $nonempty_tbl, $page_tbl"
239 . " WHERE $nonempty_tbl.id=$page_tbl.id"
241 return $sth->fetchAll(PDO::FETCH_NUM);
244 function numPages($filter = false, $exclude = '')
247 extract($this->_table_names);
248 $sth = $dbh->exec("SELECT count(*)"
249 . " FROM $nonempty_tbl, $page_tbl"
250 . " WHERE $nonempty_tbl.id=$page_tbl.id");
251 return $sth->fetchColumn();
254 function increaseHitCount($pagename)
257 $page_tbl = $this->_table_names['page_tbl'];
258 $sth = $dbh->prepare("UPDATE $page_tbl SET hits=hits+1"
259 . " WHERE pagename=?"
261 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
266 * Read page information from database.
268 function get_pagedata($pagename)
271 $page_tbl = $this->_table_names['page_tbl'];
272 $sth = $dbh->prepare("SELECT id,pagename,hits,pagedata FROM $page_tbl"
273 . " WHERE pagename=? LIMIT 1");
274 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
276 $row = $sth->fetch(PDO::FETCH_NUM);
277 return $row ? $this->_extract_page_data($row[3], $row[2]) : false;
280 function _extract_page_data($data, $hits)
283 return array('hits' => $hits);
285 return array_merge(array('hits' => $hits), $this->_unserialize($data));
288 function update_pagedata($pagename, $newdata)
291 $page_tbl = $this->_table_names['page_tbl'];
293 // Hits is the only thing we can update in a fast manner.
294 if (count($newdata) == 1 && isset($newdata['hits'])) {
295 // Note that this will fail silently if the page does not
296 // have a record in the page table. Since it's just the
297 // hit count, who cares?
298 $sth = $dbh->prepare("UPDATE $page_tbl SET hits=? WHERE pagename=? LIMIT 1");
299 $sth->bindParam(1, $newdata['hits'], PDO::PARAM_INT);
300 $sth->bindParam(2, $pagename, PDO::PARAM_STR, 100);
304 $this->beginTransaction();
305 $data = $this->get_pagedata($pagename);
308 $this->_get_pageid($pagename, true); // Creates page record
311 $hits = (empty($data['hits'])) ? 0 : (int)$data['hits'];
312 unset($data['hits']);
314 foreach ($newdata as $key => $val) {
317 else if (empty($val))
322 $sth = $dbh->prepare("UPDATE $page_tbl"
323 . " SET hits=?, pagedata=?"
324 . " WHERE pagename=?"
326 $sth->bindParam(1, $hits, PDO::PARAM_INT);
327 $sth->bindParam(2, $this->_serialize($data), PDO::PARAM_LOB);
328 $sth->bindParam(3, $pagename, PDO::PARAM_STR, 100);
329 if ($sth->execute()) {
338 function get_cached_html($pagename)
341 $page_tbl = $this->_table_names['page_tbl'];
342 $sth = $dbh->prepare("SELECT cached_html FROM $page_tbl WHERE pagename=? LIMIT 1");
343 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
345 return $sth->fetchColumn(PDO::FETCH_NUM);
348 function set_cached_html($pagename, $data)
351 $page_tbl = $this->_table_names['page_tbl'];
352 if (empty($data)) $data = '';
353 $sth = $dbh->prepare("UPDATE $page_tbl"
354 . " SET cached_html=?"
355 . " WHERE pagename=?"
357 $sth->bindParam(1, $data, PDO::PARAM_STR);
358 $sth->bindParam(2, $pagename, PDO::PARAM_STR, 100);
362 function _get_pageid($pagename, $create_if_missing = false)
366 $cache =& $request->_dbi->_cache->_id_cache;
367 if (isset($cache[$pagename])) {
368 if ($cache[$pagename] or !$create_if_missing) {
369 return $cache[$pagename];
373 // attributes play this game.
374 if ($pagename === '') return 0;
377 $page_tbl = $this->_table_names['page_tbl'];
378 $sth = $dbh->prepare("SELECT id FROM $page_tbl WHERE pagename=? LIMIT 1");
379 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
380 $id = $sth->fetchColumn();
381 if (!$create_if_missing) {
385 //mysql, mysqli or mysqlt
386 if (substr($dbh->databaseType, 0, 5) == 'mysql') {
387 // have auto-incrementing, atomic version
388 $sth = $dbh->prepare("INSERT INTO $page_tbl"
390 . " VALUES (NULL,?)");
391 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
393 $id = $dbh->lastInsertId();
395 $this->beginTransaction();
396 $sth = $dbh->prepare("SELECT MAX(id) FROM $page_tbl");
398 $id = $sth->fetchColumn();
399 $sth = $dbh->prepare("INSERT INTO $page_tbl"
400 . " (id,pagename,hits)"
401 . " VALUES (?,?,0)");
403 $sth->bindParam(1, $id, PDO::PARAM_INT);
404 $sth->bindParam(2, $pagename, PDO::PARAM_STR, 100);
415 function get_latest_version($pagename)
418 extract($this->_table_names);
419 $sth = $dbh->prepare("SELECT latestversion"
420 . " FROM $page_tbl, $recent_tbl"
421 . " WHERE $page_tbl.id=$recent_tbl.id"
424 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
426 return $sth->fetchColumn();
429 function get_previous_version($pagename, $version)
432 extract($this->_table_names);
433 $sth = $dbh->prepare("SELECT version"
434 . " FROM $version_tbl, $page_tbl"
435 . " WHERE $version_tbl.id=$page_tbl.id"
438 . " ORDER BY version DESC"
440 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
441 $sth->bindParam(2, $version, PDO::PARAM_INT);
443 return $sth->fetchColumn();
449 * @param $version int Which version to get.
451 * @return hash The version data, or false if specified version does not
454 function get_versiondata($pagename, $version, $want_content = false)
457 extract($this->_table_names);
458 extract($this->_expressions);
460 assert(is_string($pagename) and $pagename != '');
461 assert($version > 0);
463 // FIXME: optimization: sometimes don't get page data?
465 $fields = $this->page_tbl_fields . ", $page_tbl.pagedata AS pagedata"
466 . ', ' . $this->version_tbl_fields;
468 $fields = $this->page_tbl_fields . ", '' AS pagedata"
469 . ", $version_tbl.version AS version, $version_tbl.mtime AS mtime, "
470 . "$version_tbl.minor_edit AS minor_edit, $iscontent AS have_content, "
471 . "$version_tbl.versiondata as versiondata";
473 $sth = $dbh->prepare("SELECT $fields"
474 . " FROM $page_tbl, $version_tbl"
475 . " WHERE $page_tbl.id=$version_tbl.id"
479 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
480 $sth->bindParam(2, $version, PDO::PARAM_INT);
482 $row = $sth->fetch(PDO::FETCH_NUM);
483 return $row ? $this->_extract_version_data_num($row, $want_content) : false;
486 function _extract_version_data_num($row, $want_content)
492 //$pagename &= $row[1];
493 $data = empty($row[8]) ? array() : $this->_unserialize($row[8]);
494 $data['mtime'] = $row[5];
495 $data['is_minor_edit'] = !empty($row[6]);
497 $data['%content'] = $row[7];
499 $data['%content'] = !empty($row[7]);
501 if (!empty($row[3])) {
502 $data['%pagedata'] = $this->_extract_page_data($row[3], $row[2]);
507 function _extract_version_data_assoc($row)
513 $data = empty($versiondata) ? array() : $this->_unserialize($versiondata);
514 $data['mtime'] = $mtime;
515 $data['is_minor_edit'] = !empty($minor_edit);
517 $data['%content'] = $content;
518 elseif ($have_content)
519 $data['%content'] = true; else
520 $data['%content'] = '';
521 if (!empty($pagedata)) {
522 $data['%pagedata'] = $this->_extract_page_data($pagedata, $hits);
528 * Create a new revision of a page.
530 function set_versiondata($pagename, $version, $data)
533 $version_tbl = $this->_table_names['version_tbl'];
535 $minor_edit = (int)!empty($data['is_minor_edit']);
536 unset($data['is_minor_edit']);
538 $mtime = (int)$data['mtime'];
539 unset($data['mtime']);
540 assert(!empty($mtime));
542 @$content = (string)$data['%content'];
543 unset($data['%content']);
544 unset($data['%pagedata']);
546 $this->lock(array('page', 'recent', 'version', 'nonempty'));
547 $this->beginTransaction();
548 $id = $this->_get_pageid($pagename, true);
549 $backend_type = $this->backendType();
550 // optimize: mysql can do this with one REPLACE INTO.
551 if (substr($backend_type, 0, 5) == 'mysql') {
552 $sth = $dbh->prepare("REPLACE INTO $version_tbl"
553 . " (id,version,mtime,minor_edit,content,versiondata)"
554 . " VALUES(?,?,?,?,?,?)");
555 $sth->bindParam(1, $id, PDO::PARAM_INT);
556 $sth->bindParam(2, $version, PDO::PARAM_INT);
557 $sth->bindParam(3, $mtime, PDO::PARAM_INT);
558 $sth->bindParam(4, $minor_edit, PDO::PARAM_INT);
559 $sth->bindParam(5, $content, PDO::PARAM_STR, 100);
560 $sth->bindParam(6, $this->_serialize($data), PDO::PARAM_STR, 100);
561 $rs = $sth->execute();
563 $sth = $dbh->prepare("DELETE FROM $version_tbl"
564 . " WHERE id=? AND version=?");
565 $sth->bindParam(1, $id, PDO::PARAM_INT);
566 $sth->bindParam(2, $version, PDO::PARAM_INT);
568 $sth = $dbh->prepare("INSERT INTO $version_tbl"
569 . " (id,version,mtime,minor_edit,content,versiondata)"
570 . " VALUES(?,?,?,?,?,?)");
571 $sth->bindParam(1, $id, PDO::PARAM_INT);
572 $sth->bindParam(2, $version, PDO::PARAM_INT);
573 $sth->bindParam(3, $mtime, PDO::PARAM_INT);
574 $sth->bindParam(4, $minor_edit, PDO::PARAM_INT);
575 $sth->bindParam(5, $content, PDO::PARAM_STR, 100);
576 $sth->bindParam(6, $this->_serialize($data), PDO::PARAM_STR, 100);
577 $rs = $sth->execute();
579 $this->_update_recent_table($id);
580 $this->_update_nonempty_table($id);
581 if ($rs) $this->commit();
582 else $this->rollBack();
583 $this->unlock(array('page', 'recent', 'version', 'nonempty'));
587 * Delete an old revision of a page.
589 function delete_versiondata($pagename, $version)
592 extract($this->_table_names);
594 $this->lock(array('version'));
595 if (($id = $this->_get_pageid($pagename))) {
596 $dbh->query("DELETE FROM $version_tbl"
597 . " WHERE id=$id AND version=$version");
598 $this->_update_recent_table($id);
599 // This shouldn't be needed (as long as the latestversion
600 // never gets deleted.) But, let's be safe.
601 $this->_update_nonempty_table($id);
603 $this->unlock(array('version'));
607 * Delete page from the database with backup possibility.
608 * i.e save_page('') and DELETE nonempty id
610 * deletePage increments latestversion in recent to a non-existent version,
611 * and removes the nonempty row,
612 * so that get_latest_version returns id+1 and get_previous_version returns prev id
613 * and page->exists returns false.
615 function delete_page($pagename)
618 extract($this->_table_names);
620 $this->beginTransaction();
621 //$dbh->CommitLock($recent_tbl);
622 if (($id = $this->_get_pageid($pagename, false)) === false) {
627 $user =& $GLOBALS['request']->_user;
628 $meta = array('author' => $user->getId(),
629 'author_id' => $user->getAuthenticatedId(),
631 $this->lock(array('version', 'recent', 'nonempty', 'page', 'link'));
632 $version = $this->get_latest_version($pagename);
633 if ($dbh->query("UPDATE $recent_tbl SET latestversion=latestversion+1,"
634 . "latestmajor=latestversion+1,latestminor=NULL WHERE id=$id")
636 $insert = $dbh->prepare("INSERT INTO $version_tbl"
637 . " (id,version,mtime,minor_edit,content,versiondata)"
638 . " VALUES(?,?,?,?,?,?)");
639 $insert->bindParam(1, $id, PDO::PARAM_INT);
640 $insert->bindParam(2, $version + 1, PDO::PARAM_INT);
641 $insert->bindParam(3, $mtime, PDO::PARAM_INT);
642 $insert->bindParam(4, 0, PDO::PARAM_INT);
643 $insert->bindParam(5, '', PDO::PARAM_STR, 100);
644 $insert->bindParam(6, $this->_serialize($meta), PDO::PARAM_STR, 100);
645 if ($insert->execute()
646 and $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$id")
647 and $this->set_links($pagename, false)
649 // need to keep perms and LOCKED, otherwise you can reset the perm
650 // by action=remove and re-create it with default perms
651 // keep hits but delete meta-data
652 //and $dbh->Execute("UPDATE $page_tbl SET pagedata='' WHERE id=$id")
653 $this->unlock(array('version', 'recent', 'nonempty', 'page', 'link'));
658 $this->unlock(array('version', 'recent', 'nonempty', 'page', 'link'));
664 function purge_page($pagename)
667 extract($this->_table_names);
669 $this->lock(array('version', 'recent', 'nonempty', 'page', 'link'));
670 if (($id = $this->_get_pageid($pagename, false))) {
671 $dbh->query("DELETE FROM $version_tbl WHERE id=$id");
672 $dbh->query("DELETE FROM $recent_tbl WHERE id=$id");
673 $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$id");
674 $this->set_links($pagename, false);
675 $sth = $dbh->prepare("SELECT COUNT(*) FROM $link_tbl WHERE linkto=$id");
677 if ($sth->fetchColumn()) {
678 // We're still in the link table (dangling link) so we can't delete this
680 $dbh->query("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");
683 $dbh->query("DELETE FROM $page_tbl WHERE id=$id");
687 $result = -1; // already purged or not existing
689 $this->unlock(array('version', 'recent', 'nonempty', 'page', 'link'));
693 // The only thing we might be interested in updating which we can
694 // do fast in the flags (minor_edit). I think the default
695 // update_versiondata will work fine...
696 //function update_versiondata($pagename, $version, $data) {
699 function set_links($pagename, $links)
701 // Update link table.
702 // FIXME: optimize: mysql can do this all in one big INSERT/REPLACE.
705 extract($this->_table_names);
707 $this->lock(array('link'));
708 $pageid = $this->_get_pageid($pagename, true);
711 $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
712 foreach ($links as $link) {
713 if (isset($linkseen[$link]))
715 $linkseen[$link] = true;
716 $linkid = $this->_get_pageid($link, true);
718 $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto)"
719 . " VALUES ($pageid, $linkid)");
722 // purge page table: delete all non-referenced pages
723 // for all previously linked pages...
724 $sth = $dbh->prepare("SELECT $link_tbl.linkto as id FROM $link_tbl" .
725 " WHERE linkfrom=$pageid");
727 foreach ($sth->fetchAll(PDO::FETCH_NUM) as $id) {
728 // ...check if the page is empty and has no version
729 $sth1 = $dbh->prepare("SELECT $page_tbl.id FROM $page_tbl"
730 . " LEFT JOIN $nonempty_tbl USING (id) "
731 . " LEFT JOIN $version_tbl USING (id)"
732 . " WHERE ISNULL($nonempty_tbl.id) AND"
733 . " ISNULL($version_tbl.id) AND $page_tbl.id=$id");
735 if ($sth1->fetchColumn()) {
736 $dbh->query("DELETE FROM $page_tbl WHERE id=$id"); // this purges the link
737 $dbh->query("DELETE FROM $recent_tbl WHERE id=$id"); // may fail
740 $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid");
742 $this->unlock(array('link'));
747 * Find pages which link to or are linked from a page.
749 * Optimization: save request->_dbi->_iwpcache[] to avoid further iswikipage checks
750 * (linkExistingWikiWord or linkUnknownWikiWord)
751 * This is called on every page header GleanDescription, so we can store all the existing links.
753 function get_links($pagename, $reversed = true, $include_empty = false,
754 $sortby = '', $limit = '', $exclude = '')
757 extract($this->_table_names);
760 list($have, $want) = array('linkee', 'linker');
762 list($have, $want) = array('linker', 'linkee');
763 $orderby = $this->sortby($sortby, 'db', array('pagename'));
764 if ($orderby) $orderby = " ORDER BY $want." . $orderby;
765 if ($exclude) // array of pagenames
766 $exclude = " AND $want.pagename NOT IN " . $this->_sql_set($exclude);
769 $limit = $this->_limit_sql($limit);
771 $sth = $dbh->prepare("SELECT $want.id AS id, $want.pagename AS pagename,"
772 . " $want.hits AS hits"
773 . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee"
774 . (!$include_empty ? ", $nonempty_tbl" : '')
775 . " WHERE linkfrom=linker.id AND linkto=linkee.id"
776 . " AND $have.pagename=?"
777 . (!$include_empty ? " AND $nonempty_tbl.id=$want.id" : "")
778 //. " GROUP BY $want.id"
782 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
784 $result = $sth->fetch(PDO::FETCH_BOTH);
785 return new WikiDB_backend_PDO_iter($this, $result, $this->page_tbl_field_list);
789 * Find if a page links to another page
791 function exists_link($pagename, $link, $reversed = false)
794 extract($this->_table_names);
797 list($have, $want) = array('linkee', 'linker');
799 list($have, $want) = array('linker', 'linkee');
800 $sth = $dbh->prepare("SELECT CASE WHEN $want.pagename THEN 1 ELSE 0 END"
801 . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee, $nonempty_tbl"
802 . " WHERE linkfrom=linker.id AND linkto=linkee.id"
803 . " AND $have.pagename=?"
804 . " AND $want.pagename=?");
805 $sth->bindParam(1, $pagename, PDO::PARAM_STR, 100);
806 $sth->bindParam(2, $link, PDO::PARAM_STR, 100);
808 return $sth->fetchColumn();
811 function get_all_pages($include_empty = false, $sortby = '', $limit = '', $exclude = '')
814 extract($this->_table_names);
815 $orderby = $this->sortby($sortby, 'db');
816 if ($orderby) $orderby = ' ORDER BY ' . $orderby;
817 if ($exclude) // array of pagenames
818 $exclude = " AND $page_tbl.pagename NOT IN " . $this->_sql_set($exclude);
821 $limit = $this->_limit_sql($limit);
823 if (strstr($orderby, 'mtime ')) { // was ' mtime'
824 if ($include_empty) {
826 . $this->page_tbl_fields
827 . " FROM $page_tbl, $recent_tbl, $version_tbl"
828 . " WHERE $page_tbl.id=$recent_tbl.id"
829 . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
834 . $this->page_tbl_fields
835 . " FROM $nonempty_tbl, $page_tbl, $recent_tbl, $version_tbl"
836 . " WHERE $nonempty_tbl.id=$page_tbl.id"
837 . " AND $page_tbl.id=$recent_tbl.id"
838 . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"
843 if ($include_empty) {
845 . $this->page_tbl_fields
847 . ($exclude ? " WHERE $exclude" : '')
851 . $this->page_tbl_fields
852 . " FROM $nonempty_tbl, $page_tbl"
853 . " WHERE $nonempty_tbl.id=$page_tbl.id"
858 $sth = $dbh->prepare($sql . $limit);
860 $result = $sth->fetch(PDO::FETCH_BOTH);
861 return new WikiDB_backend_PDO_iter($this, $result, $this->page_tbl_field_list);
867 function text_search($search, $fullsearch = false, $sortby = '', $limit = '', $exclude = '')
870 extract($this->_table_names);
871 $orderby = $this->sortby($sortby, 'db');
872 if ($orderby) $orderby = ' ORDER BY ' . $orderby;
873 $limit = $this->_limit_sql($limit);
875 $table = "$nonempty_tbl, $page_tbl";
876 $join_clause = "$nonempty_tbl.id=$page_tbl.id";
877 $fields = $this->page_tbl_fields;
878 $field_list = $this->page_tbl_field_list;
879 $searchobj = new WikiDB_backend_PDO_search($search, $dbh);
882 $table .= ", $recent_tbl";
883 $join_clause .= " AND $page_tbl.id=$recent_tbl.id";
885 $table .= ", $version_tbl";
886 $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version";
888 $fields .= ",$page_tbl.pagedata as pagedata," . $this->version_tbl_fields;
889 $field_list = array_merge($field_list, array('pagedata'), $this->version_tbl_field_list);
890 $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");
892 $callback = new WikiMethodCb($searchobj, "_pagename_match_clause");
895 $search_clause = $search->makeSqlClauseObj($callback);
896 $sth = $dbh->prepare("SELECT $fields FROM $table"
897 . " WHERE $join_clause"
898 . " AND ($search_clause)"
902 $result = $sth->fetch(PDO::FETCH_NUM);
903 $iter = new WikiDB_backend_PDO_iter($this, $result, $field_list);
904 $iter->stoplisted = $searchobj->stoplisted;
909 * TODO: efficiently handle wildcards exclusion: exclude=Php* => 'Php%',
910 * not sets. See above, but the above methods find too much.
911 * This is only for already resolved wildcards:
912 * " WHERE $page_tbl.pagename NOT IN ".$this->_sql_set(array('page1','page2'));
914 function _sql_set(&$pagenames)
917 foreach ($pagenames as $p) {
918 $s .= ($this->_dbh->qstr($p) . ",");
920 return substr($s, 0, -1) . ")";
924 * Find highest or lowest hit counts.
926 function most_popular($limit = 20, $sortby = '-hits')
929 extract($this->_table_names);
936 $where = " AND hits > 0";
938 if ($sortby != '-hits') {
939 if ($order = $this->sortby($sortby, 'db')) $orderby = " ORDER BY " . $order;
942 $orderby = " ORDER BY hits $order";
944 . $this->page_tbl_fields
945 . " FROM $nonempty_tbl, $page_tbl"
946 . " WHERE $nonempty_tbl.id=$page_tbl.id"
950 $sth = $dbh->prepare($sql . $this->_limit_sql($limit));
952 $sth = $dbh->prepare($sql);
955 $result = $sth->fetch(PDO::FETCH_NUM);
956 return new WikiDB_backend_PDO_iter($this, $result, $this->page_tbl_field_list);
960 * Find recent changes.
962 function most_recent($params)
966 $include_minor_revisions = false;
967 $exclude_major_revisions = false;
968 $include_all_revisions = false;
972 extract($this->_table_names);
976 $pick[] = "mtime >= $since";
978 if ($include_all_revisions) {
979 // Include all revisions of each page.
980 $table = "$page_tbl, $version_tbl";
981 $join_clause = "$page_tbl.id=$version_tbl.id";
983 if ($exclude_major_revisions) {
984 // Include only minor revisions
985 $pick[] = "minor_edit <> 0";
986 } elseif (!$include_minor_revisions) {
987 // Include only major revisions
988 $pick[] = "minor_edit = 0";
991 $table = "$page_tbl, $recent_tbl";
992 $join_clause = "$page_tbl.id=$recent_tbl.id";
993 $table .= ", $version_tbl";
994 $join_clause .= " AND $version_tbl.id=$page_tbl.id";
996 if ($exclude_major_revisions) {
997 // Include only most recent minor revision
998 $pick[] = 'version=latestminor';
999 } elseif (!$include_minor_revisions) {
1000 // Include only most recent major revision
1001 $pick[] = 'version=latestmajor';
1003 // Include only the latest revision (whether major or minor).
1004 $pick[] = 'version=latestversion';
1012 $where_clause = $join_clause;
1014 $where_clause .= " AND " . join(" AND ", $pick);
1016 . $this->page_tbl_fields . ", " . $this->version_tbl_fields
1018 . " WHERE $where_clause"
1019 . " ORDER BY mtime $order";
1021 $sth = $dbh->prepare($sql . $this->_limit_sql($limit));
1023 $sth = $dbh->prepare($sql);
1026 $result = $sth->fetch(PDO::FETCH_NUM);
1027 return new WikiDB_backend_PDO_iter($this, $result,
1028 array_merge($this->page_tbl_field_list, $this->version_tbl_field_list));
1032 * Find referenced empty pages.
1034 function wanted_pages($exclude_from = '', $exclude = '', $sortby = '', $limit = '')
1036 $dbh = &$this->_dbh;
1037 extract($this->_table_names);
1038 if ($orderby = $this->sortby($sortby, 'db', array('pagename', 'wantedfrom')))
1039 $orderby = 'ORDER BY ' . $orderby;
1041 if ($exclude_from) // array of pagenames
1042 $exclude_from = " AND linked.pagename NOT IN " . $this->_sql_set($exclude_from);
1043 if ($exclude) // array of pagenames
1044 $exclude = " AND $page_tbl.pagename NOT IN " . $this->_sql_set($exclude);
1047 all empty pages, independent of linkstatus:
1048 select pagename as empty from page left join nonempty using(id) where isnull(nonempty.id);
1049 only all empty pages, which have a linkto:
1050 select page.pagename, linked.pagename as wantedfrom from link, page as linked
1051 left join page on(link.linkto=page.id) left join nonempty on(link.linkto=nonempty.id)
1052 where isnull(nonempty.id) and linked.id=link.linkfrom;
1054 $sql = "SELECT p.pagename, pp.pagename as wantedfrom"
1055 . " FROM $page_tbl p JOIN $link_tbl linked"
1056 . " LEFT JOIN $page_tbl pp ON linked.linkto = pp.id"
1057 . " LEFT JOIN $nonempty_tbl ne ON linked.linkto = ne.id"
1058 . " WHERE ne.id is NULL"
1059 . " AND p.id = linked.linkfrom"
1064 $sth = $dbh->prepare($sql . $this->_limit_sql($limit));
1066 $sth = $dbh->prepare($sql);
1069 $result = $sth->fetch(PDO::FETCH_NUM);
1070 return new WikiDB_backend_PDO_iter($this, $result, array('pagename', 'wantedfrom'));
1074 * Rename page in the database.
1076 function rename_page($pagename, $to)
1078 $dbh = &$this->_dbh;
1079 extract($this->_table_names);
1081 $this->lock(array('page', 'version', 'recent', 'nonempty', 'link'));
1082 if (($id = $this->_get_pageid($pagename, false))) {
1083 if ($new = $this->_get_pageid($to, false)) {
1085 // This page does not exist (already verified before), but exists in the page table.
1086 // So we delete this page.
1087 $dbh->query("DELETE FROM $page_tbl WHERE id=$new");
1088 $dbh->query("DELETE FROM $version_tbl WHERE id=$new");
1089 $dbh->query("DELETE FROM $recent_tbl WHERE id=$new");
1090 $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$new");
1091 // We have to fix all referring tables to the old id
1092 $dbh->query("UPDATE $link_tbl SET linkfrom=$id WHERE linkfrom=$new");
1093 $dbh->query("UPDATE $link_tbl SET linkto=$id WHERE linkto=$new");
1095 $sth = $dbh->prepare("UPDATE $page_tbl SET pagename=? WHERE id=?");
1096 $sth->bindParam(1, $to, PDO::PARAM_STR, 100);
1097 $sth->bindParam(2, $id, PDO::PARAM_INT);
1100 $this->unlock(array('page'));
1104 function _update_recent_table($pageid = false)
1106 $dbh = &$this->_dbh;
1107 extract($this->_table_names);
1108 extract($this->_expressions);
1110 $pageid = (int)$pageid;
1112 // optimize: mysql can do this with one REPLACE INTO.
1113 $backend_type = $this->backendType();
1114 if (substr($backend_type, 0, 5) == 'mysql') {
1115 $sth = $dbh->prepare("REPLACE INTO $recent_tbl"
1116 . " (id, latestversion, latestmajor, latestminor)"
1117 . " SELECT id, $maxversion, $maxmajor, $maxminor"
1118 . " FROM $version_tbl"
1119 . ($pageid ? " WHERE id=$pageid" : "")
1123 $this->lock(array('recent'));
1124 $sth = $dbh->prepare("DELETE FROM $recent_tbl"
1125 . ($pageid ? " WHERE id=$pageid" : ""));
1127 $sth = $dbh->prepare("INSERT INTO $recent_tbl"
1128 . " (id, latestversion, latestmajor, latestminor)"
1129 . " SELECT id, $maxversion, $maxmajor, $maxminor"
1130 . " FROM $version_tbl"
1131 . ($pageid ? " WHERE id=$pageid" : "")
1134 $this->unlock(array('recent'));
1138 function _update_nonempty_table($pageid = false)
1140 $dbh = &$this->_dbh;
1141 extract($this->_table_names);
1142 extract($this->_expressions);
1144 $pageid = (int)$pageid;
1146 extract($this->_expressions);
1147 $this->lock(array('nonempty'));
1148 $dbh->query("DELETE FROM $nonempty_tbl"
1149 . ($pageid ? " WHERE id=$pageid" : ""));
1150 $dbh->query("INSERT INTO $nonempty_tbl (id)"
1151 . " SELECT $recent_tbl.id"
1152 . " FROM $recent_tbl, $version_tbl"
1153 . " WHERE $recent_tbl.id=$version_tbl.id"
1154 . " AND version=latestversion"
1155 // We have some specifics here (Oracle)
1156 //. " AND content<>''"
1157 . " AND content $notempty"
1158 . ($pageid ? " AND $recent_tbl.id=$pageid" : ""));
1159 $this->unlock(array('nonempty'));
1163 * Grab a write lock on the tables in the SQL database.
1165 * Calls can be nested. The tables won't be unlocked until
1166 * _unlock_database() is called as many times as _lock_database().
1168 public function lock($tables, $write_lock = true)
1170 if ($this->_lock_count++ == 0) {
1171 $this->_current_lock = $tables;
1172 if (!$this->_hasTransactions)
1173 $this->_lock_tables($tables, $write_lock);
1178 * Overridden by non-transaction safe backends.
1180 function _lock_tables($tables, $write_lock)
1182 $lock_type = $write_lock ? "WRITE" : "READ";
1183 foreach ($this->_table_names as $key => $table) {
1184 $locks[] = "$table $lock_type";
1186 $this->_dbh->query("LOCK TABLES " . join(",", $locks));
1190 * Release a write lock on the tables in the SQL database.
1192 * @param $force boolean Unlock even if not every call to lock() has been matched
1193 * by a call to unlock().
1195 * @see _lock_database
1197 public function unlock($tables = false, $force = false)
1199 if ($this->_lock_count == 0) {
1200 $this->_current_lock = false;
1203 if (--$this->_lock_count <= 0 || $force) {
1204 if (!$this->_hasTransactions)
1205 $this->_unlock_tables($tables);
1206 $this->_current_lock = false;
1207 $this->_lock_count = 0;
1212 * overridden by non-transaction safe backends
1214 function _unlock_tables($tables)
1216 $this->_dbh->query("UNLOCK TABLES");
1222 function _serialize($data)
1226 assert(is_array($data));
1227 return serialize($data);
1233 function _unserialize($data)
1235 return empty($data) ? array() : unserialize($data);
1238 /* some variables and functions for DB backend abstraction (action=upgrade) */
1241 return $this->_dbh->database;
1244 function backendType()
1246 return $this->_dbh->databaseType;
1249 function connection()
1251 trigger_error("PDO: connectionID unsupported", E_USER_ERROR);
1255 function listOfTables()
1257 trigger_error("PDO: virtual listOfTables", E_USER_ERROR);
1261 function listOfFields($database, $table)
1263 trigger_error("PDO: virtual listOfFields", E_USER_ERROR);
1268 * LIMIT with OFFSET is not SQL specified.
1269 * mysql: LIMIT $offset, $count
1270 * pgsql,sqlite: LIMIT $count OFFSET $offset
1271 * InterBase,FireBird: ROWS $offset TO $last
1272 * mssql: TOP $rows => TOP $last
1274 * IBM DB2: FetchFirst
1275 * See http://search.cpan.org/dist/SQL-Abstract-Limit/lib/SQL/Abstract/Limit.pm
1277 SELECT field_list FROM $table X WHERE where_clause AND
1279 SELECT COUNT(*) FROM $table WHERE $pk > X.$pk
1281 BETWEEN $offset AND $last
1282 ORDER BY $pk $asc_desc
1284 function _limit_sql($limit = false)
1287 list($offset, $count) = $this->limit($limit);
1289 $limit = " LIMIT $count";
1290 trigger_error("unsupported OFFSET in SQL ignored", E_USER_WARNING);
1292 $limit = " LIMIT $count";
1298 function write_accesslog(&$entry)
1301 $dbh = &$this->_dbh;
1302 $log_tbl = $entry->_accesslog->logtable;
1303 $dbh->prepare("INSERT INTO $log_tbl"
1304 . " (time_stamp,remote_host,remote_user,request_method,request_line,request_args,"
1305 . "request_file,request_uri,request_time,status,bytes_sent,referer,agent,request_duration)"
1306 . " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
1307 // Either use unixtime as %d (long), or the native timestamp format.
1308 $sth->bindParam(1, $entry->time, PDO::PARAM_INT);
1309 $sth->bindParam(2, $entry->host, PDO::PARAM_STR, 100);
1310 $sth->bindParam(3, $entry->user, PDO::PARAM_STR, 50);
1311 $sth->bindParam(4, $entry->request_method, PDO::PARAM_STR, 10);
1312 $sth->bindParam(5, $entry->request, PDO::PARAM_STR, 255);
1313 $sth->bindParam(6, $entry->request_args, PDO::PARAM_STR, 255);
1314 $sth->bindParam(7, $entry->request_uri, PDO::PARAM_STR, 255);
1315 $sth->bindParam(8, $entry->_ncsa_time($entry->time), PDO::PARAM_STR, 28);
1316 $sth->bindParam(9, $entry->time, PDO::PARAM_INT);
1317 $sth->bindParam(10, $entry->status, PDO::PARAM_INT);
1318 $sth->bindParam(11, $entry->size, PDO::PARAM_INT);
1319 $sth->bindParam(12, $entry->referer, PDO::PARAM_STR, 255);
1320 $sth->bindParam(13, $entry->user_agent, PDO::PARAM_STR, 255);
1321 $sth->bindParam(14, $entry->duration, PDO::PARAM_FLOAT);
1326 class WikiDB_backend_PDO_generic_iter
1327 extends WikiDB_backend_iterator
1329 function __construct($backend, $query_result, $field_list = NULL)
1331 $this->_backend = &$backend;
1332 $this->_result = $query_result;
1333 //$this->_fields = $field_list;
1338 if (!is_object($this->_result)) {
1341 $count = $this->_result->rowCount();
1347 $result = &$this->_result;
1348 if (!is_object($result)) {
1351 return $result->fetch(PDO::FETCH_BOTH);
1356 if ($this->_result) {
1357 unset($this->_result);
1362 class WikiDB_backend_PDO_iter
1363 extends WikiDB_backend_PDO_generic_iter
1367 $result = &$this->_result;
1368 if (!is_object($result)) {
1371 $this->_backend = &$backend;
1372 $rec = $result->fetch(PDO::FETCH_ASSOC);
1374 if (isset($rec['pagedata']))
1375 $rec['pagedata'] = $backend->_extract_page_data($rec['pagedata'], $rec['hits']);
1376 if (!empty($rec['version'])) {
1377 $rec['versiondata'] = $backend->_extract_version_data_assoc($rec);
1383 class WikiDB_backend_PDO_search extends WikiDB_backend_search_sql
1387 // Following function taken from Pear::DB (prev. from adodb-pear.inc.php).
1388 // Eventually, change index.php to provide the relevant information
1391 * Parse a data source name.
1393 * Additional keys can be added by appending a URI query string to the
1396 * The format of the supplied DSN is in its fullest form:
1398 * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
1401 * Most variations are allowed:
1403 * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
1404 * phptype://username:password@hostspec/database_name
1405 * phptype://username:password@hostspec
1406 * phptype://username@hostspec
1407 * phptype://hostspec/database
1408 * phptype://hostspec
1413 * @param string $dsn Data Source Name to be parsed
1415 * @return array an associative array with the following keys:
1416 * + phptype: Database backend used in PHP (mysql, odbc etc.)
1417 * + dbsyntax: Database used with regards to SQL syntax etc. (ignored with PDO)
1418 * + protocol: Communication protocol to use (tcp, unix, pipe etc.)
1419 * + hostspec: Host specification (hostname[:port])
1420 * + database: Database to use on the DBMS server
1421 * + username: User name for login
1422 * + password: Password for login
1424 * @author Tomas V.V.Cox <cox@idecnet.com>
1426 function parseDSN($dsn)
1430 'dbsyntax' => false,
1431 'username' => false,
1432 'password' => false,
1433 'protocol' => false,
1434 'hostspec' => false,
1437 'database' => false,
1440 if (is_array($dsn)) {
1441 $dsn = array_merge($parsed, $dsn);
1442 if (!$dsn['dbsyntax']) {
1443 $dsn['dbsyntax'] = $dsn['phptype'];
1448 // Find phptype and dbsyntax
1449 if (($pos = strpos($dsn, '://')) !== false) {
1450 $str = substr($dsn, 0, $pos);
1451 $dsn = substr($dsn, $pos + 3);
1457 // Get phptype and dbsyntax
1458 // $str => phptype(dbsyntax)
1459 if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
1460 $parsed['phptype'] = $arr[1];
1461 $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
1463 $parsed['phptype'] = $str;
1464 $parsed['dbsyntax'] = $str;
1471 // Get (if found): username and password
1472 // $dsn => username:password@protocol+hostspec/database
1473 if (($at = strrpos($dsn, '@')) !== false) {
1474 $str = substr($dsn, 0, $at);
1475 $dsn = substr($dsn, $at + 1);
1476 if (($pos = strpos($str, ':')) !== false) {
1477 $parsed['username'] = rawurldecode(substr($str, 0, $pos));
1478 $parsed['password'] = rawurldecode(substr($str, $pos + 1));
1480 $parsed['username'] = rawurldecode($str);
1484 // Find protocol and hostspec
1486 // $dsn => proto(proto_opts)/database
1487 if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
1489 $proto_opts = $match[2] ? $match[2] : false;
1492 // $dsn => protocol+hostspec/database (old format)
1494 if (strpos($dsn, '+') !== false) {
1495 list($proto, $dsn) = explode('+', $dsn, 2);
1497 if (strpos($dsn, '/') !== false) {
1498 list($proto_opts, $dsn) = explode('/', $dsn, 2);
1505 // process the different protocol options
1506 $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
1507 $proto_opts = rawurldecode($proto_opts);
1508 if ($parsed['protocol'] == 'tcp') {
1509 if (strpos($proto_opts, ':') !== false) {
1510 list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
1512 $parsed['hostspec'] = $proto_opts;
1514 } elseif ($parsed['protocol'] == 'unix') {
1515 $parsed['socket'] = $proto_opts;
1518 // Get dabase if any
1522 if (($pos = strpos($dsn, '?')) === false) {
1523 $parsed['database'] = $dsn;
1524 // /database?param1=value1¶m2=value2
1526 $parsed['database'] = substr($dsn, 0, $pos);
1527 $dsn = substr($dsn, $pos + 1);
1528 if (strpos($dsn, '&') !== false) {
1529 $opts = explode('&', $dsn);
1530 } else { // database?param1=value1
1531 $opts = array($dsn);
1533 foreach ($opts as $opt) {
1534 list($key, $value) = explode('=', $opt);
1535 if (!isset($parsed[$key])) {
1536 // don't allow params overwrite
1537 $parsed[$key] = rawurldecode($value);
1549 // c-basic-offset: 4
1550 // c-hanging-comment-ender-p: nil
1551 // indent-tabs-mode: nil