Skip to content

Commit 76f5d33

Browse files
authored
Merge branch 'trunk' into add/emoji-support
2 parents cefc518 + dfc23ad commit 76f5d33

18 files changed

+516
-177
lines changed

Diff for: .github/workflows/phpunit.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ jobs:
1515
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
1616
strategy:
1717
matrix:
18-
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
18+
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1919
include:
2020
- wp-version: latest
21-
- wp-version: '6.5'
22-
php-versions: '7.0'
23-
- wp-version: '6.5'
24-
php-versions: '7.1'
21+
- wp-version: '5.9'
22+
php-versions: '7.2'
2523
steps:
2624
- name: Install svn
2725
run: |

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
* Support for custom emoji in interaction contents and actor names
13+
* Comment counts get updated when the plugin is activated/deactivated/deleted
1314
* Added a filter to make custom comment types manageable in WP.com Calypso
1415

1516
### Changed
1617

1718
* Hide ActivityPub post meta keys from the custom Fields UI
19+
* Bumped minimum required PHP version to 7.2
1820

1921
### Fixed
2022

2123
* Undefined array key warnings in various places
24+
* @-mentions in federated comments being displayed with a line break
2225
* Fetching replies from the same instance for Enable Mastodon Apps
2326
* Image captions not being included in the ActivityPub representation when the image is attached to the post
2427

Diff for: activitypub.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Author URI: https://automattic.com/
99
* License: MIT
1010
* License URI: http://opensource.org/licenses/MIT
11-
* Requires PHP: 7.0
11+
* Requires PHP: 7.2
1212
* Text Domain: activitypub
1313
* Domain Path: /languages
1414
*
@@ -44,12 +44,12 @@ function rest_init() {
4444
Rest\Inbox::init();
4545
Rest\Followers::init();
4646
Rest\Following::init();
47-
Rest\Webfinger::init();
4847
Rest\Comment::init();
4948
Rest\Server::init();
5049
Rest\Collection::init();
5150
Rest\Interaction::init();
5251
Rest\Post::init();
52+
( new Rest\Webfinger_Controller() )->register_routes();
5353

5454
// Load NodeInfo endpoints only if blog is public.
5555
if ( is_blog_public() ) {

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"description": "The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.",
44
"type": "wordpress-plugin",
55
"require": {
6-
"php": ">=7.0",
6+
"php": ">=7.2",
77
"composer/installers": "^1.0 || ^2.0"
88
},
99
"require-dev": {
10-
"phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8",
10+
"phpunit/phpunit": "^8 || ^9",
1111
"phpcompatibility/php-compatibility": "*",
1212
"phpcompatibility/phpcompatibility-wp": "*",
1313
"squizlabs/php_codesniffer": "3.*",

Diff for: includes/class-activitypub.php

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public static function init() {
6262
public static function activate() {
6363
self::flush_rewrite_rules();
6464
Scheduler::register_schedules();
65+
66+
\add_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ), 10, 3 );
67+
Migration::update_comment_counts();
6568
}
6669

6770
/**
@@ -70,13 +73,19 @@ public static function activate() {
7073
public static function deactivate() {
7174
self::flush_rewrite_rules();
7275
Scheduler::deregister_schedules();
76+
77+
\remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) );
78+
Migration::update_comment_counts( 2000 );
7379
}
7480

7581
/**
7682
* Uninstall Hook.
7783
*/
7884
public static function uninstall() {
7985
Scheduler::deregister_schedules();
86+
87+
\remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ) );
88+
Migration::update_comment_counts( 2000 );
8089
}
8190

8291
/**

Diff for: includes/rest/class-webfinger-controller.php

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php
2+
/**
3+
* WebFinger REST-Class file.
4+
*
5+
* @package Activitypub
6+
*/
7+
8+
namespace Activitypub\Rest;
9+
10+
/**
11+
* ActivityPub WebFinger REST-Class.
12+
*
13+
* @author Matthias Pfefferle
14+
*
15+
* @see https://webfinger.net/
16+
*/
17+
class Webfinger_Controller extends \WP_REST_Controller {
18+
/**
19+
* The namespace of this controller's route.
20+
*
21+
* @var string
22+
*/
23+
protected $namespace = ACTIVITYPUB_REST_NAMESPACE;
24+
25+
/**
26+
* The base of this controller's route.
27+
*
28+
* @var string
29+
*/
30+
protected $rest_base = 'webfinger';
31+
32+
/**
33+
* Register routes.
34+
*/
35+
public function register_routes() {
36+
\register_rest_route(
37+
$this->namespace,
38+
'/' . $this->rest_base,
39+
array(
40+
array(
41+
'methods' => \WP_REST_Server::READABLE,
42+
'callback' => array( $this, 'get_item' ),
43+
'permission_callback' => '__return_true',
44+
'args' => array(
45+
'resource' => array(
46+
'description' => 'The WebFinger resource.',
47+
'type' => 'string',
48+
'required' => true,
49+
'pattern' => '^(acct:)|^(https?://)(.+)$',
50+
),
51+
),
52+
),
53+
'schema' => array( $this, 'get_item_schema' ),
54+
)
55+
);
56+
}
57+
58+
/**
59+
* Retrieves the WebFinger profile.
60+
*
61+
* @param \WP_REST_Request $request The request object.
62+
*
63+
* @return \WP_REST_Response Response object.
64+
*/
65+
public function get_item( $request ) {
66+
/**
67+
* Action triggered prior to the ActivityPub profile being created and sent to the client.
68+
*/
69+
\do_action( 'activitypub_rest_webfinger_pre' );
70+
71+
$resource = $request->get_param( 'resource' );
72+
$response = $this->get_profile( $resource );
73+
$code = 200;
74+
75+
if ( \is_wp_error( $response ) ) {
76+
$code = 400;
77+
$error_data = $response->get_error_data();
78+
79+
if ( isset( $error_data['status'] ) ) {
80+
$code = $error_data['status'];
81+
}
82+
}
83+
84+
return new \WP_REST_Response(
85+
$response,
86+
$code,
87+
array(
88+
'Access-Control-Allow-Origin' => '*',
89+
'Content-Type' => 'application/jrd+json; charset=' . \get_option( 'blog_charset' ),
90+
)
91+
);
92+
}
93+
94+
/**
95+
* Get the WebFinger profile.
96+
*
97+
* @param string $webfinger The WebFinger resource.
98+
*
99+
* @return array|\WP_Error The WebFinger profile or WP_Error if not found.
100+
*/
101+
public function get_profile( $webfinger ) {
102+
/**
103+
* Filter the WebFinger data.
104+
*
105+
* @param array $data The WebFinger data.
106+
* @param string $webfinger The WebFinger resource.
107+
*/
108+
return \apply_filters( 'webfinger_data', array(), $webfinger );
109+
}
110+
111+
/**
112+
* Retrieves the schema for the WebFinger endpoint.
113+
*
114+
* @return array Schema data.
115+
*/
116+
public function get_item_schema() {
117+
if ( $this->schema ) {
118+
return $this->add_additional_fields_schema( $this->schema );
119+
}
120+
121+
$this->schema = array(
122+
'$schema' => 'http://json-schema.org/draft-04/schema#',
123+
'title' => 'webfinger',
124+
'type' => 'object',
125+
'required' => array( 'subject', 'links' ),
126+
'properties' => array(
127+
'subject' => array(
128+
'description' => 'The subject of this WebFinger record.',
129+
'type' => 'string',
130+
'format' => 'uri',
131+
),
132+
'aliases' => array(
133+
'description' => 'Alternative identifiers for the subject.',
134+
'type' => 'array',
135+
'items' => array(
136+
'type' => 'string',
137+
'format' => 'uri',
138+
),
139+
),
140+
'links' => array(
141+
'description' => 'Links associated with the subject.',
142+
'type' => 'array',
143+
'items' => array(
144+
'type' => 'object',
145+
'properties' => array(
146+
'rel' => array(
147+
'description' => 'The relation type of the link.',
148+
'type' => 'string',
149+
'required' => true,
150+
),
151+
'type' => array(
152+
'description' => 'The content type of the link.',
153+
'type' => 'string',
154+
),
155+
'href' => array(
156+
'description' => 'The target URL of the link.',
157+
'type' => 'string',
158+
'format' => 'uri',
159+
),
160+
'template' => array(
161+
'description' => 'A URI template for the link.',
162+
'type' => 'string',
163+
'format' => 'uri',
164+
),
165+
),
166+
),
167+
),
168+
),
169+
);
170+
171+
return $this->add_additional_fields_schema( $this->schema );
172+
}
173+
}

Diff for: includes/rest/class-webfinger.php

-116
This file was deleted.

0 commit comments

Comments
 (0)