r76127 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76126‎ | r76127 | r76128 >
Date:19:06, 5 November 2010
Author:mah
Status:reverted (Comments)
Tags:
Comment:
Resolves Bug#542 by removing the link title from in-wiki links where
the title just duplicates the link text.
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Linker.php
@@ -198,7 +198,7 @@
199199
200200 $attribs = array_merge(
201201 $attribs,
202 - $this->linkAttribs( $target, $customAttribs, $options )
 202+ $this->linkAttribs( $target, $customAttribs, $options, $text )
203203 );
204204 if ( is_null( $text ) ) {
205205 $text = $this->linkText( $target );
@@ -248,7 +248,7 @@
249249 /**
250250 * Returns the array of attributes used when linking to the Title $target
251251 */
252 - private function linkAttribs( $target, $attribs, $options ) {
 252+ private function linkAttribs( $target, $attribs, $options, $linkText ) {
253253 wfProfileIn( __METHOD__ );
254254 global $wgUser;
255255 $defaults = array();
@@ -279,12 +279,13 @@
280280 }
281281
282282 # Get a default title attribute.
 283+ $known = in_array( 'known', $options );
283284 if ( $target->getPrefixedText() == '' ) {
284285 # A link like [[#Foo]]. This used to mean an empty title
285286 # attribute, but that's silly. Just don't output a title.
286 - } elseif ( in_array( 'known', $options ) ) {
 287+ } elseif ( $known && strtolower($linkText) !== strtolower($target->getPrefixedText() ) ) {
287288 $defaults['title'] = $target->getPrefixedText();
288 - } else {
 289+ } elseif ( !$known ) {
289290 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
290291 }
291292
@@ -312,7 +313,7 @@
313314 return '';
314315 }
315316
316 - # If the target is just a fragment, with no title, we return the frag-
 317+ # If the target is just a fragment, with no title, we return the frag-
317318 # ment text. Otherwise, we return the title text itself.
318319 if ( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
319320 return htmlspecialchars( $target->getFragment() );
@@ -324,14 +325,14 @@
325326 * Generate either a normal exists-style link or a stub link, depending
326327 * on the given page size.
327328 *
328 - * @param $size Integer
329 - * @param $nt Title object.
330 - * @param $text String
331 - * @param $query String
332 - * @param $trail String
333 - * @param $prefix String
334 - * @return string HTML of link
335 - * @deprecated
 329+ * @param $size Integer
 330+ * @param $nt Title object.
 331+ * @param $text String
 332+ * @param $query String
 333+ * @param $trail String
 334+ * @param $prefix String
 335+ * @return string HTML of link
 336+ * @deprecated
336337 */
337338 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
338339 global $wgUser;
@@ -1317,7 +1318,7 @@
13181319 */
13191320 function tocLineEnd() {
13201321 return "</li>\n";
1321 - }
 1322+ }
13221323
13231324 /**
13241325 * Wraps the TOC in a table and provides the hide/collapse javascript.
@@ -1739,7 +1740,7 @@
17401741 */
17411742 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
17421743 wfProfileIn( __METHOD__ );
1743 - $nt = Title::newFromText( $title );
 1744+ $nt = Title::newFromText( $title );
17441745 if ( $nt instanceof Title ) {
17451746 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
17461747 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r76129followup r76127 - update parser tests.mah19:39, 5 November 2010
r83521followup r76127 — use language-aware comparison between link text and possi...mah14:38, 8 March 2011
r83535* Followup r76127 and r83521 by adding parsertests and using caseFoldmah18:09, 8 March 2011
r87030revert r76127, r76129, and r83535 b/c I'm backing out the fix for bug #542. ...mah19:13, 27 April 2011

Comments

#Comment by MarkAHershberger (talk | contribs)   19:11, 5 November 2010

forgot to update parsertests...

#Comment by Platonides (talk | contribs)   19:33, 5 November 2010

Use spaces: Bug 542

Fine except for the parsertests

#Comment by MarkAHershberger (talk | contribs)   19:37, 5 November 2010

Also note the w/s changes were unintended.

#Comment by Bawolff (talk | contribs)   23:44, 12 February 2011

This broke a screen scraper that was powering the (en) Wikinews RSS feed. However I imagine keeping the screen scrapers happy is not really a valid complaint against a commit given they should be using the api and all that jaz :(

#Comment by Dispenser (talk | contribs)   16:57, 17 February 2011

This is bad usability. I sit there waiting for a tool-tip to eventually popup wondering where the hell it is. There is also no option in the API to turn this off. Meaning that more complicated code to parse the href= is required to find the target.

#Comment by MarkAHershberger (talk | contribs)   18:31, 17 February 2011

This sort of comment belongs in Bugzilla (probably a new bug) rather than in code review. Especially when it has been 3.5 months since the commit was made and it appears you were only made aware of this after it showed up on Wikipedia.

In other words, at this point, your issue is more likely to be addressed in Bugzilla rather than CodeReview.

#Comment by Fomafix (talk | contribs)   14:41, 7 March 2011

Lower case ASCII characters gets no title but lower case non ASCII characters gets a title:

[[A]] [[a]] [[Ä]] [[ä]]

is converted to

<a href="https://www.mediawiki.org/wiki/A">A</a>
<a href="https://www.mediawiki.org/wiki/A">a</a>
<a href="https://www.mediawiki.org/wiki/%C3%84">Ä</a>
<a href="https://www.mediawiki.org/wiki/%C3%84" title="Ä">ä</a>
#Comment by Platonides (talk | contribs)   00:23, 8 March 2011

That's because strtolower("Ä") may be Ä or ä depending on your locale.

#Comment by Bawolff (talk | contribs)   01:24, 8 March 2011

Shouldn't it use $wgContLang->lc functions instead to avoid that?

Status & tagging log