Skip to content

Commit

Permalink
Merge branch 'trunk' into update/comment-count-deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland authored Jan 10, 2025
2 parents 69b5c9f + 370d8c8 commit 3e770e3
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 169 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
strategy:
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
include:
- wp-version: latest
- wp-version: '6.5'
php-versions: '7.0'
- wp-version: '6.5'
php-versions: '7.1'
- wp-version: '5.9'
php-versions: '7.2'
steps:
- name: Install svn
run: |
Expand Down
1 change: 1 addition & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"WP_SITEURL": "http://example.org",
"WP_HOME": "http://example.org"
},
"port": 80,
"mappings": {
"wp-content/plugins/activitypub": ".",
"wp-content/plugins/activitypub/tests": "./tests"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Comment counts get updated when the plugin is activated/deactivated/deleted
* Added a filter to make custom comment types manageable in WP.com Calypso

### Changed

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

### Fixed

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

## [4.6.0] - 2024-12-20

Expand Down
2 changes: 1 addition & 1 deletion activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Author URI: https://automattic.com/
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Requires PHP: 7.0
* Requires PHP: 7.2
* Text Domain: activitypub
* Domain Path: /languages
*
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"description": "The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.",
"type": "wordpress-plugin",
"require": {
"php": ">=7.0",
"php": ">=7.2",
"composer/installers": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8",
"phpunit/phpunit": "^8 || ^9",
"phpcompatibility/php-compatibility": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"squizlabs/php_codesniffer": "3.*",
Expand Down
12 changes: 6 additions & 6 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public static function get_avatar_url( $comment ) {
public static function trash_post( $post_id ) {
\add_post_meta(
$post_id,
'activitypub_canonical_url',
'_activitypub_canonical_url',
\get_permalink( $post_id ),
true
);
Expand All @@ -360,7 +360,7 @@ public static function trash_post( $post_id ) {
* @param string $post_id The Post ID.
*/
public static function untrash_post( $post_id ) {
\delete_post_meta( $post_id, 'activitypub_canonical_url' );
\delete_post_meta( $post_id, '_activitypub_canonical_url' );
}

/**
Expand Down Expand Up @@ -491,7 +491,7 @@ private static function register_post_types() {

\register_post_meta(
Followers::POST_TYPE,
'activitypub_inbox',
'_activitypub_inbox',
array(
'type' => 'string',
'single' => true,
Expand All @@ -501,7 +501,7 @@ private static function register_post_types() {

\register_post_meta(
Followers::POST_TYPE,
'activitypub_errors',
'_activitypub_errors',
array(
'type' => 'string',
'single' => false,
Expand All @@ -517,7 +517,7 @@ private static function register_post_types() {

\register_post_meta(
Followers::POST_TYPE,
'activitypub_user_id',
'_activitypub_user_id',
array(
'type' => 'string',
'single' => false,
Expand All @@ -529,7 +529,7 @@ private static function register_post_types() {

\register_post_meta(
Followers::POST_TYPE,
'activitypub_actor_json',
'_activitypub_actor_json',
array(
'type' => 'string',
'single' => true,
Expand Down
23 changes: 23 additions & 0 deletions includes/class-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public static function maybe_migrate() {
if ( \version_compare( $version_from_db, '4.5.0', '<' ) ) {
\wp_schedule_single_event( \time() + MINUTE_IN_SECONDS, 'activitypub_update_comment_counts' );
}
if ( \version_compare( $version_from_db, '4.6.0', '<' ) ) {
self::migrate_to_4_6_0();
}

/**
* Fires when the system has to be migrated.
Expand Down Expand Up @@ -387,6 +390,26 @@ public static function migrate_to_4_1_0() {
);
}

/**
* Updates post meta keys to be prefixed with an underscore.
*/
public static function migrate_to_4_6_0() {
global $wpdb;

$meta_keys = array(
'activitypub_actor_json',
'activitypub_canonical_url',
'activitypub_errors',
'activitypub_inbox',
'activitypub_user_id',
);

foreach ( $meta_keys as $meta_key ) {
// phpcs:ignore WordPress.DB
$wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_' . $meta_key ), array( 'meta_key' => $meta_key ) );
}
}

/**
* Update comment counts for posts in batches.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/collection/class-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function get_by_username( $username ) {
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'activitypub_user_identifier',
'key' => '_activitypub_user_identifier',
'value' => $username,
'compare' => 'LIKE',
),
Expand Down
40 changes: 20 additions & 20 deletions includes/collection/class-followers.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public static function add_follower( $user_id, $actor ) {
return $id;
}

$post_meta = get_post_meta( $id, 'activitypub_user_id', false );
$post_meta = get_post_meta( $id, '_activitypub_user_id', false );

// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
if ( is_array( $post_meta ) && ! in_array( $user_id, $post_meta ) ) {
add_post_meta( $id, 'activitypub_user_id', $user_id );
add_post_meta( $id, '_activitypub_user_id', $user_id );
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public static function remove_follower( $user_id, $actor ) {
*/
do_action( 'activitypub_followers_pre_remove_follower', $follower, $user_id, $actor );

return delete_post_meta( $follower->get__id(), 'activitypub_user_id', $user_id );
return delete_post_meta( $follower->get__id(), '_activitypub_user_id', $user_id );
}

/**
Expand All @@ -106,7 +106,7 @@ public static function get_follower( $user_id, $actor ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
$post_id = $wpdb->get_var(
$wpdb->prepare(
"SELECT DISTINCT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.post_type = %s AND pm.meta_key = 'activitypub_user_id' AND pm.meta_value = %d AND p.guid = %s",
"SELECT DISTINCT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.post_type = %s AND pm.meta_key = '_activitypub_user_id' AND pm.meta_value = %d AND p.guid = %s",
array(
esc_sql( self::POST_TYPE ),
esc_sql( $user_id ),
Expand Down Expand Up @@ -188,7 +188,7 @@ public static function get_followers_with_count( $user_id, $number = -1, $page =
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'meta_query' => array(
array(
'key' => 'activitypub_user_id',
'key' => '_activitypub_user_id',
'value' => $user_id,
),
),
Expand Down Expand Up @@ -219,11 +219,11 @@ public static function get_all_followers() {
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'activitypub_inbox',
'key' => '_activitypub_inbox',
'compare' => 'EXISTS',
),
array(
'key' => 'activitypub_actor_json',
'key' => '_activitypub_actor_json',
'compare' => 'EXISTS',
),
),
Expand All @@ -247,15 +247,15 @@ public static function count_followers( $user_id ) {
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'activitypub_user_id',
'key' => '_activitypub_user_id',
'value' => $user_id,
),
array(
'key' => 'activitypub_inbox',
'key' => '_activitypub_inbox',
'compare' => 'EXISTS',
),
array(
'key' => 'activitypub_actor_json',
'key' => '_activitypub_actor_json',
'compare' => 'EXISTS',
),
),
Expand Down Expand Up @@ -290,15 +290,15 @@ public static function get_inboxes( $user_id ) {
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'activitypub_inbox',
'key' => '_activitypub_inbox',
'compare' => 'EXISTS',
),
array(
'key' => 'activitypub_user_id',
'key' => '_activitypub_user_id',
'value' => $user_id,
),
array(
'key' => 'activitypub_inbox',
'key' => '_activitypub_inbox',
'value' => '',
'compare' => '!=',
),
Expand All @@ -318,7 +318,7 @@ public static function get_inboxes( $user_id ) {
$wpdb->prepare(
"SELECT DISTINCT meta_value FROM {$wpdb->postmeta}
WHERE post_id IN (" . implode( ', ', array_fill( 0, count( $posts ), '%d' ) ) . ")
AND meta_key = 'activitypub_inbox'
AND meta_key = '_activitypub_inbox'
AND meta_value IS NOT NULL",
$posts
)
Expand Down Expand Up @@ -378,24 +378,24 @@ public static function get_faulty_followers( $number = 20 ) {
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'activitypub_errors',
'key' => '_activitypub_errors',
'compare' => 'EXISTS',
),
array(
'key' => 'activitypub_inbox',
'key' => '_activitypub_inbox',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'activitypub_actor_json',
'key' => '_activitypub_actor_json',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'activitypub_inbox',
'key' => '_activitypub_inbox',
'value' => '',
'compare' => '=',
),
array(
'key' => 'activitypub_actor_json',
'key' => '_activitypub_actor_json',
'value' => '',
'compare' => '=',
),
Expand Down Expand Up @@ -437,7 +437,7 @@ public static function add_error( $post_id, $error ) {

return add_post_meta(
$post_id,
'activitypub_errors',
'_activitypub_errors',
$error_message
);
}
Expand Down
15 changes: 11 additions & 4 deletions includes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
'ACTIVITYPUB_MASTODON_HTML_SANITIZER',
array(
'p' => array(),
'span' => array( 'class' ),
'span' => array( 'class' => true ),
'br' => array(),
'a' => array( 'href', 'rel', 'class' ),
'a' => array(
'href' => true,
'rel' => true,
'class' => true,
),
'del' => array(),
'pre' => array(),
'code' => array(),
Expand All @@ -46,8 +50,11 @@
'i' => array(),
'u' => array(),
'ul' => array(),
'ol' => array( 'start', 'reversed' ),
'li' => array( 'value' ),
'ol' => array(
'start' => true,
'reversed' => true,
),
'li' => array( 'value' => true ),
'blockquote' => array(),
'h1' => array(),
'h2' => array(),
Expand Down
4 changes: 2 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function is_json( $data ) {
}

/**
* Check whther a blog is public based on the `blog_public` option.
* Check whether a blog is public based on the `blog_public` option.
*
* @return bool True if public, false if not
*/
Expand Down Expand Up @@ -1071,7 +1071,7 @@ function ( $enclosure ) {
*
* @param int|\WP_Comment $comment Comment ID or comment object.
*
* @return \WP_Comment[] Array of ancestor comments or empty array if there are none.
* @return int[] Array of ancestor IDs.
*/
function get_comment_ancestors( $comment ) {
$comment = \get_comment( $comment );
Expand Down
12 changes: 6 additions & 6 deletions includes/model/class-follower.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Follower extends Actor {
* @return mixed
*/
public function get_errors() {
return get_post_meta( $this->_id, 'activitypub_errors', false );
return get_post_meta( $this->_id, '_activitypub_errors', false );
}

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ public function get_url() {
* Reset (delete) all errors.
*/
public function reset_errors() {
delete_post_meta( $this->_id, 'activitypub_errors' );
delete_post_meta( $this->_id, '_activitypub_errors' );
}

/**
Expand Down Expand Up @@ -216,9 +216,9 @@ public function delete() {
* Update the post meta.
*/
protected function get_post_meta_input() {
$meta_input = array();
$meta_input['activitypub_inbox'] = $this->get_shared_inbox();
$meta_input['activitypub_actor_json'] = $this->to_json();
$meta_input = array();
$meta_input['_activitypub_inbox'] = $this->get_shared_inbox();
$meta_input['_activitypub_actor_json'] = $this->to_json();

return $meta_input;
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public function get_shared_inbox() {
* @return \Activitypub\Activity\Base_Object|WP_Error
*/
public static function init_from_cpt( $post ) {
$actor_json = get_post_meta( $post->ID, 'activitypub_actor_json', true );
$actor_json = get_post_meta( $post->ID, '_activitypub_actor_json', true );
$object = self::init_from_json( $actor_json );
$object->set__id( $post->ID );
$object->set_id( $post->guid );
Expand Down
Loading

0 comments on commit 3e770e3

Please sign in to comment.