r49330 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49329‎ | r49330 | r49331 >
Date:05:15, 9 April 2009
Author:rememberthedot
Status:resolved (Comments)
Tags:
Comment:
(bug 12998) Allow <sup>, <sub>, etc. in DISPLAYTITLE
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/skins/Modern.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/MonoBook.php
@@ -115,7 +115,7 @@
116116 <div id="content">
117117 <a name="top" id="top"></a>
118118 <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
119 - <h1 id="firstHeading" class="firstHeading"><?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?></h1>
 119+ <h1 id="firstHeading" class="firstHeading"><?php $this->html('title') ?></h1>
120120 <div id="bodyContent">
121121 <h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
122122 <div id="contentSub"><?php $this->html('subtitle') ?></div>
Index: trunk/phase3/skins/Modern.php
@@ -102,7 +102,7 @@
103103 class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
104104
105105 <!-- heading -->
106 - <div id="mw_header"><h1 id="firstHeading"><?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?></h1></div>
 106+ <div id="mw_header"><h1 id="firstHeading"><?php $this->html('title') ?></h1></div>
107107
108108 <div id="mw_main">
109109 <div id="mw_contentwrapper">
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -606,7 +606,7 @@
607607 * @param $forContent Boolean
608608 * @return String: the requested message.
609609 */
610 -function wfMsgReal( $key, $args, $useDB = true, $forContent=false, $transform = true ) {
 610+function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform = true ) {
611611 wfProfileIn( __METHOD__ );
612612 $message = wfMsgGetKey( $key, $useDB, $forContent, $transform );
613613 $message = wfMsgReplaceArgs( $message, $args );
@@ -618,7 +618,7 @@
619619 * This function provides the message source for messages to be edited which are *not* stored in the database.
620620 * @param $key String:
621621 */
622 -function wfMsgWeirdKey ( $key ) {
 622+function wfMsgWeirdKey( $key ) {
623623 $source = wfMsgGetKey( $key, false, true, false );
624624 if ( wfEmptyMsg( $key, $source ) )
625625 return "";
Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -229,17 +229,15 @@
230230 * @param string $text Desired title text
231231 * @return string
232232 */
233 - static function displaytitle( $parser, $text = '' ) {
234 - global $wgRestrictDisplayTitle;
235 - $text = trim( Sanitizer::decodeCharReferences( $text ) );
 233+ static function displaytitle( $parser, $displayTitle = '' ) {
 234+ #only requested titles that normalize to the actual title are allowed through
 235+ #mimic the escaping process that occurs in OutputPage::setPageTitle
 236+ $title = Title::newFromText( Sanitizer::stripAllTags( Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $displayTitle ) ) ) );
236237
237 - if ( !$wgRestrictDisplayTitle ) {
238 - $parser->mOutput->setDisplayTitle( $text );
239 - } else {
240 - $title = Title::newFromText( $text );
241 - if( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) )
242 - $parser->mOutput->setDisplayTitle( $text );
 238+ if ( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) {
 239+ $parser->mOutput->setDisplayTitle( $displayTitle );
243240 }
 241+
244242 return '';
245243 }
246244
Index: trunk/phase3/includes/OutputPage.php
@@ -320,18 +320,34 @@
321321 }
322322 }
323323
324 - public function setHTMLTitle( $name ) { $this->mHTMLtitle = $name; }
 324+ /**
 325+ * "HTML title" means the contents of <title>. It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
 326+ */
 327+ public function setHTMLTitle( $name ) {
 328+ $this->mHTMLtitle = $name;
 329+ }
 330+
 331+ /**
 332+ * "Page title" means the contents of <h1>. It is stored as a valid HTML fragment.
 333+ * This function allows good tags like <sup> in the <h1> tag, but not bad tags like <script>.
 334+ * This function automatically sets <title> to the same content as <h1> but with all tags removed.
 335+ * Bad tags that were escaped in <h1> will still be escaped in <title>, and good tags like <i> will be dropped entirely.
 336+ */
325337 public function setPageTitle( $name ) {
326338 global $wgContLang;
327339 $name = $wgContLang->convert( $name, true );
328 - $this->mPagetitle = $name;
 340+ # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
 341+ # but leave "<i>foobar</i>" alone
 342+ $nameWithTags = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $name ) );
 343+ $this->mPagetitle = $nameWithTags;
329344
330345 $taction = $this->getPageTitleActionText();
331346 if( !empty( $taction ) ) {
332347 $name .= ' - '.$taction;
333348 }
334349
335 - $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
 350+ # change "<i>foo&amp;bar</i>" to "foo&bar"
 351+ $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer::stripAllTags( $nameWithTags ) ) );
336352 }
337353
338354 public function setTitle( $t ) {
Index: trunk/phase3/RELEASE-NOTES
@@ -332,6 +332,7 @@
333333 * (bug 18009) $wgHooks and $wgExtensionFunctions now support closures
334334 * (bug 17948) Maintenance scripts now exit(0) or exit(1) as appropriate
335335 * (bug 18377) Time in Enhanced ChangesList lacking localisation
 336+* (bug 12998) Allow <sup>, <sub>, etc. in DISPLAYTITLE
336337
337338 == API changes in 1.15 ==
338339 * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions

Follow-up revisions

RevisionCommit summaryAuthorDate
r49610Follow-up to r49330: removed $wgRestrictDisplayTitle from DefaultSettings.phprememberthedot00:56, 18 April 2009
r49654Follow-up on r49330...skizzerz23:48, 19 April 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r44271(bug 12998) Weaken DISPLAYTITLE restictions (patch by 'rememberthedot@gmail.c...aaron18:00, 6 December 2008
r44432Revert r44271 "(bug 12998) Weaken DISPLAYTITLE restictions (patch by 'remembe...brion23:21, 10 December 2008
r45181(Bug 12998) Weaken DISPLAYTITLE restictions (patch by rememberthedot@gmail.com)aaron12:22, 30 December 2008
r45226Pull back r45181 "(Bug 12998) Weaken DISPLAYTITLE restictions (patch by remem...brion16:49, 31 December 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   15:17, 9 April 2009

This really needs some test cases and validation for safety.

#Comment by Remember the dot (talk | contribs)   18:43, 9 April 2009

See bugzilla:12998#c21 for test cases.

#Comment by Remember the dot (talk | contribs)   19:39, 9 April 2009

For your convenience, the test cases are:

Main Page
{{DISPLAYTITLE:<span style="text-decoration:underline">Main Page</span>}}
<title>Main Page</title>
<h1><span style="text-decoration:underline">Main Page</span></h1>

Main Page
{{DISPLAYTITLE:<i>Main Page}}
<title>Main Page</title>
<h1><i>Main Page</i></h1>

Main Page
{{DISPLAYTITLE:<a href="https://www.mediawiki.org/wiki/Main_Page">Main Page</a>}}
<title>Main Page</title>
<h1>Main Page</h1>

Main Page
{{DISPLAYTITLE:<script>Main Page</script>}}
<title>Main Page</title>
<h1>Main Page</h1>

Dweeb (band)
{{DISPLAYTITLE:[dweeb] (band)}}
<title>Dweeb (band)</title>
<h1>Dweeb (band)</h1>

Dweeb (band)
{{DISPLAYTITLE:dweeb (band)}}
<title>dweeb (band)</title>
<h1>dweeb (band)</h1>

E=MC2 (song)
{{DISPLAYTITLE:E=MC<sup>2</sup> (song)}}
<title>E=MC2 (song)</title>
<h1>E=MC<sup>2</sup> (song)</h1>

Signaling System 7
{{DISPLAYTITLE:Signaling System #7}}
<title>Signaling System 7</title>
<h1>Signaling System 7</h1>
#Comment by IAlex (talk | contribs)   15:10, 10 April 2009

And what happend to $wgRestrictDisplayTitle?

#Comment by Remember the dot (talk | contribs)   18:09, 10 April 2009

I removed it because it was complicating things and it seemed really confusing to allow the display title to be arbitrarily different from the actual title. For example, you might try to type the display title into the search box, and it could take you to a completely different page. Or you might try to link to the article, only to have the link not work or link to a completely different page. Is there really demand for this "feature"?

#Comment by IAlex (talk | contribs)   19:57, 14 April 2009

This is useful for the ones who want to be able to set any title without having to use JavaScript hacks. And according to Wikimedia's configuration (http://noc.wikimedia.org/conf/highlight.php?file=InitialiseSettings.php) it's used on Chinese Wikipedia and Wikimania 2009 wiki.

If you really want to remove it, also remove it from DefaultSettings.php and add an entry in RELEASE-NOTES about that.

#Comment by Remember the dot (talk | contribs)   05:21, 16 April 2009
#Comment by PhiLiP (talk | contribs)   18:53, 17 April 2009

The reason why we supported to set the varible to false was the cache problem caused by using -{T|}- syntax. Before r45828, one who saved a article recently need to purges that page again, in order to display the converted title correctly. At that time, I called a request to disable $wgRestrictDisplayTitle, since we could use to set the title for different variants.

But after r45828, the problem has been solved. Actually, there is no need for Zh MediaWiki to use the anymore, because people can use -{T|}- instead of it completely.

#Comment by Remember the dot (talk | contribs)   01:04, 18 April 2009

Glad to hear that the bug has been fixed and the Chinese Wikipedia no longer needs $wgRestrictDisplayTitle! I've removed the setting properly in r49610.

#Comment by Simetrical (talk | contribs)   11:12, 19 April 2009

Some non-Wikimedia parties are likely using $wgRestrictDisplayTitle = false. It's arguable whether it's really necessary to have the title be linkable; I agree with you that it's a good idea, but some people seem to prefer aesthetically superior or more correct titles. For instance, the lack of validation would permit display titles that include prohibited characters like <>[]| etc., which might be more correct for some pages (although you couldn't then copy-paste the title). I think this decision should be left up to local site admins for the time being unless there's a compelling reason to remove it.

#Comment by Remember the dot (talk | contribs)   18:51, 19 April 2009

99% of the time, the solution to an incorrect page title is to move the page to the correct title. Introducing a hack to make it look like the page is where it should be, but really it isn't, is confusing and problematic. If there are really wikis out there that you think need wanton DISPLAYTITLEs, please point me to them.

If we are going to support <>[]| etc. in page titles, we ought to add a way to escape page titles so that they can contain those characters without conflicting with those characters' special meanings. In fact, one syntax we could use is already in place: percent-encoding. For example, we might use [[Mac%7CLife|click here]] to link to an article titled "Mac|Life".

#Comment by Skizzerz (talk | contribs)   21:13, 19 April 2009

Here's one example: http://strategywiki.org/wiki/Pok%C3%A9mon_Trading_Card_Game/Imakuni -- Currently a js hack is used in lieu of DISPLAYTITLE, but basically we needed to add a "?" to the end of the title in order for the page name to be correct (in-game the name ends with a question mark, but the ? character is disallowed in titles).

I could forsee unrestricting DISPLAYTITLE useful in other cases as well, listed below:

  1. Truncating the title to the last part (useful when using sub-pages to place pages in a hierarchy instead of using categories).
  2. Allowing users to further customize their user pages by adding handles, etc. to the page title (moving the page won't work in this case)
  3. Appending additional information to the page title, such as a product id (moving the page to include the product id would make linking difficult)
  4. Probably others, but I can't really think of any more right now.

If you don't provide any definitive reason that the software shouldn't support this variable, then I'm going to add it back in a week from now. The reason being, even if you don't use it, why should you prevent others from being to use it as well if they want to?

#Comment by Remember the dot (talk | contribs)   22:09, 19 April 2009

Question marks are allowed in titles, see http://en.wikipedia.org/wiki/How_Long%3F for example. http://strategywiki.org/wiki/Pokémon_Trading_Card_Game/Imakuni could easily be moved to http://strategywiki.org/wiki/Pokémon_Trading_Card_Game/Imakuni%3F. This is a great example of why unrestricted DISPLAYTITLEs are a bad idea: instead of moving the page properly, the editors of that wiki have simply slapped on a hack and called it good.

The problematic characters []{}|#<> can be enabled by overriding $wgLegalTitleChars in LocalSettings.php. Just be warned that you will need to escape links to titles containing these characters and MediaWiki will not work perfectly with them. But even though there are some problems, it does work and should be reasonably reliable.

About your use cases:

  1. Categorization and navigation boxes are a much better solution. Or if you're desperate, you could use {{DISPLAYTITLE:<span style="display:none">Really/Long/Page/</span>Title}}.
  2. What is a "handle", and why is having it more important than being able to move the page?
  3. Use redirects. Redirects are perfect for having short links to long titles.

The use case for unrestricted DISPLAYTITLEs is so narrow that it does not outweigh the confusion and inconsistency it creates, apart from making MediaWiki more complicated, more difficult to maintain, and a tiny bit slower because of the extra global variable check.

#Comment by Skizzerz (talk | contribs)   22:37, 19 April 2009

A "handle" is a nickname, aka another name you might be known by. You can't simply move the user page because the user page must correspond to the user's name. Yes, I know that it isn't necessary to add to the title, but having that avenue open to use is nice.

Also, mediawiki is actually faster if $wgRestrictDisplayTitle is false, so that claim is entirely unfounded (checking a boolean versus normalizing a title and checking it -- I wonder which takes more time).

In addition, if you want to make mediawiki less complicated, why don't you do something useful such as cleaning up all the code marked FIXME in the files? Surely that will help much more than removing a global variable THAT ACTUALLY HAS USES (and don't give me that "oh, you can simply move the page or set up a redirect." Workarounds are exactly that -- workarounds. They aren't solutions to issues, they only attempt to quickfix the issue until a more desirable solution is implemented).

Or, better yet, why don't I just use your arguments against you? We should just remove DISPLAYTITLE entirely. The use case for restricted DISPLAYTITLE is so narrow that it does not outweigh the confusion and inconsistency it creates (superscript isn't allowed in titles, so why should it be shown? That is just confusing). In addition, it makes MediaWiki much more complicated, more difficult to maintain, and a tiny bit slower because of the extra normalization checks. Because of that, we should just eliminate DISPLAYTITLE entirely even though wikis actually use it. Sounds like a great idea, no?

That's basically what you just said for the $wgRestrictDisplayTitle global.

And again I repeat: just because you don't use it doesn't mean others won't. The use cases I listed can be achieved via other means, yes, but that doesn't mean that the sitemasters WANT to do it that way. In addition, as you said yourself, allowing various characters is problematic and requires even MORE hacks to make them work properly than it does to simply change the title.

TL;DR version of this discussion: Don't remove things simply because you don't like them. If I was to follow your example, I'd kill off i18n because it takes up the vast majority of space and is way slower than hard-coded strings. Yet I don't. Why? Because i18n is useful to people that speak different languages and because I respect the community that uses it and wouldn't take it out without contacting them first. Did you contact anyone before removing $wgRestrictDisplayTitle? Judging by iAlex's comment, I'd say that the answer is no.

Also, I have yet to see a good reason for not putting it back. 0.0001 seconds of load time for those that have it set to true isn't a good reason. Forcing pages that already use it as unrestricted to do it "properly" isn't a good reason. Removing ONE if and ONE global statement from the codebase isn't a good reason.

#Comment by Remember the dot (talk | contribs)   23:13, 19 April 2009

Well, my nickname is "Dot". What if I wanted my user page to say "Dot" instead of "User:Remember the dot"? It would cause confusion because "Dot" could also refer to the punctuation mark or "User:Dot".

The default configuration would take a tiny performance hit from having to check $wgRestrictDisplayTitle over and over and then perform the title normalization anyway. This performance hit is not worth worrying about. The added complexity to the code is what concerns me, but what worries me much more is the confusion that unrestricted DISPLAYTITLEs would cause.

Moving pages to their proper titles is usually the solution. If "Pokémon Trading Card Game/Imakuni" should be "Pokémon Trading Card Game/Imakuni?" then move it there. Problem solved, cleanly, easily, and completely. Redirects are also a good, easy-to-understand solution in many cases.

Superscript and subscript should be allowed in page titles because they are simple formatting. No one is going to be confused if "E=MC2" turns into "E=MC2" in their watchlist. But if the page that says "E=MC2" is actually titled "Mass-energy equivalence relationship discovered by Einstein", confusion abounds.

Personally, I think adding more characters to the whitelist would work better than allowing unrestricted DISPLAYTITLEs. Try it, tell me if it works okay for you. The problems did not seem so severe to me. At the same time, I can see why others might disagree. If you can show me some wikis out there that would prefer unrestricted DISPLAYTITLEs, then I wouldn't mind adding the option back until we resolve the problems that adding characters to the whitelist creates.

I'm not against unrestricted DISPLAYTITLEs because I don't like them, I'm against them because they're almost always a bad idea. I'm not in favor of supporting poor ways to use the software. At bugzilla:12998#c27 I brought this up back in February and no one said a word.

#Comment by Simetrical (talk | contribs)   23:09, 19 April 2009

The use case for unrestricted DISPLAYTITLEs is so narrow that it does not outweigh the confusion and inconsistency it creates

Which only appears on wikis whose administrators choose to enable it. So that's their problem.

apart from making MediaWiki more complicated

When in doubt between simplicity and flexibility for user-exposed features, simplicity has a strong case. But the complexity of administrative settings is not an issue. Admins who don't care can just ignore them.

more difficult to maintain

Negligibly. It touches what, two functions?

and a tiny bit slower because of the extra global variable check.

Completely trivial. Do not cite performance unless it would actually be measurable.

The basic point is that this is an existing feature that people are using. It is something that some people, for whatever reason, want to use, and have been happily using for years in some cases. Removing it would be a regression in functionality for several wikis of nontrivial size, and any such regression has to be justified by a serious argument. Simplifying two functions slightly is not a serious argument.

Originally we had only unrestricted display titles. This dates back to before my time in MediaWiki; I believe Magnus added the feature. A couple of years ago Rob Church changed it to only work when restricted, exactly as you propose. We received complaints about the regression in functionality, which eventually led to the current configuration setting. The setting was added due to administrator demand. We have already tried your way and found it was a bad idea. If you think using it is a bad idea, convince the wiki administrators who want it. MediaWiki is intended to permit administrators to do stupid things if they want to, up to and including things like $wgRawHtml.

#Comment by Remember the dot (talk | contribs)   23:17, 19 April 2009

Thanks for your reply, Simetrical. Again, I'm concerned foremost with the confusion it would cause to end users, secondly with the added complexity in MediaWiki's code, and trivially with the performance impact. The reasons you gave are good reasons to put the feature back in, ones that I was not aware of. Could you show me the sites that are actually using this, though?

#Comment by Simetrical (talk | contribs)   23:58, 19 April 2009

Well, see bug 17307 for a Wikimedia site that's apparently using it. This wiki is apparently closed-edit and so unintuitive links aren't really an issue; it seems to serve the purpose of just "set the page title arbitrarily to look pretty", like a CMS might have. Brion specifically authorized that use, so I assume he'd prefer it if the feature didn't suddenly disappear.

#Comment by Remember the dot (talk | contribs)   00:55, 20 April 2009

As far as I can tell, even though the Wikimania 2009 site enabled the capability, they never used it (see link). A couple of problems with the "just set the page title arbitrarily to look pretty" approach are that the URL won't match and the search feature won't work right, which is perhaps why that wiki left unrestricted DISPLAYTITLEs by the wayside. Do you have any other examples?

http://wikimania2009.wikimedia.org/w/index.php?ns0=1&ns1=1&ns2=1&ns3=1&ns4=1&ns5=1&ns6=1&ns7=1&ns8=1&ns9=1&ns10=1&ns11=1&ns12=1&ns13=1&ns14=1&ns15=1&ns100=1&ns101=1&redirs=1&search=DISPLAYTITLE&title=Special%3ASearch&fulltext=Advanced+search&fulltext=Advanced+search

#Comment by Simetrical (talk | contribs)   01:13, 20 April 2009

No, I don't remember them offhand. Some examples were provided earlier. You might argue that they're misusing the feature, but they're using it nonetheless, and their wikis will break on upgrade if it's removed.

There's not much point in discussing this further. If you think the feature should be removed, probably best to talk to Brion.

#Comment by Skizzerz (talk | contribs)   23:50, 19 April 2009

$wgRestrictDisplayTitle re-added in r49654 In addition, r49654 fixes some bugs with block-level tags being allowed in DISPLAYTITLE (such as , which normalizes to the correct title, but makes it look weird)

#Comment by Skizzerz (talk | contribs)   23:51, 19 April 2009

er... such as {{DISPLAYTITLE:</h1>This page}}

#Comment by Simetrical (talk | contribs)   18:52, 1 June 2009

Problem #3: {{DISPLAYTITLE:<span style="display:none;">{{FULLPAGENAME}}</span>}}. style attributes need to be stripped here. I'd say all attributes should be stripped, possibly. There might be uses for class, but it could be easily abused. Just do class="mainLegend" or something to achieve the same "display: none" effect. So stripping all attributes seems most sensible ― that's the approach I took when I allowed sup and sub in the TOC.

#Comment by Remember the dot (talk | contribs)   01:40, 2 June 2009

If we didn't allow attributes, then how could editors add <span class="Unicode"> to improve display of titles that contain unusual characters?

I know that page titles can be vandalized, but really, it's no worse than what vandals can already do to the body of the article, not to mention pagemove vandalism which vandalizes the title everywhere and not just in the main view.

Interestingly, the English Wikipedia already technically permits the vandalism you're worried about via wikipedia:Template:Wrongtitle, and it hasn't caused much trouble.

#Comment by Simetrical (talk | contribs)   17:32, 2 June 2009

I wasn't really worried about vandals. I was concerned that this might be done deliberately for some reason, breaking the linkability of the title. But since, as you point out, allowing (safe) attributes has legitimate uses and there's clearly demand for it, such that it's in fact already possible on enwiki, I retract my objection.

Status & tagging log