[BLOCK] Increase type strictness

This commit is contained in:
Alexei Sorokin 2020-07-31 16:35:27 +03:00 committed by Diogo Peralta Cordeiro
parent bee3dea9c2
commit 50dd216f44
1 changed files with 84 additions and 75 deletions

View File

@ -1,50 +1,44 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Block a user action class. * Block a user action class.
* *
* PHP version 5 * @category Action
* * @package GNUsocial
* @category Action * @author Evan Prodromou <evan@status.net>
* @package StatusNet * @author Robin Millette <millette@status.net>
* @author Evan Prodromou <evan@status.net> * @copyright 2008, 2009 StatusNet, Inc.
* @author Robin Millette <millette@status.net> * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Block a user action class. * Block a user action class.
* *
* @category Action * @category Action
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net> * @author Robin Millette <millette@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class BlockAction extends ProfileFormAction class BlockAction extends ProfileFormAction
{ {
var $profile = null; public $profile = null;
/** /**
* Take arguments for running * Take arguments for running
@ -53,7 +47,7 @@ class BlockAction extends ProfileFormAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare(array $args = array()) public function prepare(array $args = []): bool
{ {
if (!parent::prepare($args)) { if (!parent::prepare($args)) {
return false; return false;
@ -78,7 +72,7 @@ class BlockAction extends ProfileFormAction
* *
* @return void * @return void
*/ */
function handle() public function handle(): void
{ {
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($this->arg('no')) { if ($this->arg('no')) {
@ -94,16 +88,19 @@ class BlockAction extends ProfileFormAction
} }
} }
function showContent() { public function showContent(): void
{
$this->areYouSureForm(); $this->areYouSureForm();
} }
function title() { public function title(): string
{
// TRANS: Title for block user page. // TRANS: Title for block user page.
return _('Block user'); return _('Block user');
} }
function showNoticeForm() { public function showNoticeForm(): void
{
// nop // nop
} }
@ -114,7 +111,7 @@ class BlockAction extends ProfileFormAction
* *
* @return void * @return void
*/ */
function areYouSureForm() public function areYouSureForm()
{ {
// @fixme if we ajaxify the confirmation form, skip the preview on ajax hits // @fixme if we ajaxify the confirmation form, skip the preview on ajax hits
$profile = new ArrayWrapper(array($this->profile)); $profile = new ArrayWrapper(array($this->profile));
@ -131,35 +128,44 @@ class BlockAction extends ProfileFormAction
$this->hidden('token', common_session_token()); $this->hidden('token', common_session_token());
// TRANS: Legend for block user form. // TRANS: Legend for block user form.
$this->element('legend', _('Block user')); $this->element('legend', _('Block user'));
$this->element('p', null, $this->element(
// TRANS: Explanation of consequences when blocking a user on the block user page. 'p',
_('Are you sure you want to block this user? '. null,
'Afterwards, they will be unsubscribed from you, '. // TRANS: Explanation of consequences when blocking a user on the block user page.
'unable to subscribe to you in the future, and '. _('Are you sure you want to block this user? '
'you will not be notified of any @-replies from them.')); . 'Afterwards, they will be unsubscribed from you, '
$this->element('input', array('id' => 'blockto-' . $id, . 'unable to subscribe to you in the future, and '
'name' => 'profileid', . 'you will not be notified of any @-replies from them.')
'type' => 'hidden', );
'value' => $id)); $this->element('input', [
'id' => 'blockto-' . $id,
'name' => 'profileid',
'type' => 'hidden',
'value' => $id
]);
foreach ($this->args as $k => $v) { foreach ($this->args as $k => $v) {
if (substr($k, 0, 9) == 'returnto-') { if (substr($k, 0, 9) == 'returnto-') {
$this->hidden($k, $v); $this->hidden($k, $v);
} }
} }
$this->submit('form_action-no', $this->submit(
// TRANS: Button label on the user block form. 'form_action-no',
_m('BUTTON','No'), // TRANS: Button label on the user block form.
'submit form_action-primary', _m('BUTTON', 'No'),
'no', 'submit form_action-primary',
// TRANS: Submit button title for 'No' when blocking a user. 'no',
_('Do not block this user.')); // TRANS: Submit button title for 'No' when blocking a user.
$this->submit('form_action-yes', _('Do not block this user.')
// TRANS: Button label on the user block form. );
_m('BUTTON','Yes'), $this->submit(
'submit form_action-secondary', 'form_action-yes',
'yes', // TRANS: Button label on the user block form.
// TRANS: Submit button title for 'Yes' when blocking a user. _m('BUTTON', 'Yes'),
_('Block this user.')); 'submit form_action-secondary',
'yes',
// TRANS: Submit button title for 'Yes' when blocking a user.
_('Block this user.')
);
$this->elementEnd('fieldset'); $this->elementEnd('fieldset');
$this->elementEnd('form'); $this->elementEnd('form');
} }
@ -170,7 +176,7 @@ class BlockAction extends ProfileFormAction
* @return void * @return void
*/ */
function handlePost() public function handlePost(): void
{ {
$cur = common_current_user(); $cur = common_current_user();
@ -187,7 +193,7 @@ class BlockAction extends ProfileFormAction
} }
} }
function showScripts() public function showScripts(): void
{ {
parent::showScripts(); parent::showScripts();
$this->autofocus('form_action-yes'); $this->autofocus('form_action-yes');
@ -201,13 +207,14 @@ class BlockAction extends ProfileFormAction
* @throws ClientException if token is bad on POST request or if we have * @throws ClientException if token is bad on POST request or if we have
* confirmation parameters which could trigger something. * confirmation parameters which could trigger something.
*/ */
function checkSessionToken() public function checkSessionToken(): void
{ {
if ($_SERVER['REQUEST_METHOD'] == 'POST' || if (
$this->arg('yes') || $_SERVER['REQUEST_METHOD'] === 'POST'
$this->arg('no')) { || $this->arg('yes')
|| $this->arg('no')
return parent::checkSessionToken(); ) {
parent::checkSessionToken();
} }
} }
@ -217,12 +224,14 @@ class BlockAction extends ProfileFormAction
* *
* @return string URL * @return string URL
*/ */
function defaultReturnTo() public function defaultReturnTo()
{ {
$user = common_current_user(); $user = common_current_user();
if ($user) { if ($user) {
return common_local_url('subscribers', return common_local_url(
array('nickname' => $user->nickname)); 'subscribers',
['nickname' => $user->nickname]
);
} else { } else {
return common_local_url('public'); return common_local_url('public');
} }