Same for $this->user
[lhc/web/wiklou.git] / includes / FileDeleteForm.php
index e9a252f..3824d10 100644 (file)
@@ -35,14 +35,10 @@ class FileDeleteForm {
                if( wfReadOnly() ) {
                        $wgOut->readOnlyPage();
                        return;
-               } elseif( !$wgUser->isLoggedIn() ) {
-                       $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
-                       return;
-               } elseif( !$wgUser->isAllowed( 'delete' ) ) {
-                       $wgOut->permissionRequired( 'delete' );
-                       return;
-               } elseif( $wgUser->isBlocked() ) {
-                       $wgOut->blockedPage();
+               } 
+               $permission_errors = $this->title->getUserPermissionsErrors('delete', $wgUser);
+               if (count($permission_errors)>0) {
+                       $wgOut->showPermissionsErrorPage( $permission_errors );
                        return;
                }
                
@@ -51,14 +47,14 @@ class FileDeleteForm {
                # Flag to hide all contents of the archived revisions
                $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed('deleterevision');
                
-               if( $this->oldimage && !$this->isValidOldSpec() ) {
+               if( $this->oldimage && !self::isValidOldSpec($this->oldimage) ) {
                        $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) );
                        return;
                }
                if( $this->oldimage )
                        $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage );
                
-               if( !$this->haveDeletableFile() ) {
+               if( !self::haveDeletableFile($this->file, $this->oldfile, $this->oldimage) ) {
                        $wgOut->addHtml( $this->prepareMessage( 'filedelete-nofile' ) );
                        $wgOut->addReturnTo( $this->title );
                        return;
@@ -234,10 +230,10 @@ class FileDeleteForm {
         *
         * @return bool
         */
-       private function isValidOldSpec() {
-               return strlen( $this->oldimage ) >= 16
-                       && strpos( $this->oldimage, '/' ) === false
-                       && strpos( $this->oldimage, '\\' ) === false;
+       public static function isValidOldSpec($oldimage) {
+               return strlen( $oldimage ) >= 16
+                       && strpos( $oldimage, '/' ) === false
+                       && strpos( $oldimage, '\\' ) === false;
        }
        
        /**
@@ -247,10 +243,10 @@ class FileDeleteForm {
         *
         * @return bool
         */
-       private function haveDeletableFile() {
-               return $this->oldimage
-                       ? $this->oldfile && $this->oldfile->exists() && $this->oldfile->isLocal()
-                       : $this->file && $this->file->exists() && $this->file->isLocal();
+       public static function haveDeletableFile(&$file, &$oldfile, $oldimage) {
+               return $oldimage
+                       ? $oldfile && $oldfile->exists() && $oldfile->isLocal()
+                       : $file && $file->exists() && $file->isLocal();
        }
        
        /**