Merge "FormatJson: Skip whitespace cleanup when unnecessary"
[lhc/web/wiklou.git] / includes / specials / SpecialRevisiondelete.php
index 05c8872..4edf33c 100644 (file)
  * @ingroup SpecialPage
  */
 class SpecialRevisionDelete extends UnlistedSpecialPage {
-       /** True if the submit button was clicked, and the form was posted */
-       var $submitClicked;
+       /** @var bool Was the DB modified in this request */
+       protected $wasSaved = false;
 
-       /** Target ID list */
-       var $ids;
+       /** @var bool True if the submit button was clicked, and the form was posted */
+       private $submitClicked;
 
-       /** Archive name, for reviewing deleted files */
-       var $archiveName;
+       /** @var array Target ID list */
+       private $ids;
 
-       /** Edit token for securing image views against XSS */
-       var $token;
+       /** @var string Archive name, for reviewing deleted files */
+       private $archiveName;
 
-       /** Title object for target parameter */
-       var $targetObj;
+       /** @var string Edit token for securing image views against XSS */
+       private $token;
 
-       /** Deletion type, may be revision, archive, oldimage, filearchive, logging. */
-       var $typeName;
+       /** @var Title Title object for target parameter */
+       private $targetObj;
 
-       /** Array of checkbox specs (message, name, deletion bits) */
-       var $checks;
+       /** @var string Deletion type, may be revision, archive, oldimage, filearchive, logging. */
+       private $typeName;
 
-       /** UI Labels about the current type */
-       var $typeLabels;
+       /** @var array Array of checkbox specs (message, name, deletion bits) */
+       private $checks;
 
-       /** The RevDel_List object, storing the list of items to be deleted/undeleted */
-       var $list;
+       /** @var array UI Labels about the current type */
+       private $typeLabels;
 
-       /** Was the DB modified in this request */
-       protected $wasSaved = false;
+       /** @var RevDel_List RevDel_List object, storing the list of items to be deleted/undeleted */
+       private $revDelList;
+
+       /** @var bool Whether user is allowed to perform the action */
+       private $mIsAllowed;
+
+       /** @var string */
+       private $otherReason;
 
        /**
         * UI labels for each type.
         */
-       static $UILabels = array(
+       private static $UILabels = array(
                'revision' => array(
                        'check-label' => 'revdelete-hide-text',
                        'success' => 'revdelete-success',
                        'failure' => 'revdelete-failure',
                        'text' => 'revdelete-text-text',
+                       'selected'=> 'revdelete-selected-text',
                ),
                'archive' => array(
                        'check-label' => 'revdelete-hide-text',
                        'success' => 'revdelete-success',
                        'failure' => 'revdelete-failure',
                        'text' => 'revdelete-text-text',
+                       'selected'=> 'revdelete-selected-text',
                ),
                'oldimage' => array(
                        'check-label' => 'revdelete-hide-image',
                        'success' => 'revdelete-success',
                        'failure' => 'revdelete-failure',
                        'text' => 'revdelete-text-file',
+                       'selected'=> 'revdelete-selected-file',
                ),
                'filearchive' => array(
                        'check-label' => 'revdelete-hide-image',
                        'success' => 'revdelete-success',
                        'failure' => 'revdelete-failure',
                        'text' => 'revdelete-text-file',
+                       'selected'=> 'revdelete-selected-file',
                ),
                'logging' => array(
                        'check-label' => 'revdelete-hide-name',
                        'success' => 'logdelete-success',
                        'failure' => 'logdelete-failure',
                        'text' => 'logdelete-text',
+                       'selected' => 'logdelete-selected',
                ),
        );
 
@@ -137,6 +148,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $this->token = $request->getVal( 'token' );
                if ( $this->archiveName && $this->targetObj ) {
                        $this->tryShowFile( $this->archiveName );
+
                        return;
                }
 
@@ -156,6 +168,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                # We need a target page!
                if ( is_null( $this->targetObj ) ) {
                        $output->addWikiMsg( 'undelete-header' );
+
                        return;
                }
                # Give a link to the logs/hist for this page
@@ -163,6 +176,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
 
                # Initialise checkboxes
                $this->checks = array(
+                       # Messages: revdelete-hide-text, revdelete-hide-image, revdelete-hide-name
                        array( $this->typeLabels['check-label'], 'wpHidePrimary',
                                RevisionDeleter::getRevdelConstant( $this->typeName )
                        ),
@@ -257,12 +271,14 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $conds['log_action'] = $this->getList()->getLogAction();
                $conds['ls_field'] = RevisionDeleter::getRelationType( $this->typeName );
                $conds['ls_value'] = $this->ids;
+
                return $conds;
        }
 
        /**
         * Show a deleted file version requested by the visitor.
         * TODO Mostly copied from Special:Undelete. Refactor.
+        * @param string $archiveName
         */
        protected function tryShowFile( $archiveName ) {
                $repo = RepoGroup::singleton()->getLocalRepo();
@@ -271,6 +287,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                // Check if user is allowed to see this file
                if ( !$oimage->exists() ) {
                        $this->getOutput()->addWikiMsg( 'revdelete-no-file' );
+
                        return;
                }
                $user = $this->getUser();
@@ -300,6 +317,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                Xml::submitButton( $this->msg( 'revdelete-show-file-submit' )->text() ) .
                                '</form>'
                        );
+
                        return;
                }
                $this->getOutput()->disable();
@@ -318,14 +336,16 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
 
        /**
         * Get the list object for this request
+        * @return RevDel_List
         */
        protected function getList() {
-               if ( is_null( $this->list ) ) {
-                       $this->list = RevisionDeleter::createList(
+               if ( is_null( $this->revDelList ) ) {
+                       $this->revDelList = RevisionDeleter::createList(
                                $this->typeName, $this->getContext(), $this->targetObj, $this->ids
                        );
                }
-               return $this->list;
+
+               return $this->revDelList;
        }
 
        /**
@@ -335,12 +355,9 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        protected function showForm() {
                $userAllowed = true;
 
-               if ( $this->typeName == 'logging' ) {
-                       $this->getOutput()->addWikiMsg( 'logdelete-selected', $this->getLanguage()->formatNum( count( $this->ids ) ) );
-               } else {
-                       $this->getOutput()->addWikiMsg( 'revdelete-selected',
-                               $this->targetObj->getPrefixedText(), count( $this->ids ) );
-               }
+               // Messages: revdelete-selected-text, revdelete-selected-file, logdelete-selected
+               $this->getOutput()->wrapWikiMsg( "<strong>$1</strong>", array( $this->typeLabels['selected'],
+                       $this->getLanguage()->formatNum( count( $this->ids ) ), $this->targetObj->getPrefixedText() ) );
 
                $this->getOutput()->addHTML( "<ul>" );
 
@@ -436,6 +453,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
         * @todo FIXME: Wikimedia-specific policy text
         */
        protected function addUsageText() {
+               // Messages: revdelete-text-text, revdelete-text-file, logdelete-text
                $this->getOutput()->wrapWikiMsg( "<strong>$1</strong>\n$2", $this->typeLabels['text'], 'revdelete-text-others' );
                if ( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
                        $this->getOutput()->addWikiMsg( 'revdelete-suppress-text' );
@@ -446,7 +464,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
        }
 
        /**
-        * @return String: HTML
+        * @return string HTML
         */
        protected function buildCheckBoxes() {
                $html = '<table>';
@@ -459,6 +477,8 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                $bitfield = RevisionDeleter::extractBitfield( $this->extractBitParams(), $bitfield );
                        }
                        foreach ( $this->checks as $item ) {
+                               // Messages: revdelete-hide-text, revdelete-hide-image, revdelete-hide-name,
+                               // revdelete-hide-comment, revdelete-hide-user, revdelete-hide-restricted
                                list( $message, $name, $field ) = $item;
                                $innerHTML = Xml::checkLabel( $this->msg( $message )->text(), $name, $name, $bitfield & $field );
                                if ( $field == Revision::DELETED_RESTRICTED ) {
@@ -467,14 +487,16 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                $line = Xml::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML );
                                $html .= "<tr>$line</tr>\n";
                        }
-               // Otherwise, use tri-state radios
                } else {
+                       // Otherwise, use tri-state radios
                        $html .= '<tr>';
                        $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-same' )->escaped() . '</th>';
                        $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-unset' )->escaped() . '</th>';
                        $html .= '<th class="mw-revdel-checkbox">' . $this->msg( 'revdelete-radio-set' )->escaped() . '</th>';
                        $html .= "<th></th></tr>\n";
                        foreach ( $this->checks as $item ) {
+                               // Messages: revdelete-hide-text, revdelete-hide-image, revdelete-hide-name,
+                               // revdelete-hide-comment, revdelete-hide-user, revdelete-hide-restricted
                                list( $message, $name, $field ) = $item;
                                // If there are several items, use third state by default...
                                if ( $this->submitClicked ) {
@@ -495,6 +517,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                }
 
                $html .= '</table>';
+
                return $html;
        }
 
@@ -508,6 +531,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $token = $this->getRequest()->getVal( 'wpEditToken' );
                if ( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) {
                        $this->getOutput()->addWikiMsg( 'sessionfailure' );
+
                        return false;
                }
                $bitParams = $this->extractBitParams();
@@ -527,11 +551,13 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $status = $this->save( $bitParams, $comment, $this->targetObj );
                if ( $status->isGood() ) {
                        $this->success();
+
                        return true;
-               # ...otherwise, bounce back to form...
                } else {
+                       # ...otherwise, bounce back to form...
                        $this->failure( $status );
                }
+
                return false;
        }
 
@@ -539,10 +565,11 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
         * Report that the submit operation succeeded
         */
        protected function success() {
+               // Messages: revdelete-success, logdelete-success
                $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
                $this->getOutput()->wrapWikiMsg( "<span class=\"success\">\n$1\n</span>", $this->typeLabels['success'] );
                $this->wasSaved = true;
-               $this->list->reloadFromMaster();
+               $this->revDelList->reloadFromMaster();
                $this->showForm();
        }
 
@@ -550,6 +577,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
         * Report that the submit operation failed
         */
        protected function failure( $status ) {
+               // Messages: revdelete-failure, logdelete-failure
                $this->getOutput()->setPageTitle( $this->msg( 'actionfailed' ) );
                $this->getOutput()->addWikiText( $status->getWikiText( $this->typeLabels['failure'] ) );
                $this->showForm();
@@ -573,15 +601,16 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                if ( !isset( $bitfield[Revision::DELETED_RESTRICTED] ) ) {
                        $bitfield[Revision::DELETED_RESTRICTED] = 0;
                }
+
                return $bitfield;
        }
 
        /**
         * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
-        * @param $bitfield
-        * @param $reason
-        * @param $title
-        * @return
+        * @param int $bitfield
+        * @param string $reason
+        * @param Title $title
+        * @return Status
         */
        protected function save( $bitfield, $reason, $title ) {
                return $this->getList()->setVisibility(