r53534 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53533‎ | r53534 | r53535 >
Date:06:29, 20 July 2009
Author:mrzman
Status:reverted (Comments)
Tags:
Comment:
(bug 15745) Make the edit summary link parser detect links more like the real parser, added a parser test for it
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -7456,6 +7456,17 @@
74577457 <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a>
74587458 !! end
74597459
 7460+!! test
 7461+Edit comment with mismatched brackets (bug 15745)
 7462+!! options
 7463+comment
 7464+title=[[Main Page]]
 7465+!!input
 7466+Some text, a [[broken link|bad and a [[good link|good]]
 7467+!! result
 7468+Some text, a [[broken link|bad and a <a href="https://www.mediawiki.org/index.php?title=Good_link&amp;action=edit&amp;redlink=1" class="new" title="Good link (page does not exist)">good</a>
 7469+!! end
 7470+
74607471 TODO:
74617472 more images
74627473 more tables
Index: trunk/phase3/includes/Linker.php
@@ -1012,10 +1012,22 @@
10131013 public function formatLinksInComment( $comment, $title = null, $local = false ) {
10141014 $this->commentContextTitle = $title;
10151015 $this->commentLocal = $local;
1016 - $html = preg_replace_callback(
1017 - '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1018 - array( $this, 'formatLinksInCommentCallback' ),
1019 - $comment );
 1016+ # Borrowed from Parser::replaceInternalLinks2
 1017+ $parts = StringUtils::explode( '[[', ' ' . $comment );
 1018+ $start = $parts->current();
 1019+ $parts->next();
 1020+ $line = $parts->current();
 1021+ $html = substr( $start, 1 );
 1022+ for ( ; $line !== false && $line !== null ; $parts->next(), $line = $parts->current() ) {
 1023+ $linked = preg_replace_callback(
 1024+ '/^:?(.*?)(\|(.*?))*\]\]([^[]*)/',
 1025+ array( $this, 'formatLinksInCommentCallback' ),
 1026+ $line, -1, $count );
 1027+ if( !$count ) { // No valid link found, put the brackets back
 1028+ $linked = '[[' . $linked;
 1029+ }
 1030+ $html .= $linked;
 1031+ }
10201032 unset( $this->commentContextTitle );
10211033 unset( $this->commentLocal );
10221034 return $html;
@@ -1043,7 +1055,7 @@
10441056 $submatch = array();
10451057 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
10461058 # Media link; trail not supported.
1047 - $linkRegexp = '/\[\[(.*?)\]\]/';
 1059+ $linkRegexp = '/^(.*?)\]\]/';
10481060 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
10491061 $thelink = $this->makeMediaLinkObj( $title, $text );
10501062 } else {
@@ -1053,7 +1065,7 @@
10541066 } else {
10551067 $trail = "";
10561068 }
1057 - $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
 1069+ $linkRegexp = '/^(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
10581070 if (isset($match[1][0]) && $match[1][0] == ':')
10591071 $match[1] = substr($match[1], 1);
10601072 list( $inside, $trail ) = Linker::splitTrail( $trail );
Index: trunk/phase3/RELEASE-NOTES
@@ -304,6 +304,8 @@
305305 * (bug 17374) Special:Export no longer exports multiple copies of pages
306306 * (bug 19818) Edits to user CSS/JS subpages can now be marked as patrolled by
307307 users who can't edit them
 308+* (bug 15745) The edit summary link parser now handles mismatched brackets
 309+ better
308310
309311 == API changes in 1.16 ==
310312

Follow-up revisions

RevisionCommit summaryAuthorDate
r55644Revert r53534 (bug 15745, Make the edit summary link parser detect links more...demon22:27, 27 August 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   16:34, 24 July 2009

There seems to be some regression causing a fatal error with some input -- bug 19845

#Comment by 😂 (talk | contribs)   18:07, 19 August 2009

Reported again at http://lists.wikimedia.org/pipermail/mediawiki-l/2009-August/031809.html. I haven't been able to pin down the issue exactly, and I haven't been able to replicate any of the described symptoms in 5.2.10 or 5.3. Definitely needs some more poking!

#Comment by 😂 (talk | contribs)   18:38, 19 August 2009

Seems to have been an issue with preg_replace_callback() (see http://bugs.php.net/bug.php?id=48501). Has been fixed in the 5.2.x branch (5.2.10 seems fine) and in 5.3 release. Not really sure we can do a sanity check on install like we do with libxml2, we'll just tell people that hit the issue that they need to upgrade PHP.

#Comment by 😂 (talk | contribs)   22:30, 27 August 2009

Reverted in r55644.

Status & tagging log