}
/**
- * Get the base name, i.e. the leftmost parts before the /
+ * Get the base page name, i.e. the leftmost part before any slashes
*
* @return String Base name
*/
}
/**
- * Get the lowest-level subpage name, i.e. the rightmost part after /
+ * Get the lowest-level subpage name, i.e. the rightmost part after any slashes
*
* @return String Subpage name
*/
* Determines if $user is unable to edit this page because it has been protected
* by $wgNamespaceProtection.
*
- * @param $user User object, $wgUser will be used if not passed
+ * @param $user User object to check permissions
* @return Bool
*/
- public function isNamespaceProtected( User $user = null ) {
+ public function isNamespaceProtected( User $user ) {
global $wgNamespaceProtection;
- if ( $user === null ) {
- global $wgUser;
- $user = $wgUser;
- }
-
if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
if ( $right != '' && !$user->isAllowed( $right ) ) {
* @return Array list of errors
*/
private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
+ $ns = $this->getNamespace();
+
if ( $action == 'create' ) {
- if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
- ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
+ if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk', $ns ) ) ||
+ ( !$this->isTalkPage() && !$user->isAllowed( 'createpage', $ns ) ) ) {
$errors[] = $user->isAnon() ? array( 'nocreatetext' ) : array( 'nocreate-loggedin' );
}
} elseif ( $action == 'move' ) {
- if ( !$user->isAllowed( 'move-rootuserpages' )
- && $this->mNamespace == NS_USER && !$this->isSubpage() ) {
+ if ( !$user->isAllowed( 'move-rootuserpages', $ns )
+ && $ns == NS_USER && !$this->isSubpage() ) {
// Show user page-specific message only if the user can move other pages
$errors[] = array( 'cant-move-user-page' );
}
// Check if user is allowed to move files if it's a file
- if ( $this->mNamespace == NS_FILE && !$user->isAllowed( 'movefile' ) ) {
+ if ( $ns == NS_FILE && !$user->isAllowed( 'movefile', $ns ) ) {
$errors[] = array( 'movenotallowedfile' );
}
- if ( !$user->isAllowed( 'move' ) ) {
+ if ( !$user->isAllowed( 'move', $ns) ) {
// User can't move anything
- global $wgGroupPermissions;
- $userCanMove = false;
- if ( isset( $wgGroupPermissions['user']['move'] ) ) {
- $userCanMove = $wgGroupPermissions['user']['move'];
- }
- $autoconfirmedCanMove = false;
- if ( isset( $wgGroupPermissions['autoconfirmed']['move'] ) ) {
- $autoconfirmedCanMove = $wgGroupPermissions['autoconfirmed']['move'];
- }
+
+ $userCanMove = in_array( 'move', User::getGroupPermissions(
+ array( 'user' ), $ns ), true );
+ $autoconfirmedCanMove = in_array( 'move', User::getGroupPermissions(
+ array( 'autoconfirmed' ), $ns ), true );
+
if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
// custom message if logged-in users without any special rights can move
$errors[] = array( 'movenologintext' );
}
}
} elseif ( $action == 'move-target' ) {
- if ( !$user->isAllowed( 'move' ) ) {
+ if ( !$user->isAllowed( 'move', $ns ) ) {
// User can't move anything
$errors[] = array( 'movenotallowed' );
- } elseif ( !$user->isAllowed( 'move-rootuserpages' )
- && $this->mNamespace == NS_USER && !$this->isSubpage() ) {
+ } elseif ( !$user->isAllowed( 'move-rootuserpages', $ns )
+ && $ns == NS_USER && !$this->isSubpage() ) {
// Show user page-specific message only if the user can move other pages
$errors[] = array( 'cant-move-to-user-page' );
}
- } elseif ( !$user->isAllowed( $action ) ) {
+ } elseif ( !$user->isAllowed( $action, $ns ) ) {
// We avoid expensive display logic for quickUserCan's and such
$groups = false;
if ( !$short ) {
$groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
- User::getGroupsWithPermission( $action ) );
+ User::getGroupsWithPermission( $action, $ns ) );
}
if ( $groups ) {
private function checkCSSandJSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
# Protect css/js subpages of user pages
# XXX: this might be better using restrictions
- # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssSubpage()
- # and $this->userCanEditJsSubpage() from working
# XXX: right 'editusercssjs' is deprecated, for backward compatibility only
if ( $action != 'patrol' && !$user->isAllowed( 'editusercssjs' )
&& !preg_match( '/^' . preg_quote( $user->getName(), '/' ) . '\//', $this->mTextform ) ) {
if ( $right == 'sysop' ) {
$right = 'protect';
}
- if ( $right != '' && !$user->isAllowed( $right ) ) {
+ if ( $right != '' && !$user->isAllowed( $right, $this->mNamespace ) ) {
// Users with 'editprotected' permission can edit protected pages
- if ( $action == 'edit' && $user->isAllowed( 'editprotected' ) ) {
+ if ( $action == 'edit' && $user->isAllowed( 'editprotected', $this->mNamespace ) ) {
// Users with 'editprotected' permission cannot edit protected pages
// with cascading option turned on.
if ( $this->mCascadeRestriction ) {
if ( isset( $restrictions[$action] ) ) {
foreach ( $restrictions[$action] as $right ) {
$right = ( $right == 'sysop' ) ? 'protect' : $right;
- if ( $right != '' && !$user->isAllowed( $right ) ) {
+ if ( $right != '' && !$user->isAllowed( $right, $this->mNamespace ) ) {
$pages = '';
foreach ( $cascadingSources as $page )
$pages .= '* [[:' . $page->getPrefixedText() . "]]\n";
if( $title_protection['pt_create_perm'] == 'sysop' ) {
$title_protection['pt_create_perm'] = 'protect'; // B/C
}
- if( $title_protection['pt_create_perm'] == '' || !$user->isAllowed( $title_protection['pt_create_perm'] ) ) {
+ if( $title_protection['pt_create_perm'] == '' ||
+ !$user->isAllowed( $title_protection['pt_create_perm'],
+ $this->mNamespace ) ) {
$errors[] = array( 'titleprotected', User::whoIs( $title_protection['pt_user'] ), $title_protection['pt_reason'] );
}
}
* @return Bool
*/
public function isCssOrJsPage() {
- return $this->mNamespace == NS_MEDIAWIKI
+ $retval = $this->mNamespace == NS_MEDIAWIKI
&& preg_match( '!\.(?:css|js)$!u', $this->mTextform ) > 0;
+ wfRunHooks( 'TitleIsCssOrJsPage', array( $this, &$retval ) );
+ return $retval;
}
/**
* Protect css subpages of user pages: can $wgUser edit
* this page?
*
+ * @deprecated in 1.19; will be removed in 1.20. Use getUserPermissionsErrors() instead.
* @return Bool
- * @todo XXX: this might be better using restrictions
*/
public function userCanEditCssSubpage() {
global $wgUser;
+ wfDeprecated( __METHOD__ );
return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'editusercss' ) )
|| preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
}
* Protect js subpages of user pages: can $wgUser edit
* this page?
*
+ * @deprecated in 1.19; will be removed in 1.20. Use getUserPermissionsErrors() instead.
* @return Bool
- * @todo XXX: this might be better using restrictions
*/
public function userCanEditJsSubpage() {
global $wgUser;
+ wfDeprecated( __METHOD__ );
return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
|| preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
}
$conditions = array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() );
if( !$includeSuppressed ) {
- $suppressedTextBits = REVISION::DELETED_TEXT | REVISION::DELETED_RESTRICTED;
+ $suppressedTextBits = Revision::DELETED_TEXT | Revision::DELETED_RESTRICTED;
$conditions[] = $dbr->bitAnd('ar_deleted', $suppressedTextBits ) .
' != ' . $suppressedTextBits;
}
if ( $this->getNamespace() == NS_FILE ) {
$fconditions = array( 'fa_name' => $this->getDBkey() );
if( !$includeSuppressed ) {
- $suppressedTextBits = FILE::DELETED_FILE | FILE::DELETED_RESTRICTED;
+ $suppressedTextBits = File::DELETED_FILE | File::DELETED_RESTRICTED;
$fconditions[] = $dbr->bitAnd('fa_deleted', $suppressedTextBits ) .
' != ' . $suppressedTextBits;
}
if ( $u ) {
$u->doUpdate();
}
+
# Update message cache for interface messages
if ( $this->getNamespace() == NS_MEDIAWIKI ) {
# @bug 17860: old article can be deleted, if this the case,
}
$nullRevId = $nullRevision->insertOn( $dbw );
+ $now = wfTimestampNow();
# Change the name of the target page:
$dbw->update( 'page',
/* SET */ array(
- 'page_touched' => $dbw->timestamp(),
+ 'page_touched' => $dbw->timestamp( $now ),
'page_namespace' => $nt->getNamespace(),
'page_title' => $nt->getDBkey(),
'page_latest' => $nullRevId,
$article = new Article( $nt );
wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
+ $article->setCachedLastEditTime( $now );
# Recreate the redirect, this time in the other direction.
if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {