Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7620
magic_links_v2.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 11:29 PM
2014-11-21 23:29:41 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
magic_links_v2.diff
View Options
--- includes/parser/Parser.php Thu Dec 22 10:24:48 2011
+++ includes/parser/Parser.php Mon Jan 23 21:30:29 2012
@@ -1078,17 +1078,21 @@
$prots = wfUrlProtocolsWithoutProtRel();
$urlChar = self::EXT_LINK_URL_CLASS;
$text = preg_replace_callback(
- '!(?: # Start cases
- (<a[ \t\r\n>].*?</a>) | # m[1]: Skip link text
- (<.*?>) | # m[2]: Skip stuff inside HTML elements' . "
- (\\b(?:$prots)$urlChar+) | # m[3]: Free external links" . '
- (?:RFC|PMID)\s+([0-9]+) | # m[4]: RFC or PMID, capture number
- ISBN\s+(\b # m[5]: ISBN, capture number
- (?: 97[89] [\ \-]? )? # optional 13-digit ISBN prefix
- (?: [0-9] [\ \-]? ){9} # 9 digits with opt. delimiters
- [0-9Xx] # check digit
+ '!(?: # Start cases
+ (<a[ \t\r\n>].*?</a>) | # m[1]: Skip link text
+ (<.*?>) | # m[2]: Skip stuff inside HTML elements' . "
+ (\\b(?:$prots)$urlChar+) | # m[3]: Free external links" . '
+ (?:RFC|PMID) # m[4/5]: RFC or PMID
+ ((?:\s| |&\#0?160;|\x{00A0})+) # m[4] capture spaces
+ ([0-9]+) | # m[5] capture number
+ ISBN # m[6/7]: ISBN
+ ((?:\s| |&\#0?160;|\x{00A0})+) # m[6] capture spaces
+ (\b # m[7] capture number
+ (?: 97[89] [\ \-]? )? # optional 13-digit ISBN prefix
+ (?: [0-9] [\ \-]? ){9} # 9 digits with opt. delimiters
+ [0-9Xx] # check digit
\b)
- )!x', array( &$this, 'magicLinkCallback' ), $text );
+ )!ux', array( &$this, 'magicLinkCallback' ), $text );
wfProfileOut( __METHOD__ );
return $text;
}
@@ -1110,34 +1114,41 @@
return $this->makeFreeExternalLink( $m[0] );
} elseif ( isset( $m[4] ) && $m[4] !== '' ) {
# RFC or PMID
+ $spaces = $m[4];
+ $id = $m[5];
+ if ( substr_count( $spaces, "\n" ) > 1 || strpos( $spaces, "\n " ) !== false ) {
+ return $m[0];
+ }
if ( substr( $m[0], 0, 3 ) === 'RFC' ) {
$keyword = 'RFC';
$urlmsg = 'rfcurl';
$CssClass = 'mw-magiclink-rfc';
- $id = $m[4];
} elseif ( substr( $m[0], 0, 4 ) === 'PMID' ) {
$keyword = 'PMID';
$urlmsg = 'pubmedurl';
$CssClass = 'mw-magiclink-pmid';
- $id = $m[4];
} else {
throw new MWException( __METHOD__.': unrecognised match type "' .
substr( $m[0], 0, 20 ) . '"' );
}
$url = wfMsgForContent( $urlmsg, $id );
- return Linker::makeExternalLink( $url, "{$keyword} {$id}", true, $CssClass );
- } elseif ( isset( $m[5] ) && $m[5] !== '' ) {
+ return Linker::makeExternalLink( $url, "{$keyword}{$spaces}{$id}", false, $CssClass );
+ } elseif ( isset( $m[6] ) && $m[6] !== '' ) {
# ISBN
- $isbn = $m[5];
+ $spaces = $m[6];
+ $isbn = $m[7];
+ if ( substr_count( $spaces, "\n" ) > 1 || strpos( $spaces, "\n " ) !== false ) {
+ return $m[0];
+ }
$num = strtr( $isbn, array(
'-' => '',
' ' => '',
'x' => 'X',
));
$titleObj = SpecialPage::getTitleFor( 'Booksources', $num );
- return'<a href="' .
+ return '<a href="' .
$titleObj->escapeLocalUrl() .
- "\" class=\"internal mw-magiclink-isbn\">ISBN $isbn</a>";
+ "\" class=\"internal mw-magiclink-isbn\">ISBN{$spaces}{$isbn}</a>";
} else {
return $m[0];
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7149
Default Alt Text
magic_links_v2.diff (3 KB)
Attached To
Mode
T30950: ISBN, RFC and PMID "magic links" might support non-breaking spaces ( ) too
Attached
Detach File
Event Timeline
Log In to Comment