From dbe2ecfc6ab2b23dfc39d54e3520c230dc7c1112 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sat, 9 Jun 2007 16:19:38 +0000 Subject: [PATCH] * Clean up and document Linker::makeBrokenImageLinkObj() * (bug 6743) Don't link broken image links to the upload form when uploads are disabled --- RELEASE-NOTES | 4 +++- includes/Linker.php | 54 ++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a81bf8b719..30f80282be 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -150,7 +150,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN files are found, and make the list of extensions an option (defaults to $wgFileExtensions) * (bug 9909) Ensure access to binary fields in the math table use encodeBlob() - and decodeBlob. + and decodeBlob() +* (bug 6743) Don't link broken image links to the upload form when uploads + are disabled == MediaWiki API changes since 1.10 == diff --git a/includes/Linker.php b/includes/Linker.php index 989a2895ea..af771b765b 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -627,34 +627,38 @@ class Linker { } /** - * Pass a title object, not a title string + * Make a "broken" link to an image + * + * @param Title $title Image title + * @param string $text Link label + * @param string $query Query string + * @param string $trail Link trail + * @param string $prefix Link prefix + * @return string */ - function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - # Fail gracefully - if ( ! isset($nt) ) { - # throw new MWException(); + public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) { + global $wgEnableUploads; + if( $title instanceof Title ) { + wfProfileIn( __METHOD__ ); + if( $wgEnableUploads ) { + $upload = SpecialPage::getTitleFor( 'Upload' ); + if( $text == '' ) + $text = htmlspecialchars( $title->getPrefixedText() ); + $q = 'wpDestFile=' . $title->getPrefixedUrl(); + if( $query != '' ) + $q .= '&' . $query; + list( $inside, $trail ) = self::splitTrail( $trail ); + $style = $this->getInternalLinkAttributesObj( $title, $text, 'yes' ); + wfProfileOut( __METHOD__ ); + return '' . $prefix . $text . $inside . '' . $trail; + } else { + wfProfileOut( __METHOD__ ); + return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix ); + } + } else { return "{$prefix}{$text}{$trail}"; } - - $fname = 'Linker::makeBrokenImageLinkObj'; - wfProfileIn( $fname ); - - $q = 'wpDestFile=' . urlencode( $nt->getDBkey() ); - if ( '' != $query ) { - $q .= "&$query"; - } - $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); - $url = $uploadTitle->escapeLocalURL( $q ); - - if ( '' == $text ) { - $text = htmlspecialchars( $nt->getPrefixedText() ); - } - $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" ); - list( $inside, $trail ) = Linker::splitTrail( $trail ); - $s = "{$prefix}{$text}{$inside}{$trail}"; - - wfProfileOut( $fname ); - return $s; } /** @deprecated use Linker::makeMediaLinkObj() */ -- 2.20.1