Removing MicroID as well as simplifying profileaction

sorry, forgot to commit in between
This commit is contained in:
Mikael Nordfeldth
2015-07-14 16:52:20 +02:00
parent e868ac41cd
commit 01a4ab30dc
12 changed files with 33 additions and 236 deletions

View File

@@ -36,35 +36,6 @@ class GalleryAction extends ProfileAction
parent::handle();
}
protected function doPreparation()
{
// showstream requires a nickname
$nickname_arg = $this->arg('nickname');
$nickname = common_canonical_nickname($nickname_arg);
// Permanent redirect on non-canonical nickname
if ($nickname_arg != $nickname) {
$args = array('nickname' => $nickname);
if ($this->arg('page') && $this->arg('page') != 1) {
$args['page'] = $this->arg['page'];
}
common_redirect(common_local_url($this->getActionName(), $args), 301);
}
$this->user = User::getKV('nickname', $nickname);
if (!$this->user) {
$group = Local_group::getKV('nickname', $nickname);
if ($group instanceof Local_group) {
common_redirect($group->getProfile()->getUrl());
}
// TRANS: Client error displayed when calling a profile action without specifying a user.
$this->clientError(_('No such user.'), 404);
}
$this->target = $this->user->getProfile();
}
function showContent()
{
$this->showTagsDropdown();

View File

@@ -126,17 +126,6 @@ abstract class ImPlugin extends Plugin
*/
abstract function daemonScreenname();
/**
* get the microid uri of a given screenname
*
* @param string $screenname screenname
*
* @return string microid uri
*/
function microiduri($screenname)
{
return $this->transport . ':' . $screenname;
}
//========================UTILITY FUNCTIONS USEFUL TO IMPLEMENTATIONS - MISC ========================\
/**
@@ -571,25 +560,12 @@ abstract class ImPlugin extends Plugin
$user_im_prefs->user_id = $action->notice->getProfile()->getID();
$user_im_prefs->transport = $this->transport;
if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->notice->uri) {
$id = new Microid($this->microiduri($user_im_prefs->screenname),
$action->notice->uri);
$action->element('meta', array('name' => 'microid',
'content' => $id->toString()));
}
} elseif ($action instanceof ShowstreamAction) {
$user_im_prefs = new User_im_prefs();
$user_im_prefs->user_id = $action->getTarget()->getID();
$user_im_prefs->transport = $this->transport;
if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->getTarget()->getUrl()) {
$id = new Microid($this->microiduri($user_im_prefs->screenname),
$action->selfUrl());
$action->element('meta', array('name' => 'microid',
'content' => $id->toString()));
}
}
}

View File

@@ -1,97 +0,0 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Microid class
*
* PHP version 5
*
* LICENCE: 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/>.
*
* @category ID
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2008 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
/**
* A class for microids
*
* @category ID
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @see http://microid.org/
*/
class Microid
{
/** Agent part of the ID. */
var $agent = null;
/** Resource part of the ID. */
var $resource = null;
/**
* Constructor
*
* @param string $agent Agent of the ID
* @param string $resource Resource part
*/
function __construct($agent, $resource)
{
$this->agent = $agent;
$this->resource = $resource;
}
/**
* Generate a MicroID string
*
* @return string MicroID for agent and resource
*/
function toString()
{
$agent_proto = $this->_getProto($this->agent);
$resource_proto = $this->_getProto($this->resource);
return $agent_proto.'+'.$resource_proto.':sha1:'.
sha1(sha1($this->agent).sha1($this->resource));
}
/**
* Utility for getting the protocol part of a URI
*
* @param string $uri URI to parse
*
* @return string scheme part of the URI
*/
function _getProto($uri)
{
$colon = strpos($uri, ':');
return substr($uri, 0, $colon);
}
}

View File

@@ -48,6 +48,36 @@ abstract class ProfileAction extends ManagedAction
protected $target = null; // Profile that we're showing
protected function doPreparation()
{
// showstream requires a nickname
$nickname_arg = $this->trimmed('nickname');
$nickname = common_canonical_nickname($nickname_arg);
// Permanent redirect on non-canonical nickname
if ($nickname_arg != $nickname) {
$args = array('nickname' => $nickname);
if ($this->arg('page') && $this->arg('page') != 1) {
$args['page'] = $this->arg['page'];
}
common_redirect(common_local_url($this->getActionName(), $args), 301);
}
try {
$user = User::getByNickname($nickname);
} catch (NoSuchUserException $e) {
$group = Local_group::getKV('nickname', $nickname);
if ($group instanceof Local_group) {
common_redirect($group->getProfile()->getUrl());
}
// No user nor group found, throw the NoSuchUserException again
throw $e;
}
$this->target = $user->getProfile();
}
protected function prepare(array $args=array())
{
// this will call ->doPreparation() which child classes use to set $this->target
@@ -65,11 +95,6 @@ abstract class ProfileAction extends ManagedAction
return true;
}
protected function profileActionPreparation()
{
// Nothing to do by default.
}
public function getTarget()
{
if (!$this->target instanceof Profile) {