⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 peardb.php

📁 PhpWiki是sourceforge的一个开源项目
💻 PHP
📖 第 1 页 / 共 4 页
字号:
        return $data;    }    /**     * Create a new revision of a page.     */    function set_versiondata($pagename, $version, $data) {        $dbh = &$this->_dbh;        $version_tbl = $this->_table_names['version_tbl'];                $minor_edit = (int) !empty($data['is_minor_edit']);        unset($data['is_minor_edit']);                $mtime = (int)$data['mtime'];        unset($data['mtime']);        assert(!empty($mtime));        @$content = (string) $data['%content'];        unset($data['%content']);        unset($data['%pagedata']);                $this->lock();        $id = $this->_get_pageid($pagename, true);        // FIXME: optimize: mysql can do this with one REPLACE INTO (I think).        $dbh->query(sprintf("DELETE FROM $version_tbl"                            . " WHERE id=%d AND version=%d",                            $id, $version));        /* mysql optimized version.         $dbh->query(sprintf("INSERT INTO $version_tbl"                            . " (id,version,mtime,minor_edit,content,versiondata)"                            . " VALUES(%d,%d,%d,%d,'%s','%s')",                            $id, $version, $mtime, $minor_edit,                            $dbh->quoteSmart($content),                            $dbh->quoteSmart($this->_serialize($data))));        */        // generic slow PearDB bind eh quoting.        $dbh->query("INSERT INTO $version_tbl"                    . " (id,version,mtime,minor_edit,content,versiondata)"                    . " VALUES(?, ?, ?, ?, ?, ?)",                    array($id, $version, $mtime, $minor_edit, $content,                    $this->_serialize($data)));        $this->_update_recent_table($id);        $this->_update_nonempty_table($id);                $this->unlock();    }        /**     * Delete an old revision of a page.     */    function delete_versiondata($pagename, $version) {        $dbh = &$this->_dbh;        extract($this->_table_names);        $this->lock();        if ( ($id = $this->_get_pageid($pagename)) ) {            $dbh->query("DELETE FROM $version_tbl"                        . " WHERE id=$id AND version=$version");            $this->_update_recent_table($id);            // This shouldn't be needed (as long as the latestversion            // never gets deleted.)  But, let's be safe.            $this->_update_nonempty_table($id);        }        $this->unlock();    }    /**     * Delete page from the database with backup possibility.     * i.e save_page('') and DELETE nonempty id     * Can be undone and is seen in RecentChanges.     */    /* // see parent backend.php    function delete_page($pagename) {        $mtime = time();        $user =& $GLOBALS['request']->_user;        $vdata = array('author' => $user->getId(),                       'author_id' => $user->getAuthenticatedId(),                       'mtime' => $mtime);        $this->lock();        $version = $this->get_latest_version($pagename);        $this->set_versiondata($pagename, $version+1, $vdata);        $this->set_links($pagename, false);        $pagedata = get_pagedata($pagename);        $this->update_pagedata($pagename, array('hits' => $pagedata['hits']));        $this->unlock();    }    */    /**     * Delete page completely from the database.     * I'm not sure if this is what we want. Maybe just delete the revisions     */    function purge_page($pagename) {        $dbh = &$this->_dbh;        extract($this->_table_names);                $this->lock();        if ( ($id = $this->_get_pageid($pagename, false)) ) {            $dbh->query("DELETE FROM $version_tbl  WHERE id=$id");            $dbh->query("DELETE FROM $recent_tbl   WHERE id=$id");            $dbh->query("DELETE FROM $nonempty_tbl WHERE id=$id");            $dbh->query("DELETE FROM $link_tbl     WHERE linkfrom=$id");            $nlinks = $dbh->getOne("SELECT COUNT(*) FROM $link_tbl WHERE linkto=$id");            if ($nlinks) {                // We're still in the link table (dangling link) so we can't delete this                // altogether.                $dbh->query("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");                $result = 0;            }            else {                $dbh->query("DELETE FROM $page_tbl WHERE id=$id");                $result = 1;            }            $this->_update_recent_table();            $this->_update_nonempty_table();        } else {            $result = -1; // already purged or not existing        }        $this->unlock();        return $result;    }    // The only thing we might be interested in updating which we can    // do fast in the flags (minor_edit).   I think the default    // update_versiondata will work fine...    //function update_versiondata($pagename, $version, $data) {    //}    function set_links($pagename, $links) {        // Update link table.        // FIXME: optimize: mysql can do this all in one big INSERT.        $dbh = &$this->_dbh;        extract($this->_table_names);        $this->lock();        $pageid = $this->_get_pageid($pagename, true);        $dbh->query("DELETE FROM $link_tbl WHERE linkfrom=$pageid");	if ($links) {            foreach($links as $link) {                if (isset($linkseen[$link]))                    continue;                $linkseen[$link] = true;                $linkid = $this->_get_pageid($link, true);                $dbh->query("INSERT INTO $link_tbl (linkfrom, linkto)"                            . " VALUES ($pageid, $linkid)");            }	}        $this->unlock();    }        /**     * Find pages which link to or are linked from a page.     */    function get_links($pagename, $reversed=true, $include_empty=false,                       $sortby=false, $limit=false, $exclude='') {        $dbh = &$this->_dbh;        extract($this->_table_names);        if ($reversed)            list($have,$want) = array('linkee', 'linker');        else            list($have,$want) = array('linker', 'linkee');        $orderby = $this->sortby($sortby, 'db', array('pagename'));        if ($orderby) $orderby = ' ORDER BY $want.' . $orderby;        if ($exclude) // array of pagenames            $exclude = " AND $want.pagename NOT IN ".$this->_sql_set($exclude);        else             $exclude='';        $qpagename = $dbh->escapeSimple($pagename);        $sql = "SELECT $want.id as id, $want.pagename as pagename, $want.hits as hits"            // Looks like 'AS' in column alias is a MySQL thing, Oracle does not like it            // and the PostgresSQL manual does not have it either            // Since it is optional in mySQL, just remove it...            . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee"            . (!$include_empty ? ", $nonempty_tbl" : '')            . " WHERE linkfrom=linker.id AND linkto=linkee.id"            . "  AND $have.pagename='$qpagename'"            . (!$include_empty ? " AND $nonempty_tbl.id=$want.id" : "")            //. " GROUP BY $want.id"            . $exclude            . $orderby;        if ($limit) {            // extract from,count from limit            list($from,$count) = $this->limit($limit);            $result = $dbh->limitQuery($sql, $from, $count);        } else {            $result = $dbh->query($sql);        }                return new WikiDB_backend_PearDB_iter($this, $result);    }    /**     * Find if a page links to another page     */    function exists_link($pagename, $link, $reversed=false) {        $dbh = &$this->_dbh;        extract($this->_table_names);        if ($reversed)            list($have, $want) = array('linkee', 'linker');        else            list($have, $want) = array('linker', 'linkee');        $qpagename = $dbh->escapeSimple($pagename);        $qlink = $dbh->escapeSimple($link);        $row = $dbh->GetRow("SELECT IF($want.pagename,1,0) as result"                                . " FROM $link_tbl, $page_tbl linker, $page_tbl linkee, $nonempty_tbl"                                . " WHERE linkfrom=linker.id AND linkto=linkee.id"                                . " AND $have.pagename='$qpagename'"                                . " AND $want.pagename='$qlink'"                                . " LIMIT 1");        return $row['result'];    }    function get_all_pages($include_empty=false, $sortby=false, $limit=false, $exclude='') {        $dbh = &$this->_dbh;        extract($this->_table_names);        $orderby = $this->sortby($sortby, 'db');        if ($orderby) $orderby = ' ORDER BY ' . $orderby;        if ($exclude) // array of pagenames            $exclude = " AND $page_tbl.pagename NOT IN ".$this->_sql_set($exclude);        else             $exclude='';        if (strstr($orderby, 'mtime ')) { // multiple columns possible            if ($include_empty) {                $sql = "SELECT "                    . $this->page_tbl_fields                    . " FROM $page_tbl, $recent_tbl, $version_tbl"                    . " WHERE $page_tbl.id=$recent_tbl.id"                    . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"                    . $exclude                    . $orderby;            }            else {                $sql = "SELECT "                    . $this->page_tbl_fields                    . " FROM $nonempty_tbl, $page_tbl, $recent_tbl, $version_tbl"                    . " WHERE $nonempty_tbl.id=$page_tbl.id"                    . " AND $page_tbl.id=$recent_tbl.id"                    . " AND $page_tbl.id=$version_tbl.id AND latestversion=version"                    . $exclude                    . $orderby;            }        } else {            if ($include_empty) {                $sql = "SELECT "                    . $this->page_tbl_fields                     ." FROM $page_tbl"                    . ($exclude ? " WHERE $exclude" : '')                    . $orderby;            }            else {                $sql = "SELECT "                    . $this->page_tbl_fields                    . " FROM $nonempty_tbl, $page_tbl"                    . " WHERE $nonempty_tbl.id=$page_tbl.id"                    . $exclude                    . $orderby;            }        }        if ($limit) {            // extract from,count from limit            list($from,$count) = $this->limit($limit);            $result = $dbh->limitQuery($sql, $from, $count);        } else {            $result = $dbh->query($sql);        }        return new WikiDB_backend_PearDB_iter($this, $result);    }            /**     * Title search.     */    function text_search($search, $fulltext=false) {        $dbh = &$this->_dbh;        extract($this->_table_names);        $searchclass = get_class($this)."_search";        // no need to define it everywhere and then fallback. memory!        if (!class_exists($searchclass))            $searchclass = "WikiDB_backend_PearDB_search";        $searchobj = new $searchclass($search, $dbh);                $table = "$nonempty_tbl, $page_tbl";        $join_clause = "$nonempty_tbl.id=$page_tbl.id";        $fields = $this->page_tbl_fields;        if ($fulltext) {            $table .= ", $recent_tbl";            $join_clause .= " AND $page_tbl.id=$recent_tbl.id";            $table .= ", $version_tbl";            $join_clause .= " AND $page_tbl.id=$version_tbl.id AND latestversion=version";            $fields .= ", $page_tbl.pagedata as pagedata, " . $this->version_tbl_fields;            $callback = new WikiMethodCb($searchobj, "_fulltext_match_clause");        } else {            $callback = new WikiMethodCb($searchobj, "_pagename_match_clause");        }        $search_clause = $search->makeSqlClauseObj($callback);                $result = $dbh->query("SELECT $fields FROM $table"                              . " WHERE $join_clause"                              . "  AND ($search_clause)"                              . " ORDER BY pagename");                return new WikiDB_backend_PearDB_iter($this, $result);    }    //Todo: check if the better Mysql MATCH operator is supported,    // (ranked search) and also google like expressions.    function _sql_match_clause($word) {        $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);        $word = $this->_dbh->escapeSimple($word);        //$page_tbl = $this->_table_names['page_tbl'];        //Note: Mysql 4.1.0 has a bug which fails with binary fields.        //      e.g. if word is lowercased.        // http://bugs.mysql.com/bug.php?id=1491        return "LOWER(pagename) LIKE '%$word%'";    }    function _sql_casematch_clause($word) {        $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);        $word = $this->_dbh->escapeSimple($word);        return "pagename LIKE '%$word%'";    }    function _fullsearch_sql_match_clause($word) {        $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);        $word = $this->_dbh->escapeSimple($word);        //$page_tbl = $this->_table_names['page_tbl'];        //Mysql 4.1.1 has a bug which fails here if word is lowercased.        return "LOWER(pagename) LIKE '%$word%' OR content LIKE '%$word%'";    }    function _fullsearch_sql_casematch_clause($word) {        $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);        $word = $this->_dbh->escapeSimple($word);        return "pagename LIKE '%$word%' OR content LIKE '%$word%'";    }    /**     * Find highest or lowest hit counts.     */    function most_popular($limit=0, $sortby='-hits') {        $dbh = &$this->_dbh;        extract($this->_table_names);        if ($limit < 0){             $order = "hits ASC";            $limit = -$limit;            $where = "";         } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -