From c2a862264b07f5e8deeafdf0840e3d1080b4c17e Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sun, 15 Feb 2004 10:05:52 +0000 Subject: [PATCH] allow "foo[[bar]]" to extend the link over the whole word "foobar" --- includes/OutputPage.php | 38 ++++++++++++++++++++++++++++++-------- includes/Skin.php | 28 ++++++++++++++-------------- languages/Language.php | 4 ++++ languages/LanguageAr.php | 2 ++ 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 998489e73d..617ba0973c 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -985,21 +985,43 @@ $t[] = "" ; $s = array_shift( $a ); $s = substr( $s, 1 ); + # Match a link having the form [[namespace:link|alternate]]trail $e1 = "/^([{$tc}]+)(?:\\|([^]]+))?]](.*)\$/sD"; + # Match the end of a line for a word that's not followed by whitespace, + # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched + #$e2 = "/^(.*)\\b(\\w+)\$/suD"; + #$e2 = "/^(.*\\s)(\\S+)\$/suD"; + $e2 = '/^(.*\s)([a-zA-Z\x80-\xff]+)$/sD'; + # Special and Media are pseudo-namespaces; no pages actually exist in them $image = Namespace::getImage(); $special = Namespace::getSpecial(); $media = Namespace::getMedia(); $nottalk = !Namespace::isTalk( $wgTitle->getNamespace() ); + + if ( $wgLang->linkPrefixExtension() && preg_match( $e2, $s, $m ) ) { + $new_prefix = $m[2]; + $s = $m[1]; + } else { + $new_prefix=""; + } + wfProfileOut( "$fname-setup" ); foreach ( $a as $line ) { + $prefix = $new_prefix; + if ( $wgUseLinkPrefixCombination && preg_match( $e2, $line, $m ) ) { + $new_prefix = $m[2]; + $line = $m[1]; + } else { + $new_prefix = ""; + } if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt $text = $m[2]; $trail = $m[3]; } else { # Invalid form; output directly - $s .= "[[" . $line ; + $s .= $prefix . "[[" . $line ; continue; } @@ -1036,7 +1058,7 @@ $t[] = "" ; $nt = Title::newFromText( $link ); if( !$nt ) { - $s .= "[[" . $line; + $s .= $prefix . "[[" . $line; continue; } $ns = $nt->getNamespace(); @@ -1044,29 +1066,29 @@ $t[] = "" ; if( $noforce ) { if( $iw && $wgInterwikiMagic && $nottalk && $wgLang->getLanguageName( $iw ) ) { array_push( $this->mLanguageLinks, $nt->getPrefixedText() ); - $s .= $trail; + $s .= $prefix . $trail; continue; } if( $ns == $image ) { - $s .= $sk->makeImageLinkObj( $nt, $text ) . $trail; + $s .= $prefix . $sk->makeImageLinkObj( $nt, $text ) . $trail; $wgLinkCache->addImageLinkObj( $nt ); continue; } } if( ( $nt->getPrefixedText() == $wgTitle->getPrefixedText() ) && ( strpos( $link, "#" ) == FALSE ) ) { - $s .= "" . $text . "" . $trail; + $s .= $prefix . "" . $text . "" . $trail; continue; } if( $ns == $media ) { - $s .= $sk->makeMediaLinkObj( $nt, $text ) . $trail; + $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text ) . $trail; $wgLinkCache->addImageLinkObj( $nt ); continue; } elseif( $ns == $special ) { - $s .= $sk->makeKnownLinkObj( $nt, $text, "", $trail ); + $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, "", $trail ); continue; } - $s .= $sk->makeLinkObj( $nt, $text, "", $trail ); + $s .= $sk->makeLinkObj( $nt, $text, "", $trail , $prefix ); } wfProfileOut( $fname ); return $s; diff --git a/includes/Skin.php b/includes/Skin.php index f817d61876..9d8c199572 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1257,7 +1257,7 @@ class Skin { } # Pass a title object, not a title string - function makeLinkObj( &$nt, $text= "", $query = "", $trail = "" ) + function makeLinkObj( &$nt, $text= "", $query = "", $trail = "", $prefix = "" ) { global $wgOut, $wgUser; if ( $nt->isExternal() ) { @@ -1274,14 +1274,14 @@ class Skin { } $retVal = "{$text}{$inside}{$trail}"; } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) { - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail ); + $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } elseif ( ( -1 == $nt->getNamespace() ) || ( Namespace::getImage() == $nt->getNamespace() ) ) { - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail ); + $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } else { $aid = $nt->getArticleID() ; if ( 0 == $aid ) { - $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail ); + $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); } else { $threshold = $wgUser->getOption("stubthreshold") ; if ( $threshold > 0 ) { @@ -1301,9 +1301,9 @@ class Skin { $size = 1 ; } if ( $size < $threshold ) { - $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail ); + $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix ); } else { - $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail ); + $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } } } @@ -1311,7 +1311,7 @@ class Skin { } # Pass a title object, not a title string - function makeKnownLinkObj( &$nt, $text = "", $query = "", $trail = "" ) + function makeKnownLinkObj( &$nt, $text = "", $query = "", $trail = "", $prefix = "" ) { global $wgOut, $wgTitle; @@ -1339,13 +1339,13 @@ class Skin { $trail = $m[2]; } } - $r = "{$text}{$inside}{$trail}"; + $r = "{$prefix}{$text}{$inside}{$trail}"; wfProfileOut( $fname ); return $r; } # Pass a title object, not a title string - function makeBrokenLinkObj( &$nt, $text = "", $query = "", $trail = "" ) + function makeBrokenLinkObj( &$nt, $text = "", $query = "", $trail = "", $prefix = "" ) { global $wgOut, $wgUser; @@ -1370,9 +1370,9 @@ class Skin { } if ( $wgOut->isPrintable() || ( 1 == $wgUser->getOption( "highlightbroken" ) ) ) { - $s = "{$text}{$inside}{$trail}"; + $s = "{$prefix}{$text}{$inside}{$trail}"; } else { - $s = "{$text}{$inside}?{$trail}"; + $s = "{$prefix}{$text}{$inside}?{$trail}"; } wfProfileOut( $fname ); @@ -1380,7 +1380,7 @@ class Skin { } # Pass a title object, not a title string - function makeStubLinkObj( &$nt, $text = "", $query = "", $trail = "" ) + function makeStubLinkObj( &$nt, $text = "", $query = "", $trail = "", $prefix = "" ) { global $wgOut, $wgUser; @@ -1400,9 +1400,9 @@ class Skin { } if ( $wgOut->isPrintable() || ( 1 == $wgUser->getOption( "highlightbroken" ) ) ) { - $s = "{$text}{$inside}{$trail}"; + $s = "{$prefix}{$text}{$inside}{$trail}"; } else { - $s = "{$text}{$inside}!{$trail}"; + $s = "{$prefix}{$text}{$inside}!{$trail}"; } return $s; } diff --git a/languages/Language.php b/languages/Language.php index bf9924792e..3d8f73e791 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1662,6 +1662,10 @@ class Language { # For right-to-left language support function isRTL() { return false; } + # To allow "foo[[bar]]" to extend the link over the whole word "foobar" + function linkPrefixExtension() { return false; } + + function getMagicWords() { global $wgMagicWordsEn; diff --git a/languages/LanguageAr.php b/languages/LanguageAr.php index 25eb29df9d..6ec3269127 100644 --- a/languages/LanguageAr.php +++ b/languages/LanguageAr.php @@ -77,6 +77,8 @@ class LanguageAr extends LanguageUtf8 { function isRTL() { return true; } + function linkPrefixExtension() { return true; } + function getDefaultUserOptions () { global $wgDefaultUserOptionsEn; $opt = $wgDefaultUserOptionsEn; -- 2.20.1