Skip to content

Conversation

@pfefferle
Copy link
Owner

@pfefferle pfefferle commented Dec 8, 2025

Summary

Refactors the plugin to use a filter-based architecture, aligning with the pattern used in wordpress-activitypub.

This makes it easier for other plugins to extend NodeInfo data by hooking into filters rather than modifying core files.

Changes

  • Add PSR-4 style autoloader for class loading
  • Reorganize files into controller/ and integration/ folders
  • Add Nodeinfo namespace to all classes
  • Separate integration class for each NodeInfo version (1.0, 1.1, 2.0, 2.1, 2.2)
  • NodeInfo endpoint (Nodeinfo\Controller\Nodeinfo) uses filters for all data
  • NodeInfo2 endpoint (Nodeinfo\Controller\Nodeinfo2) is self-contained with WordPress defaults
  • Schemas updated to match official specs with all enums and constraints
  • Add wp-env, phpcs, and phpunit setup with GitHub Actions CI

New Structure

includes/
├── class-autoloader.php           # Nodeinfo\Autoloader
├── functions.php                  # Helper functions
├── controller/
│   ├── class-nodeinfo.php         # Nodeinfo\Controller\Nodeinfo
│   └── class-nodeinfo2.php        # Nodeinfo\Controller\Nodeinfo2
└── integration/
    ├── class-nodeinfo10.php       # Nodeinfo\Integration\Nodeinfo10
    ├── class-nodeinfo11.php       # Nodeinfo\Integration\Nodeinfo11
    ├── class-nodeinfo20.php       # Nodeinfo\Integration\Nodeinfo20
    ├── class-nodeinfo21.php       # Nodeinfo\Integration\Nodeinfo21
    └── class-nodeinfo22.php       # Nodeinfo\Integration\Nodeinfo22

Available Filters

NodeInfo (1.0, 1.1, 2.0, 2.1, 2.2):

  • nodeinfo_versions - Registered versions
  • nodeinfo_discovery_links - Discovery links (also used for JRD)
  • nodeinfo_schema - REST API schema
  • nodeinfo_data_software - Software info
  • nodeinfo_data_protocols - Protocols array
  • nodeinfo_data_services - Services (inbound/outbound)
  • nodeinfo_data_usage - Usage statistics
  • nodeinfo_data_metadata - Metadata
  • nodeinfo_data - Complete response
  • nodeinfo_protocols - Shared filter for protocols (2.0+)

NodeInfo2 (1.0):

  • nodeinfo2_data_server - Server info
  • nodeinfo2_data_protocols - Protocols array
  • nodeinfo2_data_services - Services
  • nodeinfo2_data_usage - Usage statistics
  • nodeinfo2_data_metadata - Metadata
  • nodeinfo2_data - Complete response

Schema Updates

All schemas now match the official NodeInfo specifications with:

  • Protocol enums (e.g., activitypub, diaspora, nostr for 2.2)
  • Service enums (inbound/outbound)
  • Integer minimum constraints
  • Pattern validation for software name (2.0+)
  • Instance field with maxLength constraints (2.2)
  • Links to official schema files in docblocks

Example Usage

// Add ActivityPub protocol (for 2.0+)
add_filter( 'nodeinfo_protocols', function( $protocols ) {
    $protocols[] = 'activitypub';
    return $protocols;
} );

Test Plan

  • Visit /.well-known/nodeinfo and verify discovery document
  • Check /wp-json/nodeinfo/2.2 returns valid NodeInfo 2.2
  • Check /wp-json/nodeinfo/2.1 returns valid NodeInfo 2.1
  • Check /wp-json/nodeinfo/2.0 returns valid NodeInfo 2.0
  • Check /wp-json/nodeinfo/1.1 returns valid NodeInfo 1.1
  • Check /wp-json/nodeinfo/1.0 returns valid NodeInfo 1.0
  • Check /wp-json/nodeinfo2/1.0 returns valid NodeInfo2
  • Verify filters work by adding custom data via nodeinfo_data filter
  • Run composer phpcs - should pass
  • Run composer phpunit - should pass

- Add autoloader for PSR-4 style class loading
- Split endpoints into controller/ folder (Nodeinfo\Controller namespace)
- Add integration/ folder for WordPress-specific implementations
- NodeInfo endpoint uses filters for extensibility (other plugins can hook in)
- NodeInfo2 endpoint is self-contained with filters for customization
- Add Nodeinfo namespace to all classes
- Follow WordPress coding standards for file/class naming

This aligns with the architecture used in wordpress-activitypub plugin,
making it easier for other plugins to extend NodeInfo data via filters.
Each NodeInfo version now has its own integration class that:
- Registers its version to the endpoint enum
- Adds its discovery and JRD links
- Provides version-specific schema
- Implements version-specific data via filters

This allows other plugins to add new NodeInfo versions or modify
existing ones by hooking into the appropriate filters.

New filters:
- nodeinfo_versions: Register supported versions
- nodeinfo_discovery_links: Add discovery document links
- nodeinfo_jrd_links: Add WebFinger/Host-Meta links
- nodeinfo_schema: Modify the JSON schema
Move JRD (WebFinger/Host-Meta) discovery link generation to the
controller's jrd() method, which translates nodeinfo_discovery_links
to JRD format. This removes duplicate jrd_link methods from individual
integration classes since they now only need to register their
discovery links once.
- Replace docker-compose with wp-env (ports 8889/8890)
- Update phpcs.xml to match ActivityPub standards
- Update composer.json with modern dev dependencies
- Restructure tests to tests/phpunit/ directory
- Add PHPUnit workflow for CI
- Update PHPCS workflow with modern actions
- Bump minimum PHP to 7.2 and WordPress to 6.5
- Fix missing @Package tag in nodeinfo.php
- Add phpcs:ignore for lowercase software name (per NodeInfo spec)
- Remove unused $request parameter in get_discovery()
- Add unit tests for NodeInfo endpoint
- Add unit tests for NodeInfo2 endpoint
- Add unit tests for helper functions
Remove MARIADB_DATABASE from service config to let the install script
create the database instead of MariaDB creating it automatically.
- Remove coverage config from phpunit.xml.dist (not supported in PHPUnit 8)
- Fix test_get_masked_version: function always masks, test format instead
- Fix test_invalid_version: returns 400 (enum validation) not 404
- Fix test_nodeinfo2_endpoint_registered: use regex route pattern
Schema descriptions are not user-facing and should not be translated.
- Add missing schema method to NodeInfo 1.1 integration
- Add NodeInfo 2.2 integration with:
  - instance object (name, description)
  - activeWeek in usage.users
  - repository in software
Adds stricter schema validation for NodeInfo versions 1.0, 1.1, 2.0, 2.1, and 2.2, including enums, patterns, and minimums for properties. Introduces protocol handling hooks for NodeInfo 2.x versions and updates supported protocol/service lists. Adds homepage to software metadata for 2.1 and 2.2, and improves documentation with schema links.
Updated the plugin version in nodeinfo.php from 2.3.1 to 3.0.0 to reflect a new release. No other changes were made.
Raised minimum WordPress and PHP versions, updated stable tag to 3.0.0, and added changelog for major refactor, NodeInfo 2.2 support, new integration classes, PSR-4 autoloader, schema updates, protocol filter, and homepage field.
Added sections describing the information shared by the plugin, supported NodeInfo versions, available endpoints, and frequently asked questions. This improves documentation for users and developers integrating with the plugin.
Introduces a Health_Check class to provide Site Health tests for NodeInfo endpoints, verifying accessibility of the well-known and REST endpoints. Updates documentation and plugin initialization to include these checks, helping users diagnose configuration issues.
All WordPress core functions and classes are now called with a leading backslash to ensure global namespace resolution and avoid conflicts with custom functions. Site Health checks initialization was moved to an admin-only hook for better separation of concerns.
- Add deprecated Nodeinfo_Endpoint class for backwards compatibility
- Update package.json with wp-env scripts and remove grunt
- Change wp-env ports to avoid conflicts
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the NodeInfo plugin to a modern filter-based architecture, enabling better extensibility for other plugins. The major enhancement is adding support for NodeInfo 2.2 and introducing a PSR-4 autoloader with a clean separation of concerns through controller and integration classes.

Key Changes

  • Implemented filter-based architecture with separate integration classes for each NodeInfo version (1.0, 1.1, 2.0, 2.1, 2.2)
  • Added PSR-4 autoloader and reorganized code structure into controller/ and integration/ folders
  • Introduced Site Health checks to verify endpoint accessibility
  • Updated schemas to match official NodeInfo specifications with proper enums and validation

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/phpunit/tests/class-test-nodeinfo-endpoint.php Test suite for NodeInfo endpoints with version discovery tests
tests/phpunit/tests/class-test-nodeinfo2-endpoint.php Test suite for NodeInfo2 endpoint functionality
tests/phpunit/tests/class-test-functions.php Tests for helper functions (active users, version masking)
tests/phpunit/bootstrap.php PHPUnit bootstrap configuration
includes/controller/class-nodeinfo.php Main NodeInfo REST controller with filter-based data retrieval
includes/controller/class-nodeinfo2.php NodeInfo2 REST controller implementation
includes/integration/class-nodeinfo10.php through class-nodeinfo22.php Version-specific integration classes implementing schemas and data providers
includes/functions.php Helper functions for user activity and version formatting
includes/class-autoloader.php PSR-4 autoloader following WordPress naming conventions
includes/class-health-check.php Site Health integration for endpoint verification
includes/class-nodeinfo-endpoint.php Deprecated wrapper for backwards compatibility
nodeinfo.php Main plugin file with initialization logic
phpcs.xml Updated PHP CodeSniffer configuration
phpunit.xml.dist Updated PHPUnit configuration
composer.json Updated dependencies and minimum PHP version (7.2)
package.json Added wp-env and updated scripts
.wp-env.json WordPress environment configuration for development
.github/workflows/phpunit.yml CI workflow for PHPUnit tests
.github/workflows/phpcs.yml CI workflow for code standards
README.md Comprehensive documentation updates with FAQ and changelog

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pfefferle and others added 3 commits December 8, 2025 12:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add backslash to @return WP_REST_Response types
- Add fields parameter to get_users for performance
- Add version 2.2 to test coverage
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pfefferle pfefferle merged commit bc227e1 into master Dec 8, 2025
4 checks passed
@pfefferle pfefferle deleted the refactor/filter-based-architecture branch December 8, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants