* @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
*/
public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) {
+ if( !StubObject::isRealObject( $user ) ) {
+ //Since StubObject is always used on globals, we can unstub $wgUser here and set $user = $wgUser
+ global $wgUser;
+ $wgUser->_unstub( '', 5 );
+ $user = $wgUser;
+ }
$errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
global $wgContLang;
global $wgLang;
global $wgEmailConfirmToEdit;
- if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) {
+ if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
$errors[] = array( 'confirmedittext' );
}
$right = 'protect';
}
if( '' != $right && !$user->isAllowed( $right ) ) {
- //Users with 'editprotected' permission can edit protected pages
- if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) {
- //Users with 'editprotected' permission cannot edit protected pages
- //with cascading option turned on.
- if($this->mCascadeRestriction) {
- $errors[] = array( 'protectedpagetext', $right );
- } else {
- //Nothing, user can edit!
- }
+ // Users with 'editprotected' permission can edit protected
+ // pages if protection is not with cascading option turned on.
+ if( $action=='edit' && $user->isAllowed( 'editprotected' ) && !$this->areRestrictionsCascading() ) {
+ // Nothing, user can edit!
} else {
$errors[] = array( 'protectedpagetext', $right );
}
* The restriction array is an array of each type, each of which contains an array of unique groups
*/
public function getCascadeProtectionSources( $get_pages = true ) {
- global $wgEnableCascadingProtection, $wgRestrictionTypes;
+ global $wgRestrictionTypes;
# Define our dimension of restrictions types
$pagerestrictions = array();
foreach( $wgRestrictionTypes as $action )
$pagerestrictions[$action] = array();
- if (!$wgEnableCascadingProtection)
- return array( false, $pagerestrictions );
-
if ( isset( $this->mCascadeSources ) && $get_pages ) {
return array( $this->mCascadeSources, $this->mCascadingRestrictions );
} else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) {
wfProfileIn( __METHOD__ );
- $dbr = wfGetDb( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
if ( $this->getNamespace() == NS_IMAGE ) {
$tables = array ('imagelinks', 'page_restrictions');
# Backwards-compatibility: also load the restrictions from the page record (old format).
if ( $oldFashionedRestrictions === NULL ) {
- $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__ );
+ $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions',
+ array( 'page_id' => $this->getArticleId() ), __METHOD__ );
}
if ($oldFashionedRestrictions != '') {
if ($this->mLatestID !== false)
return $this->mLatestID;
- $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE);
+ $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
return $this->mLatestID = $db->selectField( 'revision',
"max(rev_id)",
array('rev_page' => $this->getArticleID($flags)),
* @return mixed True on success, getUserPermissionsErrors()-like array on failure
*/
public function isValidMoveOperation( &$nt, $auth = true ) {
- if( !$this or !$nt ) {
+ $errors = array();
+ if( !$nt ) {
+ // Normally we'd add this to $errors, but we'll get
+ // lots of syntax errors if $nt is not an object
return array(array('badtitletext'));
}
if( $this->equals( $nt ) ) {
- return array(array('selfmove'));
+ $errors[] = array('selfmove');
}
if( !$this->isMovable() || !$nt->isMovable() ) {
- return array(array('immobile_namespace'));
+ $errors[] = array('immobile_namespace');
}
$oldid = $this->getArticleID();
$newid = $nt->getArticleID();
if ( strlen( $nt->getDBkey() ) < 1 ) {
- return array(array('articleexists'));
+ $errors[] = array('articleexists');
}
if ( ( '' == $this->getDBkey() ) ||
( !$oldid ) ||
( '' == $nt->getDBkey() ) ) {
- return array(array('badarticleerror'));
+ $errors[] = array('badarticleerror');
}
// Image-specific checks
$file = wfLocalFile( $this );
if( $file->exists() ) {
if( $nt->getNamespace() != NS_IMAGE ) {
- return array(array('imagenocrossnamespace'));
+ $errors[] = array('imagenocrossnamespace');
}
if( !File::checkExtensionCompatibility( $file, $nt->getDbKey() ) ) {
- return array(array('imagetypemismatch'));
+ $errors[] = array('imagetypemismatch');
}
}
}
if ( $auth ) {
global $wgUser;
- $errors = array_merge($this->getUserPermissionsErrors('move', $wgUser),
+ $errors = array_merge($errors,
+ $this->getUserPermissionsErrors('move', $wgUser),
$this->getUserPermissionsErrors('edit', $wgUser),
$nt->getUserPermissionsErrors('move', $wgUser),
$nt->getUserPermissionsErrors('edit', $wgUser));
- if($errors !== array())
- return $errors;
}
global $wgUser;
$err = null;
if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err ) ) ) {
- return array(array('hookaborted', $err));
+ $errors[] = array('hookaborted', $err);
}
# The move is allowed only if (1) the target doesn't exist, or
if ( 0 != $newid ) { # Target exists; check for validity
if ( ! $this->isValidMoveTarget( $nt ) ) {
- return array(array('articleexists'));
+ $errors[] = array('articleexists');
}
} else {
$tp = $nt->getTitleProtection();
$right = ( $tp['pt_create_perm'] == 'sysop' ) ? 'protect' : $tp['pt_create_perm'];
if ( $tp and !$wgUser->isAllowed( $right ) ) {
- return array(array('cantmove-titleprotected'));
+ $errors[] = array('cantmove-titleprotected');
}
}
- return true;
+ if(empty($errors))
+ return true;
+ return $errors;
}
/**
*/
public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
$err = $this->isValidMoveOperation( $nt, $auth );
- if( is_array($err) ) {
+ if( is_array( $err ) ) {
return $err;
}
$err = $this->moveToNewTitle( $nt, $reason, $createRedirect );
$pageCountChange = ($createRedirect ? 1 : 0);
}
- if( is_string( $err ) ) {
+
+ if( is_array( $err ) ) {
return $err;
}
$redirid = $this->getArticleID();
$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
$nullRevId = $nullRevision->insertOn( $dbw );
- $article = new Article( $nt );
+ $article = new Article( $this );
wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
# Change the name of the target page:
$status = $file->move( $nt );
if( !$status->isOk() ) {
$dbw->rollback();
- return $status->getWikiText();
+ return $status->getErrorsArray();
}
}
}
$u = new SquidUpdate( $urls );
$u->doUpdate();
}
+
}
/**
$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
$nullRevId = $nullRevision->insertOn( $dbw );
- $article = new Article( $nt );
+ $article = new Article( $this );
wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, false) );
# Rename page entry
$status = $file->move( $nt );
if( !$status->isOk() ) {
$dbw->rollback();
- return $status->getWikiText();
+ return $status->getErrorsArray();
}
}
}
# Purge old title from squid
# The new title, and links to the new title, are purged in Article::onArticleCreate()
$this->purgeSquid();
+
}
/**