I am learning MediaWiki 1.31.1 and hope to change default interface strings. For example, out-of-the-box signup page displays this:
Email address (optional)
I would like to show (remove optional)
Email address
I am able to hack the MediaWiki string file (/languages/i18n/en.json) and make changes there. Any better way?
If you are running a multilingual wiki, or if your users are likely to use different interface languages (such as when using the Universal Language Selector extension to automatically use visitor's preferred language), then you should use the MessageCache::get hook so that the customization is used in all languages. Otherwise user's using a different interface language will not see the customization.
It's used like this:
LocalSettings.php:
$wgHooks['MessageCache::get'][] = function ( &$key ) {
$keys = [ // The list of messages you want to customize
'prefs-help-realname',
'createacct-realname',
];
if ( in_array( $key, $keys, true ) ) {
$key = "myprefix-$key";
}
};
Then you need to edit https://example.org/wiki/MediaWiki:myprefix-key (replace with your wiki domain and key with the original message key (which you can find with uselang=qqx).
Append uselang=qqx to the URL to see message names instead of the text of the messages: https://en.wikipedia.org/wiki/Special:CreateAccount?uselang=qqx
You should only see the (optional) part though if you configured email to be optional, so I'm not sure the message text is your real problem.
Any language string can also be edited by going to the page MediaWiki:name-of-language-string on your wiki and editing that.
Related
I want to know if there is a way to replace a character by another in a variable. For example replacing every dots with underscores in a string variable.
I haven't tried it, but based on the Variables specification, the way I'd try to approach this would be to try to match on the text before and after a dot, and then make new variables based on the matches. Something like:
set "value" "abc.def";
if string :matches "${value}" "*.*" {
set "newvalue" "${1}_${2}
}
This will, of course, only match on a single period because Sieve doesn't include any looping structures. While there's a regex match option, I'm not aware of any regex replacement Sieve extensions.
Another approach to complex mail filtering you can do with Dovecot (if you do need loops and have full access to the mail server) is their Dovecot-specific extensions like vnd.dovecot.pipe which allows the mail administrator to define full programs (written in whatever language one wishes) to process mail on its way through.
Following #BluE's comment, if your use case is to store e-mails in folders per recipient address or something like that, perhaps you don't actually want a generic character replace function but some way to create mailboxes with dots in their names. In the case of dovecot, there seem to be a solution: [Dovecot] . (dot) in maildir folder names
https://wiki2.dovecot.org/Plugins/Listescape
Ensure one of the files in /etc/dovecot/conf.d contains this line:
mail_plugins = listescape
Then you can filter mailing lists into separate boxes based on their IDs.
This Sieve script snippet picks the ID from the x-list-id header:
if exists "x-list-id" {
if header :regex "x-list-id" "<([\.#a-z_0-9-]+)" {
set :lower "listname" "${1}";
fileinto :create "mailing_list\\${listname}";
} else {
keep;
}
stop;
}
I'm building a Mediawiki site which will include a few thousand Bot-generated articles. I want users to be able to edit lower sections of each article, but not edit the bot-generated sections.
I found an abandoned extension called ProtectSection which did this, but I don't have the skills to update it to work with the current Mediawiki release.
I'm considering making the Bot-generated articles protected, and then transcluding them into user-editable articles. If I do that, can I hide the original Bot-generated articles from search engines, and from being navigable within the wiki?
Also, I'd like users to be able to reference prior versions of the bot-generated articles, as their text will be updated from time to time by the bot. If I transclude and hide the bot-generated articles, I'm assuming their history then will be inaccessible. This wouldn't be a problem if I could keep the bot-generated articles available, with user-editable sections in them.
I got a bad news. It's really difficult to make part of article protected. Current mediawiki architecture doesn't allow it from scratch.
What I suggest you to do is create custom namespase and place all bot's articles there.
// Define constants for my additional namespaces.
define("NS_FOO", 3000); // This MUST be even.
define("NS_FOO_TALK", 3001); // This MUST be the following odd integer.
// Add namespaces.
$wgExtraNamespaces[NS_FOO] = "Foo";
$wgExtraNamespaces[NS_FOO_TALK] = "Foo_talk"; // Note underscores in the namespace name.
Resrict ordinary users edit this custom namespace, here is some info. But allow users to watch history of this pages.
# Only allow autoconfirmed users to edit Project namespace
$wgNamespaceProtection[NS_PROJECT] = array( 'autoconfirmed' );
# Don't allow anyone to edit non-talk pages until they've confirmed their
# e-mail address (assuming we have no custom namespaces and allow edits
# from non-emailconfirmed users to start with)
# Note for 1.13: emailconfirmed group and right were removed from default
# setup, if you want to use it, you'll have to re-enable it manually
$wgNamespaceProtection[NS_MAIN] = $wgNamespaceProtection[NS_USER] =
$wgNamespaceProtection[NS_PROJECT] = $wgNamespaceProtection[NS_IMAGE] =
$wgNamespaceProtection[NS_TEMPLATE] = $wgNamespaceProtection[NS_HELP] =
$wgNamespaceProtection[NS_CATEGORY] = array( 'emailconfirmed' );
# Only allow sysops to edit "Policy" namespace
$wgGroupPermissions['sysop']['editpolicy'] = true;
$wgNamespaceProtection[NS_POLICY] = array( 'editpolicy' );
Last step you already know - use Tranclution.
In my code I use Registry pattern like that:
$data = Registry::get('classA')->methodOfClassA($param1, param2);
Registry class stores instances of some classes in internal array, so in any place of my code I can call class methods for handy functions like in line above.
But, the problem is that PHP-storm does not autocomplete when I type:
Registry::get('classA')->
And, that is worse, it does not go to declaration of the method "methodOfClassA" when I hover mouse cursor holding mac-button (analogue of control-button on windows)
I suppose, that IDE AI is not so good to recognise cases like that, but maybe there is some tricks to do that in a hard way? hardcoding classes+method names in some file and so on...
At least, I want it to understand to go to method declaration when I click method name...
Any advices?
http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
This link describes it all -- it is already used by multiple projects/frameworks/code-generation helpers, like Magento, for example (some other can be found mentioned in the comments of the actual ticket).
For other situations you may want to check out DynamicReturnTypePlugin plugin (Settings | Plugins | Browse repositories...) -- have not tried myself and therefore cannot comment how good/fast/laggy it is.
You can always indicate the variable type in two steps:
/** #var $foo MyClass */
$foo = $this->get('MyClass');
$foo->bar(); // autocomplete works
I have a hashmap with some information(key and value) in a perl file. I want to display them in HTML output and each displayed (key, value) will link to something. When I click the link then there will be some information there.
Anyone suggests me how can I do that. Is this similar to creating a CGI file and use CGI.pm? I will update more detail on this question later.
Yes, you can use the excellent CGI module to render HTML content for you, even if you are not processing CGI forms (i.e. use the module only on output, rather than also for input processing):
use CGI;
my $q = CGI->new;
my #html_list = map {
$q->li($_ . ": " . $hash{$_};
} keys %hash;
print $q->ul($q->li({-type=>'foo'}, #html_list);
Depending on the data you're trying to display, something like HTML::Table may be useful if you want to display it in tabular format and don't want the drugery of assembling the appropriate HTML yourself.
For instance, you could do something like:
my $table = HTML::Table->new(-columns => 2);
for my $key (sort keys %hash) {
$table->addRow($key, $hash{$key});
}
$table->print;
Also, there is a free Beginning Perl book available online, which has a chapter devoted to CGI scripts, along with a lot of other useful information.
If this is more than just a simple one-off script, you might also wish to consider using one of the many Perl web frameworks like Dancer, Catalyst, Mojo etc.
I receive input in the form of URL strings (aka controller/action?example=yes), and I'm wondering if I need to escape the content of the string for security.
For example, if I assign the param to a variable:
example = params[:example].to_s
do I need to escape anything? or do I only apply h() when I put the value of :example back in the view file?
It depends on what you are doing with it, if you are worried of SQL injections , then you can trust ActiveRecord, like doing:
Examples.find_by_name params[:example]
or
Examples.find(:conditions=> ["name = ?", params[:example]])
On the other side, the common strategy of filtering is on display side, so you save the input as is, and you filter on display(views) by using h().
If you still want to save some HTML input from the user like when doing in rich editors, then you have to pay extra attention to XSS attacks, and so you have to filter the input. One great gem for filtering HTML is Sanitize, use it to save a modified filtered version of user input to use it in views.