[pmwiki-users] automatic page titles (aless)

aless alessors at gmail.com
Sun Aug 3 12:52:51 CDT 2008


Hello John,

Thanks for the hints, I modified the script with your suggestions. It 
still doesn't work, though, but the problem now is in the way the new 
name pattern affects PmWiki, I guess.

If I create a page by inserting the new name in the address bar, the 
substitution works as expected:

page_with_spaces => Page with spaces

carol~s_page => Carol's page

The problem is, anything I type in the edit box is not saved in the 
page, even is the page is created. This is the content of Carol~s-page, 
created, saved, then edited and saved again (of course every time I 
typed something in the edit box):

version=pmwiki-2.2.0-beta67 ordered=1 urlencoded=1
agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) 
Gecko/2008052906 Firefox/3.0
author=
charset=UTF-8
csum=
ctime=1217785147
host=127.0.0.1
name=Main.Carol~s_page
rev=2
targets=
text=
time=1217785183
author:1217785183=
diff:1217785183:1217785147:=
host:1217785183=127.0.0.1
author:1217785147=
diff:1217785147:1217785147:=
host:1217785147=127.0.0.1

Here's the modified script:

***script***
<?php if (!defined('PmWiki')) exit();

define(SPACEDTITLES_VERSION, '1.0');

/*  Copyright 2005 Mateusz Czaplinski (mateusz at czaplinski.pl)
     This file is spacedTitles.php; 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.

     >>> Modified to substiute single quotes with ~ and display ~ as 	 
          single quote



     *** DOES NOT WORK at the moment ***


*/

## Add to local/config.php:
#
# $NamePattern = '[[:upper:]\\d][\\w]*(?:[-~]\\w+)*';
# include_once("$FarmD/cookbook/spacedTitles.php");

if( $Charset=='UTF-8' ) {
   $PageNameChars='-_~[:alnum:]\\x80-\\xfe';
   $MakePageNamePatterns = array(
     "/'/" => '~',                          # convert single quotes to ~
     "/[^$PageNameChars]+/" => ' ',         # convert everything else to 
spaces
     "/(^\\s+)|(\\s+\$)/" => '',            # trim whitespaces
     "/^([a-z])/e" => "strtoupper('$1')",   # uppercase first letter
     "/^([\\xc0-\\xdf].)/e" => "utf8toupper('$1')",  # uppercase first 
letter (utf8)
     "/ /" => '_');                         # convert spaces to underscores
} else {
   $PageNameChars = '-_~[:alnum:]';
   $MakePageNamePatterns = array(
     "/'/" => '~',                          # convert single quotes to ~
     "/[^$PageNameChars]+/" => ' ',         # convert everything else to 
spaces
     "/(^\\s+)|(\\s+\$)/" => '',            # trim whitespaces
     "/^(\\w)/e" => "strtoupper('$1')",     # uppercase first letter
     "/ /" => '_'                           # convert spaces to underscores
   );
}

$AsSpacedFunction = 'AsSpacedUnderlines';
function AsSpacedUnderlines($text) {
   return str_replace(array('_','~'), array(' ','&rsquo;'), $text);
}

$SpaceWikiWords = 1;
***script/***

For the moment I settled with the spaces and apostrophes to underscores, 
which breaks the original links of a fresh installation of PmWiki, but 
works fine with newly created pages. I put everything in local/config.php:

***cut***
$PageNameChars='-_[:alnum:]\\x80-\\xfe';
$NamePattern = '[[:upper:]\\d][\\w]*(?:[-]\\w+)*';
$MakePageNamePatterns = array(
   "/'/" => ' ',                          # convert single quotes to spaces
   "/[^$PageNameChars]+/" => ' ',         # convert everything else to 
spaces
   "/(^\\s+)|(\\s+\$)/" => '',            # trim whitespaces
   "/^([a-z])/e" => "strtoupper('$1')",   # uppercase first letter
   "/^([\\xc0-\\xdf].)/e" => "utf8toupper('$1')",  # uppercase first 
letter (utf8)
   "/ /" => '_');                         # convert spaces to underscores
***cut***

cheers,
  alessandro




More information about the pmwiki-users mailing list