Ticket #16379: 16379.diff
File 16379.diff, 20.5 KB (added by , 12 years ago) |
---|
-
wp-includes/script-loader.php
369 369 370 370 $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 ); 371 371 372 $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 ); 372 $scripts->add( 'sample-permalink', "wp-admin/js/sample-permalink.js", array(), false, 1 ); 373 374 $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'sample-permalink' ), false, 1 ); 373 375 did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array( 374 376 'ok' => __('OK'), 375 377 'cancel' => __('Cancel'), -
wp-admin/includes/post.php
1059 1059 * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. 1060 1060 */ 1061 1061 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { 1062 global $wpdb; 1062 global $wpdb, $current_screen; 1063 1063 1064 $post = get_post($id); 1064 1065 1066 if ( isset( $current_screen ) ) 1067 $context = $current_screen->id; 1068 else 1069 $context = isset( $_POST['context'] ) ? $_POST['context'] : ''; 1070 1065 1071 list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); 1066 1072 1067 1073 if ( 'publish' == get_post_status( $post ) ) { … … 1072 1078 $title = __('Temporary permalink. Click to edit this part.'); 1073 1079 } 1074 1080 1075 if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { 1076 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; 1081 if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) { 1082 $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; 1083 $return .= '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; 1077 1084 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) 1078 1085 $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; 1079 if ( isset( $view_post))1086 if ( isset( $view_post ) && 'options-reading' == $context ) 1080 1087 $return .= "<span id='view-post-btn'><a href='$permalink' class='button button-small'>$view_post</a></span>\n"; 1081 1088 1082 1089 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1099 1106 } 1100 1107 1101 1108 $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>'; 1102 $display_link = str_replace( array('%pagename%','%postname%'), $post_name_html, $permalink);1103 $view_link = str_replace( array('%pagename%','%postname%'), $post_name, $permalink);1104 $return = '<strong>' . __('Permalink:') . "</strong>\n";1109 $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, $permalink ); 1110 $view_link = str_replace( array( '%pagename%', '%postname%' ), $post_name, $permalink ); 1111 $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n"; 1105 1112 $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; 1106 1113 $return .= '‎'; // Fix bi-directional text display defect in RTL languages. 1107 1114 $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n"; 1108 1115 $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n"; 1109 if ( isset( $view_post))1116 if ( isset( $view_post ) && 'options-reading' != $context ) 1110 1117 $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n"; 1111 1118 1112 1119 $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); … … 1322 1329 1323 1330 return $url; 1324 1331 } 1332 1333 /** 1334 * Creates new pages to be set as a front page or a page for posts in Reading Settings. 1335 * 1336 * @since 3.5.0 1337 * @access private 1338 */ 1339 function _create_pages_for_reading_settings() { 1340 if ( ! isset( $_POST['show_on_front'] ) ) 1341 return; 1342 1343 $post_type = get_post_type_object( 'page' ); 1344 if ( ! current_user_can( $post_type->cap->edit_posts ) ) 1345 wp_die( __( 'You are not allowed to create pages on this site.' ) ); 1346 1347 if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) { 1348 1349 $title = esc_html( stripslashes( $_POST['page_on_front_title'] ) ); 1350 $existing_page = get_page_by_title( $title ); 1351 1352 // If page already exists and it's public, there's no need to create a new page 1353 if ( $existing_page && 'publish' == $existing_page->post_status ) { 1354 $page_id = $existing_page->ID; 1355 } else { 1356 $page_id = wp_insert_post( array( 1357 'post_title' => $title, 1358 'post_type' => 'page', 1359 'post_status' => 'publish' 1360 ) ); 1361 } 1362 1363 if ( $page_id && ! is_wp_error( $page_id ) ) 1364 $_POST['page_on_front'] = $page_id; 1365 } 1366 1367 if ( isset( $_POST['page_for_posts'] ) ) { 1368 if ( ! $page = get_post( (int) $_POST['page_for_posts'] ) ) 1369 return; 1370 1371 $page->post_title = esc_html( stripslashes( $_POST['page_for_posts_title'] ) ); 1372 $page->post_name = esc_html( stripslashes( $_POST['post_name'] ) ); 1373 $page->post_status = 'publish'; 1374 1375 wp_update_post( $page ); 1376 } 1377 } 1378 add_action( 'admin_init', '_create_pages_for_reading_settings' ); -
wp-admin/js/sample-permalink.js
1 var editPermalink, makeSlugeditClickable; 2 3 (function($){ 4 if ( ! $('#edit-slug-box').length ) 5 return; 6 editPermalink = function(post_id) { 7 var i, c = 0, 8 e = $('#editable-post-name'), 9 revert_e = e.html(), 10 real_slug = $('#post_name'), 11 evert_slug = real_slug.val(), 12 b = $('#edit-slug-buttons'), 13 revert_b = b.html(), 14 full = $('#editable-post-name-full').html(); 15 16 $('#view-post-btn').hide(); 17 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>'); 18 b.children('.save').click(function() { 19 var new_slug = e.children('input').val(); 20 if ( new_slug == $('#editable-post-name-full').text() ) { 21 return $('.cancel', '#edit-slug-buttons').click(); 22 } 23 $.post(ajaxurl, { 24 action: 'sample-permalink', 25 post_id: post_id, 26 new_slug: new_slug, 27 new_title: $('#title').val(), 28 context: pagenow, 29 samplepermalinknonce: $('#samplepermalinknonce').val() 30 }, function(data) { 31 $('#edit-slug-box').html(data); 32 b.html(revert_b); 33 real_slug.val(new_slug); 34 makeSlugeditClickable(); 35 $('#view-post-btn').show(); 36 }); 37 return false; 38 }); 39 40 $('.cancel', '#edit-slug-buttons').click(function() { 41 $('#view-post-btn').show(); 42 e.html(revert_e); 43 b.html(revert_b); 44 real_slug.val(revert_slug); 45 return false; 46 }); 47 48 for ( i = 0; i < full.length; ++i ) { 49 if ( '%' == full.charAt(i) ) 50 c++; 51 } 52 53 slug_value = ( c > full.length / 4 ) ? '' : full; 54 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){ 55 var key = e.keyCode || 0; 56 // on enter, just save the new slug, don't save the post 57 if ( 13 == key ) { 58 b.children('.save').click(); 59 return false; 60 } 61 if ( 27 == key ) { 62 b.children('.cancel').click(); 63 return false; 64 } 65 real_slug.val(this.value); 66 }).focus(); 67 } 68 69 makeSlugeditClickable = function() { 70 $('#editable-post-name').click(function() { 71 $('#edit-slug-buttons').children('.edit-slug').click(); 72 }); 73 } 74 makeSlugeditClickable(); 75 })(jQuery); 76 No newline at end of file -
wp-admin/js/post.js
559 559 }); 560 560 } // end submitdiv 561 561 562 // permalink563 if ( $('#edit-slug-box').length ) {564 editPermalink = function(post_id) {565 var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html();566 567 $('#view-post-btn').hide();568 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');569 b.children('.save').click(function() {570 var new_slug = e.children('input').val();571 if ( new_slug == $('#editable-post-name-full').text() ) {572 return $('.cancel', '#edit-slug-buttons').click();573 }574 $.post(ajaxurl, {575 action: 'sample-permalink',576 post_id: post_id,577 new_slug: new_slug,578 new_title: $('#title').val(),579 samplepermalinknonce: $('#samplepermalinknonce').val()580 }, function(data) {581 $('#edit-slug-box').html(data);582 b.html(revert_b);583 real_slug.val(new_slug);584 makeSlugeditClickable();585 $('#view-post-btn').show();586 });587 return false;588 });589 590 $('.cancel', '#edit-slug-buttons').click(function() {591 $('#view-post-btn').show();592 e.html(revert_e);593 b.html(revert_b);594 real_slug.val(revert_slug);595 return false;596 });597 598 for ( i = 0; i < full.length; ++i ) {599 if ( '%' == full.charAt(i) )600 c++;601 }602 603 slug_value = ( c > full.length / 4 ) ? '' : full;604 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){605 var key = e.keyCode || 0;606 // on enter, just save the new slug, don't save the post607 if ( 13 == key ) {608 b.children('.save').click();609 return false;610 }611 if ( 27 == key ) {612 b.children('.cancel').click();613 return false;614 }615 real_slug.val(this.value);616 }).focus();617 }618 619 makeSlugeditClickable = function() {620 $('#editable-post-name').click(function() {621 $('#edit-slug-buttons').children('.edit-slug').click();622 });623 }624 makeSlugeditClickable();625 }626 627 562 // word count 628 563 if ( typeof(wpWordCount) != 'undefined' ) { 629 564 $(document).triggerHandler('wpcountwords', [ co.val() ]); -
wp-admin/css/wp-admin-rtl.css
915 915 border-bottom-right-radius: 3px; 916 916 } 917 917 918 #front-page-warning, 919 #front-static-pages ul, 918 #front-static-pages .sub-option, 920 919 ul.export-filters, 921 920 .inline-editor ul.cat-checklist ul, 922 921 .categorydiv ul.categorychecklist ul, -
wp-admin/css/wp-admin.css
2929 2929 font-size: 11px; 2930 2930 } 2931 2931 2932 #front-static-pages #edit-slug-box { 2933 padding: 0; 2934 } 2935 2932 2936 #editable-post-name-full { 2933 2937 display: none; 2934 2938 } … … 3414 3418 margin: 0; 3415 3419 } 3416 3420 3417 #front-page-warning, 3418 #front-static-pages ul, 3421 #front-static-pages .sub-option, 3419 3422 ul.export-filters, 3420 3423 .inline-editor ul.cat-checklist ul, 3421 3424 .categorydiv ul.categorychecklist ul, … … 4988 4991 margin: -3px 3px; 4989 4992 } 4990 4993 4994 .js.options-reading-php .if-page-on-front, 4995 .js.options-reading-php .if-page-for-posts, 4996 .options-reading-php .if-new-front-page { 4997 display: none; 4998 } 4999 .options-reading-php .page-on-front .if-page-on-front, 5000 .options-reading-php .page-for-posts .if-page-for-posts { 5001 display: block; 5002 } 5003 .options-reading-php .new-front-page .if-new-front-page { 5004 display: inline; 5005 } 5006 4991 5007 /*------------------------------------------------------------------------------ 4992 5008 21.0 - Admin Footer 4993 5009 ------------------------------------------------------------------------------*/ -
wp-admin/options-reading.php
15 15 $title = __( 'Reading Settings' ); 16 16 $parent_file = 'options-general.php'; 17 17 18 wp_enqueue_script( 'sample-permalink' ); 19 18 20 /** 19 21 * Display JavaScript on the page. 20 22 * … … 22 24 */ 23 25 function options_reading_add_js() { 24 26 ?> 25 <script type="text/javascript"> 26 //<![CDATA[ 27 jQuery(document).ready(function($){ 28 var section = $('#front-static-pages'), 29 staticPage = section.find('input:radio[value="page"]'), 30 selects = section.find('select'), 31 check_disabled = function(){ 32 selects.prop( 'disabled', ! staticPage.prop('checked') ); 33 }; 34 check_disabled(); 35 section.find('input:radio').change(check_disabled); 27 <script> 28 jQuery(document).ready( function($) { 29 var section = $('#front-static-pages'); 30 $('#show_on_front').change( function() { 31 section.toggleClass('page-on-front', $(this).prop('checked')); 36 32 }); 37 //]]> 33 $('#page_for_posts').change( function() { 34 section.toggleClass('page-for-posts', $(this).prop('checked')); 35 }); 36 $('#page_on_front').change( function() { 37 section.toggleClass('new-front-page', 'new' === $(this).val()); 38 }); 39 }); 38 40 </script> 39 41 <?php 40 42 } 41 add_action( 'admin_head', 'options_reading_add_js');43 add_action( 'admin_head', 'options_reading_add_js' ); 42 44 43 45 /** 44 46 * Render the blog charset setting. … … 82 84 <form method="post" action="options.php"> 83 85 <?php 84 86 settings_fields( 'reading' ); 85 87 wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); 88 ?> 89 <table class="form-table"> 90 <?php 86 91 if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) 87 92 add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); 88 ?>89 93 90 <?php if ( ! get_pages() ) : ?> 91 <input name="show_on_front" type="hidden" value="posts" /> 92 <table class="form-table"> 93 <?php 94 if ( 'posts' != get_option( 'show_on_front' ) ) : 94 $classes = ''; 95 if ( 'page' == get_option( 'show_on_front' ) ) { 96 if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { 95 97 update_option( 'show_on_front', 'posts' ); 96 endif; 98 } else { 99 $classes = 'page-on-front'; 100 if ( get_option( 'page_for_posts' ) ) 101 $classes .= ' page-for-posts'; 102 } 103 } 97 104 98 else : 99 if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) 100 update_option( 'show_on_front', 'posts' ); 101 ?> 102 <table class="form-table"> 105 $all_pages = get_pages(); 106 $new_front_page_only = ! get_option( 'page_on_front' ) && ( ! $all_pages || ( 1 == count( $all_pages ) && __( 'sample-page' ) == $all_pages[0]->post_name ) ); 107 108 if ( current_user_can( 'create_posts', 'page' ) && ! ( get_option( 'page_for_posts' ) && $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) ) { 109 $title = _x( 'Blog', 'default page for posts title' ); 110 if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) { 111 $page_for_posts = get_default_post_to_edit( 'page', true ); 112 $page_for_posts->post_title = $title; 113 $page_for_posts->post_name = sanitize_title( $title ); 114 } 115 } 116 117 if ( ! $new_front_page_only || current_user_can( 'create_posts', 'page' ) ) : ?> 103 118 <tr valign="top"> 104 <th scope="row"><?php _e( 'Front page displays' ); ?></th> 105 <td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend> 106 <p><label> 107 <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> /> 108 <?php _e( 'Your latest posts' ); ?> 109 </label> 119 <th scope="row"><?php _e( 'Enable a static front page' ); ?></th> 120 <td id="front-static-pages" class="<?php echo $classes; ?>"> 121 <fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend> 122 <p><label for="show_on_front"> 123 <input id="show_on_front" name="show_on_front" type="checkbox" value="page" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> 124 <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?> 125 </label></p> 126 <p class="if-page-on-front sub-option"> 127 <?php if ( $new_front_page_only ) : // If no pages, or only sample page, only allow a new page to be added ?> 128 <label for="page_on_front_title"><?php _e( 'Add new page titled:' ); ?> 129 <?php else : ?> 130 <label for="page_on_front"> 131 <select name="page_on_front" id="page_on_front"> 132 <option value="0"><?php _e( '— Select —' ); ?></option> 133 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 134 <option value="new" id="new-page"><?php _e( '— Add new page —' ); ?></option> 135 <?php endif; ?> 136 <?php echo walk_page_dropdown_tree( $all_pages, 0, array( 'selected' => get_option( 'page_on_front' ) ) ); ?> 137 </select> 138 </label> 139 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 140 <label for="page_on_front_title" class="if-new-front-page"><?php _e( 'titled:' ); ?> 141 <?php endif; ?> 142 <?php endif; ?> 143 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 144 <input name="page_on_front_title" type="text" id="page_on_front_title" value="<?php echo esc_attr_x( 'Home', 'default page on front title' ); ?>" /> 145 </label> 146 <?php endif; ?> 110 147 </p> 111 <p><label> 112 <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> 113 <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?> 114 </label> 148 <p class="if-page-on-front"><label for="page_for_posts"> 149 <input id="page_for_posts" name="page_for_posts" type="checkbox" value="<?php echo $page_for_posts->ID; ?>" <?php checked( (bool) get_option( 'page_for_posts' ) ); ?> /> 150 <?php _e( 'Show latest posts on a separate page' ); ?> 151 </label></p> 152 <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?> 153 <p class="if-page-for-posts sub-option"><label for="page_for_posts_title"><?php _e( 'Page title:' ); ?> 154 <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" /> 155 </label></p> 156 <p class="if-page-for-posts sub-option" id="edit-slug-box"> 157 <?php echo get_sample_permalink_html( $page_for_posts->ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?> 158 <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" /> 115 159 </p> 116 <ul> 117 <li><label for="page_on_front"><?php printf( __( 'Front page: %s' ), wp_dropdown_pages( array( 'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label></li> 118 <li><label for="page_for_posts"><?php printf( __( 'Posts page: %s' ), wp_dropdown_pages( array( 'name' => 'page_for_posts', 'echo' => 0, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) ) ) ); ?></label></li> 119 </ul> 120 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 121 <div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 122 <?php endif; ?> 123 </fieldset></td> 160 <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?> 161 <div class="error inline sub-option"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div> 162 <?php endif; ?> 163 </fieldset> 164 <?php else : // cannot create pages, so fall back to a selector of existing pages ?> 165 <p class="if-page-for-posts sub-option"><label for="page_for_posts"> 166 <?php wp_dropdown_pages( array( 167 'name' => 'page_for_posts', 'show_option_none' => __( '— Select —' ), 168 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) 169 ) ); ?> 170 <?php endif; // create pages ?> 171 </td> 124 172 </tr> 125 <?php endif; ?> 173 <?php endif; // if no pages to choose from and can't create pages ?> 174 126 175 <tr valign="top"> 127 176 <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th> 128 177 <td>