* Introduce getUserPermissionsErrorsExpensive hook
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Mon, 14 Jan 2008 13:50:55 +0000 (13:50 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Mon, 14 Jan 2008 13:50:55 +0000 (13:50 +0000)
docs/hooks.txt
includes/Title.php

index ffb58ee..bf6ca62 100644 (file)
@@ -594,6 +594,9 @@ $user : Current user object
 $action: Action being checked
 $result: User permissions error to add. If none, return true.
 
+'getUserPermissionsErrorsExpensive': Absolutely the same, but is called only
+       if expensive checks are enabled.
+
 'ImageOpenShowImageInlineBefore': Call potential extension just before showing the image on an image page
 $imagePage: ImagePage object ($this)
 $output: $wgOut
index 61f7c9a..6326d74 100644 (file)
@@ -1130,6 +1130,16 @@ class Title {
                        else if ($result === false )
                                $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
                }
+               if ($doExpensiveQueries && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
+                       if ($result != array() && is_array($result) && !is_array($result[0]))
+                               $errors[] = $result; # A single array representing an error
+                       else if (is_array($result) && is_array($result[0]))
+                               $errors = array_merge( $errors, $result ); # A nested array representing multiple errors
+                       else if ($result != '' && $result != null && $result !== true && $result !== false)
+                               $errors[] = array($result); # A string representing a message-id
+                       else if ($result === false )
+                               $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
+               }
 
                if( NS_SPECIAL == $this->mNamespace ) {
                        $errors[] = array('ns-specialprotected');
@@ -2279,6 +2289,7 @@ class Title {
         * @return mixed true on success, message name on failure
         */
        public function isValidMoveOperation( &$nt, $auth = true ) {
+               global $wgUser;
                if( !$this or !$nt ) {
                        return 'badtitletext';
                }
@@ -2303,7 +2314,8 @@ class Title {
 
                if ( $auth && (
                                !$this->userCan( 'edit' ) || !$nt->userCan( 'edit' ) ||
-                               !$this->userCan( 'move' ) || !$nt->userCan( 'move' ) ) ) {
+                               !$this->userCan( 'move' ) || !$nt->userCan( 'move' ) ||
+                               $this->getNamespace() == NS_IMAGE && !$wgUser->isAllowed( 'upload' ) ) ) {
                        return 'protectedpage';
                }
 
@@ -2346,6 +2358,17 @@ class Title {
                        return $err;
                }
 
+               // If it's existent image, move it as image
+               if( $this->getNamespace() == NS_IMAGE && $nt->getNamespace() == NS_IMAGE && wfFindFile( $this )  ) {
+                       $oldfile = wfFindFile( $this );
+                       $newfile = wfFindFile( $nt );
+                       var_dump( array( $oldfile, $newfile ) );
+                       if( $newfile ) {
+                               return 'articleexists';
+                       }
+                       return 'a';
+               }
+
                $pageid = $this->getArticleID();
                if( $nt->exists() ) {
                        $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
@@ -2584,6 +2607,11 @@ class Title {
                $this->purgeSquid();
        }
 
+       /**
+        * Moves image to new title
+        */
+       //private function moveImage
+
        /**
         * Checks if $this can be moved to a given Title
         * - Selects for update, so don't call it unless you mean business