summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSheldon Rampton2007-02-03 06:46:22 (GMT)
committerSheldon Rampton2007-02-03 06:46:22 (GMT)
commit4f6096d4599e1063b461d007dcbe8347fa8b6c90 (patch)
tree0a508f32b4be17f33cc95043de676427595f30d0
parent6393ff29951662d2e1322838a0363036d9d3baaa (diff)
update to 5.0
-rw-r--r--interwiki.info3
-rw-r--r--interwiki.install41
-rw-r--r--interwiki.module73
3 files changed, 92 insertions, 25 deletions
diff --git a/interwiki.info b/interwiki.info
new file mode 100644
index 0000000..abf9dea
--- /dev/null
+++ b/interwiki.info
@@ -0,0 +1,3 @@
+; $Id$
+name = interwiki
+description = Easily link to wikis and other websites.
diff --git a/interwiki.install b/interwiki.install
new file mode 100644
index 0000000..e871925
--- /dev/null
+++ b/interwiki.install
@@ -0,0 +1,41 @@
+<?php
+// $Id$
+
+function interwiki_install() {
+ switch ($GLOBALS['db_type']) {
+ case 'mysqli':
+ case 'mysql':
+ $result = db_query("
+ CREATE TABLE {interwiki} (
+ iw_prefix char(32) NOT NULL default '',
+ iw_url char(127) NOT NULL default '',
+ iw_local tinyint(1) NOT NULL default '0',
+ iw_rel char(32) NOT NULL default '',
+ UNIQUE KEY iw_prefix (iw_prefix)
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+ $result = _interwiki_insert('kos', 'http://www.dkosopedia.com/index.php/$1', 0);
+ $result = _interwiki_insert('w', 'http://en.wikipedia.org/wiki/$1', 0);
+ $result = _interwiki_insert('dis', 'http://www.sourcewatch.org/index.php?title=$1', 0);
+ $result = _interwiki_insert('http', 'http:$1', 0);
+ $result = _interwiki_insert('', '$1', 1);
+ $result = _interwiki_insert('ebay', 'http://search.ebay.com/$4', 0);
+ $result = _interwiki_insert('googledef', 'http://www.google.com/search?&q=define%3A$2', 0);
+ $result = _interwiki_insert('google', 'http://www.google.com/search?q=%22$2%22', 0);
+ $result = _interwiki_insert('sw', 'http://www.sourcewatch.org/index.php?title=$1', 0);
+ $result = _interwiki_insert('th', 'http://thesaurus.reference.com/search?q=$3', 0);
+ $result = _interwiki_insert('archive', 'http://web.archive.org/web/*/http://$1', 0);
+ $result = _interwiki_insert('whois', 'http://reports.internic.net/cgi/whois?whois_nic=$1&type=domain', 0);
+ $result = _interwiki_insert('opendir', 'http://search.dmoz.org/cgi-bin/search?search=$2', 0);
+ $result = _interwiki_insert('technorati', 'http://technorati.com/tag/$2', 0, 'tag');
+ break;
+ }
+}
+
+function _interwiki_insert($prefix,$url,$local,$rel='') {
+ return db_query("INSERT INTO {interwiki} VALUES ('$prefix', '$url', $local, '$rel')");
+}
+
+function interwiki_uninstall() {
+ db_query('DROP TABLE {interwiki}');
+}
+
diff --git a/interwiki.module b/interwiki.module
index ae53576..50bec4c 100644
--- a/interwiki.module
+++ b/interwiki.module
@@ -7,6 +7,7 @@
* syntax to wikis and other websites
*
* Upgraded to Drupal 4.7, 5/13/2006
+ * Updated to Drupal 5.0, 2/03/2007
*
* This module, when configured, is responsible for translating user-inputted links of the form
* '[prefix:some term]' into the form '<a href="http://www.domain.com/some_term">some term</a>'
@@ -40,7 +41,7 @@ function interwiki_help($section) {
'%settings' => l(t("administer &raquo; filters"), "admin/filters", array(), NULL, NULL, FALSE, TRUE),
'%modules' => l(t("administer &raquo; modules"), "admin/modules", array(), NULL, NULL, FALSE, TRUE),
'%access' => l(t("administer &raquo; access control"), "admin/access", array(), NULL, NULL, FALSE, TRUE),
- '%interwikis' => l(t("administer &raquo; interwiki"), "admin/interwiki", array(), NULL, NULL, FALSE, TRUE)
+ '%interwikis' => l(t("administer &raquo; interwiki"), "admin/settings/interwiki", array(), NULL, NULL, FALSE, TRUE)
)) .
t("<h3>Included search prefixes</h3>".
"<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".
@@ -99,17 +100,18 @@ function interwiki_menu($may_cache) {
'access' => TRUE,
'callback' => 'interwiki_list',
'type' => MENU_CALLBACK);
- $items[] = array('path' => 'admin/interwiki',
+ $items[] = array('path' => 'admin/settings/interwiki',
'title' => t('interwiki'),
+ 'description' => t('Manage interwiki.'),
'access' => user_access('administer interwiki'),
'callback' => 'interwiki_admin');
- $items[] = array('path' => 'admin/interwiki/list',
+ $items[] = array('path' => 'admin/settings/interwiki/list',
'title' => t('list'),
'access' => user_access('administer interwiki'),
'callback' => 'interwiki_admin',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10 );
- $items[] = array('path' => 'admin/interwiki/add',
+ $items[] = array('path' => 'admin/settings/interwiki/add',
'title' => t('add'),
'access' => user_access('administer interwiki'),
'callback' => 'interwiki_admin',
@@ -168,15 +170,15 @@ function interwiki_list() {
'%piped' => $piped,
'%trans' => $trans_result
));
- $result = db_query("SELECT iw_prefix, iw_url from {interwiki}");
- $header = array(t('Prefix'), t('Translates to'));
+ $result = db_query("SELECT iw_prefix, iw_url, iw_rel from {interwiki}");
+ $header = array(t('Prefix'), t('rel'), t('Translates to'));
while ($record = db_fetch_object($result)) {
// Strip out $1, $2, $3 and $4 from interwiki tables ...
$url = preg_replace(array('/\$1/', '/\$2/', '/\$3/', '/\$4/'), '', $record->iw_url);
if ($url == '') {
$url = t('<i>a local path on this website</i>');
}
- $rows[] = array ($record->iw_prefix . ":", $url);
+ $rows[] = array ($record->iw_prefix . ":", $record->iw_rel, $url);
}
$output .= t('Available prefixes are:') . '<p>';
$output .= theme('table',$header,$rows);
@@ -195,11 +197,12 @@ function interwiki_filter($op, $delta = 0, $format = -1, $text = '') {
return t('Easily link to wikis and other reference websites');
case 'process':
- $result = db_query("SELECT iw_prefix, iw_url, iw_local from {interwiki}");
+ $result = db_query("SELECT iw_prefix, iw_url, iw_local, iw_rel from {interwiki}");
$targets = array();
while ($record = db_fetch_object($result)) {
$matcha[$record->iw_prefix] = $record->iw_url;
$targets[$record->iw_prefix] = $record->iw_local ? '_self' : '_blank';
+ $rels[$record->iw_prefix] = $record->iw_rel;
}
$syntax = variable_get("interwiki_syntax_$format", array('single'));
if (!(array_search('double', $syntax) === FALSE)) {
@@ -222,6 +225,7 @@ function interwiki_filter($op, $delta = 0, $format = -1, $text = '') {
$url_terminator = '|';
}
$target = $targets[$match[1][$index]];
+ $rel = $rels[$match[1][$index]];
$term = trim($match[2][$index]);
$term_array = explode($url_terminator, $term, 2);
$display_term = $term_array[1] ? $term_array[1] : $display_prefix . $term;
@@ -241,7 +245,7 @@ function interwiki_filter($op, $delta = 0, $format = -1, $text = '') {
$url = preg_replace(array('/\$1/','/\$2/', '/\$3/', '/\$4/'), array($url_term1, $url_term2, $url_term3, $url_term4), $matcha[$match[1][$index]]);
// If it's an external path, don't use the l() function
if (preg_match("/^(http|https|mailto|ftp):/i", $url)) {
- $html = '<a href="' . $url .'" title="reference on '. $display_term .'" target="'. $target .'">'. $display_term .'</a>';
+ $html = '<a href="' . $url .'" title="reference on '. $display_term . ($rel != "" ? ('" rel="' . $rel) : '') .'" target="'. $target .'">'. $display_term .'</a>';
} else {
$html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
}
@@ -269,6 +273,7 @@ function interwiki_filter($op, $delta = 0, $format = -1, $text = '') {
$url_terminator = '|';
}
$target = $targets[$match_default];
+ $rel = $rels[$match_default];
$term = trim($match[1][$index]);
$term_array = explode($url_terminator, $term, 2);
$display_term = $term_array[1] ? $term_array[1] : $display_prefix . $term;
@@ -287,7 +292,7 @@ function interwiki_filter($op, $delta = 0, $format = -1, $text = '') {
$url = preg_replace(array('/\$1/','/\$2/', '/\$3/', '/\$4/'), array($url_term1, $url_term2, $url_term3, $url_term4), $matcha[$match_default]);
// If it's an external path, don't use the l() function
if (preg_match("/^(http|https|mailto|ftp):/i", $url)) {
- $html = '<a href="' . $url .'" title="reference on '. $display_term .'" target="'. $target .'">'. $display_term .'</a>';
+ $html = '<a href="' . $url .'" title="reference on '. $display_term . ($rel != "" ? ('" rel="' . $rel) : '') .'" target="'. $target .'">'. $display_term .'</a>';
} else {
$html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
}
@@ -380,6 +385,10 @@ function interwiki_get($iw_prefix) {
*
*/
function interwiki_form($edit = array()) {
+ return drupal_get_form('interwiki_edit_form', $edit);
+}
+
+function interwiki_edit_form($edit) {
$form["iw_prefix"] = array(
'#type' => 'textfield',
'#title' => t("Prefix"),
@@ -388,12 +397,20 @@ function interwiki_form($edit = array()) {
'#maxlength' => 32,
'#description' => t("The prefix goes before a colon when users edit content, e.g., \"[prefix:some text].\""),
);
+ $form["iw_rel"] = array(
+ '#type' => 'textfield',
+ '#title' => t("rel"),
+ '#default_value' => $edit["iw_rel"],
+ '#size' => 32,
+ '#maxlength' => 32,
+ '#description' => t('The rel= parameter, if any, required in this link. This may be blank.'),
+ );
$form["iw_url"] = array(
'#type' => 'textfield',
'#title' => t("URL"),
'#default_value' => $edit["iw_url"],
'#size' => 50,
- '#maxlength' => 128,
+ '#maxlength' => 255,
'#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".'),
);
$form["iw_local"] = array(
@@ -414,9 +431,10 @@ function interwiki_form($edit = array()) {
'#value' => t("Delete"),
);
}
- return drupal_get_form('interwiki_add', $form);
+ return $form;
}
+
/**
* Update, insert or delete a filter from the database.
*
@@ -424,24 +442,29 @@ function interwiki_form($edit = array()) {
function interwiki_save($edit) {
db_query("DELETE FROM {interwiki} WHERE iw_prefix = '%s'", $edit["iw_prefix"]);
if ($edit["action"] != 'delete') {
- db_query("INSERT INTO {interwiki} (iw_prefix, iw_url, iw_local) VALUES ('%s', '%s', '%d')", $edit["iw_prefix"], $edit["iw_url"], $edit["iw_local"]);
+ 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"]);
}
}
/**Confirm deletion of filter*/
function _interwiki_confirm_del($edit=array()) {
+ return drupal_get_form('interwiki_delete_confirm_form', $edit['iw_prefix']);
+}
+
+function interwiki_delete_confirm_form($iw_prefix) {
$form['confirm'] = array(
'#type' => 'hidden',
'#value' => 1,
);
$form['iw_prefix'] = array(
'#type' => 'hidden',
- '#value' => $edit['iw_prefix'],
+ '#value' => $iw_prefix,
);
-
- $output = confirm_form('interwiki_confirm_del', $form, t('Are you sure you want to delete the interwiki prefix %name?', array('%name' => theme('placeholder', $edit['iw_prefix']))), 'admin/interwiki', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
- return $output;
+ return confirm_form($form,
+ t('Are you sure you want to delete the interwiki prefix %name?', array('%name' => $iw_prefix)),
+ 'admin/settings/interwiki', t('This action cannot be undone.'),
+ t('Delete'), t('Cancel') );
}
/**
@@ -451,10 +474,10 @@ function _interwiki_confirm_del($edit=array()) {
function interwiki_display() {
$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 ".
"\"some term\" article on the website specified by \"prefix.\" Available prefixes and the paths to which they point are:") . '</p>';
- $result = db_query("SELECT iw_prefix, iw_url, iw_local from {interwiki}");
- $header = array(t('Prefix'), t('Translates to'), t('Local?'), array("data" => t("operations"), "colspan" => 2));
+ $result = db_query("SELECT iw_prefix, iw_url, iw_rel, iw_local from {interwiki}");
+ $header = array(t('Prefix'), t('rel'), t('Translates to'), t('Local?'), array("data" => t("operations"), "colspan" => 2));
while ($record = db_fetch_object($result)) {
- $rows[] = array ($record->iw_prefix . ":", $record->iw_url, ($record->iw_local ? 'Yes' : 'No'), l(t("edit"), "admin/interwiki/edit/$record->iw_prefix"), l(t("delete"), "admin/interwiki/delete/$record->iw_prefix"));
+ $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"));
}
$output .= theme('table',$header,$rows);
$output .= '<p>' . t('The paths in the "translates to" row above use placeholder strings to specify how the space character should be ' .
@@ -474,10 +497,10 @@ function interwiki_display() {
*/
function interwiki_admin() {
$op = $_POST["op"];
- $edit = $_POST["edit"];
+ $edit = $_POST;
if (empty($op)) {
- $op = arg(2);
+ $op = arg(3);
}
switch ($op) {
@@ -485,10 +508,10 @@ function interwiki_admin() {
$output = interwiki_form();
break;
case "edit":
- $output = interwiki_form(interwiki_get(arg(3)));
+ $output = interwiki_form(interwiki_get(arg(4)));
break;
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
- $edit = interwiki_get(arg(3));
+ $edit = interwiki_get(arg(4));
// fall through:
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)
if (!$edit['confirm']) {
@@ -509,4 +532,4 @@ function interwiki_admin() {
print theme('page', $output);
}
-?>
+?> \ No newline at end of file