From 8e476b31cc2e6f8aef6f8617a47ec78f37e4dc4a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 13 Feb 2008 05:59:14 +0000 Subject: [PATCH 1/1] * (bug 12935, 12981) Fully-qualify archive URLs in delete, revert messages Replaced a bunch of instances of 'if-this-is-not-fully-qualified-prepend-$wgServer' with a function, wfExpandUrl() --- RELEASE-NOTES | 2 +- includes/Feed.php | 10 +++------- includes/FileDeleteForm.php | 9 ++------- includes/FileRevertForm.php | 9 +++++---- includes/GlobalFunctions.php | 15 +++++++++++++++ includes/ImagePage.php | 3 +-- includes/OutputPage.php | 7 ++----- includes/filerepo/File.php | 7 +------ opensearch_desc.php | 7 ++----- 9 files changed, 32 insertions(+), 37 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index bb34ac9add..99025bc4c8 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 diff --git a/includes/Feed.php b/includes/Feed.php index 03cda1a0e2..309b29bda9 100644 --- a/includes/Feed.php +++ b/includes/Feed.php @@ -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 '' . "\n"; echo '\n"; + htmlspecialchars( wfExpandUrl( "$wgStylePath/common/feed.css?$wgStyleVersion" ) ) . + '"?' . ">\n"; } } diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 8537ca0f26..71e2c1aec0 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -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, diff --git a/includes/FileRevertForm.php b/includes/FileRevertForm.php index 55f21fffbf..f335d024d1 100644 --- a/includes/FileRevertForm.php +++ b/includes/FileRevertForm.php @@ -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 .= '
' . wfMsgHtml( 'filerevert-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 .= '

' . Xml::inputLabel( wfMsg( 'filerevert-comment' ), 'wpComment', 'wpComment', 60, wfMsgForContent( 'filerevert-defaultcomment', $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ) ) . '

'; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1c6fd3564d..d98d111929 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 83368373fb..5afaf6fb19 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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() ) ); } /** diff --git a/includes/OutputPage.php b/includes/OutputPage.php index b0dd3aa96f..21cf86b41d 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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"); diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index f4b28dbf18..5172ad0fc6 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -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() { diff --git a/opensearch_desc.php b/opensearch_desc.php index 70e90351bc..d766f1970f 100644 --- a/opensearch_desc.php +++ b/opensearch_desc.php @@ -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}' ); -- 2.20.1