]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LinkSearch.php
Remove unused
[SourceForge/phpwiki.git] / lib / plugin / LinkSearch.php
1 <?php
2
3 /*
4  * Copyright 2007 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 require_once 'lib/TextSearchQuery.php';
24 require_once 'lib/PageList.php';
25
26 /**
27  * Similar to SemanticSearch, just for ordinary in- or outlinks.
28  *
29  * @author: Reini Urban
30  */
31 class WikiPlugin_LinkSearch
32     extends WikiPlugin
33 {
34     function getName()
35     {
36         return _("LinkSearch");
37     }
38
39     function getDescription()
40     {
41         return _("Search page and link names.");
42     }
43
44     function getDefaultArguments()
45     {
46         return array_merge
47         (
48             PageList::supportedArgs(), // paging and more.
49             array(
50                 's' => "", // linkvalue query string
51                 'page' => "*", // which pages (glob allowed), default: all
52                 'direction' => "out", // or in
53                 'case_exact' => false,
54                 'regex' => 'auto',
55                 'noform' => false, // don't show form with results.
56                 'noheader' => false // no caption
57             ));
58     }
59
60     function showForm(&$dbi, &$request, $args)
61     {
62         $action = $request->getPostURL();
63         $hiddenfield = HiddenInputs($request->getArgs(), '',
64             array('action', 'page', 's', 'direction'));
65         $pagefilter = HTML::input(array('name' => 'page',
66             'value' => $args['page'],
67             'title' => _("Search only in these pages. With autocompletion."),
68             'class' => 'dropdown',
69             'acdropdown' => 'true',
70             'autocomplete_complete' => 'true',
71             'autocomplete_matchsubstring' => 'false',
72             'autocomplete_list' => 'xmlrpc:wiki.titleSearch ^[S] 4'
73         ), '');
74         $query = HTML::input(array('name' => 's',
75             'value' => $args['s'],
76             'title' => _("Filter by this link. These are pagenames. With autocompletion."),
77             'class' => 'dropdown',
78             'acdropdown' => 'true',
79             'autocomplete_complete' => 'true',
80             'autocomplete_matchsubstring' => 'true',
81             'autocomplete_list' => 'xmlrpc:wiki.titleSearch ^[S] 4'
82         ), '');
83         $dirsign_switch = JavaScript("
84 function dirsign_switch() {
85   var d = document.getElementById('dirsign')
86   d.innerHTML = (d.innerHTML == ' =&gt; ') ? ' &lt;= ' : ' =&gt; '
87 }
88 ");
89         $dirsign = " => ";
90         $in = $out = array('name' => 'direction', 'type' => 'radio', 'onChange' => 'dirsign_switch()');
91         $out['value'] = 'out';
92         $out['id'] = 'dir_out';
93         if ($args['direction'] == 'out') $out['checked'] = 'checked';
94         $in['value'] = 'in';
95         $in['id'] = 'dir_in';
96         if ($args['direction'] == 'in') {
97             $in['checked'] = 'checked';
98             $dirsign = " <= ";
99         }
100         $direction = HTML(HTML::input($out), HTML::label(array('for' => 'dir_out'), _("outgoing")),
101             HTML::input($in), HTML::label(array('for' => 'dir_in'), _("incoming")));
102         /*
103         $direction = HTML::select(array('name'=>'direction',
104                                         'onChange' => 'dirsign_switch()'));
105         $out = array('value' => 'out');
106         if ($args['direction']=='out') $out['selected'] = 'selected';
107         $in = array('value' => 'in');
108         if ($args['direction']=='in') {
109             $in['selected'] = 'selected';
110             $dirsign = " <= ";
111         }
112         $direction->pushContent(HTML::option($out, _("outgoing")));
113         $direction->pushContent(HTML::option($in, _("incoming")));
114         */
115         $submit = Button('submit:search', _("LinkSearch"), false);
116         $instructions = _("Search in pages for links with the matching name.");
117         $form = HTML::form(array('action' => $action,
118                 'method' => 'GET',
119                 'accept-charset' => $GLOBALS['charset']),
120             $dirsign_switch,
121             $hiddenfield,
122             $instructions, HTML::br(),
123             $pagefilter,
124             HTML::strong(HTML::tt(array('id' => 'dirsign'), $dirsign)),
125             $query,
126             HTML::raw('&nbsp;'), $direction,
127             HTML::raw('&nbsp;'), $submit);
128         return $form;
129     }
130
131     function run($dbi, $argstr, &$request, $basepage)
132     {
133         global $WikiTheme;
134         $args = $this->getArgs($argstr, $request);
135
136         if (empty($args['page']))
137             $args['page'] = "*";
138         $form = $this->showForm($dbi, $request, $args);
139         extract($args);
140         if (empty($s))
141             return $form;
142         $pagequery = new TextSearchQuery($page, $args['case_exact'], $args['regex']);
143         $linkquery = new TextSearchQuery($s, $args['case_exact'], $args['regex']);
144         $links = $dbi->linkSearch($pagequery, $linkquery, $direction == 'in' ? 'linkfrom' : 'linkto');
145         $pagelist = new PageList($args['info'], $args['exclude'], $args);
146         $pagelist->_links = array();
147         while ($link = $links->next()) {
148             $pagelist->addPage($link['pagename']);
149             $pagelist->_links[] = $link;
150         }
151         $pagelist->addColumnObject
152         (new _PageList_Column_LinkSearch_link('link', _("Link"), $pagelist));
153
154         if (!$noheader) {
155             // We put the form into the caption just to be able to return one pagelist object,
156             // and to still have the convenience form at the top. we could workaround this by
157             // putting the form as WikiFormRich into the actionpage. but thid doesnt look as
158             // nice as this here.
159             $pagelist->setCaption
160             ( // on mozilla the form doesn't fit into the caption very well.
161                 HTML($noform ? '' : HTML($form, HTML::hr()),
162                     fmt("LinkSearch result for \"%s\" in pages \"%s\", direction %s", $s, $page, $direction)));
163         }
164         return $pagelist;
165     }
166 }
167
168 // FIXME: sortby errors with this column
169 class _PageList_Column_LinkSearch_link
170     extends _PageList_Column
171 {
172     function _PageList_Column_LinkSearch_link($field, $heading, &$pagelist)
173     {
174         $this->_field = $field;
175         $this->_heading = $heading;
176         $this->_need_rev = false;
177         $this->_iscustom = true;
178         $this->_pagelist =& $pagelist;
179     }
180
181     function _getValue(&$page, $revision_handle)
182     {
183         if (is_object($page)) $text = $page->getName();
184         else $text = $page;
185         $link = $this->_pagelist->_links[$this->current_row];
186         return WikiLink($link['linkvalue'], 'if_known');
187     }
188 }
189
190 // Local Variables:
191 // mode: php
192 // tab-width: 8
193 // c-basic-offset: 4
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil
196 // End: