r53518 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53517‎ | r53518 | r53519 >
Date:02:26, 20 July 2009
Author:brion
Status:resolved (Comments)
Tags:
Comment:
Also treat [[#section]] links as expected with the 'local' param for diff view vs RC/history view.
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -7433,7 +7433,29 @@
74347434 Poked at a <a href="https://www.mediawiki.org/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> here...
74357435 !!end
74367436
 7437+!! test
 7438+Edit comment with bare anchor link (local, as on diff)
 7439+!! options
 7440+comment
 7441+local
 7442+title=[[Main Page]]
 7443+!!input
 7444+[[#section]]
 7445+!! result
 7446+<a href="#section">#section</a>
 7447+!! end
74377448
 7449+!! test
 7450+Edit comment with bare anchor link (non-local, as on history)
 7451+!! options
 7452+comment
 7453+title=[[Main Page]]
 7454+!!input
 7455+[[#section]]
 7456+!! result
 7457+<a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a>
 7458+!! end
 7459+
74387460 TODO:
74397461 more images
74407462 more tables
Index: trunk/phase3/includes/Linker.php
@@ -922,7 +922,7 @@
923923
924924 # Render autocomments and make links:
925925 $comment = $this->formatAutoComments( $comment, $title, $local );
926 - $comment = $this->formatLinksInComment( $comment, $title );
 926+ $comment = $this->formatLinksInComment( $comment, $title, $local );
927927
928928 wfProfileOut( __METHOD__ );
929929 return $comment;
@@ -1009,13 +1009,15 @@
10101010 * @param string $comment Text to format links in
10111011 * @return string
10121012 */
1013 - public function formatLinksInComment( $comment, $title = null ) {
 1013+ public function formatLinksInComment( $comment, $title = null, $local = false ) {
10141014 $this->commentContextTitle = $title;
 1015+ $this->commentLocal = $local;
10151016 $html = preg_replace_callback(
10161017 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
10171018 array( $this, 'formatLinksInCommentCallback' ),
10181019 $comment );
10191020 unset( $this->commentContextTitle );
 1021+ unset( $this->commentLocal );
10201022 return $html;
10211023 }
10221024
@@ -1060,10 +1062,18 @@
10611063 $linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle,
10621064 $match[1], $linkText );
10631065
1064 - $thelink = $this->link(
1065 - Title::newFromText( $linkTarget ),
1066 - $linkText . $inside
1067 - ) . $trail;
 1066+ $target = Title::newFromText( $linkTarget );
 1067+ if( $target ) {
 1068+ if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) {
 1069+ $newTarget = clone( $this->commentContextTitle );
 1070+ $newTarget->setFragment( '#' . $target->getFragment() );
 1071+ $target = $newTarget;
 1072+ }
 1073+ $thelink = $this->link(
 1074+ $target,
 1075+ $linkText . $inside
 1076+ ) . $trail;
 1077+ }
10681078 }
10691079 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
10701080

Follow-up revisions

RevisionCommit summaryAuthorDate
r53607Cleanup for r53518 (subpage support for edit comments)...brion17:07, 21 July 2009

Comments

#Comment by Siebrand (talk | contribs)   17:22, 20 July 2009

PHP Notice: Undefined variable: thelink in /var/www/w/includes/Linker.php on line 1090 on hitting http://translatewiki.net/w/i.php?title=Special:Log&dir=prev&user=Siebrand . It was suggested this is due to this revision.

#Comment by Brion VIBBER (talk | contribs)   17:09, 21 July 2009

r53607 should fix that up. Now checking if it was set before we go replacing it. :)

Status & tagging log