allow "foo[[bar]]" to extend the link over the whole word "foobar"
authorJens Frank <jeluf@users.mediawiki.org>
Sun, 15 Feb 2004 10:05:52 +0000 (10:05 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Sun, 15 Feb 2004 10:05:52 +0000 (10:05 +0000)
includes/OutputPage.php
includes/Skin.php
languages/Language.php
languages/LanguageAr.php

index 998489e..617ba09 100644 (file)
@@ -985,21 +985,43 @@ $t[] = "</table>" ;
                $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[] = "</table>" ;
 
                        $nt = Title::newFromText( $link );
                        if( !$nt ) {
-                               $s .= "[[" . $line;
+                               $s .= $prefix . "[[" . $line;
                                continue;
                        }
                        $ns = $nt->getNamespace();
@@ -1044,29 +1066,29 @@ $t[] = "</table>" ;
                        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 .= "<strong>" . $text . "</strong>" . $trail;
+                               $s .= $prefix . "<strong>" . $text . "</strong>" . $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;
index f817d61..9d8c199 100644 (file)
@@ -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 = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$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 = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+               $r = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$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 = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+                       $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
                } else {
-                       $s = "{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
+                       $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$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 = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>{$trail}";
+                       $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
                } else {
-                       $s = "{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
+                       $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
                }
                return $s;
        }
index bf99247..3d8f73e 100644 (file)
@@ -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;
index 25eb29d..6ec3269 100644 (file)
@@ -77,6 +77,8 @@ class LanguageAr extends LanguageUtf8 {
 
        function isRTL() { return true; }
 
+       function linkPrefixExtension() { return true; }
+
        function getDefaultUserOptions () {
                global $wgDefaultUserOptionsEn;
                $opt = $wgDefaultUserOptionsEn;