r29968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29967‎ | r29968 | r29969 >
Date:07:05, 20 January 2008
Author:vasilievvv
Status:old
Tags:
Comment:
Image redirects:
* Forbid users who can't create redirects when they are not allowed to upload files
* Move target namespace check from checkRedirect() to findFile()
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -104,9 +104,6 @@
105105 if( !$row ) {
106106 return false;
107107 }
108 - if( $row->rd_namespace != NS_IMAGE ) {
109 - return false;
110 - }
111108 return Title::makeTitle( $row->rd_namespace, $row->rd_title );
112109 }
113110 }
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -93,7 +93,7 @@
9494
9595 # Now try redirects
9696 $redir = $this->checkRedirect( $title );
97 - if( $redir ) {
 97+ if( $redir && $redir->getNamespace() == NS_IMAGE) {
9898 $img = $this->newFile( $redir );
9999 if( !$img ) {
100100 return false;
Index: trunk/phase3/includes/EditPage.php
@@ -38,6 +38,8 @@
3939 const AS_OK = 230;
4040 const AS_END = 231;
4141 const AS_SPAM_ERROR = 232;
 42+ const AS_IMAGE_REDIRECT_ANON = 233;
 43+ const AS_IMAGE_REDIRECT_LOGGED = 234;
4244
4345 var $mArticle;
4446 var $mTitle;
@@ -699,6 +701,17 @@
700702 return self::AS_HOOK_ERROR;
701703 }
702704
 705+ # Check image redirect
 706+ if ( $wgTitle->getNamespace() == NS_IMAGE &&
 707+ Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
 708+ !$wgUser->isAllowed( 'upload' ) ) {
 709+ if( $wgUser->isAnon() ) {
 710+ return self::AS_IMAGE_REDIRECT_ANON;
 711+ } else {
 712+ return self::AS_IMAGE_REDIRECT_LOGGED;
 713+ }
 714+ }
 715+
703716 # Reintegrate metadata
704717 if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
705718 $this->mMetaData = '' ;
@@ -2196,6 +2209,10 @@
21972210 $this->blockedPage();
21982211 return false;
21992212
 2213+ case self::AS_IMAGE_REDIRECT_ANON:
 2214+ $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
 2215+ return false;
 2216+
22002217 case self::AS_READ_ONLY_PAGE_ANON:
22012218 $this->userNotLoggedInPage();
22022219 return false;
@@ -2216,6 +2233,10 @@
22172234 case self::AS_BLANK_ARTICLE:
22182235 $wgOut->redirect( $wgTitle->getFullURL() );
22192236 return false;
 2237+
 2238+ case self::AS_IMAGE_REDIRECT_LOGGED:
 2239+ $wgOut->permissionRequired( 'upload' );
 2240+ return false;
22202241 }
22212242 }
22222243 }

Status & tagging log