diff --git a/interwiki.info b/interwiki.info new file mode 100644 index 0000000000000000000000000000000000000000..abf9dea329f391cdaf8f575562d316edb23f7bf2 --- /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 0000000000000000000000000000000000000000..e871925b836617913d1a614cd05e3775207bb7f5 --- /dev/null +++ b/interwiki.install @@ -0,0 +1,41 @@ +some term' @@ -40,7 +41,7 @@ function interwiki_help($section) { '%settings' => l(t("administer » filters"), "admin/filters", array(), NULL, NULL, FALSE, TRUE), '%modules' => l(t("administer » modules"), "admin/modules", array(), NULL, NULL, FALSE, TRUE), '%access' => l(t("administer » access control"), "admin/access", array(), NULL, NULL, FALSE, TRUE), - '%interwikis' => l(t("administer » interwiki"), "admin/interwiki", array(), NULL, NULL, FALSE, TRUE) + '%interwikis' => l(t("administer » interwiki"), "admin/settings/interwiki", array(), NULL, NULL, FALSE, TRUE) )) . t("

Included search prefixes

". "

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:

\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('a local path on this website'); } - $rows[] = array ($record->iw_prefix . ":", $url); + $rows[] = array ($record->iw_prefix . ":", $record->iw_rel, $url); } $output .= t('Available prefixes are:') . '

'; $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 = ''. $display_term .''; + $html = ''. $display_term .''; } 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 = ''. $display_term .''; + $html = ''. $display_term .''; } 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 = '

' . 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:") . '

'; - $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 .= '

' . 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