Ignore MediaWiki whitespace - whitespace

How do I ignore whitespace on a wiki template?
So for example, I create a template called Hello. Inside that, I put {{{text}}}.
So now when I put {{Hello |text=Hi Bye}} on a page, and save it, the page says. "Hi Bye" (of course).
I want it to display "HiBye", not "Hi Bye". What do I put in the template to do that?

To remove characters inside the value in a template (whitespace or other), you have to search and replace. You can install the extensions ParserFunctions, to get access to parser functions like replace, and then to something like this:
{{#replace:{{{text|}}}| |}}
If your MediaWiki is version 1.18 or newer (if it's not, you should upgrade anyway), ParserFunctions is already bundled with your installation. Then you just have to enable it, like this in LocalSettings.php:
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
$wgPFEnableStringFunctions = true;
On a side note, whitespace characters in the beginning and end of a variable is always stripped, if using named parameters. In other words: {{Hello |text= Hi Bye }} is equal to {{Hello |text=Hi Bye}}. On the other hand, {{Hello | Hi Bye }} is not equal to {{Hello |Hi Bye}}. Advanced templates sometimes make clever use of this difference. The replace function will work in both cases, of course.

Related

How does the # work in Bash?

When I open BashBurn source I se:
mainmenu[7]="$bb_menu_8#check_path"
I don't know what does #check_path mean? And how does it work?
It doesn't mean any special in Bash alone: # is just a part of a string here. It could have a special meaning inside the BashBurn implementation, however.
It looks like it is a part of the translation framework used inside BashBurn. You can search it on your own on GitHub for example.
mainmenu is set in BashBurn.sh, which is then passed as the second argument to the bbmenu function. The function is defined in bbmenu.sh. There is a description of the syntax, including this information:
ALL ITEMS ARE SEPERATED BY AMPERSAND.
All you need to do now is to read the rest of the documentation in the bbmenu.sh file.

Joomla INI translation

I need to translate in my ini file a word that has a "()" or an "/" sign but it seems to brake when I do it.
eg.
sometext(text)="otherLanguagetext(text)" <-- this causes an error in the ini file an brakes all translations.
sometext/text = "someOthertext/text" <-- Broken also
having spaces work correctly:
Some text="Some text1" <--Works
The fact is that the original language is database generated and doesn't have any translation tag or something like joomla translation tag.
I just type the word I want to translate in this way.
I searched for an ini editor that might fix this out automatically (e.g place '/' or something ) but I had no luck on this.
Your example key's are invalid. INI files by definition can not have any of these characters: ?{}|&~![()^" in the keys.
Note: There are reserved words which must not be used as keys for ini
files. These include: null, yes, no, true, false, on, off, none.
Values null, off, no and false result in "". Values on, yes and true
result in "1". Characters ?{}|&~![()^" must not be used anywhere in
the key and have a special meaning in the value.
— http://www.php.net/manual/en/function.parse-ini-string.php
Joomla language files also have their own specification, which if not followed will cause an error when Joomla loads and parses the language file.
In INI files and Joomla language files the value also has special interpretations for specific characters and requires escaping for the use of some characters like double quotes etc.
Finally, Joomla has language overrides that allow the end user to override any string set by the core software or third party extensions which also affect the way keys are translated.
Try to use backslash before those symbols like this:
"otherLanguagetext\(text\)"
"someOthertext\/text"
P.S. you cannot use ANY special symbols in your constants! Try to name them something like this:
OTHER_LANGUAGE_TEXT
SOME_OTHER_TEXT
Try this,
SOME_TEXT = "otherLanguagetext(text)"
SOME_OTHER_TEXT = "someOthertext/text"
Hope it works

Processing form input in a Joomla component

I am creating a Joomla component and one of the pages contains a form with a text input for an email address.
When a < character is typed in the input field, that character and everything after is not showing up in the input.
I tried $_POST['field'] and JFactory::getApplication()->input->getCmd('field')
I also tried alternatives for getCmd like getVar, getString, etc. but no success.
E.g. John Doe <j.doe#mail.com> returns only John Doe.
When the < is left out, like John Doe j.doe#mail.com> the value is coming in correctly.
What can I do to also have the < character in the posted variable?
BTW. I had to use & lt; in this question to display it as I want it. This form suffers from the same problem!!
You actually need to set the filtering that you want when you grab the input. Otherwise, you will get some heavy filtering. (Typically, I will also lose # symbols.)
Replace this line:
JFactory::getApplication()->input->getCmd('field');
with this line:
JFactory::getApplication()->input->getRaw('field');
The name after the get part of the function is the filtering that you will use. Cmd strips everything but alphanumeric characters and ., -, and _. String will run through the html clean tags feature of joomla and depending on your settings will clean out <>. (That usually doesn't happen for me, but my settings are generally pretty open to the point of no filtering on super admins and such.
getRaw should definitely work, but note that there is no filtering at all, which can open security holes in your application.
The default text filter trims html from the input for your field. You should set the property
filter="raw"
in your form's manifest (xml) file, and then use getRaw() to retrieve the value. getCmd removes the non-alphanumeric characters.

Regex Markdown Header

I'm trying to create a regular (ruby) expression which checks for multiple conditions. I use this regex to replace the content of my object. My regex is close to finished, except two problems I'm facing with regard to markdown.
First of, headers are giving me trouble. For example, I don't want to replace the word "Hi" for "Hello" if "Hi" is in a header.
Hi John <== # should not change
==================
Text: Hi, how are you? <== # Should be: Hello, how are you? after substitution
Or:
#### Hi Peter <== # should not change
Text: Hi, how are you? <== # Should be: Hello, how are you? after substitution
Question: How can I escape markdown headers within my regex? I've tried negative lookbehind and lookahead assertions, but to no avail.
My second problem should be quite easy, but somehow I'm struggling. If words are Italic "hi" I want to find and replace them, without changing the underscores. I can find the word with this regex:
\b[_]*hi[_]*\b
Question 2: But if I would replace it, I would also change the underscores. Is there a way to only detect the word itself and replace it, while still using word boundaries?
Code Example
#website.autolinks.all.each do |autolink|
autolink.name #for example returns "Iphone5"
autolink.url #for example returns "http://www.apple.com"
regex = /\b(?<!##\s)(?<![\d.\[])([_]*)#{autolink.name}([_]*)(?![\d'"<\/a>])\b/
if #permalink.blog_entry.content.match(regex)
#permalink.blog_entry.content.gsub!(regex, "[#{autolink.name}](# {autolink.url})")
end
end
Example text
Iphone5
==============
Iphone5 is the best mobile phone there is, even though the people at Samsung probably think, or perhaps only hope that their Samsung Galaxy S3 is better.
#### Samsung Galaxy S3?
Yes, that's the name of the newest Samsung phone.
This will result in a text with HTML tags, but when I use my regex my content uses Markdown syntax (used before the markdown converter).
Regexes work best when they do one clear thing. If you have multiple conditions, your code should usually reflect that by dividing the processing into steps.
In this case, you have two clear steps:
Use a simple regex or other logic to skip over the header portion of the message.
Once you know you are in the content, use another regex to process the content.
I've found a solution:
regex = /(?<!##\s)(?<![\d.\[a-z])#{autolink.name}(?![\d'"a-z<\/a>])(?!.*\n(==|--))/i
if #permalink.blog_entry.content.match(regex)
#permalink.blog_entry.content.gsub!(regex, "[\\0](#{autolink.url})")
end

Is there a gsub alternative for ruby that can run a method everytime a match is made?

I need to run a script that will rewrite the folder path of a html file, there will be many matches, and the replacement string needs to be computed, something like
"Html string".gsub( /images/([a-zA-Z0-9\-]+)/, "/images/#{replacement_method($1)}/" )
only problem is gsub, at least to my knowledge, will only run the replacement_method() once, and I need it to run every time since the desired replacement string changes occurring to the folder string.
Is there a way to make this work with gsub? something like the replace function in wordpress?
Any other realistic approaches?
You have to use a block:
"Html string".gsub( /images/(folder)/) { |match| "/images/#{replacement_method(match)}/" }
The block will be called for each match in the string.

Resources