Fixing part of bug 14688 (upload restrictions):
authorRobin Pepermans <robin@users.mediawiki.org>
Sun, 24 May 2009 20:45:31 +0000 (20:45 +0000)
committerRobin Pepermans <robin@users.mediawiki.org>
Sun, 24 May 2009 20:45:31 +0000 (20:45 +0000)
* 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
includes/ImagePage.php
includes/SkinTemplate.php
includes/Title.php
includes/specials/SpecialUpload.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index cc10190..5d73bd5 100644 (file)
@@ -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 ==
 
index 612d2a6..0bdc3da 100644 (file)
@@ -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( '<div id="mw-imagepage-nofile">' . $nofile . '</div>' );
                }
        }
 
@@ -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() )
index 8ba30c1..da5d49c 100644 (file)
@@ -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' ) );
 
index 66f42e3..74cd6f0 100644 (file)
@@ -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() )
                        {
index f234ccc..ad8366b 100644 (file)
@@ -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;
                }
 
index 25d4fc6..6e1a945 100644 (file)
@@ -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',
index 6f72afd..c921a31 100644 (file)
@@ -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',