Huji has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368592 )

Change subject: Define a "view source" permission
......................................................................

Define a "view source" permission

Bug: T157875
Change-Id: I574281f9e62cb63d7558d1431780d5622ec80d6d
---
M includes/DefaultSettings.php
M includes/EditPage.php
M languages/i18n/en.json
M languages/i18n/qqq.json
4 files changed, 43 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/92/368592/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 77d7b0e..18a25fe 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -5101,6 +5101,7 @@
 // Implicit group for all visitors
 $wgGroupPermissions['*']['createaccount'] = true;
 $wgGroupPermissions['*']['read'] = true;
+$wgGroupPermissions['*']['viewsource'] = true;
 $wgGroupPermissions['*']['edit'] = true;
 $wgGroupPermissions['*']['createpage'] = true;
 $wgGroupPermissions['*']['createtalk'] = true;
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 229a36a..c9466e0 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -738,47 +738,50 @@
         * @param string $errorMessage additional wikitext error message to 
display
         */
        protected function displayViewSourcePage( Content $content, 
$errorMessage = '' ) {
-               global $wgOut;
+               global $wgOut, $wgUser;
+               if ( $this->mTitle->userCan( 'viewsource', $wgUser ) ) {
+                       Hooks::run( 'EditPage::showReadOnlyForm:initial', [ 
$this, &$wgOut ] );
 
-               Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, 
&$wgOut ] );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
+                       $wgOut->setPageTitle( $this->context->msg(
+                               'viewsource-title',
+                               $this->getContextTitle()->getPrefixedText()
+                       ) );
+                       $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
+                       $wgOut->addHTML( $this->editFormPageTop );
+                       $wgOut->addHTML( $this->editFormTextTop );
 
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               $wgOut->setPageTitle( $this->context->msg(
-                       'viewsource-title',
-                       $this->getContextTitle()->getPrefixedText()
-               ) );
-               $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
-               $wgOut->addHTML( $this->editFormPageTop );
-               $wgOut->addHTML( $this->editFormTextTop );
-
-               if ( $errorMessage !== '' ) {
-                       $wgOut->addWikiText( $errorMessage );
-                       $wgOut->addHTML( "<hr />\n" );
-               }
-
-               # If the user made changes, preserve them when showing the 
markup
-               # (This happens when a user is blocked during edit, for 
instance)
-               if ( !$this->firsttime ) {
-                       $text = $this->textbox1;
-                       $wgOut->addWikiMsg( 'viewyourtext' );
-               } else {
-                       try {
-                               $text = $this->toEditText( $content );
-                       } catch ( MWException $e ) {
-                               # Serialize using the default format if the 
content model is not supported
-                               # (e.g. for an old revision with a different 
model)
-                               $text = $content->serialize();
+                       if ( $errorMessage !== '' ) {
+                               $wgOut->addWikiText( $errorMessage );
+                               $wgOut->addHTML( "<hr />\n" );
                        }
-                       $wgOut->addWikiMsg( 'viewsourcetext' );
+
+                       # If the user made changes, preserve them when showing 
the markup
+                       # (This happens when a user is blocked during edit, for 
instance)
+                       if ( !$this->firsttime ) {
+                               $text = $this->textbox1;
+                               $wgOut->addWikiMsg( 'viewyourtext' );
+                       } else {
+                               try {
+                                       $text = $this->toEditText( $content );
+                               } catch ( MWException $e ) {
+                                       # Serialize using the default format if 
the content model is not supported
+                                       # (e.g. for an old revision with a 
different model)
+                                       $text = $content->serialize();
+                               }
+                               $wgOut->addWikiMsg( 'viewsourcetext' );
+                       }
+
+                       $wgOut->addHTML( $this->editFormTextBeforeContent );
+                       $this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] 
);
+                       $wgOut->addHTML( $this->editFormTextAfterContent );
+
+                       $wgOut->addHTML( $this->makeTemplatesOnThisPageList( 
$this->getTemplates() ) );
+
+                       $wgOut->addModules( 
'mediawiki.action.edit.collapsibleFooter' );
+               } else {
+                       $wgOut->addWikiMsg( 'cannotviewsource' );
                }
-
-               $wgOut->addHTML( $this->editFormTextBeforeContent );
-               $this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] );
-               $wgOut->addHTML( $this->editFormTextAfterContent );
-
-               $wgOut->addHTML( $this->makeTemplatesOnThisPageList( 
$this->getTemplates() ) );
-
-               $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
 
                $wgOut->addHTML( $this->editFormTextBottom );
                if ( $this->mTitle->exists() ) {
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index b2b4179..a19ec5f 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -357,6 +357,7 @@
        "protectedpagetext": "This page has been protected to prevent editing 
or other actions.",
        "viewsourcetext": "You can view and copy the source of this page.",
        "viewyourtext": "You can view and copy the source of <strong>your 
edits</strong> to this page.",
+       "cannotviewsource": "You cannot view the source of this page.",
        "protectedinterface": "This page provides interface text for the 
software on this wiki, and is protected to prevent abuse.\nTo add or change 
translations for all wikis, please use [https://translatewiki.net/ 
translatewiki.net], the MediaWiki localisation project.",
        "editinginterface": "<strong>Warning:</strong> You are editing a page 
that is used to provide interface text for the software.\nChanges to this page 
will affect the appearance of the user interface for other users on this wiki.",
        "translateinterface": "To add or change translations for all wikis, 
please use [https://translatewiki.net/ translatewiki.net], the MediaWiki 
localisation project.",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index f2755d1..964419c 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -547,6 +547,7 @@
        "protectedpagetext": "This message is displayed when trying to edit a 
page you can't edit because it has been protected.\n\nThe title for this 
message is {{msg-mw|Protectedpage}}.\n\nParameters:\n* $1 - (Unused) the raw 
name of the right which is needed to edit the page\n* $2 - (Unused) the action 
the user attempted to perform",
        "viewsourcetext": "The text shown when displaying the source of a page 
that the user has no permission to edit",
        "viewyourtext": "Same as {{msg-mw|viewsourcetext}} but when showing the 
text submitted by the user, this happens e.g. when the user was blocked while 
he is editing the page",
+       "cannotviewsource": "The text shown when the user does not have the 
viewsource right",
        "protectedinterface": "Message shown if a user without the 
\"editinterface\" right tries to edit a page in the MediaWiki namespace.\n\nSee 
also {{msg-mw|editinginterface}}. Parameters:\n* $1 - (Unused) the action the 
user attempted to perform",
        "editinginterface": "A message shown when editing pages in the 
namespace MediaWiki:.\n\nSee also {{msg-mw|protectedinterface}}.",
        "translateinterface": "A message shown when editing pages in the 
namespace MediaWiki:, which have a default message text.\n\nSee also:\n* 
{{msg-mw|Protectedinterface}}\n* {{msg-mw|Editinginterface}}",

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I574281f9e62cb63d7558d1431780d5622ec80d6d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Huji <huji.h...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to