2

I want to add a link using existing string in in my wiki page. This string will be appended to a url to form a complete URL.

This string consists of many words, for example "Crisis Management in International Computing"

I want to split by empty space " " then construct this string: "Crisis+Management+in+International+Computing"

Here is the String variable I have in my wiki page:

{{SUBJECTPAGENAME}}

Note: I have to check first if the string consists of more than one word, as if the string is just one word like this "Crisis" I won't perform split function.

I searched the web and did not find clear semantic to us in order to perform this issue.

Anyone experienced such a matter?

Cristik
  • 30,989
  • 25
  • 91
  • 127
Ali Khalil
  • 93
  • 1
  • 2
  • 11
  • What do you use the splitted string for? Or do you just want to replace spaces with `+` – leo Aug 12 '14 at 13:17
  • I have a service running in another (external) server, that service takes some string in the url from the source server. So , a url will be placed in server A , that url points to a service in server B. And i have a string in server A which I need to append to that service url. Etc: www.xyz.com/this+is+a+string The text after the slash is a string in this format "this is a string". I just need to split any string of this type by empty string " " and add it to the url separated by + . I hope this explains it further. – Ali Khalil Aug 12 '14 at 22:34
  • Why can't you just search and replace all spaces with `+`? – leo Aug 13 '14 at 10:41
  • This what I am aiming/asking for Mr. @leo – Ali Khalil Aug 13 '14 at 13:42

2 Answers2

1

If I understand correctly from the comments, you want to replace all occurrences of space in your string, and replace it with +. That can be done with string functions of the ParserFunctions extension.

If you are running a fairly recent version of MediaWiki (>1.18, check by going to Special:Version), the ParserFunctions extension is bundled with the software. You just need to enable it by adding the following to LocalSettings.php:

require_once "$IP/extensions/ParserFunctions/ParserFunctions.php";
$wgPFEnableStringFunctions = true;

Then you will be able to write e.g.

{{#replace: {{SUBJECTPAGENAME}} |<nowiki> </nowiki>|+}} 

Note however that if all you really want is a url version of a page name, you can just use {{SUBJECTPAGENAMEE}} instead of {{SUBJECTPAGENAME}}.

leo
  • 8,106
  • 7
  • 48
  • 80
0

I would recommend you to go for a custom parser function.

Or as a hack, try splitting the string using the arraymaptemplate parser functions coming as part of Semantic Forms.

URL : arraymaptemplate parser function.

You can use an intro template to create the link and use array template to split and add the words to the intro template.

I have not tried it with delimiter character as space, but from the documentation, seems, it should be working using the html encoding for space.

arunvg
  • 1,209
  • 1
  • 20
  • 31