Jump to content

Extension talk:CorrectMainPageTitle

Add topic
From mediawiki.org
Latest comment: 13 years ago by Almuhammedi in topic Encoding problems

you can custom the title

[edit]

replace wfMsg('pagetitle-view-mainpage') with a string ( for example: 'My html title for Main Page' ) —The preceding unsigned comment was added by Superxain (talkcontribs) 13:41, 14 September 2010 (UTC). Please sign your posts with ~~~~!Reply

It's better if you edit the MediaWiki:Pagetitle-view-mainpage system message, because it is intended to be the main page title, but for some reason it doesn't work out-of-the-box without my extension (I've installed MediaWiki in Italian). --VittGam 15:23, 15 September 2010 (UTC)Reply

Error in object to string conversion and quick fix

[edit]

VittGam, thank you for the simple yet important extension. This had been an issue at our wiki too, and your extension fixed it. However, your code didn't work for me out-of-the-box. In my enviroment (PHP 5.1.6, MW 1.16.0), the following error was reported and the title did not change:

Notice: Object of class Title could not be converted to int in (...)extensions/CorrectMainPageTitle.php on line 28

The problem was in the line:

if (in_array(strtolower($request->getText('action')),array('','view','print','submit','purge')) && $title==wfMsg('mainpage')) {

I've bolded the relevant part. $title is an object, and wfMsg('mainpage') is a string. [1] So I changed that part to make it work; which is,

$title->getText() == wfMsg('mainpage')

Moreover, people say that you should use "===" or strcmp() when comparing strings [2], so I ended up with

$title->getText() === wfMsg('mainpage')

(Note: This is my first time I've meddled with PHP code, so I'm not sure if I'm doing it right.)

I hope this helps anyone who's having a similar issue. --朝彦 (Asahiko) 07:04, 9 October 2010 (UTC)Reply

You are right; it works in both ways on my wiki, but your method is the correct one. Thank you for the fix. --VittGam 15:03, 14 October 2010 (UTC)Reply

Fix for extension not functioning when main page is part of a name space

[edit]

Hi there! Not sure if this is something that others have run into before, and maybe it's bleeding obvious, but it wasn't to me. :)

Recently i've changed my main page to be part of a custom name space called 'Portal:' (inspired by Memory Alpha). This worked as expected for the most part, but it broke the CorrectMainPageTitle extension.

After some experimentation, i determined this line was at fault:

if (... && $title->getText()==wfMsg('mainpage')) {

The problem was that, although wfMsg('mainpage') was returning the expected value ('Portal:Main'), this was not matching $title->getText(). The reason for this is that the output of $title->getText() does not include the name space (at least for custom ones, apparently) — it only includes the title itself. So instead of getting 'Portal:Main', i was just getting 'Main', which obviously was not working here.

The fix in my particular case was simply to change this to the (name-space-less) title i expected:

if (... && $title->getText() === 'Main') {

However, there is probably a more elegant solution that i'm unaware of (i just don't know that much about MediaWiki's internals). ♥ kine, 08:06, 5 April 2011 (UTC)

Hi kine,
Thanks for reporting this bug. According to the MediaWiki code, I think this is the right version, but I don't use MediaWiki anymore, so I can't tell:
if (... && $title->isMainPage()) {
If you (or someone else) want to try this, feel free to test the fix and report here if it worked for you.
Bye~ --VittGam 08:34, 5 April 2011 (UTC)Reply

Encoding problems

[edit]

When I apply some utf-8 characters (Arabic), I don't get the title correctly set, but instead some unknown characters. When I open the source page, I realize that charset is set afterwards the title tag, not before:

<title>Main Page</title
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

How can this be fixed?--Almuhammedi 14:48, 29 September 2011 (UTC)Reply

Ok, I think it is my mistake. I should have just modified the Mediawiki:MainPage content.--Almuhammedi 12:50, 12 December 2011 (UTC)Reply