Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS
SVN: [24562] trunk/phase3
 

Index | Next | Previous | View Flat


werdna at svn

Aug 3, 2007, 2:27 AM


Views: 217
Permalink
SVN: [24562] trunk/phase3

Revision: 24562
Author: werdna
Date: 2007-08-03 09:27:28 +0000 (Fri, 03 Aug 2007)

Log Message:
-----------
Use the new userCan changes to display better, clearer error messages when a permissions error is encountered.

Modified Paths:
--------------
trunk/phase3/RELEASE-NOTES
trunk/phase3/includes/EditPage.php
trunk/phase3/includes/OutputPage.php
trunk/phase3/includes/Title.php

Modified: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES 2007-08-03 08:51:55 UTC (rev 24561)
+++ trunk/phase3/RELEASE-NOTES 2007-08-03 09:27:28 UTC (rev 24562)
@@ -161,6 +161,7 @@
* (bug 10701) Link to Special:Listusers in default Special:Statistics messages
* Improved file history presentation
* (bug 10739) Users can now enter comments when reverting files
+* Improved handling of permissions errors.

== Bugfixes since 1.10 ==


Modified: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php 2007-08-03 08:51:55 UTC (rev 24561)
+++ trunk/phase3/includes/EditPage.php 2007-08-03 09:27:28 UTC (rev 24562)
@@ -319,57 +319,35 @@
return;
}

- if ( ! $this->mTitle->userCan( 'edit' ) ) {
- wfDebug( "$fname: user can't edit\n" );
- $wgOut->readOnlyPage( $this->getContent(), true );
- wfProfileOut( $fname );
- return;
- }
- wfDebug( "$fname: Checking blocks\n" );
- if ( !$this->preview && !$this->diff && $wgUser->isBlockedFrom( $this->mTitle, !$this->save ) ) {
- # When previewing, don't check blocked state - will get caught at save time.
- # Also, check when starting edition is done against slave to improve performance.
- wfDebug( "$fname: user is blocked\n" );
- $this->blockedPage();
- wfProfileOut( $fname );
- return;
- }
- if ( !$wgUser->isAllowed('edit') ) {
- if ( $wgUser->isAnon() ) {
- wfDebug( "$fname: user must log in\n" );
- $this->userNotLoggedInPage();
- wfProfileOut( $fname );
- return;
- } else {
- wfDebug( "$fname: read-only page\n" );
- $wgOut->readOnlyPage( $this->getContent(), true );
- wfProfileOut( $fname );
- return;
+ $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser);
+
+ # Ignore some permissions errors.
+ $remove = array();
+ foreach( $permErrors as $error ) {
+ if ($this->preview || $this->diff &&
+ ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext'))
+ {
+ // Don't worry about blocks when previewing/diffing
+ $remove[] = $error;
}
+
+ if ($error[0] == 'readonlytext')
+ {
+ if ($this->edit)
+ $this->formtype = 'preview';
+ else if ($this->save || $this->preview || $this->diff)
+ $remove[] = $error;
+ }
}
- if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
- wfDebug("$fname: user must confirm e-mail address\n");
- $this->userNotConfirmedPage();
- wfProfileOut($fname);
- return;
- }
- if ( !$this->mTitle->userCan( 'create' ) && !$this->mTitle->exists() ) {
- wfDebug( "$fname: no create permission\n" );
- $this->noCreatePermission();
+ # array_diff returns elements in $permErrors that are not in $remove.
+ $permErrors = array_diff( $permErrors, $remove );
+
+ if ($permErrors != array())
+ {
+ wfDebug( "$fname: User can't edit\n" );
+ $wgOut->readOnlyPage( $this->getContent(), true, $permErrors );
wfProfileOut( $fname );
return;
- }
- if ( wfReadOnly() ) {
- wfDebug( "$fname: read-only mode is engaged\n" );
- if( $this->save || $this->preview ) {
- $this->formtype = 'preview';
- } else if ( $this->diff ) {
- $this->formtype = 'diff';
- } else {
- $wgOut->readOnlyPage( $this->getContent() );
- wfProfileOut( $fname );
- return;
- }
} else {
if ( $this->save ) {
$this->formtype = 'save';

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php 2007-08-03 08:51:55 UTC (rev 24561)
+++ trunk/phase3/includes/OutputPage.php 2007-08-03 09:27:28 UTC (rev 24562)
@@ -831,16 +831,7 @@
$this->mBodytext = '';

$this->addWikiText( wfMsg('permissionserrorstext') );
- $this->addHtml( '<ul class="permissions-errors">' . "\n" );
-
- foreach( $errors as $error )
- {
- $this->addHtml( '<li>' );
- $this->addWikiText( call_user_func_array( 'wfMsg', $error ) );
- $this->addHtml( '</li>');
- }
- $this->addHtml( '</ul>' );
-
+ $this->addWikitext( $this->formatPermissionsErrorMessage( $errors ) );
}

/** @deprecated */
@@ -959,20 +950,46 @@
}

/**
+ * @param array $errors An array returned by Title::getUserPermissionsErrors
+ * @return string The error-messages, formatted into a list.
+ */
+ public function formatPermissionsErrorMessage( $errors ) {
+ $text = '';
+
+ $text .= wfMsg('permissionserrorstext')."\n";
+ $text .= '<ul class="permissions-errors">' . "\n";
+
+ foreach( $errors as $error )
+ {
+ $text .= '<li>';
+ $text .= call_user_func_array( 'wfMsg', $error );
+ $text .= "</li>\n";
+ }
+ $text .= '</ul>';
+
+ return $text;
+ }
+
+ /**
* @todo document
* @param bool $protected Is the reason the page can't be reached because it's protected?
* @param mixed $source
*/
- public function readOnlyPage( $source = null, $protected = false ) {
+ public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
$skin = $wgUser->getSkin();

$this->setRobotpolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );

- if( $protected ) {
+ if ($reasons != array()) {
$this->setPageTitle( wfMsg( 'viewsource' ) );
$this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
+
+ $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
+ } else if( $protected ) {
+ $this->setPageTitle( wfMsg( 'viewsource' ) );
+ $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();

// Show an appropriate explanation depending upon the reason

Modified: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php 2007-08-03 08:51:55 UTC (rev 24561)
+++ trunk/phase3/includes/Title.php 2007-08-03 09:27:28 UTC (rev 24562)
@@ -1006,7 +1006,7 @@
}
return false;
}
-
+
/**
* Can $wgUser perform $action on this page?
* @param string $action action that permission needs to be checked for
@@ -1034,6 +1034,13 @@
$errors[] = array( 'readonlytext' );
}

+ global $wgEmailConfirmToEdit;
+
+ if ( $wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed() )
+ {
+ $errors[] = array( 'confirmedittext' );
+ }
+
if ( $user->isBlockedFrom( $this ) ) {
$block = $user->mBlock;




_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS[at]lists.wikimedia.org
http://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Subject User Time
SVN: [24562] trunk/phase3 werdna at svn Aug 3, 2007, 2:27 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.