r50961 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50960‎ | r50961 | r50962 >
Date:20:45, 24 May 2009
Author:robin
Status:resolved (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2000,8 +2000,8 @@
20012001 'sharedupload-desc-here' => 'This file is from $1 and may be used by other projects.
20022002 The description on its [$2 file description page] there is shown below.',
20032003 'shareddescriptionfollows' => '-', # do not translate or duplicate this message to other languages
2004 -'noimage' => 'No file by this name exists, but you can $1.',
2005 -'noimage-linktext' => 'upload one',
 2004+'filepage-nofile' => 'No file by this name exists.',
 2005+'filepage-nofile-link' => 'Click here to upload it.',
20062006 'uploadnewversion-linktext' => 'Upload a new version of this file',
20072007 'shared-repo-from' => 'from $1',
20082008 'shared-repo' => 'a shared repository',
@@ -2776,8 +2776,6 @@
27772777
27782778 In those cases, you will have to move or merge the page manually if desired.",
27792779 'movearticle' => 'Move page:',
2780 -'movenologin' => 'Not logged in',
2781 -'movenologintext' => 'You must be a registered user and [[Special:UserLogin|logged in]] to move a page.',
27822780 'movenotallowed' => 'You do not have permission to move pages.',
27832781 'movenotallowedfile' => 'You do not have permission to move files.',
27842782 'cant-move-user-page' => 'You do not have permission to move user pages (apart from subpages).',
@@ -3843,7 +3841,7 @@
38443842 'version-hook-name' => 'Hook name',
38453843 'version-hook-subscribedby' => 'Subscribed by',
38463844 'version-version' => '(Version $1)',
3847 -'version-svn-revision' => '(r$2)', # only translate this message to other languages if you have to change it
 3845+'version-svn-revision' => 'r$2', # only translate this message to other languages if you have to change it
38483846 'version-license' => 'License',
38493847 'version-software' => 'Installed software',
38503848 'version-software-product' => 'Product',
Index: trunk/phase3/includes/Title.php
@@ -1171,7 +1171,7 @@
11721172
11731173 if( !$user->isAllowed( 'move' ) ) {
11741174 // User can't move anything
1175 - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed');
 1175+ $errors[] = array ('movenotallowed');
11761176 }
11771177 } elseif ( $action == 'create' ) {
11781178 if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
@@ -1182,7 +1182,7 @@
11831183 } elseif( $action == 'move-target' ) {
11841184 if( !$user->isAllowed( 'move' ) ) {
11851185 // User can't move anything
1186 - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed');
 1186+ $errors[] = array ('movenotallowed');
11871187 } elseif( !$user->isAllowed( 'move-rootuserpages' )
11881188 && $this->getNamespace() == NS_USER && !$this->isSubpage() )
11891189 {
Index: trunk/phase3/includes/SkinTemplate.php
@@ -858,17 +858,12 @@
859859
860860 $nav_urls = array();
861861 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
862 - if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
863 - if( $wgUploadNavigationUrl ) {
864 - $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
865 - } else {
866 - $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
867 - }
 862+ if( $wgUploadNavigationUrl ) {
 863+ $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
 864+ } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
 865+ $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
868866 } else {
869 - if( $wgUploadNavigationUrl )
870 - $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
871 - else
872 - $nav_urls['upload'] = false;
 867+ $nav_urls['upload'] = false;
873868 }
874869 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
875870
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -245,11 +245,7 @@
246246
247247 # Check permissions
248248 if( !$wgUser->isAllowed( 'upload' ) ) {
249 - if( !$wgUser->isLoggedIn() ) {
250 - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
251 - } else {
252 - $wgOut->permissionRequired( 'upload' );
253 - }
 249+ $wgOut->permissionRequired( 'upload' );
254250 return;
255251 }
256252
Index: trunk/phase3/includes/ImagePage.php
@@ -275,7 +275,8 @@
276276 }
277277
278278 protected function openShowImage() {
279 - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
 279+ global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
 280+ $wgLang, $wgContLang, $wgEnableUploads;
280281
281282 $this->loadFile();
282283
@@ -468,12 +469,17 @@
469470 }
470471 } else {
471472 # Image does not exist
472 -
473 - $title = SpecialPage::getTitleFor( 'Upload' );
474 - $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
475 - 'wpDestFile=' . urlencode( $this->displayImg->getName() ) );
 473+ $nofile = wfMsgHtml( 'filepage-nofile' );
 474+ if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
 475+ // Only show an upload link if the user can upload
 476+ $nofile .= ' '.$sk->makeKnownLinkObj(
 477+ SpecialPage::getTitleFor( 'Upload' ),
 478+ wfMsgHtml('filepage-nofile-link'),
 479+ 'wpDestFile=' . urlencode( $this->displayImg->getName() )
 480+ );
 481+ }
476482 $wgOut->setRobotPolicy( 'noindex,nofollow' );
477 - $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
 483+ $wgOut->addHTML( '<div id="mw-imagepage-nofile">' . $nofile . '</div>' );
478484 }
479485 }
480486
@@ -516,8 +522,10 @@
517523 * external editing (and instructions link) etc.
518524 */
519525 protected function uploadLinksBox() {
520 - global $wgUser, $wgOut;
 526+ global $wgUser, $wgOut, $wgEnableUploads;
521527
 528+ if( !$wgEnableUploads ) { return; }
 529+
522530 $this->loadFile();
523531 if( !$this->img->isLocal() )
524532 return;
Index: trunk/phase3/RELEASE-NOTES
@@ -155,6 +155,10 @@
156156 .inc
157157 * Deprecated methods Title::getInterwikiLink, Title::userCanCreate(),
158158 Title::userCanEdit() and Title::userCanMove() have been removed
 159+* Only show upload links on file description if $wgEnableUploads = true
 160+ and user can upload
 161+* Don't say "You need to log in to upload/move", because it's possible that
 162+ uploading/moving is disabled for registered users as well (e.g. only sysops)
159163
160164 == API changes in 1.16 ==
161165
Index: trunk/phase3/maintenance/language/messages.inc
@@ -1255,8 +1255,8 @@
12561256 'sharedupload-desc-there',
12571257 'sharedupload-desc-here',
12581258 'shareddescriptionfollows',
1259 - 'noimage',
1260 - 'noimage-linktext',
 1259+ 'filepage-nofile',
 1260+ 'filepage-nofile-link',
12611261 'uploadnewversion-linktext',
12621262 'shared-repo-from',
12631263 'shared-repo',
@@ -1925,8 +1925,6 @@
19261926 'movepagetext',
19271927 'movepagetalktext',
19281928 'movearticle',
1929 - 'movenologin',
1930 - 'movenologintext',
19311929 'movenotallowed',
19321930 'movenotallowedfile',
19331931 'cant-move-user-page',

Follow-up revisions

RevisionCommit summaryAuthorDate
r50968Fix per comments at r50961: Update MessagesEn.php (remove unused messages and...robin22:36, 24 May 2009
r50969Update extensions per comments at r50961robin22:37, 24 May 2009
r51029Per comment at r50961: keep the messages saying "you need to be logged in to ...robin19:16, 26 May 2009

Comments

#Comment by Siebrand (talk | contribs)   21:14, 24 May 2009
  • Why does this revision contains changes to message 'version-svn-revision' that are unrelated to issues mentioned in the commit message?
  • movenologin[text] are still referenced in SVN:
    extensions/LiquidThreads/pages/SpecialMoveThread.php: $this->output->showErrorPage( 'movenologin', 'movenologintext' );
  • noimage[-linktext] are still referenced in SVN:
    /var/www/w/extensions/ImageTagging/ImageTagging.php: $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
    /var/www/w/extensions/ImageTagging/ImageTagging.php: $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );

For the extensions at least a FIXME would be nice, a fix preferred.

#Comment by Gurch (talk | contribs)   21:24, 24 May 2009

Think you removed the wrong messages from MessagesEn.php, you eliminated 'uploadnologin' and 'uploadnologintext' from SpecialUpload.php but removed 'movenologin' and 'movenologintext' from the messages.

#Comment by SPQRobin (talk | contribs)   22:25, 24 May 2009

@Siebrand:

  • It was local customisation; I didn't see it when committing. I'll add it back.
  • I'll update the extensions.

@Gurch:

  • No, I also updated permission error for 'move', but I'll also remove the messages 'uploadnologin' and 'uploadnologintext'.

Sorry for the problems!

#Comment by Tim Starling (talk | contribs)   15:27, 26 May 2009

These changes look like a substantial step backwards for usability on Wikimedia wikis. They are revertable for that reason. You can check $wgGroupPermissions to see whether or not the user can upload if they are logged in, and display a different error message if they can. Same for page moves.

#Comment by SPQRobin (talk | contribs)   19:18, 26 May 2009

Ok, done so in r51029.

Status & tagging log