[pmwiki-users] automatic page titles (aless)

Dominique Faure dominique.faure at gmail.com
Sat Aug 2 05:07:20 CDT 2008


On Sat, Aug 2, 2008 at 09:33, aless <alessors at gmail.com> wrote:
>
> >>  [...] I found also the AlternateNamingScheme recipe in the Cookbook
> >> (http://www.pmwiki.org/wiki/Cookbook/AlternateNamingScheme), and
> >> following the instructions I came up with this array that should transform
> >>
> >> l'albero di natale => L_albero_di_natale:
> >>
> >> $MakePageNamePatterns = array(
> >>      "/'/" => '',                           # strip single-quotes
> >>      "/[^$PageNameChars]+/" => ' ',         # convert non-alnums to spaces
> >>      "/(^\\w)/e" => "strtoupper('$1')",     # initial caps
> >>
> >>      "/\\s+/" => '_'                        # Convert spaces to
> >> underscores
> >> );
> >
> > It should be possible to handle the apostrophe too. One option
> > would be to use the ~ character in the pagename and url as a
> > surrogate for the ' and then convert "~" to "'" on output, in much
> > the same way as the above code converts '_' to ' '. This is done in
> > the custom $AsSpacedFunction.
>
> Hello John,
>
> actually, page names with underscores instead of apostrophes are still
> quite readable, I wanted to try your solution too, but I really don't
> know where to start, could you give me some more hints? I tried to put
> this in my config.php, but it still converts single quotes to spaces and
> then to underscores:
>
> $PageNameChars = '-~[:alnum:]';
>
> $MakePageNamePatterns = array(
>     "/'/" => '~',                           # strip single-quotes
>     "/[^-[:alnum:]]+/" => ' ',         # convert non-alnums to spaces
>     "/(^\\w)/e" => "strtoupper('$1')",     # initial caps
>     "/\\s+/" => '_');                      # Convert spaces to underscores
>
> I think I'm missing something, don't I?

You just forget to exclude the '~' from the char to convert to space:

$MakePageNamePatterns = array(
    "/'/" => '~',                          # strip single-quotes
    "/[^-~[:alnum:]]+/" => ' ',            # convert non-alnums to spaces
    "/(^\\w)/e" => "strtoupper('$1')",     # initial caps
    "/\\s+/" => '_');                      # Convert spaces to underscores

or better:

$PageNameChars = '-~[:alnum:]';

$MakePageNamePatterns = array(
    "/'/" => '~',                          # strip single-quotes
    "/[^$PageNameChars]+/" => ' ',         # convert non-alnums to spaces
    "/(^\\w)/e" => "strtoupper('$1')",     # initial caps
    "/\\s+/" => '_');                      # Convert spaces to underscores


--
Dominique



More information about the pmwiki-users mailing list