From 623b9fcbd824e3b741272140de03a9e8cee99a4f Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Sun, 24 May 2009 20:45:31 +0000 Subject: [PATCH] Fixing part of bug 14688 (upload restrictions): * Only show upload links on file description if $wgEnableUploads = true and user *can* upload * Don't say "You need to log in to upload", because it's possible that uploading is disabled for registered users as well and e.g. only sysops can upload (same for moving pages) * And a small tweak: less code in SkinTemplate.php with same result --- RELEASE-NOTES | 4 ++++ includes/ImagePage.php | 22 +++++++++++++++------- includes/SkinTemplate.php | 15 +++++---------- includes/Title.php | 4 ++-- includes/specials/SpecialUpload.php | 6 +----- languages/messages/MessagesEn.php | 8 +++----- maintenance/language/messages.inc | 6 ++---- 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index cc10190ee0..5d73bd5f28 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -155,6 +155,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN .inc * Deprecated methods Title::getInterwikiLink, Title::userCanCreate(), Title::userCanEdit() and Title::userCanMove() have been removed +* Only show upload links on file description if $wgEnableUploads = true + and user can upload +* Don't say "You need to log in to upload/move", because it's possible that + uploading/moving is disabled for registered users as well (e.g. only sysops) == API changes in 1.16 == diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 612d2a6919..0bdc3da8af 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -275,7 +275,8 @@ class ImagePage extends Article { } protected function openShowImage() { - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang; + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, + $wgLang, $wgContLang, $wgEnableUploads; $this->loadFile(); @@ -468,12 +469,17 @@ EOT } } else { # Image does not exist - - $title = SpecialPage::getTitleFor( 'Upload' ); - $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'), - 'wpDestFile=' . urlencode( $this->displayImg->getName() ) ); + $nofile = wfMsgHtml( 'filepage-nofile' ); + if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) { + // Only show an upload link if the user can upload + $nofile .= ' '.$sk->makeKnownLinkObj( + SpecialPage::getTitleFor( 'Upload' ), + wfMsgHtml('filepage-nofile-link'), + 'wpDestFile=' . urlencode( $this->displayImg->getName() ) + ); + } $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) ); + $wgOut->addHTML( '
' . $nofile . '
' ); } } @@ -516,7 +522,9 @@ EOT * external editing (and instructions link) etc. */ protected function uploadLinksBox() { - global $wgUser, $wgOut; + global $wgUser, $wgOut, $wgEnableUploads; + + if( !$wgEnableUploads ) { return; } $this->loadFile(); if( !$this->img->isLocal() ) diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 8ba30c119b..da5d49c26a 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -858,17 +858,12 @@ class SkinTemplate extends Skin { $nav_urls = array(); $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() ); - if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) { - if( $wgUploadNavigationUrl ) { - $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl ); - } else { - $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) ); - } + if( $wgUploadNavigationUrl ) { + $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl ); + } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) { + $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) ); } else { - if( $wgUploadNavigationUrl ) - $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl ); - else - $nav_urls['upload'] = false; + $nav_urls['upload'] = false; } $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) ); diff --git a/includes/Title.php b/includes/Title.php index 66f42e3ae9..74cd6f0129 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1171,7 +1171,7 @@ class Title { if( !$user->isAllowed( 'move' ) ) { // User can't move anything - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); + $errors[] = array ('movenotallowed'); } } elseif ( $action == 'create' ) { if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) || @@ -1182,7 +1182,7 @@ class Title { } elseif( $action == 'move-target' ) { if( !$user->isAllowed( 'move' ) ) { // User can't move anything - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); + $errors[] = array ('movenotallowed'); } elseif( !$user->isAllowed( 'move-rootuserpages' ) && $this->getNamespace() == NS_USER && !$this->isSubpage() ) { diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index f234ccc1f6..ad8366b519 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -245,11 +245,7 @@ class UploadForm { # Check permissions if( !$wgUser->isAllowed( 'upload' ) ) { - if( !$wgUser->isLoggedIn() ) { - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); - } else { - $wgOut->permissionRequired( 'upload' ); - } + $wgOut->permissionRequired( 'upload' ); return; } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 25d4fc65d9..6e1a94549c 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2000,8 +2000,8 @@ Please see the [$2 file description page] for further information.', 'sharedupload-desc-here' => 'This file is from $1 and may be used by other projects. The description on its [$2 file description page] there is shown below.', 'shareddescriptionfollows' => '-', # do not translate or duplicate this message to other languages -'noimage' => 'No file by this name exists, but you can $1.', -'noimage-linktext' => 'upload one', +'filepage-nofile' => 'No file by this name exists.', +'filepage-nofile-link' => 'Click here to upload it.', 'uploadnewversion-linktext' => 'Upload a new version of this file', 'shared-repo-from' => 'from $1', 'shared-repo' => 'a shared repository', @@ -2776,8 +2776,6 @@ please be sure you understand the consequences of this before proceeding.", In those cases, you will have to move or merge the page manually if desired.", 'movearticle' => 'Move page:', -'movenologin' => 'Not logged in', -'movenologintext' => 'You must be a registered user and [[Special:UserLogin|logged in]] to move a page.', 'movenotallowed' => 'You do not have permission to move pages.', 'movenotallowedfile' => 'You do not have permission to move files.', 'cant-move-user-page' => 'You do not have permission to move user pages (apart from subpages).', @@ -3843,7 +3841,7 @@ You can also [[Special:Watchlist/edit|use the standard editor]].', 'version-hook-name' => 'Hook name', 'version-hook-subscribedby' => 'Subscribed by', 'version-version' => '(Version $1)', -'version-svn-revision' => '(r$2)', # only translate this message to other languages if you have to change it +'version-svn-revision' => 'r$2', # only translate this message to other languages if you have to change it 'version-license' => 'License', 'version-software' => 'Installed software', 'version-software-product' => 'Product', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 6f72afdf4f..c921a31525 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1255,8 +1255,8 @@ $wgMessageStructure = array( 'sharedupload-desc-there', 'sharedupload-desc-here', 'shareddescriptionfollows', - 'noimage', - 'noimage-linktext', + 'filepage-nofile', + 'filepage-nofile-link', 'uploadnewversion-linktext', 'shared-repo-from', 'shared-repo', @@ -1925,8 +1925,6 @@ $wgMessageStructure = array( 'movepagetext', 'movepagetalktext', 'movearticle', - 'movenologin', - 'movenologintext', 'movenotallowed', 'movenotallowedfile', 'cant-move-user-page', -- 2.20.1