Various obvious bug fixes and better PHP 7 support

Many of these came from a XRevan86 patch
This commit is contained in:
Diogo Cordeiro 2019-04-26 00:34:17 +01:00
parent c4f962a7d0
commit 7967db6ff5
28 changed files with 652 additions and 681 deletions

View File

@ -51,25 +51,25 @@ if (!defined('STATUSNET')) {
class DeleteaccountAction extends Action class DeleteaccountAction extends Action
{ {
private $_complete = false; private $_complete = false;
private $_error = null; private $_error = null;
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$cur = common_current_user(); $cur = common_current_user();
if (empty($cur)) { if (empty($cur)) {
// TRANS: Client exception displayed trying to delete a user account while not logged in. // TRANS: Client exception displayed trying to delete a user account while not logged in.
throw new ClientException(_("Only logged-in users ". throw new ClientException(_("Only logged-in users can delete their account."), 403);
"can delete their account."), 403);
} }
if (!$cur->hasRight(Right::DELETEACCOUNT)) { if (!$cur->hasRight(Right::DELETEACCOUNT)) {
@ -83,20 +83,71 @@ class DeleteaccountAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
* @throws AuthorizationException
* @throws ServerException
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->deleteAccount(); $this->deleteAccount();
} else { } else {
$this->showPage(); $this->showPage();
} }
return; return null;
}
/**
* Delete the current user's account
*
* Checks for the "I am sure." string to make sure the user really
* wants to delete their account.
*
* Then, marks the account as deleted and begins the deletion process
* (actually done by a back-end handler).
*
* If successful it logs the user out, and shows a brief completion message.
*
* @return void
* @throws AuthorizationException
* @throws ServerException
*/
function deleteAccount()
{
$this->checkSessionToken();
// !!! If this string is changed, it also needs to be changed in DeleteAccountForm::formData()
// TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
$iamsure = _('I am sure.');
if ($this->trimmed('iamsure') != $iamsure) {
// TRANS: Notification for user about the text that must be input to be able to delete a user account.
// TRANS: %s is the text that needs to be input.
$this->_error = sprintf(_('You must write "%s" exactly in the box.'), $iamsure);
$this->showPage();
return null;
}
$cur = common_current_user();
// Mark the account as deleted and shove low-level deletion tasks
// to background queues. Removing a lot of posts can take a while...
if (!$cur->hasRole(Profile_role::DELETED)) {
$cur->grantRole(Profile_role::DELETED);
}
$qm = QueueManager::get();
$qm->enqueue($cur, 'deluser');
// The user is really-truly logged out
common_set_user(null);
common_real_login(false); // not logged in
common_forgetme(); // don't log back in!
$this->_complete = true;
$this->showPage();
} }
/** /**
@ -139,55 +190,6 @@ class DeleteaccountAction extends Action
return null; return null;
} }
/**
* Delete the current user's account
*
* Checks for the "I am sure." string to make sure the user really
* wants to delete their account.
*
* Then, marks the account as deleted and begins the deletion process
* (actually done by a back-end handler).
*
* If successful it logs the user out, and shows a brief completion message.
*
* @return void
*/
function deleteAccount()
{
$this->checkSessionToken();
// !!! If this string is changed, it also needs to be changed in DeleteAccountForm::formData()
// TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
$iamsure = _('I am sure.');
if ($this->trimmed('iamsure') != $iamsure ) {
// TRANS: Notification for user about the text that must be input to be able to delete a user account.
// TRANS: %s is the text that needs to be input.
$this->_error = sprintf(_('You must write "%s" exactly in the box.'), $iamsure);
$this->showPage();
return;
}
$cur = common_current_user();
// Mark the account as deleted and shove low-level deletion tasks
// to background queues. Removing a lot of posts can take a while...
if (!$cur->hasRole(Profile_role::DELETED)) {
$cur->grantRole(Profile_role::DELETED);
}
$qm = QueueManager::get();
$qm->enqueue($cur, 'deluser');
// The user is really-truly logged out
common_set_user(null);
common_real_login(false); // not logged in
common_forgetme(); // don't log back in!
$this->_complete = true;
$this->showPage();
}
/** /**
* Shows the page content. * Shows the page content.
* *
@ -202,9 +204,9 @@ class DeleteaccountAction extends Action
{ {
if ($this->_complete) { if ($this->_complete) {
$this->element('p', 'confirmation', $this->element('p', 'confirmation',
// TRANS: Confirmation that a user account has been deleted. // TRANS: Confirmation that a user account has been deleted.
_('Account deleted.')); _('Account deleted.'));
return; return null;
} }
if (!empty($this->_error)) { if (!empty($this->_error)) {
@ -276,16 +278,13 @@ class DeleteAccountForm extends Form
$cur = common_current_user(); $cur = common_current_user();
// TRANS: Form text for user deletion form. // TRANS: Form text for user deletion form.
$msg = '<p>' . _('This will <strong>permanently delete</strong> '. $msg = '<p>' . _('This will <strong>permanently delete</strong> your account data from this server.') . '</p>';
'your account data from this server.') . '</p>';
if ($cur->hasRight(Right::BACKUPACCOUNT)) { if ($cur->hasRight(Right::BACKUPACCOUNT)) {
// TRANS: Additional form text for user deletion form shown if a user has account backup rights. // TRANS: Additional form text for user deletion form shown if a user has account backup rights.
// TRANS: %s is a URL to the backup page. // TRANS: %s is a URL to the backup page.
$msg .= '<p>' . sprintf(_('You are strongly advised to '. $msg .= '<p>' . sprintf(_('You are strongly advised to <a href="%s">back up your data</a> before deletion.'),
'<a href="%s">back up your data</a>'. common_local_url('backupaccount')) . '</p>';
' before deletion.'),
common_local_url('backupaccount')) . '</p>';
} }
$this->out->elementStart('p'); $this->out->elementStart('p');
@ -296,13 +295,13 @@ class DeleteAccountForm extends Form
// TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation. // TRANS: Confirmation text for user deletion. The user has to type this exactly the same, including punctuation.
$iamsure = _("I am sure."); $iamsure = _("I am sure.");
$this->out->input('iamsure', $this->out->input('iamsure',
// TRANS: Field label for delete account confirmation entry. // TRANS: Field label for delete account confirmation entry.
_('Confirm'), _('Confirm'),
null, null,
// TRANS: Input title for the delete account field. // TRANS: Input title for the delete account field.
// TRANS: %s is the text that needs to be input. // TRANS: %s is the text that needs to be input.
sprintf(_('Enter "%s" to confirm that '. sprintf(_('Enter "%s" to confirm that ' .
'you want to delete your account.'),$iamsure )); 'you want to delete your account.'), $iamsure));
} }
/** /**
@ -315,11 +314,11 @@ class DeleteAccountForm extends Form
function formActions() function formActions()
{ {
$this->out->submit('submit', $this->out->submit('submit',
// TRANS: Button text for user account deletion. // TRANS: Button text for user account deletion.
_m('BUTTON', 'Delete'), _m('BUTTON', 'Delete'),
'submit', 'submit',
null, null,
// TRANS: Button title for user account deletion. // TRANS: Button title for user account deletion.
_('Permanently delete your account.')); _('Permanently delete your account.'));
} }
} }

View File

@ -63,13 +63,14 @@ class RestoreaccountAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$cur = common_current_user(); $cur = common_current_user();
@ -89,20 +90,19 @@ class RestoreaccountAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
* @throws ClientException
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->restoreAccount(); $this->restoreAccount();
} else { } else {
$this->showPage(); $this->showPage();
} }
return; return null;
} }
/** /**
@ -111,6 +111,8 @@ class RestoreaccountAction extends Action
* Uses the UserActivityStream class; may take a long time! * Uses the UserActivityStream class; may take a long time!
* *
* @return void * @return void
* @throws ClientException
* @throws Exception
*/ */
function restoreAccount() function restoreAccount()
{ {
@ -128,41 +130,33 @@ class RestoreaccountAction extends Action
// TRANS: Client exception thrown when an uploaded file is larger than set in php.ini. // TRANS: Client exception thrown when an uploaded file is larger than set in php.ini.
throw new ClientException(_('The uploaded file exceeds the ' . throw new ClientException(_('The uploaded file exceeds the ' .
'upload_max_filesize directive in php.ini.')); 'upload_max_filesize directive in php.ini.'));
return;
case UPLOAD_ERR_FORM_SIZE: case UPLOAD_ERR_FORM_SIZE:
throw new ClientException( throw new ClientException(
// TRANS: Client exception. // TRANS: Client exception.
_('The uploaded file exceeds the MAX_FILE_SIZE directive' . _('The uploaded file exceeds the MAX_FILE_SIZE directive' .
' that was specified in the HTML form.')); ' that was specified in the HTML form.'));
return;
case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_PARTIAL:
@unlink($_FILES['restorefile']['tmp_name']); @unlink($_FILES['restorefile']['tmp_name']);
// TRANS: Client exception. // TRANS: Client exception.
throw new ClientException(_('The uploaded file was only' . throw new ClientException(_('The uploaded file was only' .
' partially uploaded.')); ' partially uploaded.'));
return;
case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_NO_FILE:
// TRANS: Client exception. No file; probably just a non-AJAX submission. // TRANS: Client exception. No file; probably just a non-AJAX submission.
throw new ClientException(_('No uploaded file.')); throw new ClientException(_('No uploaded file.'));
return;
case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_NO_TMP_DIR:
// TRANS: Client exception thrown when a temporary folder is not present to store a file upload. // TRANS: Client exception thrown when a temporary folder is not present to store a file upload.
throw new ClientException(_('Missing a temporary folder.')); throw new ClientException(_('Missing a temporary folder.'));
return;
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
// TRANS: Client exception thrown when writing to disk is not possible during a file upload operation. // TRANS: Client exception thrown when writing to disk is not possible during a file upload operation.
throw new ClientException(_('Failed to write file to disk.')); throw new ClientException(_('Failed to write file to disk.'));
return;
case UPLOAD_ERR_EXTENSION: case UPLOAD_ERR_EXTENSION:
// TRANS: Client exception thrown when a file upload operation has been stopped by an extension. // TRANS: Client exception thrown when a file upload operation has been stopped by an extension.
throw new ClientException(_('File upload stopped by extension.')); throw new ClientException(_('File upload stopped by extension.'));
return;
default: default:
common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " . common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " .
$_FILES['restorefile']['error']); $_FILES['restorefile']['error']);
// TRANS: Client exception thrown when a file upload operation has failed with an unknown reason. // TRANS: Client exception thrown when a file upload operation has failed with an unknown reason.
throw new ClientException(_('System error uploading file.')); throw new ClientException(_('System error uploading file.'));
return;
} }
$filename = $_FILES['restorefile']['tmp_name']; $filename = $_FILES['restorefile']['tmp_name'];
@ -210,7 +204,7 @@ class RestoreaccountAction extends Action
// Enqueue for processing. // Enqueue for processing.
$qm = QueueManager::get(); $qm = QueueManager::get();
$qm->enqueue(array(common_current_user(), $xml, false), 'feedimp'); $qm->enqueue([common_current_user(), $xml, false], 'feedimp');
if ($qm instanceof UnQueueManager) { if ($qm instanceof UnQueueManager) {
// No active queuing means we've actually just completed the job! // No active queuing means we've actually just completed the job!

View File

@ -52,13 +52,14 @@ class SelftagAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->tag = $this->trimmed('tag'); $this->tag = $this->trimmed('tag');
@ -67,7 +68,7 @@ class SelftagAction extends Action
// TRANS: %s is the invalid list name. // TRANS: %s is the invalid list name.
$this->clientError(sprintf(_('Not a valid list: %s.'), $this->clientError(sprintf(_('Not a valid list: %s.'),
$this->tag)); $this->tag));
return; return null;
} }
$this->page = ($this->arg('page')) ? $this->arg('page') : 1; $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
@ -80,13 +81,11 @@ class SelftagAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare() * @return void is read only action?
*
* @return boolean is read only action?
*/ */
function handle($argarray) function handle()
{ {
parent::handle($argarray); parent::handle();
$this->showPage(); $this->showPage();
} }
@ -94,8 +93,6 @@ class SelftagAction extends Action
* Whips up a query to get a list of profiles based on the provided * Whips up a query to get a list of profiles based on the provided
* people tag and page, initalizes a ProfileList widget, and displays * people tag and page, initalizes a ProfileList widget, and displays
* it to the user. * it to the user.
*
* @return nothing
*/ */
function showContent() function showContent()
{ {
@ -195,7 +192,7 @@ class SelfTagProfileListItem extends ProfileListItem
$user = common_current_user(); $user = common_current_user();
if (!empty($user) && $user->id != $this->profile->id && if (!empty($user) && $user->id != $this->profile->getID() &&
$user->getProfile()->canTag($this->profile)) { $user->getProfile()->canTag($this->profile)) {
$yourtags = new PeopleTagsWidget($this->out, $user, $this->profile); $yourtags = new PeopleTagsWidget($this->out, $user, $this->profile);
$yourtags->show(); $yourtags->show();

View File

@ -4,7 +4,7 @@
* Copyright (C) 2012, StatusNet, Inc. * Copyright (C) 2012, StatusNet, Inc.
* *
* Stream of latest spam messages * Stream of latest spam messages
* *
* PHP version 5 * PHP version 5
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -34,13 +34,13 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
require_once INSTALLDIR.'/lib/noticelist.php'; require_once INSTALLDIR . '/lib/noticelist.php';
/** /**
* SpamAction * SpamAction
* *
* Shows the latest spam on the service * Shows the latest spam on the service
* *
* @category Spam * @category Spam
* @package StatusNet * @package StatusNet
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
@ -48,29 +48,30 @@ require_once INSTALLDIR.'/lib/noticelist.php';
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class SpamAction extends Action class SpamAction extends Action
{ {
var $page = null; var $page = null;
var $notices = null; var $notices = null;
function title() { function title()
{
return _("Latest Spam"); return _("Latest Spam");
} }
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
// User must be logged in. // User must be logged in.
@ -86,10 +87,10 @@ class SpamAction extends Action
$stream = new SpamNoticeStream($this->scoped); $stream = new SpamNoticeStream($this->scoped);
$this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, $this->notices = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1); NOTICES_PER_PAGE + 1);
if($this->page > 1 && $this->notices->N == 0) { if ($this->page > 1 && $this->notices->N == 0) {
throw new ClientException(_('No such page.'), 404); throw new ClientException(_('No such page.'), 404);
} }
@ -99,12 +100,10 @@ class SpamAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle(); parent::handle();
@ -130,10 +129,10 @@ class SpamAction extends Action
$this->showEmptyList(); $this->showEmptyList();
} }
$this->pagination($this->page > 1, $this->pagination($this->page > 1,
$cnt > NOTICES_PER_PAGE, $cnt > NOTICES_PER_PAGE,
$this->page, $this->page,
'spam'); 'spam');
} }
function showEmptyList() function showEmptyList()

View File

@ -54,14 +54,16 @@ class TrainAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws ServerException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
// User must be logged in. // User must be logged in.
@ -111,12 +113,11 @@ class TrainAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
* @throws ClientException
*/ */
function handle($argarray=null) function handle()
{ {
// Train // Train

View File

@ -1,32 +1,32 @@
<?php <?php
/** /**
* StatusNet - the distributed open-source microblogging tool * StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc. * Copyright (C) 2011, StatusNet, Inc.
* *
* Score of a notice by activity spam service * Score of a notice by activity spam service
* *
* PHP version 5 * PHP version 5
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* @category Spam * @category Spam
* @package StatusNet * @package StatusNet
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('STATUSNET')) {
exit(1); exit(1);
@ -43,7 +43,6 @@ if (!defined('STATUSNET')) {
* *
* @see DB_DataObject * @see DB_DataObject
*/ */
class Spam_score extends Managed_DataObject class Spam_score extends Managed_DataObject
{ {
const MAX_SCALE = 10000; const MAX_SCALE = 10000;
@ -53,27 +52,10 @@ class Spam_score extends Managed_DataObject
public $score; // float public $score; // float
public $created; // datetime public $created; // datetime
function saveNew($notice, $result) { public static function save($notice, $result)
{
$score = new Spam_score(); $orig = null;
$score->notice_id = $notice->id;
$score->score = $result->probability;
$score->is_spam = $result->isSpam;
$score->scaled = Spam_score::scale($score->score);
$score->created = common_sql_now();
$score->notice_created = $notice->created;
$score->insert();
self::blow('spam_score:notice_ids');
return $score;
}
function save($notice, $result) {
$orig = null;
$score = Spam_score::getKV('notice_id', $notice->id); $score = Spam_score::getKV('notice_id', $notice->id);
if (empty($score)) { if (empty($score)) {
@ -82,11 +64,11 @@ class Spam_score extends Managed_DataObject
$orig = clone($score); $orig = clone($score);
} }
$score->notice_id = $notice->id; $score->notice_id = $notice->id;
$score->score = $result->probability; $score->score = $result->probability;
$score->is_spam = $result->isSpam; $score->is_spam = $result->isSpam;
$score->scaled = Spam_score::scale($score->score); $score->scaled = Spam_score::scale($score->score);
$score->created = common_sql_now(); $score->created = common_sql_now();
$score->notice_created = $notice->created; $score->notice_created = $notice->created;
if (empty($orig)) { if (empty($orig)) {
@ -94,19 +76,12 @@ class Spam_score extends Managed_DataObject
} else { } else {
$score->update($orig); $score->update($orig);
} }
self::blow('spam_score:notice_ids'); self::blow('spam_score:notice_ids');
return $score; return $score;
} }
function delete($useWhere=false)
{
self::blow('spam_score:notice_ids');
self::blow('spam_score:notice_ids;last');
return parent::delete($useWhere);
}
/** /**
* The One True Thingy that must be defined and declared. * The One True Thingy that must be defined and declared.
*/ */
@ -116,20 +91,20 @@ class Spam_score extends Managed_DataObject
'description' => 'score of the notice per activityspam', 'description' => 'score of the notice per activityspam',
'fields' => array( 'fields' => array(
'notice_id' => array('type' => 'int', 'notice_id' => array('type' => 'int',
'not null' => true, 'not null' => true,
'description' => 'notice getting scored'), 'description' => 'notice getting scored'),
'score' => array('type' => 'double', 'score' => array('type' => 'double',
'not null' => true, 'not null' => true,
'description' => 'score for the notice (0.0, 1.0)'), 'description' => 'score for the notice (0.0, 1.0)'),
'scaled' => array('type' => 'int', 'scaled' => array('type' => 'int',
'description' => 'scaled score for the notice (0, 10000)'), 'description' => 'scaled score for the notice (0, 10000)'),
'is_spam' => array('type' => 'tinyint', 'is_spam' => array('type' => 'tinyint',
'description' => 'flag for spamosity'), 'description' => 'flag for spamosity'),
'created' => array('type' => 'datetime', 'created' => array('type' => 'datetime',
'not null' => true, 'not null' => true,
'description' => 'date this record was created'), 'description' => 'date this record was created'),
'notice_created' => array('type' => 'datetime', 'notice_created' => array('type' => 'datetime',
'description' => 'date the notice was created'), 'description' => 'date the notice was created'),
), ),
'primary key' => array('notice_id'), 'primary key' => array('notice_id'),
'foreign keys' => array( 'foreign keys' => array(
@ -153,7 +128,7 @@ class Spam_score extends Managed_DataObject
{ {
$score = new Spam_score(); $score = new Spam_score();
$score->whereAdd('scaled IS NULL'); $score->whereAdd('scaled IS NULL');
if ($score->find()) { if ($score->find()) {
while ($score->fetch()) { while ($score->fetch()) {
$orig = clone($score); $orig = clone($score);
@ -167,7 +142,7 @@ class Spam_score extends Managed_DataObject
{ {
$score = new Spam_score(); $score = new Spam_score();
$score->whereAdd('is_spam IS NULL'); $score->whereAdd('is_spam IS NULL');
if ($score->find()) { if ($score->find()) {
while ($score->fetch()) { while ($score->fetch()) {
$orig = clone($score); $orig = clone($score);
@ -181,7 +156,7 @@ class Spam_score extends Managed_DataObject
{ {
$score = new Spam_score(); $score = new Spam_score();
$score->whereAdd('notice_created IS NULL'); $score->whereAdd('notice_created IS NULL');
if ($score->find()) { if ($score->find()) {
while ($score->fetch()) { while ($score->fetch()) {
$notice = Notice::getKV('id', $score->notice_id); $notice = Notice::getKV('id', $score->notice_id);
@ -194,9 +169,35 @@ class Spam_score extends Managed_DataObject
} }
} }
function saveNew($notice, $result)
{
$score = new Spam_score();
$score->notice_id = $notice->id;
$score->score = $result->probability;
$score->is_spam = $result->isSpam;
$score->scaled = Spam_score::scale($score->score);
$score->created = common_sql_now();
$score->notice_created = $notice->created;
$score->insert();
self::blow('spam_score:notice_ids');
return $score;
}
public static function scale($score) public static function scale($score)
{ {
$raw = round($score * Spam_score::MAX_SCALE); $raw = round($score * Spam_score::MAX_SCALE);
return max(0, min(Spam_score::MAX_SCALE, $raw)); return max(0, min(Spam_score::MAX_SCALE, $raw));
} }
public function delete($useWhere = false)
{
self::blow('spam_score:notice_ids');
self::blow('spam_score:notice_ids;last');
return parent::delete($useWhere);
}
} }

View File

@ -63,21 +63,22 @@ class ImportdeliciousAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$cur = common_current_user(); $cur = common_current_user();
if (empty($cur)) { if (empty($cur)) {
// TRANS: Client exception thrown when trying to import bookmarks without being logged in. // TRANS: Client exception thrown when trying to import bookmarks without being logged in.
throw new ClientException(_m('Only logged-in users can '. throw new ClientException(_m('Only logged-in users can ' .
'import del.icio.us backups.'), 'import del.icio.us backups.'),
403); 403);
} }
if (!$cur->hasRight(BookmarkPlugin::IMPORTDELICIOUS)) { if (!$cur->hasRight(BookmarkPlugin::IMPORTDELICIOUS)) {
@ -91,13 +92,12 @@ class ImportdeliciousAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
* @throws ClientException
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->importDelicious(); $this->importDelicious();
@ -113,6 +113,7 @@ class ImportdeliciousAction extends Action
* Uses the DeliciousBackupImporter class; may take a long time! * Uses the DeliciousBackupImporter class; may take a long time!
* *
* @return void * @return void
* @throws ClientException
*/ */
function importDelicious() function importDelicious()
{ {
@ -124,48 +125,40 @@ class ImportdeliciousAction extends Action
} }
switch ($_FILES[ImportDeliciousForm::FILEINPUT]['error']) { switch ($_FILES[ImportDeliciousForm::FILEINPUT]['error']) {
case UPLOAD_ERR_OK: // success, jump out case UPLOAD_ERR_OK: // success, jump out
break; break;
case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_INI_SIZE:
// TRANS: Client exception thrown when an uploaded file is too large. // TRANS: Client exception thrown when an uploaded file is too large.
throw new ClientException(_m('The uploaded file exceeds the ' . throw new ClientException(_m('The uploaded file exceeds the ' .
'upload_max_filesize directive in php.ini.')); 'upload_max_filesize directive in php.ini.'));
return; case UPLOAD_ERR_FORM_SIZE:
case UPLOAD_ERR_FORM_SIZE: throw new ClientException(
throw new ClientException( // TRANS: Client exception thrown when an uploaded file is too large.
// TRANS: Client exception thrown when an uploaded file is too large. _m('The uploaded file exceeds the MAX_FILE_SIZE directive' .
_m('The uploaded file exceeds the MAX_FILE_SIZE directive' . ' that was specified in the HTML form.'));
' that was specified in the HTML form.')); case UPLOAD_ERR_PARTIAL:
return; @unlink($_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']);
case UPLOAD_ERR_PARTIAL: // TRANS: Client exception thrown when a file was only partially uploaded.
@unlink($_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']); throw new ClientException(_m('The uploaded file was only' .
// TRANS: Client exception thrown when a file was only partially uploaded. ' partially uploaded.'));
throw new ClientException(_m('The uploaded file was only' . case UPLOAD_ERR_NO_FILE:
' partially uploaded.')); // No file; probably just a non-AJAX submission.
return; // TRANS: Client exception thrown when a file upload has failed.
case UPLOAD_ERR_NO_FILE: throw new ClientException(_m('No uploaded file.'));
// No file; probably just a non-AJAX submission. case UPLOAD_ERR_NO_TMP_DIR:
// TRANS: Client exception thrown when a file upload has failed. // TRANS: Client exception thrown when a temporary folder is not present.
throw new ClientException(_m('No uploaded file.')); throw new ClientException(_m('Missing a temporary folder.'));
return; case UPLOAD_ERR_CANT_WRITE:
case UPLOAD_ERR_NO_TMP_DIR: // TRANS: Client exception thrown when writing to disk is not possible.
// TRANS: Client exception thrown when a temporary folder is not present. throw new ClientException(_m('Failed to write file to disk.'));
throw new ClientException(_m('Missing a temporary folder.')); case UPLOAD_ERR_EXTENSION:
return; // TRANS: Client exception thrown when a file upload has been stopped.
case UPLOAD_ERR_CANT_WRITE: throw new ClientException(_m('File upload stopped by extension.'));
// TRANS: Client exception thrown when writing to disk is not possible. default:
throw new ClientException(_m('Failed to write file to disk.')); common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " .
return; $_FILES[ImportDeliciousForm::FILEINPUT]['error']);
case UPLOAD_ERR_EXTENSION: // TRANS: Client exception thrown when a file upload operation has failed.
// TRANS: Client exception thrown when a file upload has been stopped. throw new ClientException(_m('System error uploading file.'));
throw new ClientException(_m('File upload stopped by extension.'));
return;
default:
common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " .
$_FILES[ImportDeliciousForm::FILEINPUT]['error']);
// TRANS: Client exception thrown when a file upload operation has failed.
throw new ClientException(_m('System error uploading file.'));
return;
} }
$filename = $_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name']; $filename = $_FILES[ImportDeliciousForm::FILEINPUT]['tmp_name'];
@ -174,19 +167,19 @@ class ImportdeliciousAction extends Action
if (!file_exists($filename)) { if (!file_exists($filename)) {
// TRANS: Server exception thrown when a file upload cannot be found. // TRANS: Server exception thrown when a file upload cannot be found.
// TRANS: %s is the file that could not be found. // TRANS: %s is the file that could not be found.
throw new ServerException(sprintf(_m('No such file "%s".'),$filename)); throw new ServerException(sprintf(_m('No such file "%s".'), $filename));
} }
if (!is_file($filename)) { if (!is_file($filename)) {
// TRANS: Server exception thrown when a file upload is incorrect. // TRANS: Server exception thrown when a file upload is incorrect.
// TRANS: %s is the irregular file. // TRANS: %s is the irregular file.
throw new ServerException(sprintf(_m('Not a regular file: "%s".'),$filename)); throw new ServerException(sprintf(_m('Not a regular file: "%s".'), $filename));
} }
if (!is_readable($filename)) { if (!is_readable($filename)) {
// TRANS: Server exception thrown when a file upload is not readable. // TRANS: Server exception thrown when a file upload is not readable.
// TRANS: %s is the file that could not be read. // TRANS: %s is the file that could not be read.
throw new ServerException(sprintf(_m('File "%s" not readable.'),$filename)); throw new ServerException(sprintf(_m('File "%s" not readable.'), $filename));
} }
common_debug(sprintf("Getting backup from file '%s'.", $filename)); common_debug(sprintf("Getting backup from file '%s'.", $filename));
@ -196,7 +189,7 @@ class ImportdeliciousAction extends Action
// Enqueue for processing. // Enqueue for processing.
$qm = QueueManager::get(); $qm = QueueManager::get();
$qm->enqueue(array(common_current_user(), $html), 'dlcsback'); $qm->enqueue([common_current_user(), $html], 'dlcsback');
if ($qm instanceof UnQueueManager) { if ($qm instanceof UnQueueManager) {
// No active queuing means we've actually just completed the job! // No active queuing means we've actually just completed the job!
@ -224,12 +217,12 @@ class ImportdeliciousAction extends Action
{ {
if ($this->success) { if ($this->success) {
$this->element('p', null, $this->element('p', null,
// TRANS: Success message after importing bookmarks. // TRANS: Success message after importing bookmarks.
_m('Bookmarks have been imported. Your bookmarks should now appear in search and your profile page.')); _m('Bookmarks have been imported. Your bookmarks should now appear in search and your profile page.'));
} else if ($this->inprogress) { } else if ($this->inprogress) {
$this->element('p', null, $this->element('p', null,
// TRANS: Busy message for importing bookmarks. // TRANS: Busy message for importing bookmarks.
_m('Bookmarks are being imported. Please wait a few minutes for results.')); _m('Bookmarks are being imported. Please wait a few minutes for results.'));
} else { } else {
$form = new ImportDeliciousForm($this); $form = new ImportDeliciousForm($this);
$form->show(); $form->show();
@ -272,9 +265,8 @@ class ImportDeliciousForm extends Form
* *
* @param HTMLOutputter $out output channel * @param HTMLOutputter $out output channel
* *
* @return ImportDeliciousForm this
*/ */
function __construct($out=null) function __construct($out = null)
{ {
parent::__construct($out); parent::__construct($out);
$this->enctype = 'multipart/form-data'; $this->enctype = 'multipart/form-data';
@ -312,17 +304,17 @@ class ImportDeliciousForm extends Form
$this->out->elementStart('p', 'instructions'); $this->out->elementStart('p', 'instructions');
// TRANS: Form instructions for importing bookmarks. // TRANS: Form instructions for importing bookmarks.
$this->out->raw(_m('You can upload a backed-up '. $this->out->raw(_m('You can upload a backed-up ' .
'delicious.com bookmarks file.')); 'delicious.com bookmarks file.'));
$this->out->elementEnd('p'); $this->out->elementEnd('p');
$this->out->elementStart('ul', 'form_data'); $this->out->elementStart('ul', 'form_data');
$this->out->elementStart('li', array ('id' => 'settings_attach')); $this->out->elementStart('li', array('id' => 'settings_attach'));
$this->out->element('input', array('name' => self::FILEINPUT, $this->out->element('input', array('name' => self::FILEINPUT,
'type' => 'file', 'type' => 'file',
'id' => self::FILEINPUT)); 'id' => self::FILEINPUT));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$this->out->elementEnd('ul'); $this->out->elementEnd('ul');
@ -339,11 +331,11 @@ class ImportDeliciousForm extends Form
function formActions() function formActions()
{ {
$this->out->submit('submit', $this->out->submit('submit',
// TRANS: Button text on form to import bookmarks. // TRANS: Button text on form to import bookmarks.
_m('BUTTON', 'Upload'), _m('BUTTON', 'Upload'),
'submit', 'submit',
null, null,
// TRANS: Button title on form to import bookmarks. // TRANS: Button title on form to import bookmarks.
_m('Upload the file.')); _m('Upload the file.'));
} }
} }

View File

@ -54,13 +54,14 @@ class NoticebyurlAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->file = File::getKV('id', $this->trimmed('id')); $this->file = File::getKV('id', $this->trimmed('id'));
@ -102,11 +103,9 @@ class NoticebyurlAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
$this->showPage(); $this->showPage();
} }

View File

@ -4,7 +4,7 @@
* Copyright (C) 2011, StatusNet, Inc. * Copyright (C) 2011, StatusNet, Inc.
* *
* Log into a site globally * Log into a site globally
* *
* PHP version 5 * PHP version 5
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -44,7 +44,6 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class GloballoginAction extends GlobalApiAction class GloballoginAction extends GlobalApiAction
{ {
var $password; var $password;
@ -52,14 +51,14 @@ class GloballoginAction extends GlobalApiAction
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare(array $args = [])
function prepare($argarray)
{ {
parent::prepare($argarray); parent::prepare($args);
$password = $this->trimmed('password'); $password = $this->trimmed('password');
@ -75,14 +74,12 @@ class GloballoginAction extends GlobalApiAction
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle()
function handle($argarray=null)
{ {
try { try {
// FIXME: $email and $password aren't defined
$url = DomainStatusNetworkPlugin::login($email, $password); $url = DomainStatusNetworkPlugin::login($email, $password);
$this->showSuccess(array('url' => $url)); $this->showSuccess(array('url' => $url));
} catch (ClientException $ce) { } catch (ClientException $ce) {

View File

@ -50,28 +50,28 @@ class GlobalrecoverAction extends GlobalApiAction
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = array())
{ {
parent::prepare($argarray); parent::prepare($args);
return true; return true;
} }
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
try { try {
// FIXME: $email isn't defined
DomainStatusNetworkPlugin::recoverPassword($email); DomainStatusNetworkPlugin::recoverPassword($email);
$this->showSuccess(); $this->showSuccess();
} catch (ClientException $ce) { } catch (ClientException $ce) {

View File

@ -50,15 +50,15 @@ class GlobalregisterAction extends GlobalApiAction
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
try { try {
parent::prepare($argarray); parent::prepare($args);
return true; return true;
} catch (ClientException $e) { } catch (ClientException $e) {
$this->showError($e->getMessage(), $e->getCode()); $this->showError($e->getMessage(), $e->getCode());
@ -73,12 +73,10 @@ class GlobalregisterAction extends GlobalApiAction
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
try { try {
$confirm = DomainStatusNetworkPlugin::registerEmail($this->email); $confirm = DomainStatusNetworkPlugin::registerEmail($this->email);

View File

@ -75,9 +75,9 @@ class EmailregisterAction extends Action
protected $error; protected $error;
protected $complete; protected $complete;
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if (common_config('site', 'closed')) { if (common_config('site', 'closed')) {
// TRANS: Client exception trown when registration by e-mail is not allowed. // TRANS: Client exception trown when registration by e-mail is not allowed.
@ -165,28 +165,27 @@ class EmailregisterAction extends Action
function title() function title()
{ {
switch ($this->state) { switch ($this->state) {
case self::NEWREGISTER: case self::NEWREGISTER:
case self::NEWEMAIL: case self::NEWEMAIL:
// TRANS: Title for registration page. // TRANS: Title for registration page.
return _m('TITLE','Register'); return _m('TITLE', 'Register');
break; break;
case self::SETPASSWORD: case self::SETPASSWORD:
case self::CONFIRMINVITE: case self::CONFIRMINVITE:
case self::CONFIRMREGISTER: case self::CONFIRMREGISTER:
// TRANS: Title for page where to register with a confirmation code. // TRANS: Title for page where to register with a confirmation code.
return _m('TITLE','Complete registration'); return _m('TITLE', 'Complete registration');
break; break;
} }
} }
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
* @throws Exception
*/ */
function handle($argarray=null) function handle()
{ {
$cur = common_current_user(); $cur = common_current_user();
@ -195,21 +194,21 @@ class EmailregisterAction extends Action
} }
switch ($this->state) { switch ($this->state) {
case self::NEWREGISTER: case self::NEWREGISTER:
$this->showRegistrationForm(); $this->showRegistrationForm();
break; break;
case self::NEWEMAIL: case self::NEWEMAIL:
$this->registerUser(); $this->registerUser();
break; break;
case self::CONFIRMINVITE: case self::CONFIRMINVITE:
$this->confirmRegistration(); $this->confirmRegistration();
break; break;
case self::CONFIRMREGISTER: case self::CONFIRMREGISTER:
$this->confirmRegistration(); $this->confirmRegistration();
break; break;
case self::SETPASSWORD: case self::SETPASSWORD:
$this->setPassword(); $this->setPassword();
break; break;
} }
return; return;
} }
@ -235,7 +234,7 @@ class EmailregisterAction extends Action
// TRANS: Confirmation text after initial registration. // TRANS: Confirmation text after initial registration.
// TRANS: %s an e-mail address. // TRANS: %s an e-mail address.
$prompt = sprintf(_m('An email was sent to %s to confirm that address. Check your email inbox for instructions.'), $prompt = sprintf(_m('An email was sent to %s to confirm that address. Check your email inbox for instructions.'),
$this->email); $this->email);
$this->complete = $prompt; $this->complete = $prompt;
@ -253,12 +252,17 @@ class EmailregisterAction extends Action
$nickname = $this->nicknameFromEmail($email); $nickname = $this->nicknameFromEmail($email);
$this->form = new ConfirmRegistrationForm($this, $this->form = new ConfirmRegistrationForm($this,
$nickname, $nickname,
$email, $email,
$this->code); $this->code);
$this->showPage(); $this->showPage();
} }
function nicknameFromEmail($email)
{
return EmailRegistrationPlugin::nicknameFromEmail($email);
}
function setPassword() function setPassword()
{ {
if (Event::handle('StartRegistrationTry', array($this))) { if (Event::handle('StartRegistrationTry', array($this))) {
@ -293,9 +297,9 @@ class EmailregisterAction extends Action
try { try {
$fields = array('nickname' => $this->nickname, $fields = array('nickname' => $this->nickname,
'email' => $email, 'email' => $email,
'password' => $this->password1, 'password' => $this->password1,
'email_confirmed' => true); 'email_confirmed' => true);
if (!empty($this->invitation)) { if (!empty($this->invitation)) {
$fields['code'] = $this->invitation->code; $fields['code'] = $this->invitation->code;
@ -346,23 +350,23 @@ class EmailregisterAction extends Action
$headers['From'] = mail_notify_from(); $headers['From'] = mail_notify_from();
$headers['To'] = trim($confirm->address); $headers['To'] = trim($confirm->address);
// TRANS: Subject for confirmation e-mail. // TRANS: Subject for confirmation e-mail.
// TRANS: %s is the StatusNet sitename. // TRANS: %s is the StatusNet sitename.
$headers['Subject'] = sprintf(_m('Confirm your registration on %s'), $sitename); $headers['Subject'] = sprintf(_m('Confirm your registration on %s'), $sitename);
$confirmUrl = common_local_url('register', array('code' => $confirm->code)); $confirmUrl = common_local_url('register', array('code' => $confirm->code));
// TRANS: Body for confirmation e-mail. // TRANS: Body for confirmation e-mail.
// TRANS: %1$s is the StatusNet sitename, %2$s is the confirmation URL. // TRANS: %1$s is the StatusNet sitename, %2$s is the confirmation URL.
$body = sprintf(_m('Someone (probably you) has requested an account on %1$s using this email address.'. $body = sprintf(_m('Someone (probably you) has requested an account on %1$s using this email address.' .
"\n". "\n" .
'To confirm the address, click the following URL or copy it into the address bar of your browser.'. 'To confirm the address, click the following URL or copy it into the address bar of your browser.' .
"\n". "\n" .
'%2$s'. '%2$s' .
"\n". "\n" .
'If it was not you, you can safely ignore this message.'), 'If it was not you, you can safely ignore this message.'),
$sitename, $sitename,
$confirmUrl); $confirmUrl);
mail_send($recipients, $headers, $body); mail_send($recipients, $headers, $body);
} }
@ -400,11 +404,6 @@ class EmailregisterAction extends Action
return false; return false;
} }
function nicknameFromEmail($email)
{
return EmailRegistrationPlugin::nicknameFromEmail($email);
}
/** /**
* A local menu * A local menu
* *

View File

@ -51,13 +51,15 @@ class GroupinboxAction extends GroupAction
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws NicknameException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$cur = common_current_user(); $cur = common_current_user();
@ -101,8 +103,8 @@ class GroupinboxAction extends GroupAction
} }
$this->gm = Group_message::forGroup($this->group, $this->gm = Group_message::forGroup($this->group,
($this->page - 1) * MESSAGES_PER_PAGE, ($this->page - 1) * MESSAGES_PER_PAGE,
MESSAGES_PER_PAGE + 1); MESSAGES_PER_PAGE + 1);
return true; return true;
} }
@ -128,20 +130,18 @@ class GroupinboxAction extends GroupAction
$this->element('p', 'guide', _m('This group has not received any private messages.')); $this->element('p', 'guide', _m('This group has not received any private messages.'));
} }
$this->pagination($this->page > 1, $this->pagination($this->page > 1,
$cnt > MESSAGES_PER_PAGE, $cnt > MESSAGES_PER_PAGE,
$this->page, $this->page,
'groupinbox', 'groupinbox',
array('nickname' => $this->group->nickname)); array('nickname' => $this->group->nickname));
} }
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
$this->showPage(); $this->showPage();
} }
@ -176,8 +176,8 @@ class GroupinboxAction extends GroupAction
// TRANS: Page title for any but first group page. // TRANS: Page title for any but first group page.
// TRANS: %1$s is a group name, $2$s is a page number. // TRANS: %1$s is a group name, $2$s is a page number.
return sprintf(_m('%1$s group inbox, page %2$d'), return sprintf(_m('%1$s group inbox, page %2$d'),
$base, $base,
$this->page); $this->page);
} }
} }
@ -190,7 +190,7 @@ class GroupinboxAction extends GroupAction
*/ */
function showPageNotice() function showPageNotice()
{ {
$instr = $this->getInstructions(); $instr = $this->getInstructions();
$output = common_markup_to_html($instr); $output = common_markup_to_html($instr);
$this->elementStart('div', 'instructions'); $this->elementStart('div', 'instructions');

View File

@ -53,13 +53,15 @@ class NewgroupmessageAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws NicknameException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->user = common_current_user(); $this->user = common_current_user();
@ -71,7 +73,7 @@ class NewgroupmessageAction extends Action
if (!$this->user->hasRight(Right::NEWMESSAGE)) { if (!$this->user->hasRight(Right::NEWMESSAGE)) {
// TRANS: Exception thrown when user %s is not allowed to send a private group message. // TRANS: Exception thrown when user %s is not allowed to send a private group message.
throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'), throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'),
$this->user->nickname)); $this->user->nickname));
} }
$nicknameArg = $this->trimmed('nickname'); $nicknameArg = $this->trimmed('nickname');
@ -112,11 +114,9 @@ class NewgroupmessageAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
if ($this->isPost()) { if ($this->isPost()) {
$this->sendNewMessage(); $this->sendNewMessage();
@ -125,12 +125,6 @@ class NewgroupmessageAction extends Action
} }
} }
function showNoticeForm()
{
$form = new GroupMessageForm($this, $this->group);
$form->show();
}
function sendNewMessage() function sendNewMessage()
{ {
$gm = Group_message::send($this->user, $this->group, $this->text); $gm = Group_message::send($this->user, $this->group, $this->text);
@ -143,10 +137,10 @@ class NewgroupmessageAction extends Action
$this->elementEnd('head'); $this->elementEnd('head');
$this->elementStart('body'); $this->elementStart('body');
$this->element('p', $this->element('p',
array('id' => 'command_result'), array('id' => 'command_result'),
// TRANS: Succes text after sending a direct message to group %s. // TRANS: Succes text after sending a direct message to group %s.
sprintf(_m('Direct message to %s sent.'), sprintf(_m('Direct message to %s sent.'),
$this->group->nickname)); $this->group->nickname));
$this->elementEnd('body'); $this->elementEnd('body');
$this->endHTML(); $this->endHTML();
} else { } else {
@ -154,6 +148,12 @@ class NewgroupmessageAction extends Action
} }
} }
function showNoticeForm()
{
$form = new GroupMessageForm($this, $this->group);
$form->show();
}
function title() function title()
{ {
// TRANS: Title of form for new private group message. // TRANS: Title of form for new private group message.

View File

@ -54,20 +54,22 @@ class ShowgroupmessageAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws ServerException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->user = common_current_user(); $this->user = common_current_user();
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client exception thrown when trying to view group private messages without being logged in. // TRANS: Client exception thrown when trying to view group private messages without being logged in.
throw new ClientException(_m('Only logged-in users can view private messages.'), throw new ClientException(_m('Only logged-in users can view private messages.'),
403); 403);
} }
$id = $this->trimmed('id'); $id = $this->trimmed('id');
@ -104,11 +106,9 @@ class ShowgroupmessageAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
$this->showPage(); $this->showPage();
} }
@ -121,9 +121,9 @@ class ShowgroupmessageAction extends Action
// TRANS: Title for private group message. // TRANS: Title for private group message.
// TRANS: %1$s is the sender name, %2$s is the group name, %3$s is a timestamp. // TRANS: %1$s is the sender name, %2$s is the group name, %3$s is a timestamp.
return sprintf(_m('Message from %1$s to group %2$s on %3$s'), return sprintf(_m('Message from %1$s to group %2$s on %3$s'),
$this->sender->nickname, $this->sender->nickname,
$this->group->nickname, $this->group->nickname,
common_exact_date($this->gm->created)); common_exact_date($this->gm->created));
} }
/** /**
@ -161,8 +161,8 @@ class ShowgroupmessageAction extends Action
function lastModified() function lastModified()
{ {
return max(strtotime($this->group->modified), return max(strtotime($this->group->modified),
strtotime($this->sender->modified), strtotime($this->sender->modified),
strtotime($this->gm->modified)); strtotime($this->gm->modified));
} }
/** /**
@ -182,11 +182,11 @@ class ShowgroupmessageAction extends Action
} }
return 'W/"' . implode(':', array($this->arg('action'), return 'W/"' . implode(':', array($this->arg('action'),
common_user_cache_hash(), common_user_cache_hash(),
common_language(), common_language(),
$this->gm->id, $this->gm->id,
strtotime($this->sender->modified), strtotime($this->sender->modified),
strtotime($this->group->modified), strtotime($this->group->modified),
$avtime)) . '"'; $avtime)) . '"';
} }
} }

View File

@ -66,13 +66,14 @@ class NewPollAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->user = common_current_user(); $this->user = common_current_user();
@ -100,13 +101,11 @@ class NewPollAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->newPoll(); $this->newPoll();

View File

@ -45,12 +45,12 @@ if (!defined('STATUSNET')) {
*/ */
class RespondPollAction extends Action class RespondPollAction extends Action
{ {
protected $user = null; protected $user = null;
protected $error = null; protected $error = null;
protected $complete = null; protected $complete = null;
protected $poll = null; protected $poll = null;
protected $selection = null; protected $selection = null;
/** /**
* Returns the title of the action * Returns the title of the action
@ -66,13 +66,14 @@ class RespondPollAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if ($this->boolean('ajax')) { if ($this->boolean('ajax')) {
GNUsocial::setApi(true); GNUsocial::setApi(true);
} }
@ -82,7 +83,7 @@ class RespondPollAction extends Action
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client exception thrown trying to respond to a poll while not logged in. // TRANS: Client exception thrown trying to respond to a poll while not logged in.
throw new ClientException(_m('You must be logged in to respond to a poll.'), throw new ClientException(_m('You must be logged in to respond to a poll.'),
403); 403);
} }
if ($this->isPost()) { if ($this->isPost()) {
@ -109,13 +110,11 @@ class RespondPollAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->respondPoll(); $this->respondPoll();
@ -135,8 +134,8 @@ class RespondPollAction extends Action
{ {
try { try {
$notice = Poll_response::saveNew($this->user->getProfile(), $notice = Poll_response::saveNew($this->user->getProfile(),
$this->poll, $this->poll,
$this->selection); $this->selection);
} catch (ClientException $ce) { } catch (ClientException $ce) {
$this->error = $ce->getMessage(); $this->error = $ce->getMessage();
$this->showPage(); $this->showPage();

View File

@ -45,12 +45,12 @@ if (!defined('STATUSNET')) {
*/ */
class QnaclosequestionAction extends Action class QnaclosequestionAction extends Action
{ {
protected $user = null; protected $user = null;
protected $error = null; protected $error = null;
protected $complete = null; protected $complete = null;
protected $question = null; protected $question = null;
protected $answer = null; protected $answer = null;
/** /**
* Returns the title of the action * Returns the title of the action
@ -66,13 +66,14 @@ class QnaclosequestionAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if ($this->boolean('ajax')) { if ($this->boolean('ajax')) {
GNUsocial::setApi(true); GNUsocial::setApi(true);
} }
@ -81,7 +82,7 @@ class QnaclosequestionAction extends Action
if (empty($this->user)) { if (empty($this->user)) {
throw new ClientException( throw new ClientException(
// TRANS: Client exception thrown trying to close a question when not logged in // TRANS: Client exception thrown trying to close a question when not logged in
_m("You must be logged in to close a question."), _m("You must be logged in to close a question."),
403 403
); );
@ -104,13 +105,11 @@ class QnaclosequestionAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->closeQuestion(); $this->closeQuestion();

View File

@ -45,12 +45,11 @@ if (!defined('STATUSNET')) {
*/ */
class QnanewanswerAction extends Action class QnanewanswerAction extends Action
{ {
protected $user = null; public $question = null;
protected $error = null; protected $user = null;
protected $error = null;
protected $complete = null; protected $complete = null;
protected $content = null;
public $question = null;
protected $content = null;
/** /**
* Returns the title of the action * Returns the title of the action
@ -66,13 +65,14 @@ class QnanewanswerAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if ($this->boolean('ajax')) { if ($this->boolean('ajax')) {
GNUsocial::setApi(true); GNUsocial::setApi(true);
} }
@ -81,7 +81,7 @@ class QnanewanswerAction extends Action
if (empty($this->user)) { if (empty($this->user)) {
throw new ClientException( throw new ClientException(
// TRANS: Client exception thrown trying to answer a question while not logged in. // TRANS: Client exception thrown trying to answer a question while not logged in.
_m("You must be logged in to answer to a question."), _m("You must be logged in to answer to a question."),
403 403
); );
@ -97,7 +97,7 @@ class QnanewanswerAction extends Action
if (empty($this->question)) { if (empty($this->question)) {
throw new ClientException( throw new ClientException(
// TRANS: Client exception thrown trying to respond to a non-existing question. // TRANS: Client exception thrown trying to respond to a non-existing question.
_m('Invalid or missing question.'), _m('Invalid or missing question.'),
404 404
); );
@ -111,13 +111,11 @@ class QnanewanswerAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->newAnswer(); $this->newAnswer();
@ -172,39 +170,24 @@ class QnanewanswerAction extends Action
} }
/** /**
* Show the Answer form * @param string $msg An error message, if any
* *
* @return void * @return void
*/ */
function showContent() function showForm($msg = null)
{ {
if (!empty($this->error)) { common_debug("show form - msg = $msg");
$this->element('p', 'error', $this->error); if ($this->boolean('ajax')) {
if ($msg) {
$this->ajaxErrorMsg($msg);
} else {
$this->ajaxShowForm();
}
return;
} }
$form = new QnanewanswerForm($this->question, $this); $this->msg = $msg;
$form->show(); $this->showPage();
return;
}
/**
* Return true if read only.
*
* MAY override
*
* @param array $args other arguments
*
* @return boolean is read only action?
*/
function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'HEAD') {
return true;
} else {
return false;
}
} }
/** /**
@ -244,7 +227,7 @@ class QnanewanswerAction extends Action
$this->startHTML('text/xml;charset=utf-8', true); $this->startHTML('text/xml;charset=utf-8', true);
$this->elementStart('head'); $this->elementStart('head');
// TRANS: Title for form to send answer to a question. // TRANS: Title for form to send answer to a question.
$this->element('title', null, _m('TITLE','Your answer')); $this->element('title', null, _m('TITLE', 'Your answer'));
$this->elementEnd('head'); $this->elementEnd('head');
$this->elementStart('body'); $this->elementStart('body');
@ -256,24 +239,39 @@ class QnanewanswerAction extends Action
} }
/** /**
* @param string $msg An error message, if any * Show the Answer form
* *
* @return void * @return void
*/ */
function showForm($msg = null) function showContent()
{ {
common_debug("show form - msg = $msg"); if (!empty($this->error)) {
if ($this->boolean('ajax')) { $this->element('p', 'error', $this->error);
if ($msg) {
$this->ajaxErrorMsg($msg);
} else {
$this->ajaxShowForm();
}
return;
} }
$this->msg = $msg; $form = new QnanewanswerForm($this->question, $this);
$this->showPage(); $form->show();
return;
}
/**
* Return true if read only.
*
* MAY override
*
* @param array $args other arguments
*
* @return boolean is read only action?
*/
function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'HEAD') {
return true;
} else {
return false;
}
} }
} }
@ -288,12 +286,15 @@ class NoticeAnswerListItem extends NoticeListItem
* Also initializes the profile attribute. * Also initializes the profile attribute.
* *
* @param Notice $notice The notice we'll display * @param Notice $notice The notice we'll display
* @param $out
* @param $question
* @param $answer
*/ */
function __construct($notice, $out=null, $question, $answer) function __construct($notice, $out, $question, $answer)
{ {
parent::__construct($notice, $out); parent::__construct($notice, $out);
$this->question = $question; $this->question = $question;
$this->answer = $answer; $this->answer = $answer;
} }
@ -334,7 +335,7 @@ class NoticeAnswerListItem extends NoticeListItem
$form->show(); $form->show();
} else { } else {
// TRANS: Error message displayed when an answer has no content. // TRANS: Error message displayed when an answer has no content.
$out->text(_m('Answer data is missing.')); $this->out->text(_m('Answer data is missing.'));
} }
$this->out->elementEnd('p'); $this->out->elementEnd('p');

View File

@ -45,10 +45,10 @@ if (!defined('STATUSNET')) {
*/ */
class QnanewquestionAction extends Action class QnanewquestionAction extends Action
{ {
protected $user = null; protected $user = null;
protected $error = null; protected $error = null;
protected $complete = null; protected $complete = null;
protected $title = null; protected $title = null;
protected $description = null; protected $description = null;
/** /**
@ -65,19 +65,20 @@ class QnanewquestionAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$this->user = common_current_user(); $this->user = common_current_user();
if (empty($this->user)) { if (empty($this->user)) {
throw new ClientException( throw new ClientException(
// TRANS: Client exception thrown trying to create a Question while not logged in. // TRANS: Client exception thrown trying to create a Question while not logged in.
_m('You must be logged in to post a question.'), _m('You must be logged in to post a question.'),
403 403
); );
@ -87,7 +88,7 @@ class QnanewquestionAction extends Action
$this->checkSessionToken(); $this->checkSessionToken();
} }
$this->title = $this->trimmed('title'); $this->title = $this->trimmed('title');
$this->description = $this->trimmed('description'); $this->description = $this->trimmed('description');
return true; return true;
@ -96,13 +97,11 @@ class QnanewquestionAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->newQuestion(); $this->newQuestion();
@ -228,7 +227,7 @@ class NoticeQuestionListItem extends NoticeListItem
* *
* @param Notice $notice The notice we'll display * @param Notice $notice The notice we'll display
*/ */
function __construct($notice, $out=null) function __construct($notice, $out = null)
{ {
parent::__construct($notice, $out); parent::__construct($notice, $out);
} }

View File

@ -45,11 +45,11 @@ if (!defined('STATUSNET')) {
*/ */
class QnareviseanswerAction extends Action class QnareviseanswerAction extends Action
{ {
protected $user = null; protected $user = null;
protected $error = null; protected $error = null;
protected $question = null; protected $question = null;
protected $answer = null; protected $answer = null;
protected $content = null; protected $content = null;
/** /**
* Returns the title of the action * Returns the title of the action
@ -65,13 +65,14 @@ class QnareviseanswerAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if ($this->boolean('ajax')) { if ($this->boolean('ajax')) {
GNUsocial::setApi(true); GNUsocial::setApi(true);
} }
@ -80,7 +81,7 @@ class QnareviseanswerAction extends Action
if (empty($this->user)) { if (empty($this->user)) {
throw new ClientException( throw new ClientException(
// TRANS: Client exception thrown trying to answer a question while not logged in. // TRANS: Client exception thrown trying to answer a question while not logged in.
_m("You must be logged in to answer to a question."), _m("You must be logged in to answer to a question."),
403 403
); );
@ -88,12 +89,12 @@ class QnareviseanswerAction extends Action
$id = substr($this->trimmed('id'), 7); $id = substr($this->trimmed('id'), 7);
$this->answer = QnA_Answer::getKV('id', $id); $this->answer = QnA_Answer::getKV('id', $id);
$this->question = $this->answer->getQuestion(); $this->question = $this->answer->getQuestion();
if (empty($this->answer) || empty($this->question)) { if (empty($this->answer) || empty($this->question)) {
throw new ClientException( throw new ClientException(
// TRANS: Client exception thrown trying to respond to a non-existing question. // TRANS: Client exception thrown trying to respond to a non-existing question.
_m('Invalid or missing answer.'), _m('Invalid or missing answer.'),
404 404
); );
@ -107,13 +108,11 @@ class QnareviseanswerAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->checkSessionToken(); $this->checkSessionToken();
@ -134,6 +133,83 @@ class QnareviseanswerAction extends Action
$this->showPage(); $this->showPage();
} }
/**
* Show the revise answer form
*
* @return void
*/
function showContent()
{
if (!empty($this->error)) {
$this->element('p', 'error', $this->error);
}
if ($this->boolean('ajax')) {
$this->showAjaxReviseForm();
} else {
$form = new QnareviseanswerForm($this->answer, $this);
$form->show();
}
return;
}
function showAjaxReviseForm()
{
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Form title for sending an answer.
$this->element('title', null, _m('TITLE', 'Answer'));
$this->elementEnd('head');
$this->elementStart('body');
$form = new QnareviseanswerForm($this->answer, $this);
$form->show();
$this->elementEnd('body');
$this->endHTML();
}
/**
* Mark the answer as the "best" answer
*
* @return void
*/
function markBest()
{
$question = $this->question;
$answer = $this->answer;
try {
// close the question to further answers
$orig = clone($question);
$question->closed = 1;
$result = $question->update($orig);
// mark this answer an the best answer
$orig = clone($answer);
$answer->best = 1;
$result = $answer->update($orig);
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
$this->showPage();
return;
}
if ($this->boolean('ajax')) {
common_debug("ajaxy part");
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Page title after sending an answer.
$this->element('title', null, _m('Answer'));
$this->elementEnd('head');
$this->elementStart('body');
$form = new QnashowanswerForm($this, $answer);
$form->show();
$this->elementEnd('body');
$this->endHTML();
} else {
common_redirect($this->answer->getUrl(), 303);
}
}
/** /**
* Revise the answer * Revise the answer
* *
@ -170,83 +246,6 @@ class QnareviseanswerAction extends Action
} }
} }
/**
* Mark the answer as the "best" answer
*
* @return void
*/
function markBest()
{
$question = $this->question;
$answer = $this->answer;
try {
// close the question to further answers
$orig = clone($question);
$question->closed = 1;
$result = $question->update($orig);
// mark this answer an the best answer
$orig = clone($answer);
$answer->best = 1;
$result = $answer->update($orig);
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
$this->showPage();
return;
}
if ($this->boolean('ajax')) {
common_debug("ajaxy part");
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Page title after sending an answer.
$this->element('title', null, _m('Answer'));
$this->elementEnd('head');
$this->elementStart('body');
$form = new QnashowanswerForm($this, $answer);
$form->show();
$this->elementEnd('body');
$this->endHTML();
} else {
common_redirect($this->answer->getUrl(), 303);
}
}
/**
* Show the revise answer form
*
* @return void
*/
function showContent()
{
if (!empty($this->error)) {
$this->element('p', 'error', $this->error);
}
if ($this->boolean('ajax')) {
$this->showAjaxReviseForm();
} else {
$form = new QnareviseanswerForm($this->answer, $this);
$form->show();
}
return;
}
function showAjaxReviseForm()
{
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Form title for sending an answer.
$this->element('title', null, _m('TITLE','Answer'));
$this->elementEnd('head');
$this->elementStart('body');
$form = new QnareviseanswerForm($this->answer, $this);
$form->show();
$this->elementEnd('body');
$this->endHTML();
}
/** /**
* Return true if read only. * Return true if read only.
* *

View File

@ -51,13 +51,15 @@ class QnashowanswerAction extends ShownoticeAction
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws ServerException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
Action::prepare($argarray); Action::prepare($args);
$this->id = $this->trimmed('id'); $this->id = $this->trimmed('id');
@ -117,8 +119,8 @@ class QnashowanswerAction extends ShownoticeAction
$question = $this->answer->getQuestion(); $question = $this->answer->getQuestion();
return sprintf( return sprintf(
// TRANS: Page title. // TRANS: Page title.
// TRANS: %1$s is the user who answered a question, %2$s is the question. // TRANS: %1$s is the user who answered a question, %2$s is the question.
_m('%1$s\'s answer to "%2$s"'), _m('%1$s\'s answer to "%2$s"'),
$this->user->nickname, $this->user->nickname,
$question->title $question->title

View File

@ -51,13 +51,15 @@ class QnashowquestionAction extends ShownoticeAction
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws ServerException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
Action::prepare($argarray); Action::prepare($args);
$this->id = $this->trimmed('id'); $this->id = $this->trimmed('id');
@ -129,7 +131,7 @@ class QnashowquestionAction extends ShownoticeAction
if (!empty($user)) { if (!empty($user)) {
$profile = $user->getProfile(); $profile = $user->getProfile();
$answer = QnA_Question::getAnswer($profile); $answer = QnA_Question::getAnswer($profile);
if (empty($answer)) { if (empty($answer)) {
$form = new QnanewanswerForm($this, $this->question, false); $form = new QnanewanswerForm($this, $this->question, false);
$form->show(); $form->show();
@ -150,8 +152,8 @@ class QnashowquestionAction extends ShownoticeAction
function title() function title()
{ {
return sprintf( return sprintf(
// TRANS: Page title for a question. // TRANS: Page title for a question.
// TRANS: %1$s is the nickname of the user who asked the question, %2$s is the question. // TRANS: %1$s is the nickname of the user who asked the question, %2$s is the question.
_m('%1$s\'s question: %2$s'), _m('%1$s\'s question: %2$s'),
$this->user->nickname, $this->user->nickname,
$this->question->title $this->question->title

View File

@ -45,12 +45,12 @@ if (!defined('STATUSNET')) {
*/ */
class Qnavote extends Action class Qnavote extends Action
{ {
protected $user = null; protected $user = null;
protected $error = null; protected $error = null;
protected $complete = null; protected $complete = null;
protected $question = null; protected $question = null;
protected $answer = null; protected $answer = null;
/** /**
* Returns the title of the action * Returns the title of the action
@ -66,13 +66,14 @@ class Qnavote extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if ($this->boolean('ajax')) { if ($this->boolean('ajax')) {
GNUsocial::setApi(true); GNUsocial::setApi(true);
} }
@ -82,7 +83,7 @@ class Qnavote extends Action
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client exception thrown trying to answer a question while not logged in. // TRANS: Client exception thrown trying to answer a question while not logged in.
throw new ClientException(_m('You must be logged in to answer to a question.'), throw new ClientException(_m('You must be logged in to answer to a question.'),
403); 403);
} }
if ($this->isPost()) { if ($this->isPost()) {
@ -105,13 +106,11 @@ class Qnavote extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
parent::handle($argarray); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->answer(); $this->answer();

View File

@ -47,18 +47,19 @@ if (!defined('STATUSNET')) {
class ClosechannelAction extends Action class ClosechannelAction extends Action
{ {
protected $channelKey = null; protected $channelKey = null;
protected $channel = null; protected $channel = null;
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if (!$this->isPost()) { if (!$this->isPost()) {
// TRANS: Client exception. Do not translate POST. // TRANS: Client exception. Do not translate POST.
@ -85,11 +86,9 @@ class ClosechannelAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
$this->channel->decrement(); $this->channel->decrement();

View File

@ -4,7 +4,7 @@
* Copyright (C) 2011, StatusNet, Inc. * Copyright (C) 2011, StatusNet, Inc.
* *
* action periodically pinged by a page to keep a channel alive * action periodically pinged by a page to keep a channel alive
* *
* PHP version 5 * PHP version 5
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -47,18 +47,19 @@ if (!defined('STATUSNET')) {
class KeepalivechannelAction extends Action class KeepalivechannelAction extends Action
{ {
protected $channelKey = null; protected $channelKey = null;
protected $channel = null; protected $channel = null;
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
if (!$this->isPost()) { if (!$this->isPost()) {
// TRANS: Client exception. Do not translate POST. // TRANS: Client exception. Do not translate POST.
@ -85,11 +86,9 @@ class KeepalivechannelAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
*/ */
function handle($argarray=null) function handle()
{ {
$this->channel->touch(); $this->channel->touch();

View File

@ -54,13 +54,15 @@ class ConfirmfirstemailAction extends Action
/** /**
* For initializing members of the class. * For initializing members of the class.
* *
* @param array $argarray misc. arguments * @param array $args misc. arguments
* *
* @return boolean true * @return boolean true
* @throws ClientException
* @throws ServerException
*/ */
function prepare($argarray) function prepare(array $args = [])
{ {
parent::prepare($argarray); parent::prepare($args);
$user = common_current_user(); $user = common_current_user();
if (!empty($user)) { if (!empty($user)) {
@ -75,7 +77,6 @@ class ConfirmfirstemailAction extends Action
if (empty($this->confirm)) { if (empty($this->confirm)) {
// TRANS: Client exception thrown when trying to register with a non-existing confirmation code. // TRANS: Client exception thrown when trying to register with a non-existing confirmation code.
throw new ClientException(_m('Confirmation code not found.')); throw new ClientException(_m('Confirmation code not found.'));
return;
} }
$this->user = User::getKV('id', $this->confirm->user_id); $this->user = User::getKV('id', $this->confirm->user_id);
@ -93,7 +94,7 @@ class ConfirmfirstemailAction extends Action
throw new ServerException(sprintf(_m('Unrecognized address type %s.'), $type)); throw new ServerException(sprintf(_m('Unrecognized address type %s.'), $type));
} }
if (!empty($this->user->email) && $this->user->email == $confirm->address) { if (!empty($this->user->email) && $this->user->email == $this->confirm->address) {
// TRANS: Client error for an already confirmed email/jabber/sms address. // TRANS: Client error for an already confirmed email/jabber/sms address.
throw new ClientException(_m('That address has already been confirmed.')); throw new ClientException(_m('That address has already been confirmed.'));
} }
@ -103,16 +104,14 @@ class ConfirmfirstemailAction extends Action
$this->checkSessionToken(); $this->checkSessionToken();
$password = $this->trimmed('password'); $password = $this->trimmed('password');
$confirm = $this->trimmed('confirm'); $confirm = $this->trimmed('confirm');
if (strlen($password) < 6) { if (strlen($password) < 6) {
// TRANS: Client exception thrown when trying to register with too short a password. // TRANS: Client exception thrown when trying to register with too short a password.
throw new ClientException(_m('Password too short.')); throw new ClientException(_m('Password too short.'));
return;
} else if (0 != strcmp($password, $confirm)) { } else if (0 != strcmp($password, $confirm)) {
// TRANS: Client exception thrown when trying to register without providing the same password twice. // TRANS: Client exception thrown when trying to register without providing the same password twice.
throw new ClientException(_m('Passwords do not match.')); throw new ClientException(_m('Passwords do not match.'));
return;
} }
$this->password = $password; $this->password = $password;
@ -124,14 +123,13 @@ class ConfirmfirstemailAction extends Action
/** /**
* Handler method * Handler method
* *
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void * @return void
* @throws AuthorizationException
*/ */
function handle($argarray=null) function handle()
{ {
$homepage = common_local_url('all', $homepage = common_local_url('all',
array('nickname' => $this->user->nickname)); array('nickname' => $this->user->nickname));
if ($this->isPost()) { if ($this->isPost()) {
$this->confirmUser(); $this->confirmUser();
@ -167,10 +165,10 @@ class ConfirmfirstemailAction extends Action
function showContent() function showContent()
{ {
$this->element('p', 'instructions', $this->element('p', 'instructions',
// TRANS: Form instructions. %s is the nickname of the to be registered user. // TRANS: Form instructions. %s is the nickname of the to be registered user.
sprintf(_m('You have confirmed the email address for your new user account %s. '. sprintf(_m('You have confirmed the email address for your new user account %s. ' .
'Use the form below to set your new password.'), 'Use the form below to set your new password.'),
$this->user->nickname)); $this->user->nickname));
$form = new ConfirmFirstEmailForm($this, $this->code); $form = new ConfirmFirstEmailForm($this, $this->code);
$form->show(); $form->show();
@ -202,7 +200,7 @@ class ConfirmFirstEmailForm extends Form
function action() function action()
{ {
return common_local_url('confirmfirstemail', return common_local_url('confirmfirstemail',
array('code' => $this->code)); array('code' => $this->code));
} }
function formClass() function formClass()
@ -216,14 +214,14 @@ class ConfirmFirstEmailForm extends Form
$this->out->elementStart('li'); $this->out->elementStart('li');
// TRANS: Field label. // TRANS: Field label.
$this->out->password('password', _m('New password'), $this->out->password('password', _m('New password'),
// TRANS: Field title for password field. // TRANS: Field title for password field.
_m('6 or more characters.')); _m('6 or more characters.'));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$this->out->elementStart('li'); $this->out->elementStart('li');
// TRANS: Field label for repeat password field. // TRANS: Field label for repeat password field.
$this->out->password('confirm', _m('LABEL','Confirm'), $this->out->password('confirm', _m('LABEL', 'Confirm'),
// TRANS: Field title for repeat password field. // TRANS: Field title for repeat password field.
_m('Same as password above.')); _m('Same as password above.'));
$this->out->elementEnd('li'); $this->out->elementEnd('li');
$this->out->elementEnd('ul'); $this->out->elementEnd('ul');
} }
@ -231,6 +229,6 @@ class ConfirmFirstEmailForm extends Form
function formActions() function formActions()
{ {
// TRANS: Button text for completing registration by e-mail. // TRANS: Button text for completing registration by e-mail.
$this->out->submit('save', _m('BUTTON','Save')); $this->out->submit('save', _m('BUTTON', 'Save'));
} }
} }

View File

@ -77,7 +77,7 @@ Plugins are configured using public instance attributes. To set their values,
site administrators use this syntax: site administrators use this syntax:
```php ```php
addPlugin('Sample', array('attr1' => 'foo', 'attr2' => 'bar')); addPlugin('Sample', ('attr1' => 'foo', 'attr2' => 'bar'));
``` ```
The same plugin class can be initialized multiple times with different arguments: The same plugin class can be initialized multiple times with different arguments:
@ -260,11 +260,11 @@ Take arguments for running
This method is called first, and it lets the action class get all its arguments This method is called first, and it lets the action class get all its arguments
and validate them. It's also the time to fetch any relevant data from the database. and validate them. It's also the time to fetch any relevant data from the database.
Action classes should run parent::prepare($args) as the first line of this Action classes should run parent::prepare(array $args = []) as the first line
method to make sure the default argument-processing happens. of this method to make sure the default argument-processing happens.
```php ```php
function prepare($args) function prepare(array $args = [])
{ {
parent::prepare($args); parent::prepare($args);
@ -286,9 +286,9 @@ should be done in the prepare() method; by the time handle() is called the
action should be more or less ready to go. action should be more or less ready to go.
```php ```php
function handle($args) function handle()
{ {
parent::handle($args); parent::handle();
$this->showPage(); $this->showPage();
} }