Merge branch 'trunk' into improve/actor-mode

This commit is contained in:
Matthias Pfefferle 2024-10-15 11:19:26 +02:00 committed by GitHub
commit e33eea667a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 81 additions and 15 deletions

View file

@ -23,6 +23,10 @@ jobs:
- wp-version: '6.5'
php-versions: '7.1'
steps:
- name: Install svn
run: |
sudo apt-get update
sudo apt-get install subversion
- name: Checkout
uses: actions/checkout@v2

View file

@ -33,11 +33,11 @@ class Hashtag {
*/
public static function filter_activity_object( $activity ) {
/* phpcs:ignore Squiz.PHP.CommentedOutCode.Found
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
if ( ! empty( $activity['summary'] ) ) {
Only changed it for Person and Group as long is not merged: https://github.com/mastodon/mastodon/pull/28629
*/
if ( ! empty( $activity['summary'] ) && in_array( $activity['type'], array( 'Person', 'Group' ), true ) ) {
$activity['summary'] = self::the_content( $activity['summary'] );
}
*/
if ( ! empty( $activity['content'] ) ) {
$activity['content'] = self::the_content( $activity['content'] );

View file

@ -29,11 +29,11 @@ class Link {
*/
public static function filter_activity_object( $activity ) {
/* phpcs:ignore Squiz.PHP.CommentedOutCode.Found
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
if ( ! empty( $activity['summary'] ) ) {
Only changed it for Person and Group as long is not merged: https://github.com/mastodon/mastodon/pull/28629
*/
if ( ! empty( $activity['summary'] ) && in_array( $activity['type'], array( 'Person', 'Group' ), true ) ) {
$activity['summary'] = self::the_content( $activity['summary'] );
}
*/
if ( ! empty( $activity['content'] ) ) {
$activity['content'] = self::the_content( $activity['content'] );

View file

@ -1135,16 +1135,44 @@ function normalize_host( $host ) {
return \str_replace( 'www.', '', $host );
}
/**
* Get the reply intent URI as a JavaScript URI.
*
* @return string The reply intent URI.
*/
function get_reply_intent_js() {
return sprintf(
'javascript:(()=>{window.open(\'%s\'+encodeURIComponent(window.location.href));})();',
get_reply_intent_url()
);
}
/**
* Get the reply intent URI.
*
* @return string The reply intent URI.
*/
function get_reply_intent_uri() {
return sprintf(
'javascript:(()=>{window.open(\'%s\'+encodeURIComponent(window.location.href));})();',
esc_url( \admin_url( 'post-new.php?in_reply_to=' ) )
);
function get_reply_intent_url() {
/**
* Filters the reply intent parameters.
*
* @param array $params The reply intent parameters.
*/
$params = \apply_filters( 'activitypub_reply_intent_params', array() );
$params += array( 'in_reply_to' => '' );
$query = \http_build_query( $params );
$path = 'post-new.php?' . $query;
$url = \admin_url( $path );
/**
* Filters the reply intent URL.
*
* @param string $url The reply intent URL.
*/
$url = \apply_filters( 'activitypub_reply_intent_url', $url );
return esc_url_raw( $url );
}
/**

View file

@ -8,6 +8,7 @@
namespace Activitypub\Rest;
use WP_Error;
use WP_REST_Server;
use WP_REST_Response;
use Activitypub\Signature;
use Activitypub\Model\Application;
@ -28,6 +29,7 @@ class Server {
\add_filter( 'rest_request_before_callbacks', array( self::class, 'validate_activitypub_requests' ), 9, 3 );
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
\add_filter( 'rest_request_parameter_order', array( self::class, 'request_parameter_order' ), 10, 2 );
}
/**
@ -181,4 +183,32 @@ class Server {
return $response;
}
/**
* Modify the parameter priority order for a REST API request.
*
* @param string[] $order Array of types to check, in order of priority.
* @param WP_REST_Request $request The request object.
*
* @return string[] The modified order of types to check.
*/
public static function request_parameter_order( $order, $request ) {
$route = $request->get_route();
// Check if it is an activitypub request and exclude webfinger and nodeinfo endpoints.
if ( ! \str_starts_with( $route, '/' . ACTIVITYPUB_REST_NAMESPACE ) ) {
return $order;
}
$type = $request->get_method();
if ( WP_REST_Server::CREATABLE !== $type ) {
return $order;
}
return array(
'POST',
'defaults',
);
}
}

View file

@ -16,7 +16,7 @@
<h3><?php esc_html_e( 'Install Bookmarklet', 'activitypub' ); ?></h3>
<p><?php esc_html_e( 'Drag and drop this button to your browsers bookmark bar or save this bookmarklet to reply to posts on other websites from your blog! When visiting a post on another site, click the bookmarklet to start a reply.', 'activitypub' ); ?></p>
<p class="activitypub-bookmarklet-wrapper">
<a class="activitypub-bookmarklet button" onclick="return false;" href="<?php echo esc_url( \Activitypub\get_reply_intent_uri() ); ?>" style="cursor: grab;">
<a class="activitypub-bookmarklet button" onclick="return false;" href="<?php echo esc_attr( \Activitypub\get_reply_intent_js() ); ?>" style="cursor: grab;">
<?php // translators: The host (domain) of the Blog. ?>
<?php printf( esc_html__( 'Reply from %s', 'activitypub' ), esc_attr( \wp_parse_url( \home_url(), PHP_URL_HOST ) ) ); ?>
</a>
@ -26,7 +26,7 @@
<?php esc_html_e( 'Or copy the following code and create a new bookmark. Paste the code into the new bookmark&#8217;s URL field.', 'activitypub' ); ?>
</p>
<p>
<textarea id="activitypub-bookmarklet-code" class="large-text activitypub-code" rows="5" readonly="readonly" aria-labelledby="activitypub-code-desc"><?php echo esc_textarea( \Activitypub\get_reply_intent_uri() ); ?></textarea>
<textarea id="activitypub-bookmarklet-code" class="large-text activitypub-code" rows="5" readonly="readonly" aria-labelledby="activitypub-code-desc"><?php echo esc_textarea( \Activitypub\get_reply_intent_js() ); ?></textarea>
</p>
<p><span class="dashicons dashicons-clipboard"></span> <a href="javascript:;" class="copy-activitypub-bookmarklet-code" style="cursor: copy;"><?php esc_html_e( 'Copy to clipboard', 'activitypub' ); ?></a></p>
</div>
@ -68,6 +68,10 @@
<td>in_reply_to</td>
<td><?php esc_html_e( 'The URL of the content you want to reply to.', 'activitypub' ); ?></td>
</tr>
<tr>
<td>post_type</td>
<td><?php esc_html_e( 'The Post-Type you want to use for replies.', 'activitypub' ); ?></td>
</tr>
</tbody>
</table>
<p><?php esc_html_e( 'There might be more query parameters in the future.', 'activitypub' ); ?></p>

View file

@ -27,13 +27,13 @@
<p>
<?php
$bookmarklet_url = \Activitypub\get_reply_intent_uri();
$bookmarklet_js = \Activitypub\get_reply_intent_js();
/* translators: %s is the domain of this site */
$reply_from_template = __( 'Reply from %s', 'activitypub' );
$button = sprintf(
'<a href="%s" class="button">%s</a>',
esc_url( $bookmarklet_url ), // Need to escape quotes for the bookmarklet.
esc_attr( $bookmarklet_js ), // Need to escape quotes for the bookmarklet.
sprintf( $reply_from_template, \wp_parse_url( \home_url(), PHP_URL_HOST ) )
);
/* translators: %s is where the button HTML will be rendered. */