4 * Copyright 2007 Reini Urban
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.
23 require_once('lib/TextSearchQuery.php');
24 require_once('lib/PageList.php');
27 * Similar to SemanticSearch, just for ordinary in- or outlinks.
29 * @author: Reini Urban
31 class WikiPlugin_LinkSearch
35 return _("LinkSearch");
37 function getDescription() {
38 return _("Search page and link names");
40 function getDefaultArguments() {
43 PageList::supportedArgs(), // paging and more.
45 's' => "", // linkvalue query string
46 'page' => "*", // which pages (glob allowed), default: all
47 'direction' => "out", // or in
48 'case_exact' => false,
50 'noform' => false, // don't show form with results.
51 'noheader' => false // no caption
55 function showForm (&$dbi, &$request, $args) {
56 $action = $request->getPostURL();
57 $hiddenfield = HiddenInputs($request->getArgs(),'',
58 array('action','page','s','direction'));
59 $pagefilter = HTML::input(array('name' => 'page',
60 'value' => $args['page'],
61 'title' => _("Search only in these pages. With autocompletion."),
62 'class' => 'dropdown',
63 'acdropdown' => 'true',
64 'autocomplete_complete' => 'true',
65 'autocomplete_matchsubstring' => 'false',
66 'autocomplete_list' => 'xmlrpc:wiki.titleSearch ^[S] 4'
68 $query = HTML::input(array('name' => 's',
69 'value' => $args['s'],
70 'title' => _("Filter by this link. These are pagenames. With autocompletion."),
71 'class' => 'dropdown',
72 'acdropdown' => 'true',
73 'autocomplete_complete' => 'true',
74 'autocomplete_matchsubstring' => 'true',
75 'autocomplete_list' => 'xmlrpc:wiki.titleSearch ^[S] 4'
77 $dirsign_switch = JavaScript("
78 function dirsign_switch() {
79 var d = document.getElementById('dirsign')
80 d.innerHTML = (d.innerHTML == ' => ') ? ' <= ' : ' => '
84 $in = $out = array('name' => 'direction', 'type'=>'radio', 'onChange' => 'dirsign_switch()');
85 $out['value'] = 'out';
86 $out['id'] = 'dir_out';
87 if ($args['direction']=='out') $out['checked'] = 'checked';
90 if ($args['direction']=='in') {
91 $in['checked'] = 'checked';
94 $direction = HTML(HTML::input($out), HTML::label(array('for'=>'dir_out'),_("outgoing")),
95 HTML::input($in), HTML::label(array('for'=>'dir_in'),_("incoming")));
97 $direction = HTML::select(array('name'=>'direction',
98 'onChange' => 'dirsign_switch()'));
99 $out = array('value' => 'out');
100 if ($args['direction']=='out') $out['selected'] = 'selected';
101 $in = array('value' => 'in');
102 if ($args['direction']=='in') {
103 $in['selected'] = 'selected';
106 $direction->pushContent(HTML::option($out, _("outgoing")));
107 $direction->pushContent(HTML::option($in, _("incoming")));
109 $submit = Button('submit:search', _("LinkSearch"), false);
110 $instructions = _("Search in pages for links with the matching name.");
111 $form = HTML::form(array('action' => $action,
113 'accept-charset' => $GLOBALS['charset']),
116 $instructions, HTML::br(),
118 HTML::strong(HTML::tt(array('id'=>'dirsign'), $dirsign)),
120 HTML::raw(' '), $direction,
121 HTML::raw(' '), $submit);
125 function run ($dbi, $argstr, &$request, $basepage) {
127 $args = $this->getArgs($argstr, $request);
129 if (empty($args['page']))
131 $form = $this->showForm($dbi, $request, $args);
135 $pagequery = new TextSearchQuery($page, $args['case_exact'], $args['regex']);
136 $linkquery = new TextSearchQuery($s, $args['case_exact'], $args['regex']);
137 $links = $dbi->linkSearch($pagequery, $linkquery, $direction == 'in' ? 'linkfrom' : 'linkto');
138 $pagelist = new PageList($args['info'], $args['exclude'], $args);
139 $pagelist->_links = array();
140 while ($link = $links->next()) {
141 $pagelist->addPage($link['pagename']);
142 $pagelist->_links[] = $link;
144 $pagelist->addColumnObject
145 (new _PageList_Column_LinkSearch_link('link', _("Link"), $pagelist));
148 // We put the form into the caption just to be able to return one pagelist object,
149 // and to still have the convenience form at the top. we could workaround this by
150 // putting the form as WikiFormRich into the actionpage. but thid doesnt look as
151 // nice as this here.
152 $pagelist->setCaption
153 ( // on mozilla the form doesn't fit into the caption very well.
154 HTML($noform ? '' : HTML($form,HTML::hr()),
155 fmt("LinkSearch result for \"%s\" in pages \"%s\", direction %s", $s, $page, $direction)));
161 // FIXME: sortby errors with this column
162 class _PageList_Column_LinkSearch_link
163 extends _PageList_Column
165 function _PageList_Column_LinkSearch_link ($field, $heading, &$pagelist) {
166 $this->_field = $field;
167 $this->_heading = $heading;
168 $this->_need_rev = false;
169 $this->_iscustom = true;
170 $this->_pagelist =& $pagelist;
172 function _getValue(&$page, $revision_handle) {
173 if (is_object($page)) $text = $page->getName();
175 $link = $this->_pagelist->_links[$this->current_row];
176 return WikiLink($link['linkvalue'],'if_known');
184 // c-hanging-comment-ender-p: nil
185 // indent-tabs-mode: nil