]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend.php
trailing_spaces
[SourceForge/phpwiki.git] / lib / WikiDB / backend.php
1 <?php
2 // $Id$
3 /*
4  * Copyright 2004-2010 Reini Urban
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 /*
24   Pagedata
25
26    maintained by WikiPage
27     //:latestversion
28     //:deleted (*)     (Set if latest content is empty.)
29     //:pagename (*)
30
31     hits
32     is_locked
33
34   Versiondata
35
36     %content (?should this be here?)
37     _supplanted : Time version ceased to be the current version
38
39     mtime (*)   : Time of version edit.
40     orig_mtime
41     is_minor_edit (*)
42     author      : nominal author
43     author_id   : authenticated author
44     summary
45
46     //version
47     //created (*)
48     //%superceded
49
50     //:serial
51
52      (types are scalars: strings, ints, bools)
53 */
54
55 /**
56  * A WikiDB_backend handles the storage and retrieval of data for a WikiDB.
57  *
58  * It does not have to be this way, of course, but the standard WikiDB uses
59  * a WikiDB_backend.  (Other WikiDB's could be written which use some other
60  * method to access their underlying data store.)
61  *
62  * The interface outlined here seems to work well with both RDBM based
63  * and flat DBM/hash based methods of data storage.
64  *
65  * Though it contains some default implementation of certain methods,
66  * this is an abstract base class.  It is expected that most efficient
67  * backends will override nearly all the methods in this class.
68  *
69  * @access protected
70  * @see WikiDB
71  */
72 class WikiDB_backend
73 {
74     /**
75      * Get page meta-data from database.
76      *
77      * @param $pagename string Page name.
78      * @return hash
79      * Returns a hash containing the page meta-data.
80      * Returns an empty array if there is no meta-data for the requested page.
81      * Keys which might be present in the hash are:
82      * <dl>
83      *  <dt> locked  <dd> If the page is locked.
84      *  <dt> hits    <dd> The page hit count.
85      *  <dt> created <dd> Unix time of page creation. (FIXME: Deprecated: I
86      *                    don't think we need this...)
87      * </dl>
88      */
89     function get_pagedata($pagename) {
90         trigger_error("virtual", E_USER_ERROR);
91     }
92
93     /**
94      * Update the page meta-data.
95      *
96      * Set page meta-data.
97      *
98      * Only meta-data whose keys are preset in $newdata is affected.
99      *
100      * For example:
101      * <pre>
102      *   $backend->update_pagedata($pagename, array('locked' => 1));
103      * </pre>
104      * will set the value of 'locked' to 1 for the specified page, but it
105      * will not affect the value of 'hits' (or whatever other meta-data
106      * may have been stored for the page.)
107      *
108      * To delete a particular piece of meta-data, set its value to false.
109      * <pre>
110      *   $backend->update_pagedata($pagename, array('locked' => false));
111      * </pre>
112      *
113      * @param $pagename string Page name.
114      * @param $newdata hash New meta-data.
115      */
116     function update_pagedata($pagename, $newdata) {
117         trigger_error("virtual", E_USER_ERROR);
118     }
119
120
121     /**
122      * Get the current version number for a page.
123      *
124      * @param $pagename string Page name.
125      * @return int The latest version number for the page.  Returns zero if
126      *  no versions of a page exist.
127      */
128     function get_latest_version($pagename) {
129         trigger_error("virtual", E_USER_ERROR);
130     }
131
132     /**
133      * Get preceding version number.
134      *
135      * @param $pagename string Page name.
136      * @param $version int Find version before this one.
137      * @return int The version number of the version in the database which
138      *  immediately preceeds $version.
139      */
140     function get_previous_version($pagename, $version) {
141         trigger_error("virtual", E_USER_ERROR);
142     }
143
144     /**
145      * Get revision meta-data and content.
146      *
147      * @param $pagename string Page name.
148      * @param $version integer Which version to get.
149      * @param $want_content boolean
150      *  Indicates the caller really wants the page content.  If this
151      *  flag is not set, the backend is free to skip fetching of the
152      *  page content (as that may be expensive).  If the backend omits
153      *  the content, the backend might still want to set the value of
154      *  '%content' to the empty string if it knows there's no content.
155      *
156      * @return hash The version data, or false if specified version does not
157      *    exist.
158      *
159      * Some keys which might be present in the $versiondata hash are:
160      * <dl>
161      * <dt> %content
162      *  <dd> This is a pseudo-meta-data element (since it's actually
163      *       the page data, get it?) containing the page content.
164      *       If the content was not fetched, this key may not be present.
165      * </dl>
166      * For description of other version meta-data see WikiDB_PageRevision::get().
167      * @see WikiDB_PageRevision::get
168      */
169     function get_versiondata($pagename, $version, $want_content = false) {
170         trigger_error("virtual", E_USER_ERROR);
171     }
172
173     /**
174      * Delete page from the database with backup possibility.
175      * This should remove all links (from the named page) from
176      * the link database.
177      *
178      * @param $pagename string Page name.
179      * i.e save_page('') and DELETE nonempty id
180      * Can be undone and is seen in RecentChanges.
181      */
182     function delete_page($pagename) {
183         $mtime = time();
184         $user =& $GLOBALS['request']->_user;
185         $vdata = array('author' => $user->getId(),
186                        'author_id' => $user->getAuthenticatedId(),
187                        'mtime' => $mtime);
188
189         $this->lock(); // critical section:
190         $version = $this->get_latest_version($pagename);
191         $this->set_versiondata($pagename, $version+1, $vdata);
192         $this->set_links($pagename, false); // links are purged.
193         // SQL needs to invalidate the non_empty id
194         if (! WIKIDB_NOCACHE_MARKUP) {
195             // need the hits, perms and LOCKED, otherwise you can reset the perm
196             // by action=remove and re-create it with default perms
197             $pagedata = $this->get_pagedata($pagename);
198             unset($pagedata['_cached_html']);
199             $this->update_pagedata($pagename, $pagedata);
200         }
201         $this->unlock();
202     }
203
204     /**
205      * Delete page (and all its revisions) from the database.
206      *
207      */
208     function purge_page($pagename) {
209         trigger_error("virtual", E_USER_ERROR);
210     }
211
212     /**
213      * Delete an old revision of a page.
214      *
215      * Note that one is never allowed to delete the most recent version,
216      * but that this requirement is enforced by WikiDB not by the backend.
217      *
218      * In fact, to be safe, backends should probably allow the deletion of
219      * the most recent version.
220      *
221      * @param $pagename string Page name.
222      * @param $version integer Version to delete.
223      */
224     function delete_versiondata($pagename, $version) {
225         trigger_error("virtual", E_USER_ERROR);
226     }
227
228     /**
229      * Create a new page revision.
230      *
231      * If the given ($pagename,$version) is already in the database,
232      * this method completely overwrites any stored data for that version.
233      *
234      * @param $pagename string Page name.
235      * @param $version int New revisions content.
236      * @param $data hash New revision metadata.
237      *
238      * @see get_versiondata
239      */
240     function set_versiondata($pagename, $version, $data) {
241         trigger_error("virtual", E_USER_ERROR);
242     }
243
244     /**
245      * Update page version meta-data.
246      *
247      * If the given ($pagename,$version) is already in the database,
248      * this method only changes those meta-data values whose keys are
249      * explicity listed in $newdata.
250      *
251      * @param $pagename string Page name.
252      * @param $version int New revisions content.
253      * @param $newdata hash New revision metadata.
254      * @see set_versiondata, get_versiondata
255      */
256     function update_versiondata($pagename, $version, $newdata) {
257         $data = $this->get_versiondata($pagename, $version, true);
258         if (!$data) {
259             assert($data);
260             return;
261         }
262         foreach ($newdata as $key => $val) {
263             if (empty($val))
264                 unset($data[$key]);
265             else
266                 $data[$key] = $val;
267         }
268         $this->set_versiondata($pagename, $version, $data);
269     }
270
271     /**
272      * Set links for page.
273      *
274      * @param $pagename string Page name.
275      *
276      * @param $links array List of page(names) which page links to.
277      */
278     function set_links($pagename, $links) {
279         trigger_error("virtual", E_USER_ERROR);
280     }
281
282     /**
283      * Find pages which link to or are linked from a page.
284      *
285      * @param $pagename string Page name.
286      * @param $reversed boolean True to get backlinks.
287      *
288      * FIXME: array or iterator?
289      * @return object A WikiDB_backend_iterator.
290      */
291     function get_links($pagename, $reversed, $include_empty=false,
292                        $sortby='', $limit='', $exclude='') {
293         //FIXME: implement simple (but slow) link finder.
294         die("FIXME get_links");
295     }
296
297     /**
298      * Get all revisions of a page.
299      *
300      * @param $pagename string The page name.
301      * @return object A WikiDB_backend_iterator.
302      */
303     function get_all_revisions($pagename) {
304         include_once('lib/WikiDB/backend/dumb/AllRevisionsIter.php');
305         return new WikiDB_backend_dumb_AllRevisionsIter($this, $pagename);
306     }
307
308     /**
309      * Get all pages in the database.
310      *
311      * Pages should be returned in alphabetical order if that is
312      * feasable.
313      *
314      * @access protected
315      *
316      * @param $include_defaulted boolean
317      * If set, even pages with no content will be returned
318      * --- but still only if they have at least one revision (not
319      * counting the default revision 0) entered in the database.
320      *
321      * Normally pages whose current revision has empty content
322      * are not returned as these pages are considered to be
323      * non-existing.
324      *
325      * @return object A WikiDB_backend_iterator.
326      */
327     function get_all_pages($include_defaulted, $orderby=false, $limit='', $exclude='') {
328         trigger_error("virtual", E_USER_ERROR);
329     }
330
331     /**
332      * Title or full text search.
333      *
334      * Pages should be returned in alphabetical order if that is
335      * feasable.
336      *
337      * @access protected
338      *
339      * @param $search object A TextSearchQuery object describing the parsed query string,
340      *                       with efficient methods for SQL and PCRE match.
341      *
342      * @param $fullsearch boolean If true, a full text search is performed,
343      *  otherwise a title search is performed.
344      *
345      * @return object A WikiDB_backend_iterator.
346      *
347      * @see WikiDB::titleSearch
348      */
349     function text_search($search, $fulltext=false, $sortby='',
350                          $limit='', $exclude='')
351     {
352         // This method implements a simple linear search
353         // through all the pages in the database.
354         //
355         // It is expected that most backends will overload
356         // this method with something more efficient.
357         include_once('lib/WikiDB/backend/dumb/TextSearchIter.php');
358         // ignore $limit
359         $pages = $this->get_all_pages(false, $sortby, false, $exclude);
360         return new WikiDB_backend_dumb_TextSearchIter($this, $pages, $search, $fulltext,
361                                                       array('limit'   => $limit,
362                                                             'exclude' => $exclude));
363     }
364
365
366     /**
367      *
368      * @access protected
369      * @param $pages     object A TextSearchQuery object.
370      * @param $linkvalue object A TextSearchQuery object for the linkvalues
371      *                          (linkto, relation or backlinks or attribute values).
372      * @param $linktype  string One of the 4 linktypes.
373      * @param $relation  object A TextSearchQuery object or false.
374      * @param $options   array Currently ignored. hash of sortby, limit, exclude.
375      * @return object A WikiDB_backend_iterator.
376      * @see WikiDB::linkSearch
377      */
378     function link_search( $pages, $linkvalue, $linktype, $relation=false, $options=array() ) {
379         include_once('lib/WikiDB/backend/dumb/LinkSearchIter.php');
380         $pageiter = $this->text_search($pages);
381         return new WikiDB_backend_dumb_LinkSearchIter($this, $pageiter, $linkvalue, $linktype, $relation, $options);
382     }
383
384     /**
385      * Find pages with highest hit counts.
386      *
387      * Find the pages with the highest hit counts.  The pages should
388      * be returned in reverse order by hit count.
389      *
390      * @access protected
391      * @param integer $limit No more than this many pages
392      * @return object A WikiDB_backend_iterator.
393      */
394     function most_popular($limit, $sortby='-hits') {
395         // This is method fetches all pages, then
396         // sorts them by hit count.
397         // (Not very efficient.)
398         //
399         // It is expected that most backends will overload
400         // method with something more efficient.
401         include_once('lib/WikiDB/backend/dumb/MostPopularIter.php');
402         $pages = $this->get_all_pages(false, $sortby, false);
403         return new WikiDB_backend_dumb_MostPopularIter($this, $pages, $limit);
404     }
405
406     /**
407      * Find recent changes.
408      *
409      * @access protected
410      * @param $params hash See WikiDB::mostRecent for a description
411      *  of parameters which can be included in this hash.
412      * @return object A WikiDB_backend_iterator.
413      * @see WikiDB::mostRecent
414      */
415     function most_recent($params) {
416         // This method is very inefficient and searches through
417         // all pages for the most recent changes.
418         //
419         // It is expected that most backends will overload
420         // method with something more efficient.
421         include_once('lib/WikiDB/backend/dumb/MostRecentIter.php');
422         $pages = $this->get_all_pages(true, '-mtime');
423         return new WikiDB_backend_dumb_MostRecentIter($this, $pages, $params);
424     }
425
426     function wanted_pages($exclude_from='', $exclude='', $sortby='', $limit='') {
427         include_once('lib/WikiDB/backend/dumb/WantedPagesIter.php');
428         $allpages = $this->get_all_pages(true,false,false,$exclude_from);
429         return new WikiDB_backend_dumb_WantedPagesIter($this, $allpages, $exclude, $sortby, $limit);
430     }
431
432     /**
433      * Lock backend database.
434      *
435      * Calls may be nested.
436      *
437      * @param $write_lock boolean Unless this is set to false, a write lock
438      *     is acquired, otherwise a read lock.  If the backend doesn't support
439      *     read locking, then it should make a write lock no matter which type
440      *     of lock was requested.
441      *
442      *     All backends <em>should</em> support write locking.
443      */
444     function lock($write_lock = true) {
445     }
446
447     /**
448      * Unlock backend database.
449      *
450      * @param $force boolean Normally, the database is not unlocked until
451      *  unlock() is called as many times as lock() has been.  If $force is
452      *  set to true, the the database is unconditionally unlocked.
453      */
454     function unlock($force = false) {
455     }
456
457
458     /**
459      * Close database.
460      */
461     function close () {
462     }
463
464     /**
465      * Synchronize with filesystem.
466      *
467      * This should flush all unwritten data to the filesystem.
468      */
469     function sync() {
470     }
471
472     /**
473      * Optimize the database.
474      */
475     function optimize() {
476     }
477
478     /**
479      * Check database integrity.
480      *
481      * This should check the validity of the internal structure of the database.
482      * Errors should be reported via:
483      * <pre>
484      *   trigger_error("Message goes here.", E_USER_WARNING);
485      * </pre>
486      *
487      * @return boolean True iff database is in a consistent state.
488      */
489     function check($args=false) {
490     }
491
492     /**
493      * Put the database into a consistent state
494      * by reparsing and restoring all pages.
495      *
496      * This should put the database into a consistent state.
497      * (I.e. rebuild indexes, etc...)
498      *
499      * @return boolean True iff successful.
500      */
501     function rebuild($args=false) {
502         global $request;
503         $dbh = $request->getDbh();
504         $iter = $dbh->getAllPages(false);
505         while ($page = $iter->next()) {
506             $current = $page->getCurrentRevision(true);
507             $pagename = $page->getName();
508             $meta = $current->_data;
509             $version = $current->getVersion();
510             $content =& $meta['%content'];
511             $formatted = new TransformedText($page, $content, $current->getMetaData());
512             $type = $formatted->getType();
513             $meta['pagetype'] = $type->getName();
514             $links = $formatted->getWikiPageLinks(); // linkto => relation
515             $this->lock(array('version','page','recent','link','nonempty'));
516             $this->set_versiondata($pagename, $version, $meta);
517             $this->set_links($pagename, $links);
518             $this->unlock(array('version','page','recent','link','nonempty'));
519         }
520     }
521
522     function _parse_searchwords($search) {
523         $search = strtolower(trim($search));
524         if (!$search)
525             return array(array(),array());
526
527         $words = preg_split('/\s+/', $search);
528         $exclude = array();
529         foreach ($words as $key => $word) {
530             if ($word[0] == '-' && $word != '-') {
531                 $word = substr($word, 1);
532                 $exclude[] = preg_quote($word);
533                 unset($words[$key]);
534             }
535         }
536         return array($words, $exclude);
537     }
538
539     /**
540      * Split the given limit parameter into offset,limit. (offset is optional. default: 0)
541      * Duplicate the PageList function here to avoid loading the whole PageList.php
542      * Usage:
543      *   list($offset,$count) = $this->limit($args['limit']);
544      */
545     function limit($limit) {
546         if (strstr($limit, ',')) {
547             list($from, $limit) = explode(',', $limit);
548             if ((!empty($from) && !is_numeric($from)) or (!empty($limit) && !is_numeric($limit))) {
549                 return $this->error(_("Illegal 'limit' argument: must be numeric"));
550             }
551             return array($from, $limit);
552         }
553         else {
554             if (!empty($limit) && !is_numeric($limit)) {
555                 return $this->error(_("Illegal 'limit' argument: must be numeric"));
556             }
557             return array(0, $limit);
558         }
559     }
560
561     /**
562      * Handle sortby requests for the DB iterator and table header links.
563      * Prefix the column with + or - like "+pagename","-mtime", ...
564      * supported actions: 'flip_order' "mtime" => "+mtime" => "-mtime" ...
565      *                    'db'         "-pagename" => "pagename DESC"
566      * In PageList all columns are sortable. (patch by DanFr)
567      * Here with the backend only some, the rest is delayed to PageList.
568      * (some kind of DumbIter)
569      * Duplicate the PageList function here to avoid loading the whole
570      * PageList.php, and it forces the backend specific sortable_columns()
571      */
572     function sortby ($column, $action, $sortable_columns=false) {
573         if (empty($column)) return '';
574         //support multiple comma-delimited sortby args: "+hits,+pagename"
575         if (strstr($column, ',')) {
576             $result = array();
577             foreach (explode(',', $column) as $col) {
578                 if (empty($this))
579                     $result[] = WikiDB_backend::sortby($col, $action);
580                 else
581                     $result[] = $this->sortby($col, $action);
582             }
583             return join(",",$result);
584         }
585         if (substr($column,0,1) == '+') {
586             $order = '+'; $column = substr($column,1);
587         } elseif (substr($column,0,1) == '-') {
588             $order = '-'; $column = substr($column,1);
589         }
590         // default order: +pagename, -mtime, -hits
591         if (empty($order))
592             if (in_array($column,array('mtime','hits')))
593                 $order = '-';
594             else
595                 $order = '+';
596         if ($action == 'flip_order') {
597             return ($order == '+' ? '-' : '+') . $column;
598         } elseif ($action == 'init') {
599             $this->_sortby[$column] = $order;
600             return $order . $column;
601         } elseif ($action == 'check') {
602             return (!empty($this->_sortby[$column]) or
603                     ($GLOBALS['request']->getArg('sortby') and
604                      strstr($GLOBALS['request']->getArg('sortby'),$column)));
605         } elseif ($action == 'db') {
606             // native sort possible?
607             if (!empty($this) and !$sortable_columns)
608                 $sortable_columns = $this->sortable_columns();
609             if (in_array($column, $sortable_columns))
610                 // asc or desc: +pagename, -pagename
611                 return $column . ($order == '+' ? ' ASC' : ' DESC');
612             else
613                 return '';
614         }
615         return '';
616     }
617
618     function sortable_columns() {
619         return array('pagename'/*,'mtime','author_id','author'*/);
620     }
621
622     // adds surrounding quotes
623     function quote ($s) { return "'".$s."'"; }
624     // no surrounding quotes because we know it's a string
625     function qstr ($s)  { return $s; }
626
627     function isSQL () {
628         return in_array(DATABASE_TYPE, array('SQL','ADODB','PDO'));
629     }
630
631     function backendType() {
632         return DATABASE_TYPE;
633     }
634
635     function write_accesslog(&$entry) {
636         global $request;
637         if (!$this->isSQL()) return;
638         $dbh = &$this->_dbh;
639         $log_tbl = $entry->_accesslog->logtable;
640         // duration problem: sprintf "%f" might use comma e.g. "100,201" in european locales
641         $dbh->query("INSERT INTO $log_tbl"
642                     . " (time_stamp,remote_host,remote_user,request_method,request_line,request_args,"
643                     .   "request_uri,request_time,status,bytes_sent,referer,agent,request_duration)"
644                     . " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",
645                     array(
646                           // Problem: date formats are backend specific. Either use unixtime as %d (long),
647                           // or the native timestamp format.
648                           $entry->time,
649                           $entry->host,
650                           $entry->user,
651                           $entry->request_method,
652                           $entry->request,
653                           $entry->request_args,
654                           $entry->request_uri,
655                           $entry->_ncsa_time($entry->time),
656                           $entry->status,
657                           (int)$entry->size,
658                           $entry->referer,
659                           $entry->user_agent,
660                           $entry->duration));
661     }
662 };
663
664 /**
665  * Iterator returned by backend methods which (possibly) return
666  * multiple records.
667  *
668  * FIXME: This might be two seperate classes: page_iter and version_iter.
669  * For the versions we have WikiDB_backend_dumb_AllRevisionsIter.
670  */
671 class WikiDB_backend_iterator
672 {
673     /**
674      * Get the next record in the iterator set.
675      *
676      * This returns a hash. The hash may contain the following keys:
677      * <dl>
678      * <dt> pagename <dt> (string) the page name or linked page name on link iterators
679      * <dt> version  <dt> (int) the version number
680      * <dt> pagedata <dt> (hash) page meta-data (as returned from backend::get_pagedata().)
681      * <dt> versiondata <dt> (hash) page meta-data (as returned from backend::get_versiondata().)
682      * <dt> linkrelation <dt> (string) the page naming the relation (e.g. isa:=page <=> isa)
683      *
684      * If this is a page iterator, it must contain the 'pagename' entry --- the others
685      * are optional.
686      *
687      * If this is a version iterator, the 'pagename', 'version', <strong>and</strong> 'versiondata'
688      * entries are mandatory.  ('pagedata' is optional.)
689      *
690      * If this is a link iterator, the 'pagename' is mandatory, 'linkrelation' is optional.
691      */
692     function next() {
693         trigger_error("virtual", E_USER_ERROR);
694     }
695
696     function count() {
697         if (!empty($this->_pages))
698             return count($this->_pages);
699         else
700             return 0;
701     }
702
703     function asArray() {
704         if (!empty($this->_pages)) {
705             reset($this->_pages);
706             return $this->_pages;
707         } else {
708             $result = array();
709             while ($page = $this->next())
710                 $result[] = $page;
711             return $result;
712         }
713     }
714
715     /**
716      * limit - if empty the pagelist iterator will do nothing.
717      * Some backends limit the result set itself (dba, file, flatfile),
718      * Some SQL based leave it to WikiDB/PageList - deferred filtering in the iterator.
719      */
720     function limit() {
721         return empty($this->_options['limit']) ? 0 : $this->_options['limit'];
722     }
723
724     /**
725      * Release resources held by this iterator.
726      */
727     function free() {
728     }
729 };
730
731 /**
732  * search baseclass, pcre-specific
733  */
734 class WikiDB_backend_search
735 {
736     function WikiDB_backend_search($search, &$dbh) {
737         $this->_dbh = $dbh;
738         $this->_case_exact = $search->_case_exact;
739         $this->_stoplist   =& $search->_stoplist;
740         $this->stoplisted = array();
741     }
742     function _quote($word) {
743         return preg_quote($word, "/");
744     }
745     //TODO: use word anchors
746     function EXACT($word) { return "^".$this->_quote($word)."$"; }
747     function STARTS_WITH($word) { return "^".$this->_quote($word); }
748     function ENDS_WITH($word) { return $this->_quote($word)."$"; }
749     function WORD($word) { return $this->_quote($word); }
750     function REGEX($word) { return $word; }
751     //TESTME
752     function _pagename_match_clause($node) {
753         $method = $node->op;
754         $word = $this->$method($node->word);
755         return "preg_match(\"/\".$word.\"/\"".($this->_case_exact ? "i":"").")";
756     }
757     /* Eliminate stoplist words.
758      *  Keep a list of Stoplisted words to inform the poor user.
759      */
760     function isStoplisted ($node) {
761         // check only on WORD or EXACT fulltext search
762         if ($node->op != 'WORD' and $node->op != 'EXACT')
763             return false;
764         if (preg_match("/^".$this->_stoplist."$/i", $node->word)) {
765             array_push($this->stoplisted, $node->word);
766             return true;
767         }
768         return false;
769     }
770     function getStoplisted($word) {
771         return $this->stoplisted;
772     }
773 }
774
775 /**
776  * search baseclass, sql-specific
777  */
778 class WikiDB_backend_search_sql extends WikiDB_backend_search
779 {
780     function _pagename_match_clause($node) {
781         // word already quoted by TextSearchQuery_node_word::_sql_quote()
782         $word = $node->sql();
783         if ($word == '%') // ALL shortcut
784             return "1=1";
785         else
786             return ($this->_case_exact
787                     ? "pagename LIKE '$word'"
788                     : "LOWER(pagename) LIKE '$word'");
789     }
790     function _fulltext_match_clause($node) {
791         // force word-style %word% for fulltext search
792         $word = '%' . $node->_sql_quote($node->word) . '%';
793         // eliminate stoplist words
794         if ($this->isStoplisted($node))
795             return "1=1";  // and (pagename or 1) => and 1
796         else
797             return $this->_pagename_match_clause($node)
798                 // probably convert this MATCH AGAINST or SUBSTR/POSITION without wildcards
799                 . ($this->_case_exact ? " OR content LIKE '$word'"
800                                       : " OR LOWER(content) LIKE '$word'");
801     }
802 }
803
804 // Local Variables:
805 // mode: php
806 // tab-width: 8
807 // c-basic-offset: 4
808 // c-hanging-comment-ender-p: nil
809 // indent-tabs-mode: nil
810 // End:
811 ?>