Generate expanded URLs for printing on the client, not server (using CSS, or JS for...
authorTom Gilder <tomgilder@users.mediawiki.org>
Sat, 15 Jan 2005 23:56:26 +0000 (23:56 +0000)
committerTom Gilder <tomgilder@users.mediawiki.org>
Sat, 15 Jan 2005 23:56:26 +0000 (23:56 +0000)
includes/Linker.php
includes/Parser.php
skins/amethyst/main.css
skins/chick/main.css
skins/common/IEFixes.js
skins/common/common.css
skins/common/commonPrint.css
skins/common/wikiprintable.css
skins/disabled/Chick.php
skins/monobook/main.css

index 7a725c4..59766bc 100644 (file)
@@ -647,8 +647,8 @@ class Linker {
                  wfMsg( $key ) );
        }
 
-       function makeExternalLink( $url, $text, $escape = true ) {
-               $style = $this->getExternalLinkAttributes( $url, $text );
+       function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
+               $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
                $url = htmlspecialchars( $url );
                if( $escape ) {
                        $text = htmlspecialchars( $text );
@@ -833,13 +833,6 @@ class Linker {
 
        }
 
-       /**
-        * @access public
-        */
-       function suppressUrlExpansion() {
-               return false;
-       }
-
 }
 
 ?>
\ No newline at end of file
index e2407e7..375f988 100644 (file)
@@ -992,14 +992,19 @@ class Parser
 
                        $dtrail = '';
 
+                       # Set linktype for CSS - if URL==text, link is essentially free
+                       $linktype = ($text == $url) ? 'free' : 'text';
+
                        # No link text, e.g. [http://domain.tld/some.link]
                        if ( $text == '' ) {
                                # Autonumber if allowed
                                if ( strpos( HTTP_PROTOCOLS, $protocol ) !== false ) {
                                        $text = '[' . ++$this->mAutonumber . ']';
+                                       $linktype = 'autonumber';
                                } else {
                                        # Otherwise just use the URL
                                        $text = htmlspecialchars( $url );
+                                       $linktype = 'free';
                                }
                        } else {
                                # Have link text, e.g. [http://domain.tld/some.link text]s
@@ -1010,19 +1015,6 @@ class Parser
                                }
                        }
 
-                       $encUrl = htmlspecialchars( $url );
-                       # Bit in parentheses showing the URL for the printable version
-                       if( $url == $text || preg_match( "!$protocol://" . preg_quote( $text, '/' ) . "/?$!", $url ) ) {
-                               $paren = '';
-                       } else {
-                               # Expand the URL for printable version
-                               if ( ! $sk->suppressUrlExpansion() ) {
-                                       $paren = "<span class='urlexpansion'>&nbsp;(<i>" . htmlspecialchars ( $encUrl ) . "</i>)</span>";
-                               } else {
-                                       $paren = '';
-                               }
-                       }
-
                        # Process the trail (i.e. everything after this link up until start of the next link),
                        # replacing any non-bracketed links
                        $trail = $this->replaceFreeExternalLinks( $trail );
@@ -1031,7 +1023,7 @@ class Parser
                        # This means that users can paste URLs directly into the text
                        # Funny characters like &ouml; aren't valid in URLs anyway
                        # This was changed in August 2004
-                       $s .= $sk->makeExternalLink( $url, $text, false ) . $dtrail. $paren . $trail;
+                       $s .= $sk->makeExternalLink( $url, $text, false, $linktype ) . $dtrail . $trail;
                }
 
                wfProfileOut( $fname );
@@ -1091,7 +1083,7 @@ class Parser
                                $text = $this->maybeMakeImageLink( $url );
                                if ( $text === false ) {
                                        # Not an image, make a link
-                                       $text = $sk->makeExternalLink( $url, $url );
+                                       $text = $sk->makeExternalLink( $url, $url, true, 'free' );
                                }
                                $s .= $text . $trail;
                        } else {
index 898910c..a48ab4e 100644 (file)
@@ -438,7 +438,7 @@ div.tleft {
     margin-right:0.5em;
     border-width: 0.5em 1.4em 0.8em 0;
 }
-.urlexpansion,
+
 .hiddenStructure {
     display: none;
 }
index a7191b1..a07ee60 100755 (executable)
@@ -309,7 +309,7 @@ div.tleft {
     margin-right:0.5em;
     border-width: 0.5em 1.4em 0.8em 0;
 }
-.urlexpansion,
+
 .hiddenStructure {
     display: none;
 }
index 2d2ba67..ec10f1b 100644 (file)
@@ -74,3 +74,44 @@ function setrelative (nodes) {
         i++;
     }
 }
+
+
+// Expand links for printing
+
+String.prototype.hasClass = function(classWanted)
+{
+    var classArr = this.split(/\s/);
+    for (var i=0; i<classArr.length; i++)
+      if (classArr[i].toLowerCase() == classWanted.toLowerCase()) return true;
+    return false;
+}
+
+var expandedURLs;
+
+onbeforeprint = function() { 
+    expandedURLs = [];
+
+    var contentEl = document.getElementById("content");
+
+    if (contentEl)
+    {
+      var allLinks = contentEl.getElementsByTagName("a");
+
+      for (var i=0; i < allLinks.length; i++) {
+          if (allLinks[i].className.hasClass("external") && !allLinks[i].className.hasClass("free")) {
+              var expandedLink = document.createElement("span");
+              var expandedText = document.createTextNode(" (" + allLinks[i].href + ")");
+              expandedLink.appendChild(expandedText);
+              allLinks[i].parentNode.insertBefore(expandedLink, allLinks[i].nextSibling);
+              expandedURLs[i] = expandedLink;
+          }
+      }
+   }
+}
+
+onafterprint = function()
+{
+    for (var i=0; i < expandedURLs.length; i++)
+        if (expandedURLs[i])
+            expandedURLs[i].removeNode(true);
+}
\ No newline at end of file
index 9878684..b5bbb9f 100644 (file)
@@ -11,7 +11,7 @@ div.floatleft p { font-style: italic; }
 
 
 /* Print-specific things to hide */
-.urlexpansion, .printfooter {
+.printfooter {
         display: none;
 }
 
index 71ae2c8..8c0aff1 100644 (file)
@@ -163,11 +163,11 @@ a:link, a:visited {
     background: transparent;
     text-decoration: underline;
 }
-/*
-#content a:link:after, 
-#content a:visited:after {
-   content: " ( " attr(href) " ) ";
-}*/
+
+#content a.external.text:after, #content a.external.autonumber:after {
+    /* Expand URLs for printing */
+    content: " (" attr(href) ") ";
+}
 
 #globalWrapper {
     width: 100% !important;
@@ -198,11 +198,6 @@ img { border: none; }
 img.tex { vertical-align: middle; }
 span.texhtml { font-family: serif; }
 
-/* Show some stuff */
-.urlexpansion {
-       display: inline ! important;
-}
-
 div.townBox {
     position:relative;
     float:right;
index 22e7193..868b36e 100644 (file)
@@ -32,11 +32,6 @@ a, a.external, a.new, a.stub {
        margin: inherit ! important;
 }
 
-/* Show some stuff */
-.urlexpansion {
-       display: inline ! important;
-}
-
 .printfooter {
        border-top: solid 1px black;
        display: block ! important;
index 205feb6..3351576 100644 (file)
@@ -27,7 +27,6 @@ class SkinChick extends SkinPHPTal {
                $this->skinname = 'chick';
                $this->template = 'Chick';
        }
-       function suppressUrlExpansion() { return true; }
        function printSource() { return ''; }
 }
 
index e3e4645..e14117d 100644 (file)
@@ -408,7 +408,7 @@ div.tleft {
     margin-right:0.5em;
     border-width: 0.5em 1.4em 0.8em 0;
 }
-.urlexpansion,
+
 .hiddenStructure {
     display: none;
 }