* (bug 1702) Display a handy upload link instead of a useless blank link
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 16 Jun 2005 05:36:10 +0000 (05:36 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 16 Jun 2005 05:36:10 +0000 (05:36 +0000)
  for [[media:]] links to nonexistent files.

RELEASE-NOTES
includes/Linker.php
maintenance/parserTests.txt

index bba2660..f93fbbf 100644 (file)
@@ -291,7 +291,8 @@ Various bugfixes, small features, and a few experimental things:
 * Added wfMsgHtml() function for escaping messages and leaving params intact
 * Fix ordering of Special:Listusers; fix groups list so it shows all groups
   when searching for a specific group and can't be split across pages
-
+* (bug 1702) Display a handy upload link instead of a useless blank link
+  for [[media:]] links to nonexistent files.
 
 === Caveats ===
 
index 3bdbab9..ed7c6c9 100644 (file)
@@ -577,16 +577,23 @@ class Linker {
                } else {
                        $name = $title->getDBKey();     
                        $img  = new Image( $title );
-                       $url  = $img->getURL();
-                       if( $nourl ) {
-                               $url = str_replace( "http://", "http-noparse://", $url );
+                       if( $img->exists() ) {
+                               $url  = $img->getURL();
+                               if( $nourl ) {
+                                       $url = str_replace( "http://", "http-noparse://", $url );
+                               }
+                               $class = 'internal';
+                       } else {
+                               $upload = Title::makeTitle( NS_SPECIAL, 'Upload' );
+                               $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $img->getName() ) );
+                               $class = 'new';
                        }
                        $alt = htmlspecialchars( $title->getText() );
                        if( $text == '' ) {
                                $text = $alt;
                        }
                        $u = htmlspecialchars( $url );
-                       return "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$text}</a>";                        
+                       return "<a href=\"{$u}\" class='$class' title=\"{$alt}\">{$text}</a>";                  
                }
        }
 
index f644fe2..a842a5b 100644 (file)
@@ -2272,6 +2272,16 @@ Media link with nasty text
 </p>
 !! end
 
+!! test
+Media link to nonexistent file (bug 1702)
+!! input
+[[Media:No such.jpg]]
+!! result
+<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such.jpg" class='new' title="No such.jpg">Media:No such.jpg</a>
+</p>
+!! end
+
+
 
 !! test
 Character reference normalization in link text (bug 1938)