I like the interwiki module. I'm using it for two things that are outside what the code in CVS does.

I posted a little about the change here: http://drupal.org/node/27527

I have two changes to submit:

  1. Allowing for longer URL's. This is because some amazon affiliate URL's are very long.
  2. Allow for the rel= attribute to be specified. This allows for technorati tag support.

With the technorati tag support I simply put

[technorati:tag name]

And this creates the technorati tag for me.

Here's the patch:

-bash-2.05b$ diff -cr interwiki ~/public_html/modules/interwiki          
diff -cr interwiki/interwiki.module /usr/home/davidh/public_html/modules/interwiki/interwiki.module
*** interwiki/interwiki.module  Sat Jun 18 22:08:40 2005
--- /usr/home/davidh/public_html/modules/interwiki/interwiki.module     Tue Jul 26 23:10:24 2005
***************
*** 134,148 ****
                                     '%unpiped' => $unpiped, 
                                     '%piped' => $piped                           
                                  ));
!   $result = db_query("SELECT iw_prefix, iw_url from {interwiki}");
!   $header = array(t('Prefix'), 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);
    }
    $output .= t('Available prefixes are:') . '<p>';
    $output .= theme('table',$header,$rows);
--- 134,148 ----
                                     '%unpiped' => $unpiped, 
                                     '%piped' => $piped                           
                                  ));
!   $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 . ":", $record->iw_rel, $url);
    }
    $output .= t('Available prefixes are:') . '<p>';
    $output .= theme('table',$header,$rows);
***************
*** 161,171 ****
        return t('Easily link to wikis and other reference websites'); 
  
      case 'process':
!       $result = db_query("SELECT iw_prefix, iw_url, iw_local 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';
        }
        $syntax = variable_get("interwiki_syntax_$format", array('single'));
        if (!(array_search('double', $syntax) === FALSE)) {
--- 161,172 ----
        return t('Easily link to wikis and other reference websites'); 
  
      case 'process':
!       $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)) {
***************
*** 188,193 ****
--- 189,195 ----
                                $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;
***************
*** 206,212 ****
                $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>';
                } else {
                  $html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
                }
--- 208,218 ----
                $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 
!                       . ($rel != "" ? ('" rel="' . $rel) : '')
!                       .'" target="'. $target .'">'.
!                       $display_term .'</a>';
                } else {
                  $html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
                }
***************
*** 234,239 ****
--- 240,246 ----
                                $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;
***************
*** 252,258 ****
                $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>';
                } else {
                  $html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
                }
--- 259,269 ----
                $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 
!                       . ($rel != "" ? ('" rel="' . $rel) : '')
!                       .'" target="'. $target .'">'. 
!                       $display_term .'</a>';
                } else {
                  $html = l($display_term, $url, array('title' => "reference on $display_term", 'target' => $target));
                }
***************
*** 334,340 ****
   */
  function interwiki_form($edit = array()) {
    $form .= form_textfield(t("Prefix"), "iw_prefix", $edit["iw_prefix"], 32, 32, t("The prefix goes before a colon when users edit content, e.g., \"[prefix:some text].\""));
!   $form .= form_textfield(t("URL"), "iw_url", $edit["iw_url"], 50, 128, 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 .= form_checkbox(t("Local?"), "iw_local", 1, $edit["iw_local"], t("Is this link local to your website? Non-local links will open in a new window."));
    $form .= form_submit(t("Submit"));
    
--- 345,352 ----
   */
  function interwiki_form($edit = array()) {
    $form .= form_textfield(t("Prefix"), "iw_prefix", $edit["iw_prefix"], 32, 32, t("The prefix goes before a colon when users edit content, e.g., \"[prefix:some text].\""));
!   $form .= form_textfield(t("rel"), "iw_rel", $edit["iw_rel"], 32, 32, t('The rel= parameter, if any, required in this link.  This may be blank.')); 
!   $form .= form_textfield(t("URL"), "iw_url", $edit["iw_url"], 50, 255, 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 .= form_checkbox(t("Local?"), "iw_local", 1, $edit["iw_local"], t("Is this link local to your website? Non-local links will open in a new window."));
    $form .= form_submit(t("Submit"));
    
***************
*** 352,358 ****
  function interwiki_save($edit) {
    db_query("DELETE FROM {interwiki} WHERE iw_prefix = '%s'", $edit["iw_prefix"]);
    if ($edit["iw_url"]) {
!     db_query("INSERT INTO {interwiki} (iw_prefix, iw_url, iw_local) VALUES  ('%s', '%s', '%d')", $edit["iw_prefix"], $edit["iw_url"], $edit["iw_local"]);
    }
  }
  
--- 364,370 ----
  function interwiki_save($edit) {
    db_query("DELETE FROM {interwiki} WHERE iw_prefix = '%s'", $edit["iw_prefix"]);
    if ($edit["iw_url"]) {
!     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"]);
    }
  }
  
***************
*** 363,372 ****
  function interwiki_display() {
    $output = t("<p>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));
    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"));
    }
    $output .= theme('table',$header,$rows);
    return $output;
--- 375,384 ----
  function interwiki_display() {
    $output = t("<p>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_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_rel, $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"));
    }
    $output .= theme('table',$header,$rows);
    return $output;
diff -cr interwiki/interwiki.sql /usr/home/davidh/public_html/modules/interwiki/interwiki.sql
*** interwiki/interwiki.sql     Fri Jun 10 04:10:14 2005
--- /usr/home/davidh/public_html/modules/interwiki/interwiki.sql        Tue Jul 26 00:29:43 2005
***************
*** 14,21 ****
  
  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',
    UNIQUE KEY iw_prefix (iw_prefix)
  ) TYPE=MyISAM;
  
--- 14,22 ----
  
  CREATE TABLE interwiki (
    iw_prefix char(32) NOT NULL default '',
!   iw_url char(255) NOT NULL default '',
    iw_local tinyint(1) NOT NULL default '0',
+   iw_rel char(32) NOT NULL DEFAULT '',
    UNIQUE KEY iw_prefix (iw_prefix)
  ) TYPE=MyISAM;
  
-bash-2.05b$ 

Comments

ohnobinki’s picture

+