r29740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29739‎ | r29740 | r29741 >
Date:13:50, 14 January 2008
Author:vasilievvv
Status:old
Tags:
Comment:
* Introduce getUserPermissionsErrorsExpensive hook
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -594,6 +594,9 @@
595595 $action: Action being checked
596596 $result: User permissions error to add. If none, return true.
597597
 598+'getUserPermissionsErrorsExpensive': Absolutely the same, but is called only
 599+ if expensive checks are enabled.
 600+
598601 'ImageOpenShowImageInlineBefore': Call potential extension just before showing the image on an image page
599602 $imagePage: ImagePage object ($this)
600603 $output: $wgOut
Index: trunk/phase3/includes/Title.php
@@ -1130,6 +1130,16 @@
11311131 else if ($result === false )
11321132 $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
11331133 }
 1134+ if ($doExpensiveQueries && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
 1135+ if ($result != array() && is_array($result) && !is_array($result[0]))
 1136+ $errors[] = $result; # A single array representing an error
 1137+ else if (is_array($result) && is_array($result[0]))
 1138+ $errors = array_merge( $errors, $result ); # A nested array representing multiple errors
 1139+ else if ($result != '' && $result != null && $result !== true && $result !== false)
 1140+ $errors[] = array($result); # A string representing a message-id
 1141+ else if ($result === false )
 1142+ $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that"
 1143+ }
11341144
11351145 if( NS_SPECIAL == $this->mNamespace ) {
11361146 $errors[] = array('ns-specialprotected');
@@ -2279,6 +2289,7 @@
22802290 * @return mixed true on success, message name on failure
22812291 */
22822292 public function isValidMoveOperation( &$nt, $auth = true ) {
 2293+ global $wgUser;
22832294 if( !$this or !$nt ) {
22842295 return 'badtitletext';
22852296 }
@@ -2303,7 +2314,8 @@
23042315
23052316 if ( $auth && (
23062317 !$this->userCan( 'edit' ) || !$nt->userCan( 'edit' ) ||
2307 - !$this->userCan( 'move' ) || !$nt->userCan( 'move' ) ) ) {
 2318+ !$this->userCan( 'move' ) || !$nt->userCan( 'move' ) ||
 2319+ $this->getNamespace() == NS_IMAGE && !$wgUser->isAllowed( 'upload' ) ) ) {
23082320 return 'protectedpage';
23092321 }
23102322
@@ -2346,6 +2358,17 @@
23472359 return $err;
23482360 }
23492361
 2362+ // If it's existent image, move it as image
 2363+ if( $this->getNamespace() == NS_IMAGE && $nt->getNamespace() == NS_IMAGE && wfFindFile( $this ) ) {
 2364+ $oldfile = wfFindFile( $this );
 2365+ $newfile = wfFindFile( $nt );
 2366+ var_dump( array( $oldfile, $newfile ) );
 2367+ if( $newfile ) {
 2368+ return 'articleexists';
 2369+ }
 2370+ return 'a';
 2371+ }
 2372+
23502373 $pageid = $this->getArticleID();
23512374 if( $nt->exists() ) {
23522375 $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
@@ -2585,6 +2608,11 @@
25862609 }
25872610
25882611 /**
 2612+ * Moves image to new title
 2613+ */
 2614+ //private function moveImage
 2615+
 2616+ /**
25892617 * Checks if $this can be moved to a given Title
25902618 * - Selects for update, so don't call it unless you mean business
25912619 *

Status & tagging log