jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/372763 )

Change subject: Consistent behavior of read-only reason
......................................................................


Consistent behavior of read-only reason

Before this commit, the reason set in the global $wgReadOnly was differently 
handled
on different special pages. While on most of them, like Special:Upload, the 
reason
is allowed to have HTML, which can be used in Wikitext, too, 
Special:CreateAccount
always outputted an escaped version of this reason.

Most special pages uses the ReadOnlyError exception to print a read-only error,
however, AuthManager uses Status objects to communicate between the backend and 
the
frontend. Therefore the same message and parameters were wrapped in a Status 
object
and, in the frontend, directly passed to the constructor of ErrorPageError. 
Unfortunately,
Status::getMessage() escapes the parameters of a message, which is the reason, 
why the
wiki is read-only. To bypass this restriction, AuthManager now creates a 
Message object
directly, does not escape the reason, and uses the resulting object to create a 
Status
object from.

Now the reason is not escaped on Special:CreateAccount anymore, like on most 
other
special pages.

The read-only message on the protection form is, also before this commit, not 
escaped and
already displayed correctly, as the read-only is checked in the constructor of 
the
protection form already and, if the Wiki is read only, handled as a permission 
error and
already displayed correctly. This commit fixes the behavior of WikiPage in case 
of it's used
somewhere else, subclassed or if the check in the frontend will be removed and 
the Status of
WikiPage will be used.

Bug: T157036
Change-Id: Idbfe556fcb90f8bda8fae9d728ca9dee5ea02f67
---
M includes/auth/AuthManager.php
M includes/page/WikiPage.php
M tests/phpunit/includes/auth/AuthManagerTest.php
3 files changed, 5 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Anomie: Looks good to me, approved



diff --git a/includes/auth/AuthManager.php b/includes/auth/AuthManager.php
index c3f798f..818f778 100644
--- a/includes/auth/AuthManager.php
+++ b/includes/auth/AuthManager.php
@@ -975,7 +975,7 @@
        public function checkAccountCreatePermissions( User $creator ) {
                // Wiki is read-only?
                if ( wfReadOnly() ) {
-                       return Status::newFatal( 'readonlytext', 
wfReadOnlyReason() );
+                       return Status::newFatal( wfMessage( 'readonlytext', 
wfReadOnlyReason() ) );
                }
 
                // This is awful, this permission check really shouldn't go 
through Title.
@@ -1579,7 +1579,7 @@
                        ] );
                        $user->setId( 0 );
                        $user->loadFromId();
-                       return Status::newFatal( 'readonlytext', 
wfReadOnlyReason() );
+                       return Status::newFatal( wfMessage( 'readonlytext', 
wfReadOnlyReason() ) );
                }
 
                // Check the session, if we tried to create this user already 
there's
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index e60f103..134bb88 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -2302,7 +2302,7 @@
                global $wgCascadingRestrictionLevels, $wgContLang;
 
                if ( wfReadOnly() ) {
-                       return Status::newFatal( 'readonlytext', 
wfReadOnlyReason() );
+                       return Status::newFatal( wfMessage( 'readonlytext', 
wfReadOnlyReason() ) );
                }
 
                $this->loadPageData( 'fromdbmaster' );
diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php 
b/tests/phpunit/includes/auth/AuthManagerTest.php
index a840599..c18af8b 100644
--- a/tests/phpunit/includes/auth/AuthManagerTest.php
+++ b/tests/phpunit/includes/auth/AuthManagerTest.php
@@ -1408,7 +1408,7 @@
                $readOnlyMode = 
\MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
                $readOnlyMode->setReason( 'Because' );
                $this->assertEquals(
-                       \Status::newFatal( 'readonlytext', 'Because' ),
+                       \Status::newFatal( wfMessage( 'readonlytext', 'Because' 
) ),
                        $this->manager->checkAccountCreatePermissions( new 
\User )
                );
                $readOnlyMode->setReason( false );
@@ -2478,7 +2478,7 @@
                $this->hook( 'LocalUserCreated', $this->never() );
                $ret = $this->manager->autoCreateUser( $user, 
AuthManager::AUTOCREATE_SOURCE_SESSION, true );
                $this->unhook( 'LocalUserCreated' );
-               $this->assertEquals( \Status::newFatal( 'readonlytext', 
'Because' ), $ret );
+               $this->assertEquals( \Status::newFatal( wfMessage( 
'readonlytext', 'Because' ) ), $ret );
                $this->assertEquals( 0, $user->getId() );
                $this->assertNotEquals( $username, $user->getName() );
                $this->assertEquals( 0, $session->getUser()->getId() );

-- 
To view, visit https://gerrit.wikimedia.org/r/372763
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idbfe556fcb90f8bda8fae9d728ca9dee5ea02f67
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to