diff options
author | pmichaud <pmichaud@524c5546-5005-0410-9a3e-e25e191bd360> | 2007-01-21 03:08:01 +0000 |
---|---|---|
committer | pmichaud <pmichaud@524c5546-5005-0410-9a3e-e25e191bd360> | 2007-01-21 03:08:01 +0000 |
commit | 2a1660e8b3b2725f7f56c5047ddba608856af399 (patch) | |
tree | eadcc6a998aa4e6d590a287a10ee647938238ba1 | |
parent | b062298f0b3f85ff018612a915ea46a1d3ac9227 (diff) | |
download | pmwiki.svn-2a1660e8b3b2725f7f56c5047ddba608856af399.tar.bz2 |
Move WikiWord processing into an optional script.
git-svn-id: svn://pmwiki.org/pmwiki/trunk@1822 524c5546-5005-0410-9a3e-e25e191bd360
-rw-r--r-- | docs/sample-config.php | 4 | ||||
-rw-r--r-- | pmwiki.php | 13 | ||||
-rw-r--r-- | scripts/stdconfig.php | 2 | ||||
-rw-r--r-- | scripts/stdmarkup.php | 10 | ||||
-rw-r--r-- | scripts/transition.php | 17 | ||||
-rw-r--r-- | scripts/wikiwords.php | 44 |
6 files changed, 69 insertions, 21 deletions
diff --git a/docs/sample-config.php b/docs/sample-config.php index 71e8e30e..88de7397 100644 --- a/docs/sample-config.php +++ b/docs/sample-config.php @@ -69,8 +69,8 @@ $WikiTitle = 'PmWiki'; ## have spaces before each sequence of capital letters. # $SpaceWikiWords = 1; # turn on WikiWord spacing -## Set $LinkWikiWords if you want to allow WikiWord links. -# $LinkWikiWords = 1; # enable WikiWord links +## Set $EnableWikiWords if you want to allow WikiWord links. +# $EnableWikiWords = 1; # enable WikiWord links ## If you want only the first occurrence of a WikiWord to be converted ## to a link, set $WikiWordCountMax=1. @@ -66,7 +66,6 @@ $EnablePost = 1; $ChangeSummary = substr(stripmagic(@$_REQUEST['csum']), 0, 100); $AsSpacedFunction = 'AsSpaced'; $SpaceWikiWords = 0; -$LinkWikiWords = 0; $RCDelimPattern = ' '; $RecentChangesFmt = array( '$SiteGroup.AllRecentChanges' => @@ -1192,18 +1191,6 @@ function FormatTableRow($x, $sep = '\\|\\|') { return "<:table,1><tr $trattr>$y</tr>"; } -function WikiLink($pagename, $word) { - global $LinkWikiWords, $WikiWordCount, $SpaceWikiWords, $AsSpacedFunction, - $MarkupFrame, $WikiWordCountMax; - if (!$LinkWikiWords || ($WikiWordCount[$word] < 0)) return $word; - $text = ($SpaceWikiWords) ? $AsSpacedFunction($word) : $word; - $text = preg_replace('!.*/!', '', $text); - if (!isset($MarkupFrame[0]['wwcount'][$word])) - $MarkupFrame[0]['wwcount'][$word] = $WikiWordCountMax; - if ($MarkupFrame[0]['wwcount'][$word]-- < 1) return $text; - return MakeLink($pagename, $word, $text); -} - function LinkIMap($pagename,$imap,$path,$title,$txt,$fmt=NULL) { global $FmtV, $IMap, $IMapLinkFmt, $UrlLinkFmt; $FmtV['$LinkUrl'] = PUE(str_replace('$1',$path,$IMap[$imap])); diff --git a/scripts/stdconfig.php b/scripts/stdconfig.php index a6ea7663..42b51615 100644 --- a/scripts/stdconfig.php +++ b/scripts/stdconfig.php @@ -44,6 +44,8 @@ if (IsEnabled($EnableSkinLayout,1)) include_once("$FarmD/scripts/skins.php"); # must come after prefs if (@$Transition || IsEnabled($EnableTransitions, 0)) include_once("$FarmD/scripts/transition.php"); # must come after skins +if (@$LinkWikiWords || IsEnabled($EnableWikiWords, 0)) + include_once("$FarmD/scripts/wikiwords.php"); # must come before stdmarkup if (IsEnabled($EnableStdMarkup,1)) include_once("$FarmD/scripts/stdmarkup.php"); # must come after transition if ($action=='diff' && @!$HandleActions['diff']) diff --git a/scripts/stdmarkup.php b/scripts/stdmarkup.php index 30334ac7..ed03cef3 100644 --- a/scripts/stdmarkup.php +++ b/scripts/stdmarkup.php @@ -276,17 +276,15 @@ Markup('img','<urllink', \$GLOBALS['ImgTagFmt']),'L')"); ## bare wikilinks -Markup('wikilink', '>urllink', - "/\\b($GroupPattern([\\/.]))?($WikiWordPattern)/e", - "Keep('<span class=\\'wikiword\\'>'.WikiLink(\$pagename,'$0').'</span>', - 'L')"); +## v2.2: markup rule moved to scripts/wikiwords.php) +Markup('wikilink', '>urllink'); -## escaped `WikiWords +## escaped `WikiWords +## v2.2: rule kept here for markup compatibility with 2.1 and earlier Markup('`wikiword', '<wikilink', "/`(($GroupPattern([\\/.]))?($WikiWordPattern))/e", "Keep('$1')"); - #### Block markups #### ## Completely blank lines don't do anything. Markup('blank', '<block', '/^\\s+$/', ''); diff --git a/scripts/transition.php b/scripts/transition.php index 698bcb67..1ea85327 100644 --- a/scripts/transition.php +++ b/scripts/transition.php @@ -14,6 +14,10 @@ Transitions defined in this script: + $Transition['wikiwords'] - 2.1-style WikiWord processing + + $Transition['version'] < 2001924 - all transitions listed above + $Transition['abslinks'] - absolute links/page vars $Transition['version'] < 2001901 - all transitions listed above @@ -54,6 +58,19 @@ ## if ?trans=0 is specified, then we don't do any fixups. if (@$_REQUEST['trans']==='0') return; +## Transitions from 2.2.0-beta24 +if (@$Transition['version'] < 2001924) + SDVA($Transition, array('wikiwords' => 1)); + +## wikiwords: +## This restores the PmWiki 2.1 behavior for WikiWord processing. +## WikiWords aren't linked by default, but appear with +## <span class='wikiword'>...</span> tags around them. +if (@$Transition['wikiwords']) { + SDV($EnableWikiWords, 1); + SDV($LinkWikiWords, 0); +} + ## Transitions from 2.2.0-beta1 if (@$Transition['version'] < 2001901) SDVA($Transition, array('abslinks' => 1)); diff --git a/scripts/wikiwords.php b/scripts/wikiwords.php new file mode 100644 index 00000000..652c1f84 --- /dev/null +++ b/scripts/wikiwords.php @@ -0,0 +1,44 @@ +<?php if (!defined('PmWiki')) exit(); +/* Copyright 2001-2007 Patrick R. Michaud (pmichaud@pobox.com) + This file is part of PmWiki; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. See pmwiki.php for full details. + + This script adds WikiWord (CamelCase) processing to PmWiki. + Originally WikiWords were part of the default configuration, + but their usage has died out over time and so it's now optional. + + To enable WikiWord links, simply add the following to + a local customization file: + + $EnableWikiWords = 1; + + To have PmWiki recognize and process WikiWords but not link + them (i.e., the default behavior in PmWiki 2.1), also add + + $LinkWikiWords = 0; + +*/ + +SDV($LinkWikiWords, 1); + +## bare wikilinks +Markup('wikilink', '>urllink', + "/\\b(?<![#&])($GroupPattern([\\/.]))?($WikiWordPattern)/e", + "Keep('<span class=\\'wikiword\\'>'.WikiLink(\$pagename,'$0').'</span>', + 'L')"); + +function WikiLink($pagename, $word) { + global $LinkWikiWords, $WikiWordCount, $SpaceWikiWords, $AsSpacedFunction, + $MarkupFrame, $WikiWordCountMax; + if (!$LinkWikiWords || ($WikiWordCount[$word] < 0)) return $word; + $text = ($SpaceWikiWords) ? $AsSpacedFunction($word) : $word; + $text = preg_replace('!.*/!', '', $text); + if (!isset($MarkupFrame[0]['wwcount'][$word])) + $MarkupFrame[0]['wwcount'][$word] = $WikiWordCountMax; + if ($MarkupFrame[0]['wwcount'][$word]-- < 1) return $text; + return MakeLink($pagename, $word, $text); +} + + |