Extension talk:CustomTitle

From mediawiki.org
Latest comment: 10 years ago by Amakuha in topic Modification that works with 1.16.0

What's the need and function?

SEO. --LauraHale 00:45, 21 May 2009 (UTC)Reply

Characters not Allowed[edit]

MediaWiki allows creation of pages with an apostraphe in it. But if you use this extension to create a title with an apostrophe ' and you try and save the page, you get an error page. Why can't we have apostrophes in the title? Is there any way to allow them? --Holygamer (talk) 18:39, 17 March 2012 (UTC)Reply

Title not work with 1.16.0[edit]

I tested it with 1.16.0. The page title part worked well, but it seems do nothing to header title tag.

How do I change the tag <title> on on certain pages? Is there an alternative?

Modification that works with 1.16.0[edit]

A small trick that does the job with 1.16.0:

   function onSkinTemplateOutputPageBeforeExec(&$m_skinTemplate, &$m_tpl)
   {
       if (isset($this->customTitle))
           $m_tpl->set('title', $this->customTitle);
       if (isset($this->customPageTitle)) {
           $m_tpl->set('pagetitle', $this->customPageTitle);
           $text = $m_tpl->data['headelement'];
           $regex = "#(\<title\>)(.*)(\<\/title\>)#e";
           $customtitle = $this->customPageTitle;
           $title = "'<title>'.'$customtitle'.'</title>'";
           $text = preg_replace($regex,$title,$text);
           $m_tpl->set('headelement', $text);
       }
       return true;
   }

79.86.134.104 15:00, 1 March 2011 (UTC)Reply

Works in 1.17.0 --Netsu 16:03, 8 September 2011 (UTC)Reply
This works in 1.18.0 too, thanks for the help! Cheers, --Till Kraemer 12:10, 12 December 2011 (UTC)Reply
Works in 1.20.3. Thanks! --Amakuha (talk) 12:41, 25 May 2013 (UTC)Reply
Don't work (in 1.19, probably others) when there is a single quote in title. See post below. Tintinux - 18:00, 28 January 2013 (UTC)

How to remove the customtitle text (xxx-CustomTitleStart-xxx) from appearing in search results[edit]

This is a very important extension that I can't operate without it in my website. However, although it does modify the title of the page to what i want it to appear. in search results the cache of all my pages has "xxx-CustomTitleStart-xxx". this happenes whther I put it in template or standalone, the cache of pages will have that which appears first in description during search results. Can someone please let me know a work around or if this can be fixed?

Thank You Wikimanz 09:20, 16 October 2011 (UTC)Reply

Parse error: syntax error CustomTitle.php on line 66[edit]

Sometimes after adding the customtitle start I get this error.

Parse error: syntax error, unexpected T_STRING in /home/........../extensions/CustomTitle.php(66) : regexp code on line 1

Fatal error: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Failed evaluating code: '<title>'.'- My title here'.'</title>' in /home/.............../extensions/CustomTitle.php on line 66

Can someone address this issue, It has happened to me, not often but occassionally but this could be a bug or something that others may experience as well.

HTML tags? Or formatting?[edit]

I want to setup my headers so that there is something in the center then another part on the righthand side. Is this possible? I was thinking of using the html tags for text-align, but html tags do not work. any advice?

Error parsing when Quote in title[edit]

With mediawiki 1.19 and the patch for Mediawiki > 1.16 (see above), and a single quote in the title, e.g : {{#customtitle:drag'n drop}} there is a fatal error :

Parse error: syntax error, unexpected T_STRING in /**********/mediawiki/extensions/CustomTitle/CustomTitle.php(107) : regexp code on line 1 Fatal error: preg_replace(): Failed evaluating code: '' in /**********/mediawiki/extensions/CustomTitle/CustomTitle.php on line 107

It works with this :

  function onSkinTemplateOutputPageBeforeExec(&$m_skinTemplate, &$m_tpl)
  {
      if (isset($this->customTitle))
          {
          $m_tpl->set('title', $this->customTitle);
          $m_tpl->set('pagetitle', $this->customTitle);
          $text = $m_tpl->data['headelement'];
          $regex = "#(\<title\>)(.*)(\<\/title\>)#e";
          $customtitle = $this->customTitle;
          $customtitle = str_replace ( "'", "\'", $customtitle );
          $title = "'<title>'.'$customtitle'.'</title>'";  
          $text = preg_replace($regex,$title,$text);
          $m_tpl->set('headelement', $text);
          }
      return true;
  }

Fix for xxx-CustomPageTitleStart-xxx... xxx-CustomPageTitleEnd-xxx etc in transclusion[edit]

When a page with a custom title is transcluded, there is an extra line just above the title that looks something like this:

xxx-CustomPageTitleStart-xxxDoel en scopexxx-CustomPageTitleEnd-xxx

This is due to the function onOutputPageBeforeHTML that only replaces the first occurrence, rather than all. This fixes that problem:

    function onOutputPageBeforeHTML(&$out, &$text)
    {
        if (($found = strpos($text, 'xxx-CustomTitleStart-xxx')) !== false) {
            if (preg_match("/xxx-CustomTitleStart-xxx(.*?)xxx-CustomTitleEnd-xxx/", $text, $matches)) {
                $this->customTitle = $matches[1];
                $text = str_replace($matches[0], "", $text);
                // replace any remaining occurrences
                while (preg_match("/xxx-CustomTitleStart-xxx(.*?)xxx-CustomTitleEnd-xxx/", $text, $matches)) {
                    $text = str_replace($matches[0], "", $text);
                }
            }
        }
 
        if (($found = strpos($text, 'xxx-CustomPageTitleStart-xxx')) !== false) {
            if (preg_match("/xxx-CustomPageTitleStart-xxx(.*?)xxx-CustomPageTitleEnd-xxx/", $text, $matches)) {
                $this->customPageTitle = $matches[1];
                $text = str_replace($matches[0], "", $text);
                // replace any remaining occurrences
                while (preg_match("/xxx-CustomPageTitleStart-xxx(.*?)xxx-CustomPageTitleEnd-xxx/", $text, $matches)) {
                    $text = str_replace($matches[0], "", $text);
                }
            }
        }
 
        return true;
    }