Wctaiwan has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/152840

Change subject: Add edit notices and protection warnings
......................................................................

Add edit notices and protection warnings

Change how page state is determined to support this: If $this->title is
set, the title is a valid delivery list; if $this->rev is set, the user
can edit the delivery list.

Change-Id: I3a9b89b778c4d3db7cb29c65e83a362220e22c5b
---
M includes/SpecialEditMassMessageList.php
1 file changed, 47 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage 
refs/changes/40/152840/1

diff --git a/includes/SpecialEditMassMessageList.php 
b/includes/SpecialEditMassMessageList.php
index a32be96..81453cc 100644
--- a/includes/SpecialEditMassMessageList.php
+++ b/includes/SpecialEditMassMessageList.php
@@ -45,25 +45,27 @@
                                || !$title->hasContentModel( 
'MassMessageListContent' )
                        ) {
                                $this->errorMsgKey = 
'massmessage-edit-invalidtitle';
-                       } else if ( !$title->userCan( 'edit' ) ) {
-                               $this->errorMsgKey = 
'massmessage-edit-nopermission';
                        } else {
                                $this->title = $title;
 
-                               $revId = $this->getRequest()->getInt( 'oldid' );
-                               if ( $revId > 0 ) {
-                                       $rev = Revision::newFromId( $revId );
-                                       if ( $rev
-                                               && $rev->getTitle()->equals( 
$title )
-                                               && $rev->getContentModel() === 
'MassMessageListContent'
-                                               && $rev->userCan( 
Revision::DELETED_TEXT, $this->getUser() )
-                                       ) {
-                                               $this->rev = $rev;
-                                       } else { // Use the latest revision for 
the title if $rev is invalid.
+                               if ( !$title->userCan( 'edit' ) ) {
+                                       $this->errorMsgKey = 
'massmessage-edit-nopermission';
+                               } else {
+                                       $revId = $this->getRequest()->getInt( 
'oldid' );
+                                       if ( $revId > 0 ) {
+                                               $rev = Revision::newFromId( 
$revId );
+                                               if ( $rev
+                                                       && 
$rev->getTitle()->equals( $title )
+                                                       && 
$rev->getContentModel() === 'MassMessageListContent'
+                                                       && $rev->userCan( 
Revision::DELETED_TEXT, $this->getUser() )
+                                               ) {
+                                                       $this->rev = $rev;
+                                               } else { // Use the latest 
revision for the title if $rev is invalid.
+                                                       $this->rev = 
Revision::newFromTitle( $title );
+                                               }
+                                       } else {
                                                $this->rev = 
Revision::newFromTitle( $title );
                                        }
-                               } else {
-                                       $this->rev = Revision::newFromTitle( 
$title );
                                }
                        }
                }
@@ -83,13 +85,35 @@
                        );
 
                        // Backlink
-                       $revId = $this->rev->getId();
-                       $query = ( $revId !== $this->title->getLatestRevId() ) ?
-                               array( 'oldid' => $revId ) : array();
+                       if ( $this->rev ) {
+                               $revId = $this->rev->getId();
+                               $query = ( $revId !== 
$this->title->getLatestRevId() ) ?
+                                       array( 'oldid' => $revId ) : array();
+                       } else {
+                               $query = array();
+                       }
                        // Modified from OutputPage::addBacklinkSubtitle()
                        $out->addSubtitle( $this->msg( 'backlinksubtitle' 
)->rawParams(
                                Linker::link( $this->title, null, array(), 
$query )
                        ) );
+
+                       // Edit notices and protection warnings; modified from 
EditPage::showHeader()
+                       if ( $this->rev ) {
+                               $out->addHTML(
+                                       implode( "\n", 
$this->title->getEditNotices( $this->rev->getId() ) )
+                               );
+                       }
+                       if ( $this->title->isProtected( 'edit' )
+                               && MWNamespace::getRestrictionLevels( 
$this->title->getNamespace() ) !== array( '' )
+                       ) {
+                               if ( $this->title->isSemiProtected() ) {
+                                       $noticeMsg = 'semiprotectedpagewarning';
+                               } else { // Full protection
+                                       $noticeMsg = 'protectedpagewarning';
+                               }
+                               LogEventsList::showLogExtract( $out, 'protect', 
$this->title, '',
+                                       array( 'lim' => 1, 'msgKey' => array( 
$noticeMsg ) ) );
+                       }
                }
        }
 
@@ -98,8 +122,8 @@
         */
        protected function getFormFields() {
 
-               // Show a hidden empty form if the title is invalid.
-               if ( !$this->title ) {
+               // Return an empty form if the title is invalid or if the user 
can't edit the list.
+               if ( !$this->rev ) {
                        return array();
                }
 
@@ -129,11 +153,11 @@
        }
 
        /**
-        * Hide the form if the title is invalid.
+        * Hide the form if the title is invalid or if the user can't edit the 
list.
         * @param HTMLForm $form
         */
        protected function alterForm( HTMLForm $form ) {
-               if ( !$this->title ) {
+               if ( !$this->rev ) {
                        $form->setWrapperLegend( false );
                        $form->suppressDefaultSubmit( true );
                }
@@ -146,7 +170,7 @@
        protected function preText() {
                global $wgAllowGlobalMessaging;
 
-               if ( $this->title ) {
+               if ( $this->rev ) {
                        // Instructions
                        if ( $wgAllowGlobalMessaging && count( 
MassMessage::getDatabases() ) > 1 ) {
                                $headerKey = 'massmessage-edit-headermulti';
@@ -179,7 +203,7 @@
         * @return string
         */
        protected function postText() {
-               if ( $this->title ) {
+               if ( $this->rev ) {
                        return EditPage::getCopyrightWarning( $this->title, 
'parse' );
                } else {
                        return '';

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a9b89b778c4d3db7cb29c65e83a362220e22c5b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: contenthandler
Gerrit-Owner: Wctaiwan <[email protected]>

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

Reply via email to