Skip to content

Commit

Permalink
Merge branch 'WordPress:trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakrohillas authored Aug 22, 2024
2 parents da22274 + 06f7c82 commit 131b76f
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 50 deletions.
110 changes: 81 additions & 29 deletions src/js/_enqueues/lib/image-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,12 @@
* @return {void}
*/
init : function(postid) {
var t = this, old = $('#image-editor-' + t.postid),
x = t.intval( $('#imgedit-x-' + postid).val() ),
y = t.intval( $('#imgedit-y-' + postid).val() );
var t = this, old = $('#image-editor-' + t.postid);

if ( t.postid !== postid && old.length ) {
t.close(t.postid);
}

t.hold.w = t.hold.ow = x;
t.hold.h = t.hold.oh = y;
t.hold.xy_ratio = x / y;
t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
t.postid = postid;
$('#imgedit-response-' + postid).empty();
Expand Down Expand Up @@ -188,6 +183,29 @@
$( document ).on( 'image-editor-ui-ready', this.focusManager );
},

/**
* Calculate the image size and save it to memory.
*
* @since 6.7.0
*
* @memberof imageEdit
*
* @param {number} postid The post ID.
*
* @return {void}
*/
calculateImgSize: function( postid ) {
var t = this,
x = t.intval( $( '#imgedit-x-' + postid ).val() ),
y = t.intval( $( '#imgedit-y-' + postid ).val() );

t.hold.w = t.hold.ow = x;
t.hold.h = t.hold.oh = y;
t.hold.xy_ratio = x / y;
t.hold.sizer = parseFloat( $( '#imgedit-sizer-' + postid ).val() );
t.currentCropSelection = null;
},

/**
* Toggles the wait/load icon in the editor.
*
Expand Down Expand Up @@ -525,7 +543,7 @@
for ( n in history ) {
i = history[n];
if ( i.hasOwnProperty('c') ) {
op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h } };
op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h, 'r': i.c.r } };
} else if ( i.hasOwnProperty('r') ) {
op[n] = { 'r': i.r.r };
} else if ( i.hasOwnProperty('f') ) {
Expand Down Expand Up @@ -860,6 +878,7 @@
if ( 'undefined' === typeof this.hold.sizer ) {
this.init( postid );
}
this.calculateImgSize( postid );

this.initCrop(postid, img, parent);
this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': 0, 'y2': 0, 'width': img.innerWidth(), 'height': img.innerHeight() } );
Expand Down Expand Up @@ -909,8 +928,6 @@
var t = this,
selW = $('#imgedit-sel-width-' + postid),
selH = $('#imgedit-sel-height-' + postid),
selX = $('#imgedit-start-x-' + postid),
selY = $('#imgedit-start-y-' + postid),
$image = $( image ),
$img;

Expand Down Expand Up @@ -945,13 +962,16 @@
*
* @return {void}
*/
parent.children().on( 'mousedown, touchstart', function(e){
var ratio = false, sel, defRatio;

if ( e.shiftKey ) {
sel = t.iasapi.getSelection();
defRatio = t.getSelRatio(postid);
ratio = ( sel && sel.width && sel.height ) ? sel.width + ':' + sel.height : defRatio;
parent.children().on( 'mousedown touchstart', function(e) {
var ratio = false,
sel = t.iasapi.getSelection(),
cx = t.intval( $( '#imgedit-crop-width-' + postid ).val() ),
cy = t.intval( $( '#imgedit-crop-height-' + postid ).val() );

if ( cx && cy ) {
ratio = t.getSelRatio( postid );
} else if ( e.shiftKey && sel && sel.width && sel.height ) {
ratio = sel.width + ':' + sel.height;
}

t.iasapi.setOptions({
Expand Down Expand Up @@ -1000,11 +1020,17 @@
* @return {void}
*/
onSelectChange: function(img, c) {
var sizer = imageEdit.hold.sizer;
selW.val( imageEdit.round(c.width / sizer) );
selH.val( imageEdit.round(c.height / sizer) );
selX.val( imageEdit.round(c.x1 / sizer) );
selY.val( imageEdit.round(c.y1 / sizer) );
var sizer = imageEdit.hold.sizer,
oldSel = imageEdit.currentCropSelection;

if ( oldSel != null && oldSel.width == c.width && oldSel.height == c.height ) {
return;
}

selW.val( Math.min( imageEdit.hold.w, imageEdit.round( c.width / sizer ) ) );
selH.val( Math.min( imageEdit.hold.h, imageEdit.round( c.height / sizer ) ) );

t.currentCropSelection = c;
}
});
},
Expand All @@ -1022,7 +1048,11 @@
* @return {boolean}
*/
setCropSelection : function(postid, c) {
var sel;
var sel,
selW = $( '#imgedit-sel-width-' + postid ),
selH = $( '#imgedit-sel-height-' + postid ),
sizer = this.hold.sizer,
hold = this.hold;

c = c || 0;

Expand All @@ -1037,7 +1067,15 @@
return false;
}

sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height };
// adjust the selection within the bounds of the image on 100% scale
var excessW = hold.w - ( Math.round( c.x1 / sizer ) + parseInt( selW.val() ) );
var excessH = hold.h - ( Math.round( c.y1 / sizer ) + parseInt( selH.val() ) );
var x = Math.round( c.x1 / sizer ) + Math.min( 0, excessW );
var y = Math.round( c.y1 / sizer ) + Math.min( 0, excessH );

// use 100% scaling to prevent rounding errors
sel = { 'r': 1, 'x': x, 'y': y, 'w': selW.val(), 'h': selH.val() };

this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 1);
$('#imgedit-selection-' + postid).val( JSON.stringify(sel) );
},
Expand Down Expand Up @@ -1165,6 +1203,11 @@
}
this.closePopup(t);
this.addStep({ 'r': { 'r': angle, 'fw': this.hold.h, 'fh': this.hold.w }}, postid, nonce);

// Clear the selection fields after rotating.
$( '#imgedit-sel-width-' + postid ).val( '' );
$( '#imgedit-sel-height-' + postid ).val( '' );
this.currentCropSelection = null;
},

/**
Expand All @@ -1187,6 +1230,11 @@
}
this.closePopup(t);
this.addStep({ 'f': { 'f': axis, 'fw': this.hold.w, 'fh': this.hold.h }}, postid, nonce);

// Clear the selection fields after flipping.
$( '#imgedit-sel-width-' + postid ).val( '' );
$( '#imgedit-sel-height-' + postid ).val( '' );
this.currentCropSelection = null;
},

/**
Expand Down Expand Up @@ -1219,10 +1267,11 @@
}

// Clear the selection fields after cropping.
$('#imgedit-sel-width-' + postid).val('');
$('#imgedit-sel-height-' + postid).val('');
$('#imgedit-start-x-' + postid).val('0');
$('#imgedit-start-y-' + postid).val('0');
$( '#imgedit-sel-width-' + postid ).val( '' );
$( '#imgedit-sel-height-' + postid ).val( '' );
$( '#imgedit-start-x-' + postid ).val( '0' );
$( '#imgedit-start-y-' + postid ).val( '0' );
this.currentCropSelection = null;
},

/**
Expand Down Expand Up @@ -1312,6 +1361,8 @@
img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
sizer = this.hold.sizer, x1, y1, x2, y2, ias = this.iasapi;

this.currentCropSelection = null;

if ( false === this.validateNumeric( el ) ) {
return;
}
Expand All @@ -1335,18 +1386,19 @@
if ( x2 > imgw ) {
x1 = 0;
x2 = imgw;
elX.val( Math.round( x2 / sizer ) );
elX.val( Math.min( this.hold.w, Math.round( x2 / sizer ) ) );
}

if ( y2 > imgh ) {
y1 = 0;
y2 = imgh;
elY.val( Math.round( y2 / sizer ) );
elY.val( Math.min( this.hold.h, Math.round( y2 / sizer ) ) );
}

ias.setSelection( x1, y1, x2, y2 );
ias.update();
this.setCropSelection(postid, ias.getSelection());
this.currentCropSelection = ias.getSelection();
}
},

Expand Down
12 changes: 7 additions & 5 deletions src/js/_enqueues/wp/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ themes.view.Appearance = wp.Backbone.View.extend({
},

// Defines search element container.
searchContainer: $( '.search-form .search-box' ),
searchContainer: $( '.search-form' ),

// Search input and view
// for current theme collection.
Expand All @@ -118,11 +118,13 @@ themes.view.Appearance = wp.Backbone.View.extend({
// Render and append after screen title.
view.render();
this.searchContainer
.find( '.search-box' )
.append( $.parseHTML( '<label for="wp-filter-search-input">' + l10n.search + '</label>' ) )
.append( view.el )
.on( 'submit', function( event ) {
event.preventDefault();
});
.append( view.el );

this.searchContainer.on( 'submit', function( event ) {
event.preventDefault();
});
},

// Checks when the user gets close to the bottom
Expand Down
3 changes: 2 additions & 1 deletion src/wp-admin/edit-tag-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<h1><?php echo $tax->labels->edit_item; ?></h1>

<?php
$class = ( isset( $msg ) && 5 === $msg ) ? 'error' : 'success';
$class = ( isset( $_REQUEST['error'] ) ) ? 'error' : 'success';

if ( $message ) {
$message = '<p><strong>' . $message . '</strong></p>';
Expand All @@ -83,6 +83,7 @@
esc_html( $tax->labels->back_to_items )
);
}

wp_admin_notice(
$message,
array(
Expand Down
9 changes: 5 additions & 4 deletions src/wp-admin/edit-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@
// Also used by the Edit Tag form.
require_once ABSPATH . 'wp-admin/includes/edit-tag-messages.php';

$class = ( isset( $_REQUEST['error'] ) ) ? 'error' : 'updated';

if ( is_plugin_active( 'wpcat2tag-importer/wpcat2tag-importer.php' ) ) {
$import_link = admin_url( 'admin.php?import=wpcat2tag' );
} else {
Expand All @@ -349,7 +347,9 @@
<hr class="wp-header-end">

<?php
if ( $message ) :
$class = ( isset( $_REQUEST['error'] ) ) ? 'error' : 'updated';

if ( $message ) {
wp_admin_notice(
$message,
array(
Expand All @@ -358,8 +358,9 @@
'dismissible' => true,
)
);

$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'error' ), $_SERVER['REQUEST_URI'] );
endif;
}
?>
<div id="ajax-response"></div>

Expand Down
10 changes: 8 additions & 2 deletions src/wp-admin/includes/class-wp-site-health-auto-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,18 @@ public function test_vcs_abspath() {
}

$check_dirs = array_unique( $check_dirs );
$updater = new WP_Automatic_Updater();
$checkout = false;

// Search all directories we've found for evidence of version control.
foreach ( $vcs_dirs as $vcs_dir ) {
foreach ( $check_dirs as $check_dir ) {
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition,Squiz.PHP.DisallowMultipleAssignments
if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) {
if ( ! $updater->is_allowed_dir( $check_dir ) ) {
continue;
}

$checkout = is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" );
if ( $checkout ) {
break 2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ public function get_test_plugin_theme_auto_updates() {
* @return array The test results.
*/
public function get_test_available_updates_disk_space() {
$available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : false;
$available_space = function_exists( 'disk_free_space' ) ? @disk_free_space( WP_CONTENT_DIR ) : false;

$result = array(
'label' => __( 'Disk space available to safely perform updates' ),
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,10 @@ function image_edit_apply_changes( $image, $changes ) {
$w = $size['width'];
$h = $size['height'];

$scale = 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
$scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
$image->crop( (int) ( $sel->x * $scale ), (int) ( $sel->y * $scale ), (int) ( $sel->w * $scale ), (int) ( $sel->h * $scale ) );
} else {
$scale = 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
$scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
$image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
}
break;
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/css/media-views.css
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@
color: #043959;
/* Only visible in Windows High Contrast mode */
outline: 2px solid transparent;
z-index: 1;
}

.media-router .active,
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/l10n/class-wp-translation-file-mo.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function parse_file(): bool {
// Metadata about the MO file is stored in the first translation entry.
if ( '' === $original ) {
foreach ( explode( "\n", $translation ) as $meta_line ) {
if ( '' === $meta_line ) {
if ( '' === $meta_line || ! str_contains( $meta_line, ':' ) ) {
continue;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/phpunit/tests/term/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public function test_get_term_should_update_term_cache_when_passed_an_object() {

$num_queries = get_num_queries();

// get_term() will only be update the cache if the 'filter' prop is unset.
unset( $term_object->filter );

$term_object_2 = get_term( $term_object, 'wptests_tax' );

// No new queries should have fired.
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/tests/term/getTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function test_passing_term_object_should_skip_database_query_when_filter_

$num_queries = get_num_queries();

unset( $term->filter );
$term_a = get_term( $term, 'wptests_tax' );

$this->assertSame( $num_queries, get_num_queries() );
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/tests/term/wpInsertTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public function test_wp_insert_term_slug_0() {
public function test_wp_insert_term_duplicate_name() {
$term = self::factory()->tag->create_and_get( array( 'name' => 'Bozo' ) );
$this->assertNotWPError( $term );
$this->assertEmpty( $term->errors );

// Test existing term name with unique slug.
$term1 = self::factory()->tag->create(
Expand Down

0 comments on commit 131b76f

Please sign in to comment.