<!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>[2114] 2013/ahoereth/trunk: General clean up of script enqueuing and such.</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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://gsoc.trac.wordpress.org/changeset/2114">2114</a></dd>
<dt>Author</dt> <dd>a.hoereth</dd>
<dt>Date</dt> <dd>2013-07-14 16:39:32 +0000 (Sun, 14 Jul 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>General clean up of script enqueuing and such. See <a href="http://gsoc.trac.wordpress.org/ticket/325">#325</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#2013ahoerethtrunkcoderevisionsphp">2013/ahoereth/trunk/code-revisions.php</a></li>
<li><a href="#2013ahoerethtrunkinceditorsphp">2013/ahoereth/trunk/inc/editors.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#2013ahoerethtrunkcssviewercss">2013/ahoereth/trunk/css/viewer.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013ahoerethtrunkcoderevisionsphp"></a>
<div class="modfile"><h4>Modified: 2013/ahoereth/trunk/code-revisions.php (2113 => 2114)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/ahoereth/trunk/code-revisions.php 2013-07-12 08:30:41 UTC (rev 2113)
+++ 2013/ahoereth/trunk/code-revisions.php 2013-07-14 16:39:32 UTC (rev 2114)
</span><span class="lines">@@ -55,23 +55,28 @@
</span><span class="cx"> add_action( 'init', array( &$this, 'editors' ) );
</span><span class="cx"> add_action( 'load-post.php', array( &$this, 'redirect' ) );
</span><span class="cx"> add_action( 'wp_restore_post_revision', array( &$this, 'restore' ), 10, 2 );
</span><del>- add_action( 'admin_head-revision.php', array( &$this, 'style' ) );
</del><ins>+ add_action( 'admin_enqueue_scripts', array( &$this, 'scripts' ) );
</ins><span class="cx">
</span><span class="cx"> $this->metakey = '_' . str_replace( '-', '_', CODE_REVISIONS_NAME );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Enables multiple white spaces. E.g. at line beginnings or to align multiple
- * lines of code. Furthermore changes padding so the code looks more like in
- * a code editor. Directly echoed to admin head in order to get one http
- * request less for just a couple lines of code.
</del><ins>+ * Enqueue scripts and styles.
</ins><span class="cx"> *
</span><del>- * @since 0.3
</del><ins>+ * @since 0.4
</ins><span class="cx"> */
</span><del>- public function style() { ?>
-<style type="text/css">table.diff td { padding: 0; }</style>
-<?php }
</del><ins>+ public function scripts( $hook ) {
+ //$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
+ $suffix = '';
</ins><span class="cx">
</span><ins>+ // revisions viewer wp-admin/revisions.php
+ if ( 'revision.php' == $hook ) {
+ wp_register_style( 'code_revisions_viewer', CODE_REVISIONS_URL . "css/viewer.css", array(), CODE_REVISIONS_VER );
+ wp_enqueue_style( 'code_revisions_viewer' );
+ }
+
+ }
+
</ins><span class="cx"> /**
</span><span class="cx"> * Register the custom post type for saving file contents
</span><span class="cx"> * as posts for revision capabilities.
</span></span></pre></div>
<a id="2013ahoerethtrunkcssviewercss"></a>
<div class="addfile"><h4>Added: 2013/ahoereth/trunk/css/viewer.css (0 => 2114)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/ahoereth/trunk/css/viewer.css (rev 0)
+++ 2013/ahoereth/trunk/css/viewer.css 2013-07-14 16:39:32 UTC (rev 2114)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+/*
+ * Only included on wp-admin/revision.php for changing some paddings
+ */
+table.diff td { padding: 0; }
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="2013ahoerethtrunkinceditorsphp"></a>
<div class="modfile"><h4>Modified: 2013/ahoereth/trunk/inc/editors.php (2113 => 2114)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/ahoereth/trunk/inc/editors.php 2013-07-12 08:30:41 UTC (rev 2113)
+++ 2013/ahoereth/trunk/inc/editors.php 2013-07-14 16:39:32 UTC (rev 2114)
</span><span class="lines">@@ -9,6 +9,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * ID of the post associated with the current file
</span><ins>+ *
</ins><span class="cx"> * @var int
</span><span class="cx"> */
</span><span class="cx"> private $id;
</span><span class="lines">@@ -28,7 +29,7 @@
</span><span class="cx"> private $meta;
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * File title: "Package: File"
</del><ins>+ * File title: "Package: subfolder/file.ext"
</ins><span class="cx"> *
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><span class="lines">@@ -79,27 +80,16 @@
</span><span class="cx"> //$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
</span><span class="cx"> $suffix = '';
</span><span class="cx">
</span><del>- wp_register_script(
- 'code_revisions',
- CODE_REVISIONS_URL . "js/editors$suffix.js",
- array( 'jquery' ),
- CODE_REVISIONS_VER,
- true
- );
- wp_enqueue_script( 'code_revisions' );
</del><ins>+ wp_register_style( 'code_revisions_editors', CODE_REVISIONS_URL . "css/editors$suffix.css", array(), CODE_REVISIONS_VER );
+ wp_enqueue_style( 'code_revisions_editors' );
</ins><span class="cx">
</span><del>- wp_localize_script( 'code_revisions', '_code_revisions', array(
</del><ins>+ wp_register_script( 'code_revisions_editors', CODE_REVISIONS_URL . "js/editors$suffix.js", array( 'jquery' ), CODE_REVISIONS_VER, true );
+ wp_enqueue_script( 'code_revisions_editors' );
+
+ wp_localize_script( 'code_revisions_editors', '_code_revisions', array(
</ins><span class="cx"> 'post_id' => $this->id,
</span><span class="cx"> 'revisions_list' => $this->get_revisions_list( $this->id ),
</span><span class="cx"> ));
</span><del>-
- wp_register_style(
- 'code_revisions',
- CODE_REVISIONS_URL . "css/editors$suffix.css",
- array(),
- CODE_REVISIONS_VER
- );
- wp_enqueue_style( 'code_revisions' );
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -233,14 +223,7 @@
</span><span class="cx"> public function notice() {
</span><span class="cx"> $revision = array_keys( wp_get_post_revisions( $this->id, array( 'numberposts' => 1 ) ) );
</span><span class="cx"> $link = get_edit_post_link( $revision[0] );
</span><del>- ?>
- <div class="updated">
- <p>
- <?php _e('This file has changed since the last time you viewed it in the editor.','code-revisions'); ?>
- <?php echo "<a href='$link'>".__('View changes','code-revisions')."</a>"; ?>
- </p>
- </div>
- <?php
</del><ins>+ echo '<div class="updated"><p>' . __('This file has changed since the last time you viewed it in the editor.', 'code-revisions') . "<a href='$link'>" . __('View changes', 'code-revisions') . '</a></p></div>';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -265,18 +248,18 @@
</span><span class="cx"> 'post_status' => 'private',
</span><span class="cx"> );
</span><span class="cx">
</span><ins>+ // insert post and add first revision
+ if ( ! $this->id ){
+ $id = wp_insert_post( $args );
+ wp_save_post_revision( $id );
+ }
+
</ins><span class="cx"> // update post
</span><del>- if ( 0 < $this->id ){
</del><ins>+ else {
</ins><span class="cx"> $args['ID'] = $this->id;
</span><span class="cx"> $id = wp_update_post($args);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // insert post
- else {
- $id = wp_insert_post( $args );
- wp_save_post_revision( $id );
- }
-
</del><span class="cx"> // update/insert post meta with new checksum
</span><span class="cx"> $this->meta['checksum'] = md5( $content );
</span><span class="cx"> update_post_meta( $id, $this->metakey, $this->meta );
</span><span class="lines">@@ -305,7 +288,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * wp_list_post_revisions directly echos it's results. We want to work
</del><ins>+ * wp_list_post_revisions() directly echos it's results. We want to work
</ins><span class="cx"> * with it in JS and therefore need to buffer it. metabox.php furthermore adds
</span><span class="cx"> * the layout around the revisions list so we get a metabox similar to the
</span><span class="cx"> * originals on the post and page edit screens.
</span><span class="lines">@@ -314,6 +297,7 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 0.2
</span><span class="cx"> * @uses code-revisions/inc/metabox.php
</span><ins>+ * @uses wp_list_post_revisions()
</ins><span class="cx"> *
</span><span class="cx"> * @param int $id The id of the post to get the revisions list for
</span><span class="cx"> * @return string Revisions list ready for printing.
</span><span class="lines">@@ -323,10 +307,7 @@
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> ob_start();
</span><del>-
- // requires $id to be set
</del><span class="cx"> include_once( CODE_REVISIONS_DIR . 'inc/metabox.php' );
</span><del>-
</del><span class="cx"> return ob_get_clean();
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>