<!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>[772] sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook: Handbook plugin: make watch/unwatch feature an action link instead of a widget</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://meta.trac.wordpress.org/changeset/772">772</a></dd>
<dt>Author</dt> <dd>coffee2code</dd>
<dt>Date</dt> <dd>2014-07-30 21:45:47 +0000 (Wed, 30 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Handbook plugin: make watch/unwatch feature an action link instead of a widget

* Remove WPorg_Handbook_Widget and WPorg_Handbook_Widget_for_Pages classes and usage thereof
* Add WPorg_Handbook_Watchlist class in new inc/watchlist.php
* Add title text to links to provide context about what watching actually does

Fixes <a href="http://meta.trac.wordpress.org/ticket/437">#437</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookfunctionalityforpagesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/functionality-for-pages.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookhandbookphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincemailpostchangesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/email-post-changes.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincwidgetsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincwatchlistphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookfunctionalityforpagesphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/functionality-for-pages.php (771 => 772)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/functionality-for-pages.php    2014-07-30 21:45:32 UTC (rev 771)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/functionality-for-pages.php       2014-07-30 21:45:47 UTC (rev 772)
</span><span class="lines">@@ -10,12 +10,6 @@
</span><span class="cx"> 
</span><span class="cx"> new WPorg_Handbook_TOC( array( 'page' ) );
</span><span class="cx"> 
</span><del>-add_action( 'widgets_init', 'wporg_handbook_functionality_for_pages_widget', 12 );
-function wporg_handbook_functionality_for_pages_widget() {
-       require_once dirname( __FILE__ ) . '/inc/widgets.php';
-       register_widget( 'WPorg_Handbook_Widget_for_Pages' );
-}
-
</del><span class="cx"> add_filter( 'wporg_email_changes_for_post_types', 'wporg_email_changes_for_pages' );
</span><span class="cx"> function wporg_email_changes_for_pages( $post_types ) {
</span><span class="cx">  if ( ! in_array( 'page', $post_types ) )
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookhandbookphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php (771 => 772)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php   2014-07-30 21:45:32 UTC (rev 771)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php      2014-07-30 21:45:47 UTC (rev 772)
</span><span class="lines">@@ -8,6 +8,7 @@
</span><span class="cx"> require_once dirname( __FILE__ ) . '/inc/glossary.php';
</span><span class="cx"> require_once dirname( __FILE__ ) . '/inc/table-of-contents.php';
</span><span class="cx"> require_once dirname( __FILE__ ) . '/inc/email-post-changes.php';
</span><ins>+require_once dirname( __FILE__ ) . '/inc/watchlist.php';
</ins><span class="cx"> 
</span><span class="cx"> //WPorg_Handbook_Glossary::init();
</span><span class="cx"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincemailpostchangesphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/email-post-changes.php (771 => 772)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/email-post-changes.php     2014-07-30 21:45:32 UTC (rev 771)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/email-post-changes.php        2014-07-30 21:45:47 UTC (rev 772)
</span><span class="lines">@@ -7,17 +7,11 @@
</span><span class="cx"> class WPorg_Handbook_Email_Post_Changes {
</span><span class="cx"> 
</span><span class="cx">  public static function init() {
</span><del>-               add_action( 'widgets_init', array( __CLASS__, 'handbook_sidebar' ), 11 ); // After P2
</del><span class="cx">           add_filter( 'email_post_changes_emails', array( __CLASS__, 'email_post_changes_emails' ), 10, 3 );
</span><span class="cx">          add_action( 'admin_post_wporg_watchlist', array( __CLASS__, 'update_watchlist' ) );
</span><span class="cx">          add_action( 'option_email_post_changes', array( __CLASS__, 'option_email_post_changes' ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       public static function handbook_sidebar() {
-               require_once dirname( __FILE__ ) . '/widgets.php';
-               register_widget( 'WPorg_Handbook_Widget' );
-       }
-
</del><span class="cx">   public static function option_email_post_changes( $values ) {
</span><span class="cx">          $values['post_types'] = apply_filters( 'wporg_email_changes_for_post_types', $values['post_types'] );
</span><span class="cx">          return $values;
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincwatchlistphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php (0 => 772)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php 2014-07-30 21:45:47 UTC (rev 772)
</span><span class="lines">@@ -0,0 +1,70 @@
</span><ins>+<?php
+
+class WPorg_Handbook_Watchlist {
+
+       private static $post_types = array( 'handbook' );
+
+       public static function init() {
+               add_action( 'init', array( __CLASS__, 'on_init' ) );
+       }
+
+       public static function on_init() {
+               self::$post_types = (array) apply_filters( 'handbook_post_types', self::$post_types );
+               self::$post_types = array_map( array( __CLASS__, 'append_suffix' ), self::$post_types );
+
+               add_action( 'p2_action_links', array(__CLASS__, 'display_action_link'), 100 );
+       }
+
+       /**
+        * Appends '-handbook' to the dynamic post type, if not already 'handbook'.
+        *
+        * @param  string $t Hanbook post type name.
+        * @return string
+        */
+       private static function append_suffix( $t ) {
+               if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
+                       return $t;
+               }
+
+               return $t . '-handbook';
+       }
+
+       /**
+        * Adds a 'Watch' action link to P2
+        */
+       public static function display_action_link() {
+
+               if ( ! is_user_logged_in() ) {
+                       return;
+               }
+
+               $post = get_post();
+
+               if ( 'page' == $post->post_type || ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) ) {
+
+                       $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
+
+                       echo ' | ';
+
+                       if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) {
+                               printf(
+                                       __( '<a href="%s" title="%s">Unwatch</a>', 'wporg' ),
+                                       wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ),
+                                       esc_attr__( 'Stop getting notified about changes to this page', 'wporg' )
+                               );
+                       } else {
+                               printf(
+                                       __( '<a href="%s" title="%s">Watch</a>', 'wporg' ),
+                                       wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ),
+                                       esc_attr__( 'Get notified about changes to this page', 'wporg' )
+                               );
+                       }
+
+               }
+
+       }
+
+}
+
+WPorg_Handbook_Watchlist::init();
+
</ins><span class="cx">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<ins>+native
</ins><span class="cx">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginshandbookincwidgetsphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php (771 => 772)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php        2014-07-30 21:45:32 UTC (rev 771)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php   2014-07-30 21:45:47 UTC (rev 772)
</span><span class="lines">@@ -1,61 +1,5 @@
</span><span class="cx"> <?php
</span><span class="cx"> 
</span><del>-class WPorg_Handbook_Widget extends WP_Widget {
-
-       protected $post_types = array( 'handbook' );
-
-       function __construct() {
-               $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types );
-               $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
-               parent::__construct( 'handbook', __( 'Handbook Tools', 'wporg' ), array( 'classname' => 'widget_wporg_handbook', 'description' => __( 'Shows watch/unwatch links for handbook pages.', 'wporg' ) ) );
-       }
-
-       function widget( $args, $instance ) {
-               if ( ! is_user_logged_in() )
-                       return;
-
-               $post = get_post();
-               if ( $post->post_type == 'page' || ( in_array( $post->post_type, $this->post_types ) && ! is_post_type_archive( $this->post_types ) ) ) {
-                       $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
-                       if ( isset( $args['before_widget'] ) && $args['before_widget'] ) {
-                               echo $args['before_widget'];
-                       }
-                       echo '<p>';
-                       if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) {
-                               printf( __( 'You are watching this page. <a href="%s">Unwatch</a>', 'wporg' ),
-                               wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ) );
-                       } else {
-                               printf( __( '<a href="%s">Watch this page</a>', 'wporg' ),
-                               wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ) );
-                       }
-                       echo '</p>';
-                       if ( isset( $args['after_widget'] ) && $args['after_widget'] ) {
-                               echo $args['after_widget'];
-                       }
-               } else {
-                       return;
-               }
-
-       }
-
-       function append_suffix( $t ) {
-               if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
-                       return $t;
-               }
-
-               return $t . '-handbook';
-       }
-}
-
-class WPorg_Handbook_Widget_for_Pages extends WPorg_Handbook_Widget {
-
-       protected $post_types = array( 'page' );
-
-       function __construct() {
-               WP_Widget::__construct( 'handbook_for_pages', __( 'Handbook Tools (for Pages)', 'wporg' ), array( 'classname' => 'widget_wporg_handbook', 'description' => __( 'Shows watch/unwatch links for Pages.', 'wporg' ) ) );
-       }
-}
-
</del><span class="cx"> class WPorg_Handbook_Pages_Widget extends WP_Widget_Pages {
</span><span class="cx"> 
</span><span class="cx">  protected $post_types = array( 'handbook' );
</span></span></pre>
</div>
</div>

</body>
</html>