<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[22127] trunk: Better UI for doing "Page on Front".</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/22127">22127</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-10-06 15:19:29 +0000 (Sat, 06 Oct 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Better UI for doing "Page on Front".
Props SergeyBiryukov, lessbloat, nacin.
see <a href="http://core.trac.wordpress.org/ticket/16379">#16379</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsswpadminrtlcss">trunk/wp-admin/css/wp-admin-rtl.css</a></li>
<li><a href="#trunkwpadmincsswpadmincss">trunk/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpadminjspostjs">trunk/wp-admin/js/post.js</a></li>
<li><a href="#trunkwpadminoptionsreadingphp">trunk/wp-admin/options-reading.php</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkwpadminjssamplepermalinkjs">trunk/wp-admin/js/sample-permalink.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincsswpadminrtlcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin-rtl.css (22126 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin-rtl.css        2012-10-06 00:43:36 UTC (rev 22126)
+++ trunk/wp-admin/css/wp-admin-rtl.css        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -915,8 +915,7 @@
</span><span class="cx">         border-bottom-right-radius: 3px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#front-page-warning,
-#front-static-pages ul,
</del><ins>+#front-static-pages .sub-option,
</ins><span class="cx"> ul.export-filters,
</span><span class="cx"> .inline-editor ul.cat-checklist ul,
</span><span class="cx"> .categorydiv ul.categorychecklist ul,
</span></span></pre></div>
<a id="trunkwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin.css (22126 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css        2012-10-06 00:43:36 UTC (rev 22126)
+++ trunk/wp-admin/css/wp-admin.css        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -2929,6 +2929,10 @@
</span><span class="cx">         font-size: 11px;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#front-static-pages #edit-slug-box {
+        padding: 0;
+}
+
</ins><span class="cx"> #editable-post-name-full {
</span><span class="cx">         display: none;
</span><span class="cx"> }
</span><span class="lines">@@ -3414,8 +3418,7 @@
</span><span class="cx">         margin: 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#front-page-warning,
-#front-static-pages ul,
</del><ins>+#front-static-pages .sub-option,
</ins><span class="cx"> ul.export-filters,
</span><span class="cx"> .inline-editor ul.cat-checklist ul,
</span><span class="cx"> .categorydiv ul.categorychecklist ul,
</span><span class="lines">@@ -4988,6 +4991,19 @@
</span><span class="cx">         margin: -3px 3px;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.js.options-reading-php .if-page-on-front,
+.js.options-reading-php .if-page-for-posts,
+.options-reading-php .if-new-front-page {
+        display: none;
+}
+.options-reading-php .page-on-front .if-page-on-front,
+.options-reading-php .page-for-posts .if-page-for-posts {
+        display: block;
+}
+.options-reading-php .new-front-page .if-new-front-page {
+        display: inline;
+}
+
</ins><span class="cx"> /*------------------------------------------------------------------------------
</span><span class="cx"> 21.0 - Admin Footer
</span><span class="cx"> ------------------------------------------------------------------------------*/
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (22126 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2012-10-06 00:43:36 UTC (rev 22126)
+++ trunk/wp-admin/includes/post.php        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -1062,6 +1062,7 @@
</span><span class="cx">         global $wpdb;
</span><span class="cx">         $post = get_post($id);
</span><span class="cx">
</span><ins>+        $context = isset( $_POST['context'] ) ? $_POST['context'] : get_current_screen()->id;
</ins><span class="cx">         list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
</span><span class="cx">
</span><span class="cx">         if ( 'publish' == get_post_status( $post ) ) {
</span><span class="lines">@@ -1073,6 +1074,8 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
</span><ins>+                if ( 'options-reading' == $context )
+                        return '';
</ins><span class="cx">                 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
</span><span class="cx">                 if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
</span><span class="cx">                         $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
</span><span class="lines">@@ -1101,12 +1104,12 @@
</span><span class="cx">         $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
</span><span class="cx">         $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
</span><span class="cx">         $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
</span><del>-        $return = '<strong>' . __('Permalink:') . "</strong>\n";
</del><ins>+        $return = ( 'options-reading' == $context ) ? __( 'Located at' ) . "\n" : '<strong>' . __( 'Permalink:' ) . "</strong>\n";
</ins><span class="cx">         $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
</span><span class="cx">         $return .= '&lrm;'; // Fix bi-directional text display defect in RTL languages.
</span><span class="cx">         $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";
</span><span class="cx">         $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
</span><del>-        if ( isset($view_post) )
</del><ins>+        if ( isset( $view_post ) && 'options-reading' != $context )
</ins><span class="cx">                 $return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n";
</span><span class="cx">
</span><span class="cx">         $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
</span><span class="lines">@@ -1322,3 +1325,87 @@
</span><span class="cx">
</span><span class="cx">         return $url;
</span><span class="cx"> }
</span><ins>+
+/**
+ * Creates new pages to be set as a front page or a page for posts in Reading Settings.
+ *
+ * @todo Make sure we are doing adequate sanitization on success, and cleanup/reset on failure.
+ *
+ * @since 3.5.0
+ * @access private
+ */
+function _create_pages_for_reading_settings() {
+        // If we're saving the Reading Settings screen, intercept.
+        if ( ! isset( $_POST['show_on_front'] ) )
+                return;
+
+        // If a new front page was meant to be created, go forth and create it.
+        if ( isset( $_POST['page_on_front'] ) && 'new' == $_POST['page_on_front'] ) {
+                if ( ! current_user_can( 'create_posts', 'page' ) ) {
+                        $_POST['page_on_front'] = 0;
+                        $_POST['show_on_front'] = 'posts';
+                        add_settings_error( 'page_on_front', __( 'You are not allowed to create pages on this site.' ) );
+                }
+
+                $existing_page = get_page_by_title( stripslashes( $_POST['page_on_front_title'] ) );
+
+                // If page already exists and it's public, there's no need to create a new page
+                if ( $existing_page && 'publish' == $existing_page->post_status ) {
+                        $page_id = $existing_page->ID;
+                } else {
+                        $page_id = wp_insert_post( array(
+                                'post_title' => $_POST['page_on_front_title'],
+                                'post_type' => 'page',
+                                'post_status' => 'publish',
+                                'comment_status' => 'closed',
+                                'ping_status' => 'closed',
+                                // @todo Create some sort of a 'context' in postmeta so we know we created a page through these means.
+                                // Consider then showing that context in the list table as a good-first-step.
+                        ), true );
+                }
+
+                // Make sure page_on_front is properly saved by options.php.
+                if ( is_wp_error( $page_id ) )
+                        $_POST['page_on_front'] = 0;
+                else
+                        $_POST['page_on_front'] = $page_id;
+        }
+
+        // If a page for posts was meant to be specified, update/create it.
+        if ( ! isset( $_POST['page_for_posts'] ) )
+                return;
+
+        $page_for_posts = (int) $_POST['page_for_posts'];
+        if ( ! $page_for_posts || ! $page = get_post( $page_for_posts, ARRAY_A ) ) {
+                $_POST['page_for_posts'] = 0;
+                return;
+        }
+
+        // @todo The UI (see @todo's in options-reading) should cover the next 3 conditionals,
+        // which means we shouldn't need to bother with setting a settings error here.
+        // However, we may wish to restore settings before bailing, beyond setting
+        // page_for_posts to 0 (which we then expect to get cleaned up by options.php).
+        if ( 'page' != $page['post_type'] || ! current_user_can( 'edit_post', $page_for_posts ) ) {
+                $_POST['page_for_posts'] = 0;
+                return;
+        }
+
+        if ( 'publish' != $page['post_status'] && ! current_user_can( 'publish_post', $page_for_posts ) ) {
+                $_POST['page_for_posts'] = 0;
+                return;
+        }
+
+        $args = add_magic_quotes( $page );
+        $args['post_title'] = $_POST['page_for_posts_title'];
+        $args['post_name'] = $_POST['post_name'];
+        $args['post_status'] = 'publish';
+        if ( 'auto-draft' == $page['post_status'] ) {
+                $args['comment_status'] = 'closed';
+                $args['ping_status'] = 'closed';
+        }
+
+        $page_id = wp_insert_post( $args, true );
+        if ( is_wp_error( $page_id ) )
+                $_POST['page_for_posts'] = 0;
+}
+add_filter( 'admin_init', '_create_pages_for_reading_settings' );
</ins></span></pre></div>
<a id="trunkwpadminjspostjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/post.js (22126 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/post.js        2012-10-06 00:43:36 UTC (rev 22126)
+++ trunk/wp-admin/js/post.js        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -559,71 +559,6 @@
</span><span class="cx">                 });
</span><span class="cx">         } // end submitdiv
</span><span class="cx">
</span><del>-        // permalink
-        if ( $('#edit-slug-box').length ) {
-                editPermalink = function(post_id) {
-                        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();
-
-                        $('#view-post-btn').hide();
-                        b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
-                        b.children('.save').click(function() {
-                                var new_slug = e.children('input').val();
-                                if ( new_slug == $('#editable-post-name-full').text() ) {
-                                        return $('.cancel', '#edit-slug-buttons').click();
-                                }
-                                $.post(ajaxurl, {
-                                        action: 'sample-permalink',
-                                        post_id: post_id,
-                                        new_slug: new_slug,
-                                        new_title: $('#title').val(),
-                                        samplepermalinknonce: $('#samplepermalinknonce').val()
-                                }, function(data) {
-                                        $('#edit-slug-box').html(data);
-                                        b.html(revert_b);
-                                        real_slug.val(new_slug);
-                                        makeSlugeditClickable();
-                                        $('#view-post-btn').show();
-                                });
-                                return false;
-                        });
-
-                        $('.cancel', '#edit-slug-buttons').click(function() {
-                                $('#view-post-btn').show();
-                                e.html(revert_e);
-                                b.html(revert_b);
-                                real_slug.val(revert_slug);
-                                return false;
-                        });
-
-                        for ( i = 0; i < full.length; ++i ) {
-                                if ( '%' == full.charAt(i) )
-                                        c++;
-                        }
-
-                        slug_value = ( c > full.length / 4 ) ? '' : full;
-                        e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){
-                                var key = e.keyCode || 0;
-                                // on enter, just save the new slug, don't save the post
-                                if ( 13 == key ) {
-                                        b.children('.save').click();
-                                        return false;
-                                }
-                                if ( 27 == key ) {
-                                        b.children('.cancel').click();
-                                        return false;
-                                }
-                                real_slug.val(this.value);
-                        }).focus();
-                }
-
-                makeSlugeditClickable = function() {
-                        $('#editable-post-name').click(function() {
-                                $('#edit-slug-buttons').children('.edit-slug').click();
-                        });
-                }
-                makeSlugeditClickable();
-        }
-
</del><span class="cx">         // word count
</span><span class="cx">         if ( typeof(wpWordCount) != 'undefined' ) {
</span><span class="cx">                 $(document).triggerHandler('wpcountwords', [ co.val() ]);
</span></span></pre></div>
<a id="trunkwpadminjssamplepermalinkjs"></a>
<div class="addfile"><h4>Added: trunk/wp-admin/js/sample-permalink.js (0 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/sample-permalink.js         (rev 0)
+++ trunk/wp-admin/js/sample-permalink.js        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -0,0 +1,75 @@
</span><ins>+var editPermalink, makeSlugeditClickable;
+
+(function($){
+        if ( ! $('#edit-slug-box').length )
+                return;
+        editPermalink = function(post_id) {
+                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();
+
+                $('#view-post-btn').hide();
+                b.html('<a href="#" class="save button button-small">'+samplePermalinkL10n.ok+'</a> <a class="cancel" href="#">'+samplePermalinkL10n.cancel+'</a>');
+                b.children('.save').click(function() {
+                        var new_slug = e.children('input').val();
+                        if ( new_slug == $('#editable-post-name-full').text() ) {
+                                return $('.cancel', '#edit-slug-buttons').click();
+                        }
+                        $.post(ajaxurl, {
+                                action: 'sample-permalink',
+                                post_id: post_id,
+                                new_slug: new_slug,
+                                new_title: $('#title').val(),
+                                context: pagenow,
+                                samplepermalinknonce: $('#samplepermalinknonce').val()
+                        }, function(data) {
+                                $('#edit-slug-box').html(data);
+                                b.html(revert_b);
+                                real_slug.val(new_slug);
+                                makeSlugeditClickable();
+                                $('#view-post-btn').show();
+                        });
+                        return false;
+                });
+
+                $('.cancel', '#edit-slug-buttons').click(function() {
+                        $('#view-post-btn').show();
+                        e.html(revert_e);
+                        b.html(revert_b);
+                        real_slug.val(revert_slug);
+                        return false;
+                });
+
+                for ( i = 0; i < full.length; ++i ) {
+                        if ( '%' == full.charAt(i) )
+                                c++;
+                }
+
+                slug_value = ( c > full.length / 4 ) ? '' : full;
+                e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){
+                        var key = e.keyCode || 0;
+                        // on enter, just save the new slug, don't save the post
+                        if ( 13 == key ) {
+                                b.children('.save').click();
+                                return false;
+                        }
+                        if ( 27 == key ) {
+                                b.children('.cancel').click();
+                                return false;
+                        }
+                        real_slug.val(this.value);
+                }).focus();
+        }
+
+        makeSlugeditClickable = function() {
+                $('#editable-post-name').click(function() {
+                        $('#edit-slug-buttons').children('.edit-slug').click();
+                });
+        }
+        makeSlugeditClickable();
+})(jQuery);
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: trunk/wp-admin/js/sample-permalink.js
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkwpadminoptionsreadingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/options-reading.php (22126 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/options-reading.php        2012-10-06 00:43:36 UTC (rev 22126)
+++ trunk/wp-admin/options-reading.php        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -15,6 +15,8 @@
</span><span class="cx"> $title = __( 'Reading Settings' );
</span><span class="cx"> $parent_file = 'options-general.php';
</span><span class="cx">
</span><ins>+wp_enqueue_script( 'sample-permalink' );
+
</ins><span class="cx"> /**
</span><span class="cx"> * Display JavaScript on the page.
</span><span class="cx"> *
</span><span class="lines">@@ -22,23 +24,26 @@
</span><span class="cx"> */
</span><span class="cx"> function options_reading_add_js() {
</span><span class="cx"> ?>
</span><del>-<script type="text/javascript">
-//<![CDATA[
-        jQuery(document).ready(function($){
-                var section = $('#front-static-pages'),
-                        staticPage = section.find('input:radio[value="page"]'),
-                        selects = section.find('select'),
-                        check_disabled = function(){
-                                selects.prop( 'disabled', ! staticPage.prop('checked') );
-                        };
-                check_disabled();
-                 section.find('input:radio').change(check_disabled);
</del><ins>+<script>
+jQuery(document).ready( function($) {
+        var section = $('#front-static-pages');
+        $('#show_on_front').change( function() {
+                var checked = $(this).prop('checked');
+                section.toggleClass('page-on-front', checked);
+                if ( checked )
+                        $('#page_for_posts').prop('checked', true).change();
</ins><span class="cx">         });
</span><del>-//]]>
</del><ins>+        $('#page_for_posts').change( function() {
+                section.toggleClass('page-for-posts', $(this).prop('checked'));
+        });
+        $('#page_on_front').change( function() {
+                section.toggleClass('new-front-page', 'new' === $(this).val());
+        });
+});
</ins><span class="cx"> </script>
</span><span class="cx"> <?php
</span><span class="cx"> }
</span><del>-add_action('admin_head', 'options_reading_add_js');
</del><ins>+add_action( 'admin_head', 'options_reading_add_js' );
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Render the blog charset setting.
</span><span class="lines">@@ -82,47 +87,100 @@
</span><span class="cx"> <form method="post" action="options.php">
</span><span class="cx"> <?php
</span><span class="cx"> settings_fields( 'reading' );
</span><del>-
</del><ins>+wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
+?>
+<table class="form-table">
+<?php
</ins><span class="cx"> if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) )
</span><span class="cx">         add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) );
</span><del>-?>
</del><span class="cx">
</span><del>-<?php if ( ! get_pages() ) : ?>
-<input name="show_on_front" type="hidden" value="posts" />
-<table class="form-table">
-<?php
-        if ( 'posts' != get_option( 'show_on_front' ) ) :
</del><ins>+$classes = '';
+if ( 'page' == get_option( 'show_on_front' ) ) {
+        if ( ! get_pages() || ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) {
</ins><span class="cx">                 update_option( 'show_on_front', 'posts' );
</span><del>-        endif;
</del><ins>+        } else {
+                $classes = 'page-on-front';
+                if ( get_option( 'page_for_posts' ) )
+                        $classes .= ' page-for-posts';
+        }
+}
</ins><span class="cx">
</span><del>-else :
-        if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) )
-                update_option( 'show_on_front', 'posts' );
-?>
-<table class="form-table">
</del><ins>+$all_pages = get_pages();
+$new_front_page_only = ! get_option( 'page_on_front' ) && ( ! $all_pages || ( 1 == count( $all_pages ) && __( 'sample-page' ) == $all_pages[0]->post_name ) );
+
+if ( current_user_can( 'create_posts', 'page' ) && ! ( get_option( 'page_for_posts' ) && $page_for_posts = get_post( get_option( 'page_for_posts' ) ) ) ) {
+        $title = _x( 'Blog', 'default page for posts title' );
+        // @todo What if the found page is post_type = attachment or post_status != publish?
+        // We could go ahead and create a new one, but we would not be able to take over
+        // the slug from another page. (We could for an attachment.)
+        // We must also check that the user can edit this page and publish a page.
+        // Otherwise, we must assume they cannot create pages (throughout), and thus
+        // should fall back to the dropdown.
+        if ( ! $page_for_posts = get_page_by_path( sanitize_title( $title ) ) ) {
+                $page_for_posts = get_default_post_to_edit( 'page', true );
+                $page_for_posts->post_title = $title;
+                $page_for_posts->post_name = sanitize_title( $title );
+        }
+}
+
+if ( ! $new_front_page_only || current_user_can( 'create_posts', 'page' ) ) : ?>
</ins><span class="cx"> <tr valign="top">
</span><del>-<th scope="row"><?php _e( 'Front page displays' ); ?></th>
-<td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( 'Front page displays' ); ?></span></legend>
-        <p><label>
-                <input name="show_on_front" type="radio" value="posts" class="tog" <?php checked( 'posts', get_option( 'show_on_front' ) ); ?> />
-                <?php _e( 'Your latest posts' ); ?>
-        </label>
</del><ins>+<th scope="row"><?php _e( 'Enable a static front page' ); ?></th>
+<td id="front-static-pages" class="<?php echo $classes; ?>">
+        <fieldset><legend class="screen-reader-text"><span><?php _e( 'Enable a static front page' ); ?></span></legend>
+        <p><label for="show_on_front">
+                <input id="show_on_front" name="show_on_front" type="checkbox" value="page" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
+                <?php printf( __( 'Show a <a href="%s">page</a> instead of your latest posts' ), 'edit.php?post_type=page' ); ?>
+        </label></p>
+        <p class="if-page-on-front sub-option">
+        <?php if ( $new_front_page_only ) : // If no pages, or only sample page, only allow a new page to be added ?>
+                <label for="page_on_front_title"><?php _e( 'Add new page titled:' ); ?>
+        <?php else : ?>
+                <label for="page_on_front">
+                        <select name="page_on_front" id="page_on_front">
+                                <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
+                                <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?>
+                                <option value="new" id="new-page"><?php _e( '&mdash; Add new page &mdash;' ); ?></option>
+                                <?php endif; ?>
+                                <?php echo walk_page_dropdown_tree( $all_pages, 0, array( 'selected' => get_option( 'page_on_front' ) ) ); ?>
+                        </select>
+                </label>
+                <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?>
+                <label for="page_on_front_title" class="if-new-front-page"><?php _e( 'titled:' ); ?>
+                <?php endif; ?>
+        <?php endif; ?>
+        <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?>
+                        <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' ); ?>" />
+                </label>
+        <?php endif; ?>
</ins><span class="cx">         </p>
</span><del>-        <p><label>
-                <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> />
-                <?php printf( __( 'A <a href="%s">static page</a> (select below)' ), 'edit.php?post_type=page' ); ?>
-        </label>
</del><ins>+        <p class="if-page-on-front"><label for="page_for_posts">
+                <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' ) ); ?> />
+                <?php _e( 'Show latest posts on a separate page' ); ?>
+        </label></p>
+        <?php if ( current_user_can( 'create_posts', 'page' ) ) : ?>
+        <p class="if-page-for-posts sub-option"><label for="page_for_posts_title"><?php _e( 'Page title:' ); ?>
+                <input name="page_for_posts_title" type="text" id="page_for_posts_title" value="<?php echo esc_attr( htmlspecialchars( $page_for_posts->post_title ) ); ?>" />
+        </label></p>
+        <p class="if-page-for-posts sub-option" id="edit-slug-box">
+                <?php echo get_sample_permalink_html( $page_for_posts->ID, $page_for_posts->post_title, $page_for_posts->post_name ); ?>
</ins><span class="cx">         </p>
</span><del>-<ul>
-        <li><label for="page_on_front"><?php printf( __( 'Front page: %s' ), wp_dropdown_pages( array( 'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) ); ?></label></li>
-        <li><label for="page_for_posts"><?php printf( __( 'Posts page: %s' ), wp_dropdown_pages( array( 'name' => 'page_for_posts', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' ) ) ) ); ?></label></li>
-</ul>
-<?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
-<div id="front-page-warning" class="error inline"><p><?php _e( '<strong>Warning:</strong> these pages should not be the same!' ); ?></p></div>
-<?php endif; ?>
-</fieldset></td>
</del><ins>+        <input name="post_name" type="hidden" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $page_for_posts->post_name ) ); ?>" />
+        <?php if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == get_option( 'page_on_front' ) ) : ?>
+        <div class="error inline"><p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'These pages should not be the same!' ); ?></p></div>
+        <?php endif; ?>
+        </fieldset>
+        <?php else : // cannot create pages, so fall back to a selector of existing pages ?>
+        <p class="if-page-for-posts sub-option"><label for="page_for_posts">
+                <?php wp_dropdown_pages( array(
+                        'name' => 'page_for_posts', 'show_option_none' => __( '&mdash; Select &mdash;' ),
+                        'option_none_value' => '0', 'selected' => get_option( 'page_for_posts' )
+                ) ); ?>
+        <?php endif; // create pages ?>
+</td>
</ins><span class="cx"> </tr>
</span><del>-<?php endif; ?>
</del><ins>+<?php endif; // if no pages to choose from and can't create pages ?>
+
</ins><span class="cx"> <tr valign="top">
</span><span class="cx"> <th scope="row"><label for="posts_per_page"><?php _e( 'Blog pages show at most' ); ?></label></th>
</span><span class="cx"> <td>
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (22126 => 22127)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2012-10-06 00:43:36 UTC (rev 22126)
+++ trunk/wp-includes/script-loader.php        2012-10-06 15:19:29 UTC (rev 22127)
</span><span class="lines">@@ -369,10 +369,14 @@
</span><span class="cx">
</span><span class="cx">                 $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 );
</span><span class="cx">
</span><del>-                $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 );
-                did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array(
</del><ins>+                $scripts->add( 'sample-permalink', "/wp-admin/js/sample-permalink.js", array(), false, 1 );
+                did_action( 'init' ) && $scripts->localize( 'sample-permalink', 'samplePermalinkL10n', array(
</ins><span class="cx">                         'ok' => __('OK'),
</span><span class="cx">                         'cancel' => __('Cancel'),
</span><ins>+                ) );
+
+                $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'sample-permalink' ), false, 1 );
+                did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array(
</ins><span class="cx">                         'publishOn' => __('Publish on:'),
</span><span class="cx">                         'publishOnFuture' => __('Schedule for:'),
</span><span class="cx">                         'publishOnPast' => __('Published on:'),
</span></span></pre>
</div>
</div>
</body>
</html>