initial commit
This commit is contained in:
commit
908b4a669b
2 changed files with 267 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.vscode
|
266
architecture design proposal.md
Normal file
266
architecture design proposal.md
Normal file
|
@ -0,0 +1,266 @@
|
||||||
|
---
|
||||||
|
gitea: none
|
||||||
|
title: WordPress/ActivityPub
|
||||||
|
lang: en
|
||||||
|
authors:
|
||||||
|
- André Menrath
|
||||||
|
- ruru
|
||||||
|
include_toc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
# A proposal for the evolvment of the WordPress ActivityPub plugin
|
||||||
|
|
||||||
|
This document describes proposals for future development in the area of interaction between a WordPress plugin that add additional ActivityPub features via the [WordPress-ActivityPub plugin](https://github.com/Automattic/WordPress-ActivityPub/).
|
||||||
|
|
||||||
|
## Terms used
|
||||||
|
The following terms are used:
|
||||||
|
|
||||||
|
### Actor related
|
||||||
|
|
||||||
|
- **Actors:** ActivityPub actors (https://www.w3.org/TR/activitypub/#actor-objects)
|
||||||
|
- **Actor Types:** ActivityPub [Actor Types](https://www.w3.org/TR/activitystreams-vocabulary/#actor types)
|
||||||
|
- **WordPress actor types:** Things on WordPress that can be mapped to actors:
|
||||||
|
- WordPress users
|
||||||
|
- Whole site/blog (relay)
|
||||||
|
- (custom) post-types
|
||||||
|
- **Mapping:** Which WordPress actor types are actually are mapped to any ActivityPub actors at all and to which one.
|
||||||
|
|
||||||
|
### Content related
|
||||||
|
|
||||||
|
- **post-type:** Post type and custom post types within WordPress
|
||||||
|
- **Object Type:** ActivityPub [Object-Type](https://www.w3.org/TR/activitystreams-vocabulary/#object-types)
|
||||||
|
- **Transformers:** a piece of code that transfers a WordPress-post of a specific WordPress-post-type to an ActivityPub object of a specific WordPress-object-type. For example a transformer that can transform:
|
||||||
|
- `post` to a `Note`
|
||||||
|
- `post` to a `Article`
|
||||||
|
- `post` to `Note`, `Article`, `Image`, `Audio` or `Article` depending on the [post-format](https://wordpress.org/documentation/article/post-formats/)
|
||||||
|
- `tribe_events` (Event post the of [The Event Calendar](https://wordpress.org/plugins/the-events-calendar/)) to `Event`
|
||||||
|
|
||||||
|
### General
|
||||||
|
|
||||||
|
- **publish:** Sending a `Create` or `Announce` [Activity](https://www.w3.org/TR/activitypub/#create-activity-outbox).
|
||||||
|
|
||||||
|
|
||||||
|
## Principals of the changes proposed to the ActivityPub plugin
|
||||||
|
The WordPress ActivityPub plugin
|
||||||
|
- should be aware (or even control) the whole chain from creating some content within WordPress to being published via ActivityPub. For sure, it should be the only plugin that directly sends and receives ActivityPub.
|
||||||
|
- should not get any more complex by default, the out-of-the box functionality/features and simplicity should be similar to version 1.0.0.
|
||||||
|
- offers other plugins the possibility to register custom transformers.
|
||||||
|
- (maybe) offers other plugins the possibility to register new WordPress actor types, e.g. the `tribe_organizer` post type of [The Event Calendar](https://wordpress.org/plugins/the-events-calendar/).
|
||||||
|
- handles the controls collisions of actor names:
|
||||||
|
* collisions that are already present during activation of a WordPress actor type on the settings page
|
||||||
|
* collisions that happen afterwards (e.g. a new user registering with the same username as the blog-wide actor)
|
||||||
|
- maybe distinguishes between the default admin user interface and advanced sections which give the user more fine-grained control:
|
||||||
|
* transformer management
|
||||||
|
* actor management
|
||||||
|
|
||||||
|
|
||||||
|
## Goals
|
||||||
|
|
||||||
|
Our primary goal is to make it possible that events created within an event plugin can federate properly as an ActivityPub object with Type `Event` along with all the meta-data belonging to the event, as found in common ActivityPub implementations, e.g. of Mobilizon, in order to ensure maximum compatibly between those services.
|
||||||
|
|
||||||
|
Nevertheless, we see a lot of other cases that can benefit, if we achieve this using a modularized approach as proposed below. The following list indicates examples what might be those other benefits:
|
||||||
|
- Other types of content get federated in a more feature rich way:
|
||||||
|
- `PodcastEpisode` (as proposed by CastoPod)
|
||||||
|
- `Question` (as used by Mastodon)
|
||||||
|
- `Product`
|
||||||
|
- ...
|
||||||
|
- ActivityPub offers features how to deal with multilingual content ([contentMap - see Example 115](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-contentmap)) which could be implemented differently by multilingual and translation plugins (example search for the current use of `->set_content_map` within the ActivityPub plugin).
|
||||||
|
|
||||||
|
|
||||||
|
## Transformer Management
|
||||||
|
|
||||||
|
### User Interface
|
||||||
|
|
||||||
|
#### Current situation
|
||||||
|
|
||||||
|
The admin user interface in v1.0.0 lets one choose to which object type all post get transformed to. The options are:
|
||||||
|
* [x] Note (default) - Should work with most platforms.
|
||||||
|
* [ ] Article - The presentation of the "Article" might change on different platforms.
|
||||||
|
* [ ] WordPress Post-Format - Maps the WordPress Post-Format to the ActivityPub Object Type.
|
||||||
|
|
||||||
|
#### Proposal
|
||||||
|
|
||||||
|
Every public WordPress post type may be transformed (have different transformers available) to a different ActivityPub object types. Transformations that are not
|
||||||
|
available for a given post-type are greyed out.
|
||||||
|
|
||||||
|
| | Note | Article | Page | Event |
|
||||||
|
| ----------------- |:----:|:-------:|:----:|:-----:|
|
||||||
|
| **post** | X | O | O | - |
|
||||||
|
| **page** | O | X | O | - |
|
||||||
|
| **tribe_events** | O | - | - | X |
|
||||||
|
| **...** | O | - | - | - |
|
||||||
|
|
||||||
|
x: ActivityPub object-types, y: WordPress post-types
|
||||||
|
|
||||||
|
- For any custom post-type, if there is a custom transformer registered, indicate that one should be selected as default (or select it right ahead?).
|
||||||
|
- Should not differ too much from the current view: Maybe completely hide the current Activity-Object-Type part of the settings and only show the buttons for `enable` and `disable` and move the transformer table to an advanced settings page.
|
||||||
|
|
||||||
|
#### Problems
|
||||||
|
|
||||||
|
- If two transformers with the same source and target are installed, then we have two possibilities:
|
||||||
|
1. A dropdown menu is displayed to select one of the transformers.
|
||||||
|
2. Adding another column and maybe add indicators where the transformer comes from (e.g. `builtin`, `custom` or showing the source)
|
||||||
|
|
||||||
|
- Should a transformer be always a many-to-one relationship or may it be a many-to-many one.
|
||||||
|
|
||||||
|
- Do we really want to manage which transformers apply to what directly or do users prefer a setting like "let a certain plugin take care of this post type"? Then further configuration would have to be managed by the other plugins.
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
|
||||||
|
Currently, only one hard-coded transformer exists in [`includes/transformer/class-post.php`](https://github.com/Automattic/wordpress-activitypub/blob/master/includes/transformer/class-post.php).
|
||||||
|
```php
|
||||||
|
/**
|
||||||
|
* WordPress Post Transformer
|
||||||
|
*
|
||||||
|
* The Post Transformer is responsible for transforming a WP_Post object into different othe
|
||||||
|
* Object-Types.
|
||||||
|
*
|
||||||
|
* Currently supported are:
|
||||||
|
*
|
||||||
|
* - Activitypub\Activity\Base_Object
|
||||||
|
*/
|
||||||
|
class Post {
|
||||||
|
...
|
||||||
|
/**
|
||||||
|
* Transforms the WP_Post object to an ActivityPub Object
|
||||||
|
*
|
||||||
|
* @see \Activitypub\Activity\Base_Object
|
||||||
|
*
|
||||||
|
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
||||||
|
*/
|
||||||
|
public function to_object() {
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
A solution could be to define a transformer interface and let the transformers be implementations.
|
||||||
|
```php
|
||||||
|
interface Transformer {
|
||||||
|
public function get_supported_post_types(): array;
|
||||||
|
public function get_target_activitypub_object_type(): string;
|
||||||
|
public function to_object(WP_Post $post);
|
||||||
|
....
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use WordPress's hook system or a public API function to let other plugins register their custom transformer implementations to the ActivityPub plugin.
|
||||||
|
|
||||||
|
#### Problem
|
||||||
|
|
||||||
|
With the design above the transformer does a lot and leaves a lot of responsibility to the developer implementing it.
|
||||||
|
|
||||||
|
Possible alternatives and solutions:
|
||||||
|
- The ActivityPub plugin could provide reusable Traits for common tasks.
|
||||||
|
- The ActivityPub plugin provides an even more height level framework for adding transformers. For example for events the ActivityPub plugin could provide a built-in transformer to the object type `Event` which only needs a mapping (might make things harder, instead of making them easier). See Appendix.
|
||||||
|
- Don't use an interface with implementations, (miss)use class extensions.
|
||||||
|
|
||||||
|
|
||||||
|
## Actor Mapping Management
|
||||||
|
|
||||||
|
More comprehensive actor management would benefit our project aims and potentially meet the needs of others in the future. Nevertheless, **its importance is considerably lower than that of Transformer management**. In the future, the following factors may become more important when larger websites should be using the ActivityPub plugin.
|
||||||
|
|
||||||
|
Currently, the admin user interface in v1.0.0 gives very limited options.
|
||||||
|
```
|
||||||
|
- [ ] Enable `blog`-actor
|
||||||
|
- [ ] Enable `author`-actors
|
||||||
|
```
|
||||||
|
Note that depending on which options are enabled, the method of federating via ActivityPub varies significantly:
|
||||||
|
|
||||||
|
- If the `blog`-actor is enabled, but the `author`-actors are not, posts are attributed and created by the blog actor.
|
||||||
|
- If both are enabled the `blog`-actor will announce (boosting) the posts of the
|
||||||
|
`author`-actors.
|
||||||
|
|
||||||
|
### Possibilities
|
||||||
|
ActivityPub knows several [actor types](https://www.w3.org/TR/activitystreams-core/#actors):
|
||||||
|
- Application
|
||||||
|
- Group
|
||||||
|
- Organization
|
||||||
|
- Person
|
||||||
|
- Service
|
||||||
|
|
||||||
|
The specifications allow for a lot of flexibility in their use. As WordPress websites serve a variety of tasks and goals, providing more detailed capabilities and options in this area **may prove challenging to accomplish in a user-friendly manner**.
|
||||||
|
|
||||||
|
### What features does our event federation project need?
|
||||||
|
|
||||||
|
- For maximum Mobilizon compatibility we would love to have simply an actor of type `Application`, preferable called `@relay@wordpress.site`, that announces all events. Nonetheless, in theory, a Mobilizon instance should have the capability to follow any other actor as well.
|
||||||
|
|
||||||
|
- Additionally, for example, organizers in [The Event Calendar](https://wordpress.org/plugins/the-events-calendar/) could also offer their own actor of type `Organizer` or `Group` to publicize events, or create events if the `author`-actors are not enabled.
|
||||||
|
|
||||||
|
### Other features
|
||||||
|
|
||||||
|
Other WordPress actor types might have valid use cases, like actors for categories, or specific post types in general: "I only want to see the blog updates, but I do not want to spam my timeline with each product they post on their site, even if they choose to federate them."
|
||||||
|
|
||||||
|
#### Problems
|
||||||
|
|
||||||
|
- Overall complexity may lead to programming and usage errors.
|
||||||
|
- Naming collisions become more likely.
|
||||||
|
- Who is the `actor`, who is the `attributedTo`, who is just sending an `Announce` of a post?
|
||||||
|
|
||||||
|
### Proposed starting point for evaluating use cases
|
||||||
|
|
||||||
|
We keep in mind that every post type shall only ever send as a `Create` Activity once by one single actor.
|
||||||
|
|
||||||
|
#### User Interface
|
||||||
|
| | users | tribe_organizers | custom | blog | category |
|
||||||
|
| -----------------|:-----:|:----------------:|:------:|:-----:|:--------:|
|
||||||
|
| **post** | C | O | O | A | A |
|
||||||
|
| **page** | C | O | O | A | O |
|
||||||
|
| **tribe_events** | O | C | - | A | 0 |
|
||||||
|
| **product** | O | - | C | 0 | 0 |
|
||||||
|
|
||||||
|
**x:** WordPress actor-types
|
||||||
|
**y:** WordPress post-types
|
||||||
|
**C:** Create
|
||||||
|
**A:** Announce
|
||||||
|
**user:** the WordPress user publishing or updating something
|
||||||
|
**all:** blog-wide actor, everything that is published (like a relay)
|
||||||
|
**custom:** e.g. only a certain post_type that gets announced with this actor
|
||||||
|
**tribe_organizers:** only posts by one organizer
|
||||||
|
|
||||||
|
- Only allow setting something to `Announce`, when a `Create` is already set.
|
||||||
|
- Maybe forbid, that a user can automatically announce a post, because it's the "lowest level".
|
||||||
|
|
||||||
|
### Actor collisions
|
||||||
|
Each ActivityPub actor must have a [unique ID](https://www.w3.org/TR/activitypub/#obj-id). In our case this is a HTTPS URI.
|
||||||
|
But in reality [webfinger](https://webfinger.net/) is used: `@actor-name@instance.tld`. Actors like Persons and Groups and Applications have Public Keys attached to them, as well as their ID is probably cached by most software. So assigning some actor-name to something new also can cause unintended behavior.
|
||||||
|
|
||||||
|
If multiple plugins want to individually federate their content (like events, products and blog posts or even the built-in WordPress categories), they must be able to have something like an actor API, the ActivityPub plugin can register. The ActivityPub plugin being the main coordinator is necessary because actors are globally unique.
|
||||||
|
- For existing (collision was created before the installation/activation of the plugin)
|
||||||
|
- For new collisions (collision was/will be created after the installation/activation of the plugin)
|
||||||
|
|
||||||
|
It seems like it is the best if collisions are avoided in the first place by encouraging the use of prefixes, like `category_<category>`.
|
||||||
|
|
||||||
|
Anyway it seems the question has to be raised wheter activitypub should store a history of all past and currently mapped actors.
|
||||||
|
|
||||||
|
#### Existing collisions
|
||||||
|
- **Easy:** Either we just tell the user to resolve all conflicts before a WordPress actor type can be activated at all
|
||||||
|
- **Complex:** We let him choose alternatives for conflicts.
|
||||||
|
|
||||||
|
#### New collisions
|
||||||
|
- **Easy** Forbid the saving of new users or posts that would conflict with an existing actor.
|
||||||
|
- **Complex** ...
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
- Anyway it seems the question has to be raised whether the ActivityPub plugin should store a history of all past and currently mapped actors.
|
||||||
|
|
||||||
|
- Additionally, shouldn't the user have a detailed overview in each case if the actor management should get more complex?
|
||||||
|
|
||||||
|
|
||||||
|
#### Proposal of how plugins register WordPress-actor types
|
||||||
|
|
||||||
|
```php
|
||||||
|
interface ActorType {
|
||||||
|
public function getActorTypeName(); // returns name of the ActorType
|
||||||
|
public function listActorsOfThisType(); // returns array of actors of this type
|
||||||
|
public function listPostsForThisActor($actor); // returns array of posts
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The registration of an actor type also registers every actor that is currently in the `listActorsOfThisType()`-list.
|
||||||
|
|
||||||
|
|
||||||
|
## Appendix
|
||||||
|
|
||||||
|
### The approach of youtube-dl
|
||||||
|
|
||||||
|
[youtube-dl](https://github.com/ytdl-org/youtube-dl) is solving a similar problem with "extractors" that return data to the processing-chain of youtube-dl. They provide a base class that includes useful functions for common issues e.g. automatic testing, geo-bypassing, login/cookie/header management.
|
||||||
|
They can also chain extractors recursivly, like a extractor for mastodon videos, that gets the video from the post and returns the source of the video, that could be youtube, vimeo or anything else youtube-dl supports.
|
Loading…
Reference in a new issue