Ticket #409 (closed enhancement: fixed)

Opened 5 years ago

Last modified 15 months ago

SmartTitle uses out-of-context headings

Reported by: MasinAlDujaili Owned by: DotMG
Priority: normal Milestone: 1.3.1
Component: core Version: 1.1.6.2
Severity: minor Keywords: title heading smarttitle
Cc:

Description (last modified by DotMG) (diff)

If a page does not contain any heading but a sample, which does contain text between a number of '=', this text is used. This behaviour is not desired but exactly what the function is supposed to do: Find the text with most equal signs surrounding it.

Example:

This is a test page demonstrating the bug.
%%
Inside this code block appears the heading
which will be found by SmartTitle.
===Heading and Title===
The heading of this section will be used as
the page title, although it is out of normal
text flow context.
%%

Currently, the only workaround is to create pages with headings if above condition is met

Related:

Attachments

409.diff Download (7.9 KB) - added by DotMG 5 years ago.
A patch for implementing this
409.zip Download (36.8 KB) - added by DotMG 5 years ago.
The 2 modified files, if you want to test (no need to merge)

Change History

Changed 5 years ago by DotMG

  • status changed from new to assigned
  • description modified (diff)
  • component changed from formatters to core
  • milestone set to 1.1.7
  • owner changed from unassigned to DotMG
  • type changed from defect to enhancement

This is becoming possible with headings id generation, which can collect all headers of the page.

Component changed to core, because it involves modifying the PageTitle() method.

Decription modified: related #411

Changed 5 years ago by DarTar

I'm against the implementation of these feature (at least as it is currently proposed) because this would most likely result in wrong parsing of titles from cases like:

if ($a == 1 && $b ==2)

In my opinion, our aim should the opposite, i.e. mark code blocks so they are skipped while rendering the source using Wikka's formatting rules (this should also make the formatters more performant).

Changed 5 years ago by DotMG

A patch for implementing this

Changed 5 years ago by DotMG

The 2 modified files, if you want to test (no need to merge)

Changed 5 years ago by DotMG

Now, let me explain what this patch is doing :

Since we're generating ids for headings, everytime we set the id attribute for the <hn> tag, we get at the same time the tagName (h1 or h2 .. h6) and the innerText of the heading tag. The job is then easier :

  • Test if we hadn't yet assigned a title to the page, (equivalent to the old preg_match(), which finds the 1st occurence)
  • skip if it is h5 or h6 (this is just backward compatibility, as for before, == weren't matched. But now, since I see DarTar's comment above, I understand why.)
  • Clean the innerText of the heading if okay.

I think it is rather an improvement (again) of performance : no need to preg_match() again the whole page. The gains are :

  • 409 automatically fixed : ==== in code blocks are ignored, since <hn> tags aren't generated for these.
  • The new methods added to the Wakka.class.php will make it easier in the future to manage page title. Just call SetPageTitle() anywhere/anytime to have another custom page title. You don't need to sanitize strings passed to it: that job will be done by the (modified) PageTitle() method.

Changed 5 years ago by DotMG

Another advantage : headings of embedded HTML is treated as well. : Suppose you've got a simple HTML raw code, and you just want to paste it as content of a Wiki page (by enclosing it with double double quote)

If page begins with

""<h1>Embedded HTML in Wikka</h1>
<p>some texts ...</p>""

Now, the title of the page will be MyWikkaSite: Embedded HTML in Wikka. The former preg_match is just unable to do that.

Changed 5 years ago by DarTar

OK, I got it. Then may I suggest the creation of a simple title.php action to override the application of PageTitle()?

The action should be used like this

{{title text="This is my title"}}

and will pass the text parameter to SetPageTitle()

On a related note, maybe we should study (not for 1.1.7!) some special kind of markup to be parsed at the end of the formatter routine and to do something with the page output as a whole (I remember somone using this to format category links in a fancy way). I think Media calls this templates.

Changed 5 years ago by DotMG

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in [546] and [547]. DarTar's last comments refer to #411.

Changed 3 years ago by DarTar

  • milestone changed from 1.2 to 1.3

Retargeting to 1.3, this ticket has already been closed in trunk, from which 1.3 will be branched. Consider backporting urgent issues to 1.2.X

Changed 15 months ago by BrianKoontz

  • milestone changed from 1.3 to 1.3.1

Updated milestone to 1.3.1

Note: See TracTickets for help on using tickets.