From 3e58e5938b0f5517aefdf1a941237b443cfaab87 Mon Sep 17 00:00:00 2001 From: rurban Date: Sun, 8 Oct 2006 12:38:11 +0000 Subject: [PATCH] New special interwiki link markup [:LinkTo] without storing the backlink git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@5166 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/CachedMarkup.php | 29 +++++++++++++++++++++++------ lib/InlineParser.php | 10 ++++++++-- lib/PageType.php | 19 +++++++++++++++---- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/lib/CachedMarkup.php b/lib/CachedMarkup.php index 7d4b346d1..7e29aafea 100644 --- a/lib/CachedMarkup.php +++ b/lib/CachedMarkup.php @@ -1,7 +1,7 @@ - * Copyright (C) 2004, 2005 $ThePhpWikiProgrammingTeam + * Copyright (C) 2004,2005,2006 $ThePhpWikiProgrammingTeam * * This file is part of PhpWiki. * @@ -77,8 +77,7 @@ class CacheableMarkup extends XmlContent { /** Get names of wikipages linked to. * - * @return array - * A hash of linkto=>pagenames, relation=>pagenames (strings). + * @return array of hashes { linkto=>pagename, relation=>pagename } */ function getWikiPageLinks() { $links = array(); @@ -89,7 +88,8 @@ class CacheableMarkup extends XmlContent { continue; $links = array_merge($links, $item_links); } - // array_unique has a bug with hashes! set_links checks for duplicates, array_merge does not + // array_unique has a bug with hashes! + // set_links checks for duplicates, array_merge does not //return array_unique($links); return $links; } @@ -524,9 +524,26 @@ class Cached_InterwikiLink extends Cached_ExternalLink { $this->_label = $label; } + function getPagename($basepage) { + list ($moniker, $page) = split (":", $this->_link, 2); + $page = new WikiPageName($page, $basepage); + if ($page->isValid()) return $page->name; + else return false; + } + + function getWikiPageLinks($basepage) { + if ($basepage == '') return false; + /* ":DontStoreLink" */ + if (substr($this->_link,0,1) == ':') return false; + /* store only links to valid pagenames */ + if ($link = $this->getPagename($basepage)) + return array(array('linkto' => $link, 'relation' => 0)); + else return false; // dont store external links + } + function _getName($basepage) { $label = isset($this->_label) ? $this->_label : false; - return ($label and is_string($label)) ? $label : $link; + return ($label and is_string($label)) ? $label : $this->_link; } function _getURL($basepage) { diff --git a/lib/InlineParser.php b/lib/InlineParser.php index e53f5f021..769ae2125 100644 --- a/lib/InlineParser.php +++ b/lib/InlineParser.php @@ -1,5 +1,5 @@ * Copyright (C) 2004,2005,2006 Reini Urban * @@ -403,6 +403,9 @@ function LinkBracketLink($bracketlink) { /* Semantic relations and attributes */ elseif (preg_match("/:[:-]/", $link) and !isImageLink($link)) return new Cached_SemanticLink($link, $label); + /* Do not store the link */ + elseif (substr($link,0,1) == ':') + return new Cached_InterwikiLink($link, $label); /* * Inline images in Interwiki urls's: * [File:my_image.gif] inlines the image, @@ -798,7 +801,7 @@ class InlineTransformer 'interwiki', /* 'wikiword', */ 'linebreak', 'old_emphasis', 'nestled_emphasis', 'html_emphasis', 'html_abbr', 'plugin', - 'isonumchars', 'isohexchars', 'html_entities' + 'isonumchars', 'isohexchars', /*'html_entities'*/ ); else $markup_types = array @@ -980,6 +983,9 @@ function TransformInlineNowiki($text, $markup = 2.0, $basepage=false) { // $Log: not supported by cvs2svn $ +// Revision 1.78 2006/09/03 09:53:52 rurban +// more colors, case-insensitive color names +// // Revision 1.77 2006/08/25 19:02:02 rurban // patch #1348996 by Robert Litwiniec: fix show image semantics if label is given // diff --git a/lib/PageType.php b/lib/PageType.php index a4474eed2..698f32317 100644 --- a/lib/PageType.php +++ b/lib/PageType.php @@ -1,7 +1,7 @@ $url)); - if (!$linktext) { + if ($moniker == '') { // ":LinkName" + $link->pushContent(HTML::span(array('class' => 'wikipage'), $page)); + $link->setAttr('class', $linktext ? 'named-wiki' : 'wiki'); + } + elseif (!$linktext) { $link->pushContent(PossiblyGlueIconToText('interwiki', "$moniker:"), HTML::span(array('class' => 'wikipage'), $page)); $link->setAttr('class', 'interwiki'); @@ -210,7 +214,7 @@ class PageType_interwikimap extends PageType $map[$m[1]] = $m[2]; } - // Add virtual monikers Upload: Talk: User: + // Add virtual monikers: "Upload:" "Talk:" "User:", ":" // and expand special variables %u, %b, %d // Upload: Should be expanded later to user-specific upload dirs. @@ -224,6 +228,7 @@ class PageType_interwikimap extends PageType if (empty($map["User"])) { $map["User"] = "%s"; } + // Talk:UserName => UserName/Discussion // Talk:PageName => PageName/Discussion as default, which might be overridden if (empty($map["Talk"])) { $pagename = $GLOBALS['request']->getArg('pagename'); @@ -233,6 +238,9 @@ class PageType_interwikimap extends PageType else $map["Talk"] = "%s".SUBPAGE_SEPARATOR._("Discussion"); } + if (empty($map[''])) { // Magic syntax: Don't store links ":PageName" as backlink + $map[''] = '%s'; + } foreach (array('Upload','User','Talk') as $special) { // Expand special variables: @@ -503,6 +511,9 @@ class PageFormatter_pdf extends PageFormatter } } // $Log: not supported by cvs2svn $ +// Revision 1.47 2005/08/07 09:14:38 rurban +// fix comments +// // Revision 1.46 2005/08/06 13:09:33 rurban // allow spaces in interwiki paths, even implicitly. fixes bug #1218733 // -- 2.45.0