Tags:
create new tag
view all tags

SID-00168: search for buildWikiWord function

Status: Answered Answered TWiki version: 4.2.4 Perl version:
Category: CategoryAPI Server OS: Last update: 16 years ago

Is there a reverse function to spaceOutWikiWord which converts an arbitrary text to the corresponding WikiWord, as the twiki does when using arbitrary text as link target?

-- TWikiGuest - 06 Mar 2009

Discussion and Answer

There is no TWikiFuncDotPm function for that. If you are a Perl programmer could you contribute it to the TWiki community?

See TWikiRegistration, it has some JavaScript to create a WikiWord out of first name and last name.

-- PeterThoeny - 06 Mar 2009

Thank yout for the answer. Yes I'm an Perl programmer and I could contribute it, but the TWiki core code must already contain the conversion. It's not a matter of effort, but a matter of consistency. I want to use the conversion in a plugin to determin the corresponding TWiki page for a given text link target as the core would do. So the implementation must - to be reliable - do excatly the same as the TWiki core code. For all cases including special characters and "special" letters as german umlaut. For now and for the future. That means that a change in the core must affect the required function, too. So I would be nice if there is one "offical" function, which the core uses and I can use.

-- TWikiGuest - 06 Mar 2009

Makes all sense, yes. Add a TWiki::Func::buildWikiWord that calls the internal existing function. We'd love to get you involved, see ReadmeFirst and SoYouWantToBeATWikiDeveloper.

-- PeterThoeny - 07 Mar 2009

Thank you for the answer. I've searched the code core and found where the convertion takes place. It's in the middle of the _handleSquareBracketedLink method in lib/TWiki/Render.pm, starting with "filter out &any; entities (legacy)". Part of the functionality it duplicated in the internalLink method in the same file, starting with "Turn spaced-out names", but I think this doesn't matter.

Because it's not up to me totally twiki newbie to change the core code, I suggest the following and kindly request the core team to change the files. Please move the lines

# filter out &any; entities (legacy)
$link =~ s/\&[a-z]+\;//gi;
# filter out { entities (legacy)
$link =~ s/\&\#[0-9]+\;//g;
# Filter junk
$link =~ s/$TWiki::cfg{NameFilter}+/ /g;
# Capitalise first word
$link =~ s/^(.)/\U$1/;
# Collapse spaces and capitalise following letter
$link =~ s/\s([$TWiki::regex{mixedAlphaNum}])/\U$1/go;
# Get rid of remaining spaces, i.e. spaces in front of -'s and ('s
$link =~ s/\s//go;

to a new buildWikiWord method located in Render.pm which takes $link as a parameter and returns the changed $link (WikiWord).

# Converts arbitrary text to a WikiWord
sub buildWikiWord {
    my( $this, $link ) = @_;

    # filter out &any; entities (legacy)
    $link =~ s/\&[a-z]+\;//gi;
    # filter out { entities (legacy)
    $link =~ s/\&\#[0-9]+\;//g;
    # Filter junk
    $link =~ s/$TWiki::cfg{NameFilter}+/ /g;
    # Capitalise first word
    $link =~ s/^(.)/\U$1/;
    # Collapse spaces and capitalise following letter
    $link =~ s/\s([$TWiki::regex{mixedAlphaNum}])/\U$1/go;
    # Get rid of remaining spaces, i.e. spaces in front of -'s and ('s
    $link =~ s/\s//go;

    return $link;
}

Call the new buildWikiWord method at the original location.

$link = $this->buildWikiWord( $link );

Add a TWiki::Func::buildWikiWord that calls the new buildWikiWord method.

=pod

---+++ buildWikiWord( $text ) -> $text

Converts arbitrary text to a WikiWord.
   * =$pre=        - Arbitrary Text
Return: =$text=

*Since:* TWiki::Plugins::VERSION ###### INSERT VERSION AND DATE HERE ######

=cut

sub buildWikiWord {
    ASSERT($TWiki::Plugins::SESSION) if DEBUG;
    return $TWiki::Plugins::SESSION->{renderer}->buildWikiWord( @_ );
}

May you please chance the code as suggested?

-- TWikiGuest - 08 Mar 2009

Thank you for the contribution! Could you please create feature request in the Codev web? (see link in sidebar).

-- PeterThoeny - 09 Mar 2009

Thank you for the answer. It's me, herbivore, and I suppose you can guess why I can't do that. I've send an email to you. Did you recieve it?

-- TWikiGuest - 10 Mar 2009

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title search for buildWikiWord function
SupportCategory CategoryAPI
TWiki version 4.2.4
Server OS

Web server

Perl version

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2009-03-10 - TWikiGuest
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.