Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/BlockParser/class-wp-block-parser-block.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
namespace WordPress\BlockParser;
/**
* Block Serialization Parser
*
Expand Down
3 changes: 3 additions & 0 deletions components/BlockParser/class-wp-block-parser-error.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
namespace WordPress\BlockParser;
use Exception;

/**
* @package WordPress
*/
Expand Down
1 change: 1 addition & 0 deletions components/BlockParser/class-wp-block-parser-frame.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
namespace WordPress\BlockParser;
/**
* Block Serialization Parser
*
Expand Down
2 changes: 2 additions & 0 deletions components/BlockParser/class-wp-block-parser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
namespace WordPress\BlockParser;

/**
* Block Serialization Parser
*
Expand Down
1 change: 1 addition & 0 deletions components/Blueprints/Steps/scripts/import-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use WordPress\Zip\ZipFilesystem;

use function WordPress\Filesystem\wp_join_unix_paths;
use function WordPress\Filesystem\add_filter;

require_once getenv('DOCROOT') . '/wp-load.php';
require_once getenv('DOCROOT') . '/php-toolkit.phar';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WordPress\DataLiberation\BlockMarkup;

use WP_Block_Parser_Error;
use WP_HTML_Tag_Processor;
use WordPress\BlockParser\WP_Block_Parser_Error;
use WordPress\HTML\WP_HTML_Tag_Processor;

/**
* A processor class capable of reading and rewriting block markup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace WordPress\DataLiberation\DataFormatConsumer;

use WP_HTML_Processor;
use WordPress\HTML\WP_HTML_Processor;
use function WordPress\Polyfill\parse_blocks;
use function WordPress\Polyfill\serialize_block;

/**
* Converts a metadata-annotated block markup into block markup+metadata pair.
Expand Down Expand Up @@ -48,7 +50,7 @@ public function consume() {
$metadata = array();
foreach ( parse_blocks( $this->original_html ) as $block ) {
if ( $block['blockName'] === null ) {
$html_converter = new MarkupProcessorConsumer( WP_HTML_Processor::create_fragment( $block['innerHTML'] ) );
$html_converter = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $block['innerHTML'] ) );
$result = $html_converter->consume();
$block_markup .= $result->get_block_markup() . "\n";
$metadata = array_merge( $metadata, $result->get_all_metadata() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use WordPress\DataLiberation\DataLiberationException;
use WordPress\DataLiberation\Importer\ImportUtils;
use WordPress\XML\XMLProcessor;
use WP_HTML_Processor;
use WP_HTML_Tag_Processor;
use WordPress\HTML\WP_HTML_Processor;
use WordPress\HTML\WP_HTML_Tag_Processor;

/**
* Creates block markup from a WP_HTML_Processor or WP_XML_Processor instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace WordPress\DataLiberation\DataFormatProducer;

use WordPress\DataLiberation\DataFormatConsumer\BlocksWithMetadata;
use WP_HTML_Tag_Processor;
use WordPress\HTML\WP_HTML_Tag_Processor;

/**
* Turns Block Markup + Metadata into a metadata-annotated Block Markup.
Expand Down
4 changes: 2 additions & 2 deletions components/DataLiberation/DataLiberationHTMLProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace WordPress\DataLiberation;

use WP_HTML_Processor;
use WP_HTML_Tag_Processor;
use WordPress\HTML\WP_HTML_Processor;
use WordPress\HTML\WP_HTML_Tag_Processor;

class DataLiberationHTMLProcessor extends WP_HTML_Processor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use WordPress\XML\XMLProcessor;

use function WordPress\Filesystem\wp_join_unix_paths;
use function WordPress\Polyfill\_doing_it_wrong;

/**
* https://www.w3.org/AudioVideo/ebook/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use WordPress\Filesystem\Visitor\FilesystemVisitor;
use WordPress\Markdown\MarkdownConsumer;
use WordPress\XML\XMLProcessor;
use WP_HTML_Processor;
use WordPress\HTML\WP_HTML_Processor;

use function WordPress\Filesystem\wp_join_unix_paths;

Expand Down Expand Up @@ -277,7 +277,7 @@ public function next_entity(): bool {
$result = $converter->consume();
break;
case 'html':
$converter = new MarkupProcessorConsumer( WP_HTML_Processor::create_fragment( $content ) );
$converter = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $content ) );
$result = $converter->consume();
break;
default:
Expand Down
1 change: 1 addition & 0 deletions components/DataLiberation/EntityReader/WXREntityReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use WordPress\DataLiberation\ImportEntity;
use WordPress\XML\XMLProcessor;
use WordPress\XML\XMLUnsupportedException;
use function WordPress\Polyfill\_doing_it_wrong;

/**
* Data Liberation API: WP_WXR_Entity_Reader class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use WordPress\HttpClient\Request;

use function WordPress\Filesystem\wp_join_unix_paths;
use function WordPress\Polyfill\_doing_it_wrong;

class AttachmentDownloader {
private $client;
Expand Down
4 changes: 4 additions & 0 deletions components/DataLiberation/Importer/EntityImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
use InvalidArgumentException;
use WordPress\DataLiberation\DataLiberationException;
use WordPress\DataLiberation\ImportEntity;
use function WordPress\Polyfill\_doing_it_wrong;
use function WordPress\Polyfill\__;
use function WordPress\Polyfill\apply_filters;
use function WordPress\Polyfill\do_action;

class EntityImporter {

Expand Down
1 change: 1 addition & 0 deletions components/DataLiberation/Importer/ImportSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use function get_all_post_meta_flat;
use function is_wp_error;
use function WordPress\Polyfill\_doing_it_wrong;

/**
* Manages import session data in the WordPress database.
Expand Down
3 changes: 3 additions & 0 deletions components/DataLiberation/Importer/StreamImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use WordPress\HttpClient\ByteStream\RequestReadStream;

use function WordPress\DataLiberation\URL\is_child_url_of;
use function WordPress\Polyfill\_doing_it_wrong;
use function WordPress\Polyfill\apply_filters;
use function WordPress\Polyfill\do_action;

/**
* Idea:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function assertMarkupMatches( $markup, $expected ) {
}

private function normalize_markup( $markup ) {
return WP_HTML_Processor::create_fragment(
return \WordPress\HTML\WP_HTML_Processor::create_fragment(
preg_replace( '/\s+/', ' ', trim( $markup ) )
)->serialize();
}
Expand Down
4 changes: 2 additions & 2 deletions components/DataLiberation/Tests/HTMLEntityReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function test_entity_reader() {
<h1>It is our pleasure to announce that WordPress 6.8 was released</h1>
<p>Last week, WordPress 6.8 was released.</p>
HTML;
$html_processor = WP_HTML_Processor::create_fragment( $html );
$html_processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $html );
$producer = new MarkupProcessorConsumer( $html_processor );
$blocks_with_meta = $producer->consume();

Expand Down Expand Up @@ -70,7 +70,7 @@ public function test_entity_reader() {
}

private function normalize_markup( $markup ) {
$processor = WP_HTML_Processor::create_fragment( $markup );
$processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $markup );
$serialized = $processor->serialize();

return $serialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function test_metadata_extraction() {
<h1>WordPress 6.8 was released</h1>
<p>Last week, WordPress 6.8 was released. This release includes a new default theme, a new block editor experience, and a new block library. It also includes a new block editor experience, and a new block library.</p>
HTML;
$consumer = new MarkupProcessorConsumer( new WP_HTML_Processor( $html ) );
$consumer = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $html ) );
$blocks_with_meta = $consumer->consume();
$metadata = $blocks_with_meta->get_all_metadata();
$expected_metadata = array(
Expand All @@ -37,14 +37,14 @@ public function test_metadata_extraction() {
* @dataProvider provider_test_conversion
*/
public function test_html_to_blocks_conversion( $html, $expected ) {
$consumer = new MarkupProcessorConsumer( new WP_HTML_Processor( $html ) );
$consumer = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $html ) );
$blocks_with_meta = $consumer->consume();

$this->assertEquals( $this->normalize_markup( $expected ), $this->normalize_markup( $blocks_with_meta->get_block_markup() ) );
}

private function normalize_markup( $markup ) {
$processor = WP_HTML_Processor::create_fragment( $markup );
$processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $markup );
$serialized = $processor->serialize();
$serialized = trim(
str_replace(
Expand Down Expand Up @@ -137,7 +137,7 @@ public static function provider_test_conversion() {

public function test_html_to_blocks_excerpt() {
$this->markTestSkipped( 'Skipping this test because of outdated fixture.' );
// $consumer = new MarkupProcessorConsumer( WP_HTML_Processor::create_fragment( $input ) );
// $consumer = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $input ) );
// $blocks_with_meta = $consumer->consume();
// $blocks = $blocks_with_meta->get_block_markup();

Expand Down
4 changes: 2 additions & 2 deletions components/DataLiberation/URL/URLInTextProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace WordPress\DataLiberation\URL;

use WordPress\DataLiberation\BlockMarkup\URL;
use WP_HTML_Text_Replacement;
use WordPress\HTML\WP_HTML_Text_Replacement;

/**
* Finds string fragments that look like URLs and allow replacing them.
Expand Down Expand Up @@ -278,7 +278,7 @@ public function set_raw_url( $new_url ) {
$new_url = substr( $new_url, strpos( $new_url, '://' ) + 3 );
}
$this->raw_url = $new_url;
$this->lexical_updates[ $this->url_starts_at ] = new WP_HTML_Text_Replacement(
$this->lexical_updates[ $this->url_starts_at ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->url_starts_at,
$this->url_length,
$new_url
Expand Down
1 change: 0 additions & 1 deletion components/Filesystem/Tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use function WordPress\Filesystem\wp_join_unix_paths;
use function WordPress\Filesystem\wp_unix_dirname;
use ValueError;

class FunctionsTest extends TestCase {
public function testBasicPathJoining() {
Expand Down
38 changes: 35 additions & 3 deletions components/Git/GitRemote.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,42 @@ private function resolve_missing_blobs_oids( $remote_commit_hash, $options ) {

$commit = $this->repository->read_object( $remote_commit_hash )->as_commit();
$subpath = trim( $path, '/' );
$requested_tree_oid = $this->repository->find_hash_by_path( $subpath, $commit->hash );
$parent_path = dirname( $subpath );
if( $parent_path === '.' || $parent_path === '' ) {
$parent_path = '/';
}

$descentant_blobs_oids = [];
if( $parent_path !== '/' ) {
$parent_tree_oid = $this->repository->find_hash_by_path( $parent_path, $commit->hash );
$parent_tree = $this->repository->read_object( $parent_tree_oid )->as_tree();
$parent_tree_entries = $parent_tree->entries;
$object_name = basename( $subpath );
foreach( $parent_tree_entries as $entry ) {
if( $entry->name === $object_name ) {
$requested_object_oid = $entry->hash;
break;
}
}

// If the object is not found, it is a blob. Trees are always fetched.
if ( ! $this->repository->has_object( $requested_object_oid ) ) {
return [$requested_object_oid];
}

$object = $this->repository->read_object( $requested_object_oid );
if( $object->get_object_type_name() === 'blob' ) {
// Requested object is a blob and, since we've just read it, it isn't
// missing. We're done.
return [];
}
}

// Requested object is a tree, we need to compute all its descendants
$requested_object_oid = $this->repository->find_hash_by_path( $subpath, $commit->hash );
$descentant_blobs_oids = get_all_descendant_oids_in_tree(
$this->repository,
$requested_tree_oid,
$requested_object_oid,
array(
'object_types' => array(
TreeEntry::FILE_MODE_REGULAR_EXECUTABLE,
Expand Down Expand Up @@ -365,7 +397,7 @@ public function fetch( $full_branch_name, $options = array() ) {
// Make double sure we have all the relevant objects from the remote commit.
// @TODO: investigate why sometimes the root tree is missing and address the
// root cause instead of plugging the hole with a bandaid.
if ( ! isset( $options['path'] ) || $options['path'] === '/' || $options['path'] === '' ) {
if ( ! isset( $options['path'] ) || $options['path'] === '/' || $options['path'] === '' ) {
if ( ! $this->repository->has_all_objects_from_commit( $remote_head ) ) {
$this->git_upload_pack(
array(
Expand Down
2 changes: 2 additions & 0 deletions components/Git/GitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function WordPress\Filesystem\wp_unix_dirname;
use function WordPress\Filesystem\wp_join_unix_paths;
use function WordPress\Filesystem\wp_unix_path_resolve_dots;
use function WordPress\Polyfill\_doing_it_wrong;

class GitRepository {

Expand Down Expand Up @@ -356,6 +357,7 @@ private function resolve_branch_file_path( $branch_name ) {
if (
strpos( $branch_name, '/' ) !== false &&
strncmp( $branch_name, 'refs/heads/', strlen( 'refs/heads/' ) ) !== 0 &&
strncmp( $branch_name, 'refs/tags/', strlen( 'refs/tags/' ) ) !== 0 &&
strncmp( $branch_name, 'refs/remotes/', strlen( 'refs/remotes/' ) ) !== 0
) {
_doing_it_wrong( __METHOD__, 'Invalid ref name: ' . $branch_name, '1.0.0' );
Expand Down
Loading
Loading