summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-04-16 12:39:11 +0200
committerandi <andi@splitbrain.org>2005-04-16 12:39:11 +0200
commit97a3e4e3d70217e2c16b0d48f9cd28f52d80368f (patch)
tree2d6fbdf6335df7a227a945a86a138d26646f1456
parent0f7321d2900379a846487bf9bbf15b62ecae4180 (diff)
downloadrpg-97a3e4e3d70217e2c16b0d48f9cd28f52d80368f.tar.gz
rpg-97a3e4e3d70217e2c16b0d48f9cd28f52d80368f.tar.bz2
new parser: interwiki links
darcs-hash:20050416103911-9977f-2c015ba3f80596ca82261eb623eabdea8d617a55.gz
-rw-r--r--inc/confutils.php2
-rw-r--r--inc/parser/xhtml.php104
-rw-r--r--interwiki/doku.gifbin952 -> 959 bytes
3 files changed, 60 insertions, 46 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
index 114fa3024..c04d39896 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -90,6 +90,8 @@ function getInterwiki() {
if ( !$wikis ) {
$wikis = confToHash(DOKU_INC . 'conf/interwiki.conf');
}
+ //add sepecial case 'this'
+ $wikis[] = 'this '.DOKU_URL.'{NAME}';
return $wikis;
}
diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php
index 83d498b47..36bfb1e02 100644
--- a/inc/parser/xhtml.php
+++ b/inc/parser/xhtml.php
@@ -449,62 +449,74 @@ class Doku_Renderer_XHTML extends Doku_Renderer {
/**
* @TODO Remove hard coded link to splitbrain.org on style
*/
- function interwikilink($link, $title = NULL, $wikiName, $wikiUri) {
+ function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
global $conf;
- // RESOLVE THE URL
- if ( isset($this->interwiki[$wikiName]) ) {
-
- $wikiUriEnc = urlencode($wikiUri);
-
- if ( strstr($this->interwiki[$wikiName],'{URL}' ) !== FALSE ) {
-
- $url = str_replace('{URL}', $wikiUriEnc, $this->interwiki[$wikiName] );
-
- } else if ( strstr($this->interwiki[$wikiName],'{NAME}' ) !== FALSE ) {
-
- $url = str_replace('{NAME}', $wikiUriEnc, $this->interwiki[$wikiName] );
-
- } else {
-
- $url = $this->interwiki[$wikiName] . urlencode($wikiUri);
-
- }
-
+ $link = array();
+ $link['target'] = $conf['target']['interwiki'];
+ $link['pre'] = '';
+ $link['suf'] = '';
+ $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"';
+ $link['name'] = $this->__getLinkTitle($name, $wikiUri, $isImage);
+
+ if ( !$isImage ) {
+ $link['class'] = 'interwiki';
} else {
- // Default to Google I'm feeling lucky
- $url = 'http://www.google.com/search?q='.urlencode($wikiUri).'&amp;btnI=lucky';
+ $link['class'] = 'media';
}
-
- // BUILD THE LINK
- echo '<a';
-
- $title = $this->__getLinkTitle($title, $wikiUri, $isImage);
-
- if ( !$isImage ) {
- echo ' class="interwiki"';
+
+ //get interwiki URL
+ if ( isset($this->interwiki[$wikiName]) ) {
+ $url = $this->interwiki[$wikiName];
} else {
- echo ' class="media"';
+ // Default to Google I'm feeling lucky
+ $url = 'http://www.google.com/search?q={URL}&amp;btnI=lucky';
+ $wikiName = 'go';
+ }
+
+ if(!$isImage){
+ //if ico exists set additional style
+ if(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.png')){
+ $link['style']='background: transparent url('.DOKU_BASE.'interwiki/'.$wikiName.'.png) 0px 1px no-repeat;';
+ }elseif(@file_exists(DOKU_INC.'interwiki/'.$wikiName.'.gif')){
+ $link['style']='background: transparent url('.DOKU_BASE.'interwiki/'.$wikiName.'.gif) 0px 1px no-repeat;';
+ }
}
-
- echo ' href="'.$this->__xmlEntities($url).'"';
-
- if ( FALSE !== ( $type = interwikiImgExists($wikiName) ) ) {
- echo ' style="background: transparent url(http://wiki.splitbrain.org/interwiki/'.
- $wikiName.'.'.$type.') 0px 1px no-repeat;"';
+
+ //do we stay at the same server? Use local target
+ if( strpos($url,DOKU_URL) === 0 ){
+ $link['target'] = $conf['target']['wiki'];
+ }
+
+ //replace placeholder
+ if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#',$url)){
+ //use placeholders
+ $url = str_replace('{URL}',urlencode($wikiUri),$url);
+ $url = str_replace('{NAME}',$wikiUri,$url);
+ $parsed = parse_url($wikiUri);
+ if(!$parsed['port']) $parsed['port'] = 80;
+ $url = str_replace('{SCHEME}',$parsed['scheme'],$url);
+ $url = str_replace('{HOST}',$parsed['host'],$url);
+ $url = str_replace('{PORT}',$parsed['port'],$url);
+ $url = str_replace('{PATH}',$parsed['path'],$url);
+ $url = str_replace('{QUERY}',$parsed['query'],$url);
+ $link['url'] = $url;
+ }else{
+ //default
+ $link['url'] = $url.urlencode($wikiUri);
}
-
- echo ' onclick="return svchk()" onkeypress="return svchk()">';
-
- echo $title;
-
- echo '</a>';
+
+ $link['title'] = htmlspecialchars($link['url']);
+
+ //output formatted
+ echo $this->__formatLink($link);
}
/**
- * @TODO Correct the CSS class for files? (not windows)
- * @TODO Remove hard coded URL to splitbrain.org
- */
+ * @deprecated not used!!!
+ * @TODO Correct the CSS class for files? (not windows)
+ * @TODO Remove hard coded URL to splitbrain.org
+ */
function filelink($link, $title = NULL) {
echo '<a';
diff --git a/interwiki/doku.gif b/interwiki/doku.gif
index f092ed1d1..0f9fc06c2 100644
--- a/interwiki/doku.gif
+++ b/interwiki/doku.gif
Binary files differ