* (bug 12935, 12981) Fully-qualify archive URLs in delete, revert messages
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 13 Feb 2008 05:59:14 +0000 (05:59 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 13 Feb 2008 05:59:14 +0000 (05:59 +0000)
Replaced a bunch of instances of 'if-this-is-not-fully-qualified-prepend-$wgServer' with a function, wfExpandUrl()

RELEASE-NOTES
includes/Feed.php
includes/FileDeleteForm.php
includes/FileRevertForm.php
includes/GlobalFunctions.php
includes/ImagePage.php
includes/OutputPage.php
includes/filerepo/File.php
opensearch_desc.php

index bb34ac9..99025bc 100644 (file)
@@ -387,7 +387,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 7681, 11559) Cookie values no longer override GET and POST variables.
 * (bug 5262) Fully-qualified $wgStylePath no longer corrupted on XML feeds
 * (bug 3269) Inaccessible titles ending in '/.' or '/..' now forbidden.
-* (bug 12935) Fully-qualify archive URLs correctly in deletion message
+* (bug 12935, 12981) Fully-qualify archive URLs in delete, revert messages
 * (bug 12938) Fix template expansion and 404 returns for action=raw with section
 * (bug 11567) Fix error checking for PEAR::Mail. UserMailer::send() now returns
   true-or-WikiError, which seems to be the calling convention expected by half
index 03cda1a..309b29b 100644 (file)
@@ -146,17 +146,13 @@ class ChannelFeed extends FeedItem {
         * @private
         */
        function outXmlHeader() {
-               global $wgServer, $wgStylePath, $wgStyleVersion;
-               if( substr( $wgStylePath, 0, 1 ) == '/' ) {
-                       $stylePath = $wgServer . $wgStylePath;
-               } else {
-                       $stylePath = $wgStylePath;
-               }
+               global $wgStylePath, $wgStyleVersion;
 
                $this->httpHeaders();
                echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
                echo '<?xml-stylesheet type="text/css" href="' .
-                       htmlspecialchars( "$stylePath/common/feed.css?$wgStyleVersion" ) . '"?' . ">\n";
+                       htmlspecialchars( wfExpandUrl( "$wgStylePath/common/feed.css?$wgStyleVersion" ) ) .
+                       '"?' . ">\n";
        }
 }
 
index 8537ca0..71e2c1a 100644 (file)
@@ -178,21 +178,16 @@ class FileDeleteForm {
         * @return string
         */
        private function prepareMessage( $message ) {
-               global $wgLang, $wgServer;
+               global $wgLang;
                if( $this->oldimage ) {
                        $url = $this->file->getArchiveUrl( $this->oldimage );
-                       if( substr( $url, 0, 1 ) == '/' ) {
-                               // Fully-qualify the URL if necessary
-                               $url = $wgServer . $url;
-                       }
                        return wfMsgExt(
                                "{$message}-old", # To ensure grep will find them: 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
                                'parse',
                                $this->title->getText(),
                                $wgLang->date( $this->getTimestamp(), true ),
                                $wgLang->time( $this->getTimestamp(), true ),
-                               $url
-                       );
+                               wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) );
                } else {
                        return wfMsgExt(
                                $message,
index 55f21ff..f335d02 100644 (file)
@@ -28,7 +28,7 @@ class FileRevertForm {
         * pending authentication, confirmation, etc.
         */
        public function execute() {
-               global $wgOut, $wgRequest, $wgUser, $wgLang, $wgServer;
+               global $wgOut, $wgRequest, $wgUser, $wgLang;
                $this->setHeaders();
 
                if( wfReadOnly() ) {
@@ -71,7 +71,7 @@ class FileRevertForm {
                                $wgOut->addHtml( wfMsgExt( 'filerevert-success', 'parse', $this->title->getText(),
                                        $wgLang->date( $this->getTimestamp(), true ),
                                        $wgLang->time( $this->getTimestamp(), true ),
-                                       $wgServer . $this->file->getArchiveUrl( $this->oldimage ) ) );
+                                       wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) ) );
                                $wgOut->returnToMain( false, $this->title );
                        } else {
                                $wgOut->addWikiText( $status->getWikiText() );
@@ -87,14 +87,15 @@ class FileRevertForm {
         * Show the confirmation form
         */
        private function showForm() {
-               global $wgOut, $wgUser, $wgRequest, $wgLang, $wgContLang, $wgServer;
+               global $wgOut, $wgUser, $wgRequest, $wgLang, $wgContLang;
                $timestamp = $this->getTimestamp();
 
                $form  = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction() ) );
                $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) );
                $form .= '<fieldset><legend>' . wfMsgHtml( 'filerevert-legend' ) . '</legend>';
                $form .= wfMsgExt( 'filerevert-intro', 'parse', $this->title->getText(),
-                       $wgLang->date( $timestamp, true ), $wgLang->time( $timestamp, true ), $wgServer . $this->file->getArchiveUrl( $this->oldimage ) );
+                       $wgLang->date( $timestamp, true ), $wgLang->time( $timestamp, true ),
+                       wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) );
                $form .= '<p>' . Xml::inputLabel( wfMsg( 'filerevert-comment' ), 'wpComment', 'wpComment',
                        60, wfMsgForContent( 'filerevert-defaultcomment',
                        $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ) ) . '</p>';
index 1c6fd35..d98d111 100644 (file)
@@ -980,6 +980,21 @@ function wfAppendQuery( $url, $query ) {
        return $url;
 }
 
+/**
+ * Expand a potentially local URL to a fully-qualified URL.
+ * Assumes $wgServer is correct. :)
+ * @param string $url, either fully-qualified or a local path + query
+ * @return string Fully-qualified URL
+ */
+function wfExpandUrl( $url ) {
+       if( substr( $url, 0, 1 ) == '/' ) {
+               global $wgServer;
+               return $wgServer . $url;
+       } else {
+               return $url;
+       }
+}
+
 /**
  * This is obsolete, use SquidUpdate::purge()
  * @deprecated
index 8336837..5afaf6f 100644 (file)
@@ -366,9 +366,8 @@ EOT
        }
 
        function getUploadUrl() {
-               global $wgServer;
                $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
-               return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
+               return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
        }
 
        /**
index b0dd3aa..21cf86b 100644 (file)
@@ -611,11 +611,8 @@ class OutputPage {
                wfProfileIn( $fname );
 
                if ( '' != $this->mRedirect ) {
-                       if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
-                               # Standards require redirect URLs to be absolute
-                               global $wgServer;
-                               $this->mRedirect = $wgServer . $this->mRedirect;
-                       }
+                       # Standards require redirect URLs to be absolute
+                       $this->mRedirect = wfExpandUrl( $this->mRedirect );
                        if( $this->mRedirectCode == '301') {
                                if( !$wgDebugRedirects ) {
                                        $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
index f4b28db..5172ad0 100644 (file)
@@ -155,12 +155,7 @@ abstract class File {
         * @return string
         */
        public function getFullUrl() {
-               $url = $this->getUrl();
-               if( substr( $url, 0, 1 ) == '/' ) {
-                       global $wgServer;
-                       return $wgServer . $url;
-               }
-               return $url;
+               return wfExpandUrl( $this->getUrl() );
        }
 
        function getViewURL() {
index 70e9035..d766f19 100644 (file)
@@ -10,11 +10,8 @@ $fullName = "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})";
 $shortName = htmlspecialchars( mb_substr( $fullName, 0, 24 ) );
 $siteName = htmlspecialchars( $fullName );
 
-if ( !preg_match( '/^https?:/', $wgFavicon ) ) {
-       $favicon = htmlspecialchars( $wgServer . $wgFavicon );
-} else {
-       $favicon = htmlspecialchars( $wgFavicon );
-}
+
+$favicon = htmlspecialchars( wfExpandUrl( $wgFavicon ) );
 
 $title = SpecialPage::getTitleFor( 'Search' );
 $template = $title->escapeFullURL( 'search={searchTerms}' );