Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/4492-…
Browse files Browse the repository at this point in the history
…widgets-registration

* 'develop' of github.com:ampproject/amp-wp: (88 commits)
  Fix grammar typo
  Bump CSS cache version
  Update composer.lock
  Use patch file instead of diff
  Update patch: Fix parsing CSS selectors which contain commas
  Update php-css-parser to dev-master#bc6ec74; remove patches/php-css-parser-138-extended.patch
  Add test to demonstrate failure to parse class names containing escaped fractions
  Restrict metaboxes which appear on the validated URL screen
  Update hook priority in test_add_admin_hooks
  Restrict row actions for taxonomy terms
  Add test for disable-inline-width on amp-img
  Exclude data-ampdevmode attribute exclusion rule
  Update spec to 2004142326360 to remove container layout from amp-list
  Bump https-proxy-agent from 2.2.2 to 2.2.4 (#4596)
  Update dependency babel-jest to v25.3.0 (#4550)
  Update dependency core-js to v3.6.5 (#4558)
  For the 'Preview AMP' button, use a title instead of a tooltip (#4601)
  Update pull request template based on new workflow
  Bump stable tag to 1.5.3
  Fix handling of Mustache templates (#4583)
  ...
  • Loading branch information
westonruter committed Apr 21, 2020
2 parents b6c6800 + 28a33fb commit b708b07
Show file tree
Hide file tree
Showing 127 changed files with 3,291 additions and 1,636 deletions.
16 changes: 11 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
## Summary

<!-- Please reference the issue this PR addresses. -->
Fixes #
<!--
Please reference the issue this PR addresses. If one doesn't exist, please
create one and put in its description what you would have otherwise put here
in the PR description. Do not use "Fixes" or "Closes" as the issue needs to
remain open for QA/UAT purposes until the release is published.
-->

Addresses issue #...

## Checklist

- [ ] My pull request is addressing an [open issue](https://github.com/ampproject/amp-wp/contributing/project-management.md#life-of-an-issue) (please create one otherwise).
- [ ] My code is tested and passes existing [tests](https://github.com/ampproject/amp-wp/contributing/engineering.md#tests).
- [ ] My code follows the [Engineering Guidelines](https://github.com/ampproject/amp-wp/contributing/engineering.md) (updates are often made to the guidelines, check it out periodically).
- [ ] My pull request is addressing an open issue (please create one otherwise).
- [ ] My code is tested and passes existing [tests](https://github.com/ampproject/amp-wp/wiki/Engineering-Guidelines#tests).
- [ ] My code follows the [Engineering Guidelines](https://github.com/ampproject/amp-wp/wiki/Engineering-Guidelines) (updates are often made to the guidelines, check it out periodically).
2 changes: 2 additions & 0 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Text Domain: amp
* Domain Path: /languages/
* License: GPLv2 or later
* Requires at least: 4.9
* Requires PHP: 5.6
*
* @package AMP
*/
Expand Down
38 changes: 18 additions & 20 deletions assets/src/block-editor/components/amp-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
* WordPress dependencies
*/
import { Component, createRef, renderToString } from '@wordpress/element';
import { Button, Icon, Tooltip } from '@wordpress/components';
import { Button, Icon } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
Expand Down Expand Up @@ -236,25 +236,23 @@ class AMPPreview extends Component {

return (
isEnabled && ! errorMessages.length && ! isStandardMode && (
<Tooltip text={ __( 'Preview AMP', 'amp' ) } >
<Button
className="amp-editor-post-preview"
href={ href }
label={ __( 'Preview AMP', 'amp' ) }
isSecondary
disabled={ ! isSaveable }
onClick={ this.openPreviewWindow }
ref={ this.buttonRef }
>
{ ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
<span className="screen-reader-text">
{
/* translators: accessibility text */
__( '(opens in a new tab)', 'amp' )
}
</span>
</Button>
</Tooltip>
<Button
className="amp-editor-post-preview"
href={ href }
title={ __( 'Preview AMP', 'amp' ) }
isSecondary
disabled={ ! isSaveable }
onClick={ this.openPreviewWindow }
ref={ this.buttonRef }
>
{ ampFilledIcon( { viewBox: '0 0 62 62', width: 18, height: 18 } ) }
<span className="screen-reader-text">
{
/* translators: accessibility text */
__( '(opens in a new tab)', 'amp' )
}
</span>
</Button>
)
);
}
Expand Down
80 changes: 57 additions & 23 deletions assets/src/block-editor/components/with-media-library-notice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { dispatch } from '@wordpress/data';

/**
Expand Down Expand Up @@ -57,47 +56,82 @@ export default ( InitialMediaUpload, minImageDimensions ) => {
*/
initFeaturedImage() {
const FeaturedImageSelectMediaFrame = getSelectMediaFrame( FeaturedImageToolbarSelect );

const FeaturedImageLibrary = wp.media.controller.FeaturedImage.extend( {
defaults: {
...wp.media.controller.FeaturedImage.prototype.defaults,
date: false,
filterable: false,
// Note: These suggestions are shown in the media library image browser.
suggestedWidth: EXPECTED_WIDTH,
suggestedHeight: EXPECTED_HEIGHT,
},
} );

this.frame = new FeaturedImageSelectMediaFrame( {
allowedTypes: this.props.allowedTypes,
button: {
text: __( 'Select', 'amp' ),
close: false,
},
states: [
new wp.media.controller.Library( {
title: __( 'Choose image', 'amp' ),
library: wp.media.query( { type: 'image' } ),
multiple: false,
date: false,
priority: 20,
// Note: These suggestions are shown in the media library image browser.
suggestedWidth: EXPECTED_WIDTH,
suggestedHeight: EXPECTED_HEIGHT,
} ),
],
state: 'featured-image',
states: [ new FeaturedImageLibrary(), new wp.media.controller.EditImage() ],
} );

this.frame.on( 'toolbar:create:featured-image', function ( toolbar ) {
/**
* @this wp.media.view.MediaFrame.Select
*/
this.createSelectToolbar( toolbar, {
text: wp.media.view.l10n.setFeaturedImage,
state: this.options.state,
});
}, this.frame );

this.frame.on( 'open', this.onOpen );

this.frame.state('featured-image').on( 'select', this.onSelectImage, this );

// See wp.media() for this.
wp.media.frame = this.frame;
}

this.frame.on( 'select', this.onSelectImage, this );
this.frame.on( 'close', () => {
this.initFeaturedImage();
}, this );
/**
* Ensure the selected image is the first item in the collection.
*
* @see https://github.com/WordPress/gutenberg/blob/c58b32266f8c950c5b9927d286608343078aee02/packages/media-utils/src/components/media-upload/index.js#L401-L417
*/
onOpen() {
const frameContent = this.frame.content.get();
if ( frameContent && frameContent.collection ) {
const collection = frameContent.collection;

// Clean all attachments we have in memory.
collection
.toArray()
.forEach( ( model ) => model.trigger( 'destroy', model ) );

// Reset has more flag, if library had small amount of items all items may have been loaded before.
collection.mirroring._hasMore = true;

// Request items.
collection.more();
}
}

/**
* Handles image selection.
*/
onSelectImage() {
const attachment = this.frame.state().get( 'selection' ).first().toJSON();
const attachment = this.frame.state( 'featured-image' ).get( 'selection' ).first().toJSON();
const dispatchImage = ( attachmentId ) => {
dispatch( 'core/editor' ).editPost( { featured_media: attachmentId } );
};
const { onSelect } = this.props;
const { url, id, width, height } = attachment;
setImageFromURL( { url, id, width, height, onSelect, dispatchImage } );
this.frame.close();

if ( ! wp.media.view.settings.post.featuredImageId ) {
return;
}

wp.media.featuredImage.set( attachment ? attachment.id : -1 );
}
};
};
4 changes: 2 additions & 2 deletions assets/src/common/components/select-media-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export const FeaturedImageToolbarSelect = wp.media.view.Toolbar.Select.extend( {
const selection = state.get( 'selection' );

const attachment = selection.models[ 0 ];
const minWidth = state.collection.get( 'library' ).get( 'suggestedWidth' );
const minHeight = state.collection.get( 'library' ).get( 'suggestedHeight' );
const minWidth = state.collection.get( 'featured-image' ).get( 'suggestedWidth' );
const minHeight = state.collection.get( 'featured-image' ).get( 'suggestedHeight' );

if (
! attachment ||
Expand Down
27 changes: 20 additions & 7 deletions bin/amphtml-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def GenValidatorProtoascii(validator_directory, out_dir):
"""
logging.info('entering ...')

protoascii_segments = [open(os.path.join(validator_directory, 'validator-main.protoascii')).read()]
protoascii_segments = [
open(os.path.join(validator_directory, 'validator-main.protoascii')).read(),
open(os.path.join(validator_directory, 'validator-css.protoascii')).read()
]
extensions = glob.glob(os.path.join(validator_directory, '../extensions/*/validator-*.protoascii'))
extensions.sort()
for extension in extensions:
Expand Down Expand Up @@ -445,10 +448,12 @@ def GetTagSpec(tag_spec, attr_lists):
if isinstance(field_value, (unicode, str, bool, int)):
cdata_dict[ field_descriptor.name ] = field_value
elif isinstance( field_value, google.protobuf.pyext._message.RepeatedCompositeContainer ):
cdata_dict[ field_descriptor.name ] = {}
cdata_dict[ field_descriptor.name ] = []
for value in field_value:
entry = {}
for (key,val) in value.ListFields():
cdata_dict[ field_descriptor.name ][ key.name ] = val
entry[ key.name ] = val
cdata_dict[ field_descriptor.name ].append( entry )
elif hasattr( field_value, '_values' ):
cdata_dict[ field_descriptor.name ] = {}
for _value in field_value._values:
Expand Down Expand Up @@ -482,10 +487,11 @@ def GetTagSpec(tag_spec, attr_lists):
cdata_dict['css_spec'] = css_spec
if len( cdata_dict ) > 0:
if 'blacklisted_cdata_regex' in cdata_dict:
if 'error_message' not in cdata_dict['blacklisted_cdata_regex']:
raise Exception( 'Missing error_message for blacklisted_cdata_regex.' );
if cdata_dict['blacklisted_cdata_regex']['error_message'] not in ( 'CSS !important', 'contents', 'html comments' ):
raise Exception( 'Unexpected error_message "%s" for blacklisted_cdata_regex.' % cdata_dict['blacklisted_cdata_regex']['error_message'] );
for entry in cdata_dict['blacklisted_cdata_regex']:
if 'error_message' not in entry:
raise Exception( 'Missing error_message for blacklisted_cdata_regex.' );
if entry['error_message'] not in ( 'contents', 'html comments', 'CSS i-amphtml- name prefix' ):
raise Exception( 'Unexpected error_message "%s" for blacklisted_cdata_regex.' % entry['error_message'] );
tag_spec_dict['cdata'] = cdata_dict

if 'spec_name' not in tag_spec_dict['tag_spec']:
Expand Down Expand Up @@ -674,6 +680,13 @@ def GetAttrs(attrs):

if value_dict is not None:

# Skip rules for dev mode attributes since the AMP plugin will allow them to pass through.
# See <https://github.com/ampproject/amphtml/pull/27174#issuecomment-601391161> for how the rules are
# defined in a way that they can never be satisfied, and thus to make the attribute never allowed.
# This runs contrary to the needs of the AMP plugin, as the internal sanitizers are built to ignore them.
if 'data-ampdevmode' == attr_spec.name:
continue

# Normalize bracketed amp-bind attribute syntax to data-amp-bind-* syntax.
name = attr_spec.name
if name[0] == '[':
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ampproject/optimizer": "^1",
"cweagans/composer-patches": "1.6.7",
"fasterimage/fasterimage": "1.5.0",
"sabberworm/php-css-parser": "dev-master#134f4e6"
"sabberworm/php-css-parser": "dev-master#bc6ec74"
},
"require-dev": {
"civicrm/composer-downloads-plugin": "^2.1",
Expand Down Expand Up @@ -50,9 +50,8 @@
},
"patches": {
"sabberworm/php-css-parser": {
"Fix parsing CSS selectors which contain commas <https://github.com/sabberworm/PHP-CSS-Parser/pull/138>": "https://github.com/sabberworm/PHP-CSS-Parser/commit/fa139f65c5b098ae652c970b25e6eb03fc495eb4.diff",
"Fix validation of selectors": "patches/php-css-parser-138-extended.patch",
"Validate name-start code points for identifier <https://github.com/sabberworm/PHP-CSS-Parser/pull/185>": "patches/php-css-parser-pull-185.patch"
"Validate name-start code points for identifier <https://github.com/sabberworm/PHP-CSS-Parser/pull/185>": "patches/php-css-parser-pull-185.patch",
"Fix parsing CSS selectors which contain commas <https://github.com/westonruter/PHP-CSS-Parser/pull/1>": "patches/php-css-parser-commit-10a2501.patch"
}
}
},
Expand Down
Loading

0 comments on commit b708b07

Please sign in to comment.