/[drupal]/contributions/modules/interwiki/interwiki.module
ViewVC logotype

Contents of /contributions/modules/interwiki/interwiki.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.25 - (show annotations) (download) (as text)
Sun May 4 04:00:52 2008 UTC (18 months, 3 weeks ago) by sheldon
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.24: +70 -86 lines
File MIME type: text/x-php
update to Drupal 6
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * An implementation of an input formatting module for a special non-html link
7 * syntax to wikis and other websites
8 *
9 * Upgraded to Drupal 4.7, 5/13/2006
10 * Updated to Drupal 5.0, 2/03/2007
11 *
12 * This module, when configured, is responsible for translating user-inputted links of the form
13 * '[prefix:some term]' into the form '<a href="http://www.domain.com/some_term">some term</a>'
14 * where prefix represents a key and http://www.domain.com/ is
15 * the path to the an article about the term
16 */
17
18 /**
19 * Implementation of hook_help().
20 */
21 function interwiki_help($section) {
22 switch ($section) {
23 case 'admin/modules#description':
24 return t('Easily link to wikis and other websites.');
25 case 'admin/help#interwiki':
26 return t("<p>This module makes it easy to link to wikis and other websites. Users avoid entering entire URLs, as they would for regular web pages, " .
27 "and instead use a shorthand similar to the syntax used by %Wikipedia and other %MediaWiki sites, in which \"[prefix:some term]\" creates a hyperlink to the ".
28 "\"some term\" article on the website specified by \"prefix.\" It is also possible to use the \"|\" character to create a \"piped link,\" with display text that is ".
29 "different from the search term. For example, \"[w:public transport|public transportation]\" could be translated as a reference to the Wikipedia article on \"public ".
30 "transport\" that displays as \"<a href=\"http://en.wikipedia.org/wiki/public_transport\">public transportation</a>.\" In addition to the single bracket syntax, ".
31 "a double bracket syntax like the one used by %MediaWiki can be chosen from the interwiki configuration in %settings. The double-bracket syntax lets you specify a ".
32 "\"default prefix\" that is used if no prefix is explicitly specified. For example, a default prefix of \"w\" means that [[some term]] is synonymous with [[w:some term]]. ".
33 "This makes it easier to cut-and-paste text from MediaWiki sites directly into your Drupal site.</p>\n".
34 "<h3>Configuration</h3><p>To use this module, you have to take a few steps:</p>".
35 "<ul><li>Install and enable the module in %modules, and create the \"interwiki\" table using file interwiki.sql.</li>".
36 "<li>Set the appropriate access right in %access<br />The access right is <b>administer interwiki</b>.</li>".
37 "<li>To add or edit new interwiki links, use %interwikis.</li></ul>\n",
38 array(
39 '%Wikipedia' => '<a href="http://www.wikipedia.org">Wikipedia</a>',
40 '%MediaWiki' => '<a href="http://wikipedia.sourceforge.net/">MediaWiki</a>',
41 '%settings' => l(t("administer &raquo; filters"), "admin/filters", array(), NULL, NULL, FALSE, TRUE),
42 '%modules' => l(t("administer &raquo; modules"), "admin/modules", array(), NULL, NULL, FALSE, TRUE),
43 '%access' => l(t("administer &raquo; access control"), "admin/access", array(), NULL, NULL, FALSE, TRUE),
44 '%interwikis' => l(t("administer &raquo; interwiki"), "admin/settings/interwiki", array(), NULL, NULL, FALSE, TRUE)
45 )) .
46 t("<h3>Included search prefixes</h3>".
47 "<p>The \"interwiki\" table created via file interwiki.sql comes with a number of records already included that facilitate linking to articles or search results on the following websites:</p>\n".
48 "<table><tr><th>Prefix</th><th>Site</th></tr>\n".
49 "<tr><td>w</td><td>%w, the online, open source encyclopedia</td></tr>".
50 "<tr><td>sw</td><td>%sw, a wiki-based encyclopedia of lobbyists, PR firms, think tanks and other political advocacy groups</td></tr>".
51 "<tr><td>kos</td><td>%kos, a wiki affiliated with the Daily Kos website</td></tr>".
52 "<tr><td>ebay</td><td>%ebay</tr>".
53 "<tr><td>google</td><td>%google, the online search engine</tr>".
54 "<tr><td>th</td><td>an online %th</td></tr>".
55 "<tr><td>archive</td><td>the %archive, also known as the Internet Archive, which stores and displays old versions of websites</td></tr>".
56 "<tr><td>whois</td><td>%whois, Internic's search tool for information about who owns a domain name</td></tr>".
57 "<tr><td>opendir</td><td>the %opendir, a human-edited web search engine</td></tr></table>\n".
58 "<p>In addition, it has entries that facilitate linking to URLs in general and to content on your own local site. For example, [http://www.somesite.org|Some Website] ".
59 "produces <a href=\"http://www.somesite.org\">Some Website</a>, and [:node/5|my fifth posting] produces <a href=\"node/5\">my fifth posting</a>. If \"http:\" is used as ".
60 "the prefix, you can use %settings to specify the space character instead of the vertical bar character as the \"URL terminator\" which separates the URL from its display text. ".
61 "(This option emulates the syntax used to specify external URLs in Wikipedia articles. If emulating Wikipedia is not important on your site, you'll probably want to use the default vertical bar character.)</p>",
62 array(
63 '%w' => l('Wikipedia', 'http://www.wikipedia.org'),
64 '%sw' => l('SourceWatch', 'http://www.sourcewatch.org'),
65 '%kos' => l('dKosopedia', 'http://www.dkosopedia.com'),
66 '%ebay' => l('eBay', 'http://www.ebay.com'),
67 '%google' => l('Google', 'http://www.google.com'),
68 '%th' => l('thesaurus', 'http://thesaurus.reference.com'),
69 '%archive' => l('Wayback Machine', 'http://web.archive.org'),
70 '%whois' => l('whois', 'http://www.internic.net/whois.html'),
71 '%opendir' => l('Open Directory project', 'http://search.dmoz.org'),
72 '%settings' => l(t("administer &raquo; filters"), "admin/filters", array(), NULL, NULL, FALSE, TRUE),
73 )) .
74 t("<h3>For more information</h3>".
75 "<ul><li><a href = \"http://en.wikipedia.org/wiki/Interwiki Wikipedia\" title = \"wikipedia interwiki definition\">Wikipedia's interwiki definition</a>.</li>".
76 "<li>Configuration and customization handbook: <a href = \"http://drupal.org/handbook/modules/interwiki\" title = \"interwikipage\">interwiki page</a>.</li></ul>");
77 }
78 }
79
80 /**
81 * hook_perm: Define user permissions for module interwiki
82 *
83 * - access content: User can view the list of available filters
84 * - administer interwiki: User can edit or add to the list of filters
85 *
86 * @note See hook_perm() for a description of parameters and return values.
87 */
88 function interwiki_perm() {
89 return array('administer interwiki');
90 }
91
92 /**
93 * Implementation of hook_menu().
94 */
95
96 function interwiki_menu() {
97 $items['interwiki'] = array(
98 'title' => 'Wiki filter prefixes',
99 'access arguments' => array(TRUE),
100 'page callback' => 'interwiki_list',
101 'type' => MENU_CALLBACK);
102 $items['admin/settings/interwiki'] = array(
103 'title' => 'Interwiki',
104 'description' => 'Manage interwiki filters.',
105 'access arguments' => array('administer interwiki'),
106 'page callback' => 'interwiki_admin');
107 $items['admin/settings/interwiki/list'] = array(
108 'title' => 'list',
109 'access arguments' => array('administer interwiki'),
110 'page callback' => 'interwiki_admin',
111 'type' => MENU_DEFAULT_LOCAL_TASK,
112 'weight' => -10 );
113 $items['admin/settings/interwiki/add'] = array(
114 'title' => 'add',
115 'access arguments' => array('administer interwiki'),
116 'page callback' => 'interwiki_admin',
117 'type' => MENU_LOCAL_TASK);
118 return $items;
119 }
120
121 /**
122 * Return a prefix from the interwiki table. The prefix chosen
123 * should be something other than "http" or the empty string "".
124 * Preference is first given to the default prefix for the specified
125 * format. If no format is specified, preference is given to
126 * prefixes that have a value of 1 for iw_local, and then to
127 * the prefix "w" if it exists. (The "w" prefix for Wikipedia is included
128 * in the standard interwiki table that ships with this module.)
129 */
130 function _interwiki_sample_prefix($format) {
131 if ($format) {
132 $default_prefix = variable_get("interwiki_default_$format", '');
133 $prefix = db_result(db_query("SELECT iw_prefix FROM {interwiki} WHERE iw_prefix = '%s'", $default_prefix));
134 }
135 if (!$prefix) {
136 $prefix = db_result(db_query("SELECT iw_prefix FROM {interwiki} WHERE iw_prefix != 'http' AND iw_prefix != '' AND iw_local = 1"));
137 }
138 if (!$prefix) {
139 $prefix = db_result(db_query("SELECT iw_prefix FROM {interwiki} WHERE iw_prefix = 'w'"));
140 }
141 if (!$prefix) {
142 $prefix = db_result(db_query("SELECT iw_prefix FROM {interwiki} WHERE iw_prefix != '' ORDER BY iw_local DESC"));
143 }
144 return $prefix;
145 }
146
147 /**
148 * List interwiki filter prefixes.
149 */
150 function interwiki_list() {
151 $format = arg(1);
152 $sample_prefix = _interwiki_sample_prefix($format);
153 $syntax = variable_get("interwiki_syntax_$format", array('single'));
154 if ((array_search('double', $syntax) === FALSE) || !(array_search('single', $syntax) === FALSE)) {
155 $unpiped = t('[prefix:some term]');
156 $piped = t("[$sample_prefix:public transport|public transportation]");
157 } else {
158 $unpiped = t('[[prefix:some term]]');
159 $piped = t("[[$sample_prefix:public transport|public transportation]]");
160 }
161 $trans_result = interwiki_filter('process', 0, $format, $piped);
162 $output = t("<p>You can easily link to terms in wikis and various other websites using a simplified markup syntax. For example, \"%unpiped\" creates a hyperlink to the ".
163 "\"some term\" article on the website specified by \"prefix.\" It is also possible to use the \"|\" character to create a \"piped link,\" with display text that is ".
164 "different from the search term. For example, \"%piped\" would be translated as a reference to an article about \"public ".
165 "transport\" that displays as \"%trans.\"</p>",
166 array(
167 '%unpiped' => $unpiped,
168 '%piped' => $piped,
169 '%trans' => $trans_result
170 ));
171 $result = db_query("SELECT iw_prefix, iw_url, iw_rel from {interwiki}");
172 $header = array(t('Prefix'), t('rel'), t('Translates to'));
173 while ($record = db_fetch_object($result)) {
174 // Strip out $1, $2, $3 and $4 from interwiki tables ...
175 $url = preg_replace(array('/\$1/', '/\$2/', '/\$3/', '/\$4/'), '', $record->iw_url);
176 if ($url == '') {
177 $url = t('<i>a local path on this website</i>');
178 }
179 $rows[] = array ($record->iw_prefix . ":", $record->iw_rel, $url);
180 }
181 $output .= t('Available prefixes are:') . '<p>';
182 $output .= theme('table',$header,$rows);
183 print theme("page", $output);
184 }
185
186 /**
187 * Implementation of hook_filter().
188 */
189 function interwiki_filter($op, $delta = 0, $format = -1, $text = '') {
190 switch ($op) {
191 case 'list':
192 return array(0 => t('Interwiki filter'));
193
194 case 'description':
195 return t('Easily link to wikis and other reference websites');
196
197 case 'process':
198 $result = db_query("SELECT iw_prefix, iw_url, iw_local, iw_rel from {interwiki}");
199 $targets = array();
200 while ($record = db_fetch_object($result)) {
201 $matcha[$record->iw_prefix] = $record->iw_url;
202 $targets[$record->iw_prefix] = $record->iw_local ? '_self' : '_blank';
203 $rels[$record->iw_prefix] = $record->iw_rel;
204 }
205 $syntax = variable_get("interwiki_syntax_$format", array('single'));
206 if (!(array_search('double', $syntax) === FALSE)) {
207 $pregs[] = '/\[\[([^]:]+)?:([^]]+)?\]\]/i';
208 }
209 if (!(array_search('single', $syntax) === FALSE) || (array_search('double', $syntax) === FALSE)) {
210 $pregs[] = '/\[([^]:]+)?:([^]]+)?\]/i';
211 }
212 foreach ($pregs as $preg) {
213 if (preg_match_all($preg, $text, $match)) {
214 $index = 0;
215 foreach($match[0] as $pattern_matched) {
216 if (! ($matcha[$match[1][$index]] == "")) {
217 // a prefix of 'http' is a special case where the prefix ought to display if no separate display term is specified
218 if ($match[1][$index] == 'http') {
219 $display_prefix = $match[1][$index] . ':';
220 $url_terminator = (variable_get("interwiki_terminator_$format", 'vert') == 'space') ? ' ' : '|';
221 } else {
222 $display_prefix = '';
223 $url_terminator = '|';
224 }
225 $target = $targets[$match[1][$index]];
226 $rel = $rels[$match[1][$index]];
227 $term = trim($match[2][$index]);
228 $term_array = explode($url_terminator, $term, 2);
229 $display_term = $term_array[1] ? $term_array[1] : $display_prefix . $term;
230 $url_term = $term_array[0];
231 // if the prefix is 'http', don't fix ampersands
232 if (!$display_prefix) {
233 $display_term = preg_replace('/\&#038;/', '&', $display_term);
234 $url_term = preg_replace('/\&#038;/', '%26', $url_term);
235 $url_term = preg_replace('/\&amp;/', '%26', $url_term);
236 $url_term = preg_replace('/\&/', '%26', $url_term);
237 }
238 $display_term = preg_replace("/<[^>]*>/", "", $display_term); // strip out any HTML tags
239 $url_term1 = preg_replace('/\ /', '_', $url_term);
240 $url_term2 = preg_replace('/\ /', '+', $url_term);
241 $url_term3 = preg_replace('/\ /', '%20', $url_term);
242 $url_term4 = preg_replace('/\ /', '-', $url_term);
243 $url = preg_replace(array('/\$1/','/\$2/', '/\$3/', '/\$4/'), array($url_term1, $url_term2, $url_term3, $url_term4), $matcha[$match[1][$index]]);
244 // If it's an external path, don't use the l() function
245 if (preg_match("/^(http|https|mailto|ftp):/i", $url)) {
246 $html = '<a href="' . $url .'" title="reference on '. $display_term . ($rel != "" ? ('" rel="' . $rel) : '') .'" target="'. $target .'">'. $display_term .'</a>';
247 } else {
248 $html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
249 }
250 $text = str_replace($pattern_matched, $html, $text);
251 }
252 $index++;
253 }
254 }
255 }
256
257 // Handle the default prefix
258 if (!(array_search('double', $syntax) === FALSE)) {
259 $preg = '/\[\[([^]]+)?\]\]/i';
260 $match_default = variable_get("interwiki_default_$format", _interwiki_sample_prefix($format));
261 if (preg_match_all($preg, $text, $match)) {
262 $index = 0;
263 foreach($match[0] as $pattern_matched) {
264 if (! ($matcha[$match_default] == "")) {
265 // a prefix of 'http' is a special case where the prefix ought to display if no separate display term is specified
266 if ($match_default == 'http') {
267 $display_prefix = $match_default . ':';
268 $url_terminator = (variable_get("interwiki_terminator_$format", 'vert') == 'space') ? ' ' : '|';
269 } else {
270 $display_prefix = '';
271 $url_terminator = '|';
272 }
273 $target = $targets[$match_default];
274 $rel = $rels[$match_default];
275 $term = trim($match[1][$index]);
276 $term_array = explode($url_terminator, $term, 2);
277 $display_term = $term_array[1] ? $term_array[1] : $display_prefix . $term;
278 $url_term = $term_array[0];
279 // if the prefix is 'http', don't fix ampersands
280 if (!$display_prefix) {
281 $display_term = preg_replace('/\&#038;/', '&', $display_term);
282 $url_term = preg_replace('/\&#038;/', '%26', $url_term);
283 $url_term = preg_replace('/\&amp;/', '%26', $url_term);
284 $url_term = preg_replace('/\&/', '%26', $url_term);
285 }
286 $url_term1 = preg_replace('/\ /', '_', $url_term);
287 $url_term2 = preg_replace('/\ /', '+', $url_term);
288 $url_term3 = preg_replace('/\ /', '%20', $url_term);
289 $url_term4 = preg_replace('/\ /', '-', $url_term);
290 $url = preg_replace(array('/\$1/','/\$2/', '/\$3/', '/\$4/'), array($url_term1, $url_term2, $url_term3, $url_term4), $matcha[$match_default]);
291 // If it's an external path, don't use the l() function
292 if (preg_match("/^(http|https|mailto|ftp):/i", $url)) {
293 $html = '<a href="' . $url .'" title="reference on '. $display_term . ($rel != "" ? ('" rel="' . $rel) : '') .'" target="'. $target .'">'. $display_term .'</a>';
294 } else {
295 $html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
296 }
297 $text = str_replace($pattern_matched, $html, $text);
298 }
299 $index++;
300 }
301 }
302 }
303
304 return $text;
305
306 case 'settings':
307 $form['interwiki'] = array('#type' => 'fieldset', '#title' => t('Interwiki settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
308 $sample_prefix = _interwiki_sample_prefix($format);
309 $syntax = variable_get("interwiki_syntax_$format", array('single'));
310 if ((array_search('double', $syntax) === FALSE) || !(array_search('single', $syntax) === FALSE)) {
311 $unpiped = t('[prefix:term]');
312 $piped = t("[$sample_prefix:public transport|public transportation]");
313 } else {
314 $unpiped = t('[[prefix:term]]');
315 $piped = t("[[$sample_prefix:public transport|public transportation]]");
316 }
317 $trans_result = interwiki_filter('process', 0, $format, $piped);
318 $output = t('The interwiki filter is enabled. You can easily link to terms in various wikis or other websites by typing %unpiped. ' .
319 'Use the "|" character to create a "piped link," e.g., "%piped" '.
320 'displays as "%trans." '.
321 'For a full list of available prefixes and the websites to which they point, see %prefixes.',
322 array(
323 '%unpiped' => $unpiped,
324 '%piped' => $piped,
325 '%trans' => $trans_result,
326 '%prefixes' => l('interwiki', "interwiki/$format")
327 ));
328 $form[interwiki]['intro'] = array('#type' => 'markup', '#value' => "<p>$output</p>");
329
330 $syntax = array('single' => 'Single brackets, e.g., [prefix:some term]', 'double' => 'Double brackets, e.g., [[prefix:some term]]');
331 $form['interwiki']["interwiki_syntax_$format"] = array( '#type' => 'checkboxes', '#title' => t('Syntax'), '#default_value' => variable_get("interwiki_syntax_$format", array('single')), '#options' => $syntax, '#description' => t('Check the boxes above to select the syntax(es) used to specify interwiki links. Single brackets are simpler, but double brackets are closer to the syntax used by <a href="http://wikipedia.sourceforge.net/">MediaWiki</a>, one of the most most popular wiki software packages. (If neither is checked, the filter defaults to single bracket syntax.)') );
332
333 $form['interwiki']["interwiki_default_$format"] = array( '#type' => 'textfield', '#title' => t('Default prefix'), '#default_value' => variable_get("interwiki_default_$format", _interwiki_sample_prefix($format)), '#size' => 10, '#maxlength' => 30, '#description' => t("The prefix used by default with the double bracket syntax. For example, a default prefix of \"$sample_prefix\" means that [[some term]] is synonymous with [[$sample_prefix:some term]]. (This may be useful if you want to be able to cut-and-paste text from an existing wiki into your site.)") );
334
335 $terminators = array('space' => t('Space character'), 'vert' => t('Vertical bar (|)'));
336 $form['interwiki']["interwiki_terminator_$format"] = array( '#type' => 'radios', '#title' => t('URL terminator'), '#default_value' => variable_get("interwiki_terminator_$format", 'vert'), '#options' => $terminators, '#description' => t('The terminator character used to mark the end of a URL. For maximum compatibility with Wikipedia\'s syntax, choose "space." Otherwise, choose the vertical bar character (|).') );
337 return $form;
338 default:
339 return $text;
340 }
341 }
342
343 /**
344 * Implementation of hook_filter_tips().
345 */
346 function interwiki_filter_tips($delta, $format, $long = false) {
347 $syntax = variable_get("interwiki_syntax_$format", array('single'));
348 $sample_prefix = _interwiki_sample_prefix($format);
349 if ((array_search('double', $syntax) === FALSE) || !(array_search('single', $syntax) === FALSE)) {
350 $unpiped = t('[prefix:term]');
351 $piped = t("[$sample_prefix:public transport|public transportation]");
352 } else {
353 $unpiped = t('[[prefix:term]]');
354 $piped = t("[[$sample_prefix:public transport|public transportation]]");
355 }
356 if ($long) {
357 return t('Easily link to terms in various wikis or other websites by typing %unpiped. ' .
358 'Use the "|" character to create a "piped link," e.g., "%piped" '.
359 'displays as "<a href="http://en.wikipedia.org/wiki/public_transport">public transportation</a>." '.
360 'For a full list of available prefixes and the websites to which they point, see %prefixes.',
361 array(
362 '%unpiped' => $unpiped,
363 '%piped' => $piped,
364 '%prefixes' => l('interwiki', "interwiki/$format")
365 ));
366 } else {
367 return t('Easily link to terms in various wikis. For help, see %prefixes.',
368 array(
369 '%prefixes' => l('interwiki', "interwiki/$format")
370 ));
371 }
372 }
373
374 /**
375 * Return a single filter from the database.
376 */
377 function interwiki_get($iw_prefix) {
378 return db_fetch_array(db_query("SELECT * FROM {interwiki} WHERE iw_prefix = '%s'", $iw_prefix));
379 }
380
381 /**
382 * Display an editing form for adding or changing an individual filter.
383 *
384 */
385 function interwiki_form($edit = array()) {
386 return drupal_get_form('interwiki_edit_form', $edit);
387 }
388
389 function interwiki_edit_form($form_state, $edit) {
390 $form["iw_prefix"] = array(
391 '#type' => 'textfield',
392 '#title' => t("Prefix"),
393 '#default_value' => $edit["iw_prefix"],
394 '#size' => 32,
395 '#maxlength' => 32,
396 '#description' => t("The prefix goes before a colon when users edit content, e.g., \"[prefix:some text].\""),
397 );
398 $form["iw_rel"] = array(
399 '#type' => 'textfield',
400 '#title' => t("rel"),
401 '#default_value' => $edit["iw_rel"],
402 '#size' => 32,
403 '#maxlength' => 32,
404 '#description' => t('The rel= parameter, if any, required in this link. This may be blank.'),
405 );
406 $form["iw_url"] = array(
407 '#type' => 'textfield',
408 '#title' => t("URL"),
409 '#default_value' => $edit["iw_url"],
410 '#size' => 50,
411 '#maxlength' => 255,
412 '#description' => t('The URL to be created. The phrase "some_text" will replace the string "$1" in the translated hyperlink, "some+text" will replace "$2", "some%20text" will replace "$3", and "some-text" will replace "$4".'),
413 );
414 $form["iw_local"] = array(
415 '#type' => 'checkbox',
416 '#title' => t("Local?"),
417 '#return_value' => 1,
418 '#default_value' => $edit["iw_local"],
419 '#description' => t("Is this link local to your website? Non-local links will open in a new window."),
420 );
421 $form[] = array(
422 '#type' => 'submit',
423 '#value' => t("Submit"),
424 );
425
426 if ($edit["iw_url"]) {
427 $form[] = array(
428 '#type' => 'submit',
429 '#value' => t("Delete"),
430 );
431 }
432 return $form;
433 }
434
435
436 /**
437 * Update, insert or delete a filter from the database.
438 *
439 */
440 function interwiki_save($edit) {
441 db_query("DELETE FROM {interwiki} WHERE iw_prefix = '%s'", $edit["iw_prefix"]);
442 if ($edit["action"] != 'delete') {
443 db_query("INSERT INTO {interwiki} (iw_prefix, iw_url, iw_rel, iw_local) VALUES ('%s', '%s', '%s', '%d')", $edit["iw_prefix"], $edit["iw_url"], $edit["iw_rel"], $edit["iw_local"]);
444 }
445 }
446
447 /**Confirm deletion of filter*/
448 function _interwiki_confirm_del($edit) {
449 return drupal_get_form('interwiki_delete_confirm_form', $edit);
450 }
451
452
453 function interwiki_delete_confirm_form($form_state, $edit) {
454
455 $form['confirm'] = array(
456 '#type' => 'hidden',
457 '#value' => 1,
458 );
459 $form['iw_prefix'] = array(
460 '#type' => 'hidden',
461 '#value' => $edit[iw_prefix],
462 );
463 return confirm_form($form,
464 t('Are you sure you want to delete the interwiki prefix %name?', array('%name' => $iw_prefix)),
465 'admin/settings/interwiki', t('This action cannot be undone.'),
466 t('Delete'), t('Cancel') );
467 }
468
469 /**
470 * Display the list of filters for editing purposes.
471 *
472 */
473 function interwiki_display() {
474 $output = '<p>' . t("The interwiki table lets website users easily link to terms in wikis and various other websites using a simplified markup syntax. For example, \"[prefix:some term]\" creates a hyperlink to the ".
475 "\"some term\" article on the website specified by \"prefix.\" Available prefixes and the paths to which they point are:") . '</p>';
476 $result = db_query("SELECT iw_prefix, iw_url, iw_rel, iw_local from {interwiki}");
477 $header = array(t('Prefix'), t('rel'), t('Translates to'), t('Local?'), array("data" => t("operations"), "colspan" => 2));
478 while ($record = db_fetch_object($result)) {
479 $rows[] = array ($record->iw_prefix . ":", $record->iw_rel, $record->iw_url, ($record->iw_local ? 'Yes' : 'No'), l(t("edit"), "admin/settings/interwiki/edit/$record->iw_prefix"), l(t("delete"), "admin/settings/interwiki/delete/$record->iw_prefix"));
480 }
481 $output .= theme('table',$header,$rows);
482 $output .= '<p>' . t('The paths in the "translates to" row above use placeholder strings to specify how the space character should be ' .
483 'escaped in the URL generated by an interwiki translation. The placeholder strings are $1, $2, $3 and $4. They have the following effect:') . '</p>';
484 $output .= '<ul><li>$1 ' . t('replaces spaces with underscore characters (_)') .'</li>
485 <li>$2 ' . t('replaces spaces with plus signs (+)') .'</li>
486 <li>$3 ' . t('replaces spaces with "%20"') .'</li>
487 <li>$4 ' . t('replaces spaces with dashes (-)') .'</li></ul>';
488 $output .= '<p>' . t('Therefore, [w:ad hominem] uses the string "ad_hominem" in building the URL to Wikipedia\'s article on <a href="http://en.wikipedia.org/wiki/ad_hominem">ad hominem</a> arguments, '.
489 'while [th:ad hominem] uses the string "ad%20hominem" in building the URL to a thesaurus reference for the phrase <a href="http://thesaurus.reference.com/search?q=ad%20hominem">ad hominem</a>.') . '</p>';
490 return $output;
491 }
492
493 /**
494 * Route all requests to administer the filters.
495 *
496 */
497 function interwiki_admin() {
498 $op = $_POST["op"];
499 $edit = $_POST;
500 if (empty($op)) {
501 $op = arg(3);
502 }
503
504 switch ($op) {
505 case "add":
506 $output = interwiki_form();
507 break;
508 case "edit":
509 $output = interwiki_form(interwiki_get(arg(4)));
510 break;
511 case "delete": // the lower-case "d" in "delete" indicates that this came from a URL, so there's no $_POST variable and therefore no $edit
512 $edit = interwiki_get(arg(4));
513 // fall through:
514 case t("Delete"): // the upper-case "D" indicates that this came from the editing form, so there is a $_POST variable but no arg(3)
515 if (!$edit['confirm']) {
516 $output = _interwiki_confirm_del($edit);
517 break;
518 }
519 else {
520 $edit['action'] = 'delete';
521 // fall through:
522 }
523 case t("Submit"):
524 $output = interwiki_save($edit);
525 // fall through:
526 default:
527 $output .= interwiki_display();
528 }
529
530 print theme('page', $output);
531 }

  ViewVC Help
Powered by ViewVC 1.1.2