<!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>[4260] sites/trunk/wordpress.org/public_html/wp-content: Plugin Directory: Move the Stats from `wp-admin` to the front-end `/$plugin/admin/` screen.</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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/4260">4260</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/4260","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-19 02:30:54 +0000 (Wed, 19 Oct 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Move the Stats from `wp-admin` to the front-end `/$plugin/admin/` screen.
This also implements the capabilities required for access to the plugin admin screen for each plugin.
See <a href="http://meta.trac.wordpress.org/ticket/2111">#2111</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclasscustomizationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasscapabilitiesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginsfunctionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginstemplatepartspluginsinglephp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginstemplatepartssectionadminphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-admin.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginsjsstatsjs">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/js/stats.js</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminmetaboxclassstatsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-stats.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjsstatsjs">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/stats.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminclasscustomizationsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -375,12 +375,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'plugin', 'side'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_meta_box(
- 'plugin-stats',
- __( 'Plugin Stats', 'wporg-plugins' ),
- array( __NAMESPACE__ . '\Metabox\Stats', 'display' ),
- 'plugin', 'normal'
- );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Remove unnecessary metaboxes.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminmetaboxclassstatsphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-stats.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-stats.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-stats.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,70 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
-use WordPressdotorg\Plugin_Directory;
-use WordPressdotorg\Plugin_Directory\Template;
-
-/**
- * The Plugin Stats metabox.
- *
- * @package WordPressdotorg\Plugin_Directory\Admin\Metabox
- */
-class Stats {
-
- /**
- * Displays the stats metabox for plugins.
- *
- * @global \wpdb $wpdb WordPress database abstraction object.
- *
- * @param \WP_Post $post
- */
- static function display( $post ) {
- global $wpdb;
-
- wp_enqueue_script( 'google-jsapi', 'https://www.google.com/jsapi', array(), false, true );
- wp_enqueue_script( 'wporg-plugins-stats', plugins_url( 'js/stats.js', Plugin_Directory\PLUGIN_FILE ) , array( 'jquery', 'google-jsapi' ), time(), true );
- wp_localize_script( 'wporg-plugins-stats', 'pluginStats', array(
- 'slug' => $post->post_name,
- 'l10n' => array(
- 'date' => __( 'Date', 'wporg-plugins' ),
- 'downloads' => __( 'Downloads', 'wporg-plugins' ),
- 'noData' => __( 'No data yet', 'wporg-plugins' ),
- ),
- ) );
-
- $today = $wpdb->get_var( $wpdb->prepare( "SELECT downloads FROM " . PLUGINS_TABLE_PREFIX . "stats WHERE stamp >= %s AND plugin_slug = %s", gmdate( 'Y-m-d' ), $post->post_name ) );
- $yesterday = $wpdb->get_var( $wpdb->prepare( "SELECT downloads FROM " . PLUGINS_TABLE_PREFIX . "stats WHERE stamp >= %s AND stamp < %s AND plugin_slug = %s",
- gmdate( 'Y-m-d', time() - DAY_IN_SECONDS ), gmdate( 'Y-m-d' ), $post->post_name
- ) );
- $last_week = $wpdb->get_var( $wpdb->prepare( "SELECT SUM(downloads) FROM " . PLUGINS_TABLE_PREFIX . "stats WHERE stamp >= %s AND plugin_slug = %s",
- gmdate( 'Y-m-d', time() - WEEK_IN_SECONDS ), $post->post_name
- ) );
-
- ?>
- <h5><?php _e( 'Active versions', 'wporg-plugins' ); ?></h5>
- <div id="plugin-version-stats" class="chart"></div>
-
- <h5><?php _e( 'Downloads Per Day', 'wporg-plugins' ); ?></h5>
- <div id="plugin-download-stats" class="chart"></div>
-
- <h5><?php _e( 'Downloads history', 'wporg-plugins' ); ?></h5>
- <table>
- <tr>
- <th scope="row"><?php _e( 'Today', 'wporg-plugins' ); ?></th>
- <td><?php echo number_format_i18n( $today ); ?></td>
- </tr>
- <tr>
- <th scope="row"><?php _e( 'Yesterday', 'wporg-plugins' ); ?></th>
- <td><?php echo number_format_i18n( $yesterday ); ?></td>
- </tr>
- <tr>
- <th scope="row"><?php _e( 'Last Week', 'wporg-plugins' ); ?></th>
- <td><?php echo number_format_i18n( $last_week ); ?></td>
- </tr>
- <tr>
- <th scope="row"><?php _e( 'All Time', 'wporg-plugins' ); ?></th>
- <td><?php echo number_format_i18n( Template::get_downloads_count( $post ) ); ?></td>
- </tr>
- </table>
- <?php
- }
-}
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclasscapabilitiesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-capabilities.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,44 +21,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Primitive caps.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function map_meta_cap( $required_caps, $cap, $user_id, $context ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin_edit_cap = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> switch( $cap ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- // TODO: Map these for the users
- case 'plugin_edit':
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'plugin_admin_edit':
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'plugin_add_committer':
</span><span class="cx" style="display: block; padding: 0 10px"> case 'plugin_remove_committer':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin_edit_cap = true;
+ // Fall through
+
+ case 'plugin_admin_view':
+ // Committers + Contributors.
+ // If no committers, post_author.
</ins><span class="cx" style="display: block; padding: 0 10px"> $required_caps = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $context[0] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $required_caps[] = 'do_not_allow';
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user = new \WP_User( $user_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user = new \WP_User( $user_id );
+ if ( $user->has_cap( 'plugin_review' ) ) {
+ $required_caps[] = 'plugin_review';
+ break;
+ }
+
+ // Committers
</ins><span class="cx" style="display: block; padding: 0 10px"> $committers = Tools::get_plugin_committers( $post->post_name );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $committers && 'publish' === $post->post_status ) {
+ // post_author in the event no committers exist (yet?)
+ $committers = array( get_user_by( 'ID', $post->post_author )->user_login );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( (int) $post->post_author === $user_id || in_array( $user->user_login, $committers, true ) ) {
- $required_caps[] = 'plugin_edit_own';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( in_array( $user->user_login, $committers ) ) {
+ $required_caps[] = 'exist'; // All users are allowed to exist, even when they have no role.
+ break;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
-
- if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
- $required_caps[] = 'plugin_review';
-
- } else {
- $required_caps[] = 'plugin_approve';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $plugin_edit_cap ) {
+ // Contributors can view, but not edit.
+ $contributors = (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'name' );
+ if ( in_array( $user->user_nicename, $contributors, true ) ) {
+ $required_caps[] = 'exist'; // All users are allowed to exist, even when they have no role.
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Don't allow any users to alter the post meta for plugins.
- case 'add_post_meta':
- case 'edit_post_meta':
- case 'delete_post_meta':
- $post = get_post( $context );
- if ( $post && 'plugin' == $post->post_type ) {
- $required_caps[] = 'do_not_allow';
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Else;
+ $required_caps[] = 'do_not_allow';
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> case 'plugin_transition':
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -84,10 +94,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $reviewer = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'read' => true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'plugin_edit_own' => true,
</del><span class="cx" style="display: block; padding: 0 10px"> 'plugin_set_category' => true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'plugin_add_committer' => true,
- 'plugin_edit_others' => true,
</del><span class="cx" style="display: block; padding: 0 10px"> 'moderate_comments' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'plugin_edit_pending' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'plugin_review' => true,
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -243,7 +243,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'search_items' => __( 'Search Tags', 'wporg-plugins' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'public' => true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'show_ui' => is_super_admin(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'show_ui' => true,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'show_admin_column' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_box_cb' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'capabilities' => array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -286,9 +286,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_rewrite_tag( '%browse%', '(featured|popular|beta|new|favorites)' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_permastruct( 'browse', 'browse/%browse%' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // /browse/ should be the popular archive view.
- add_rewrite_rule( '^browse$', 'index.php?browse=popular', 'top' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Create an archive for a users favorites too.
</span><span class="cx" style="display: block; padding: 0 10px"> add_rewrite_rule( '^browse/favorites/([^/]+)$', 'index.php?browse=favorites&favorites_user=$matches[1]', 'top' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -569,8 +566,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO: Make plugins owned by `post_author = $current_user_id` show up here when they're not-publish?
-
</del><span class="cx" style="display: block; padding: 0 10px"> $wp_query->query_vars['orderby'] = 'post_title';
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_query->query_vars['order'] = 'ASC';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -591,7 +586,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $posts;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO: Switch this to the capabilities systems
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Only the 'publish' cap shouldn't be affected by cap checks.
</ins><span class="cx" style="display: block; padding: 0 10px"> $restricted_access_statii = array_diff( $wp_query->query_vars['post_status'], array( 'publish' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $posts as $i => $post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // If the plugin is not in the restricted statuses list, show it
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -599,27 +594,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Plugin Reviewers can see all sorts of plugins
- if ( current_user_can( 'plugin_review' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If the current user can view the plugin admin, show it
+ if ( current_user_can( 'plugin_admin_view', $post ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Original submitter can always see
- if ( $post->post_author == get_current_user_id() ) {
- continue;
- }
-
- // Committers (user_login) can always see
- if ( in_array( wp_get_current_user()->user_login, (array) Tools::get_plugin_committers( $post->post_name ), true ) ) {
- continue;
- }
-
- // Contributors (user_nicename) can always see
- if ( in_array( wp_get_current_user()->user_nicename, (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'slug' ), true ) ) {
- continue;
- }
-
- // everyone else can't.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Else hide it.
</ins><span class="cx" style="display: block; padding: 0 10px"> unset( $posts[ $i ] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -801,7 +781,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> switch ( $term->taxonomy ) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'plugin_contributors':
</span><span class="cx" style="display: block; padding: 0 10px"> case 'plugin_committers':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user = get_user_by( 'slug', $term->slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user = get_user_by( 'slug', $term->name );
</ins><span class="cx" style="display: block; padding: 0 10px"> $name = $user->display_name;
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -887,24 +867,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> die();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // TODO: Switch this to the capabilities systems, check if post_author should access
</del><span class="cx" style="display: block; padding: 0 10px"> // Filter access to the plugin administration area. Only certain users are allowed access.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( get_query_var( 'plugin_admin' ) && ! current_user_can( 'plugin_review' ) ) {
- $post = Plugin_Directory::get_plugin_post( get_query_var( 'name' ) );
- if (
- // Logged out users can't access plugin admin
- ! is_user_logged_in() ||
- // Allow access to Committers OR Contributors.
- ! (
- // Committers can access plugin admin
- in_array( wp_get_current_user()->user_login, (array) Tools::get_plugin_committers( $post->post_name ), true ) ||
- // Contributors can access plugin admin (but will have a more limited access)
- in_array( wp_get_current_user()->user_nicename, (array) wp_list_pluck( get_the_terms( $post, 'plugin_contributors' ), 'slug' ), true )
- )
- ) {
- wp_safe_redirect( get_permalink( $post ) );
- die();
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( get_query_var( 'plugin_admin' ) &&
+ ! current_user_can(
+ 'plugin_admin_view',
+ $post = Plugin_Directory::get_plugin_post( get_query_var( 'name' ) )
+ )
+ ) {
+ wp_safe_redirect( get_permalink( $post ) );
+ die();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjsstatsjs"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/stats.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/stats.js 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/stats.js 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,120 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-google.load( "visualization", "1", { packages: ["corechart"] } );
-
-( function( $, settings ) {
- $( function () {
- jQuery.getJSON('https://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=' + settings.slug + '&limit=267&callback=?', function( downloads ) {
- var data = new google.visualization.DataTable(),
- count = 0,
- sml;
-
- data.addColumn( 'date', settings.l10n.date );
- data.addColumn( 'number', settings.l10n.downloads );
-
- $.each( downloads, function( key, value ) {
- data.addRow();
- data.setValue( count, 0, new Date( key ) );
- data.setValue( count, 1, Number( value ) );
- count++;
- } );
-
- sml = data.getNumberOfRows() < 225;
-
- new google.visualization.LineChart( document.getElementById( 'plugin-download-stats' ) ).draw( data, {
- colors: ['#253578'],
- legend: { position: 'none' },
- titlePosition: 'in',
- axisTitlesPosition: 'in',
- chartArea: {
- height: 280,
- left: ( sml ? 50 : 0 ),
- width: ( sml ? 482 : '100%' )
- },
- hAxis: {
- textStyle: { color: 'black', fontSize: 9 },
- format: 'MMM y'
- },
- vAxis: {
- format: '###,###',
- textPosition: ( sml ? 'out' : 'in' ),
- viewWindowMode: 'explicit',
- viewWindow: { min: 0 }
- },
- bar: { groupWidth: ( data.getNumberOfRows() > 100 ? "100%" : null ) },
- height: 350,
- width: 532,
- curveType: 'function'
- } );
- } );
-
- $.getJSON( 'https://api.wordpress.org/stats/plugin/1.0/?slug=' + settings.slug + '&callback=?', function ( versions ) {
- if ( 0 === versions.length ) {
- $( '#plugin-version-stats' ).text( settings.l10n.noData );
- return;
- }
-
- var barHeaders = [ '' ],
- barValues = [ '' ],
- versionList = [],
- index = 0,
- version, data, formatter;
-
- // Gather and sort the list of versions.
- $.each( versions, function( version ) {
- versionList.push( version );
- } );
-
- // Sort the version list by version.
- versionList.sort( function( a, b ) {
- a = a.split( '.' );
- b = b.split( '.' );
- return ( a[0] != b[0] ) ? a[0]-b[0] : a[1]-b[1];
- } );
-
- // Move 'other' versions to the beginning.
- if ( 'other' === versionList[ versionList.length - 1 ] ) {
- versionList.unshift( versionList.pop() );
- }
-
- // Add all the versions
- versionList.forEach( function( version ) {
- barHeaders.push( version );
- barValues.push( versions[ version ] );
- } );
-
- data = google.visualization.arrayToDataTable([
- barHeaders,
- barValues
- ]);
-
- // Format it as percentages
- formatter = new google.visualization.NumberFormat( {
- fractionDigits: 1,
- suffix: '%'
- } );
-
- $.each( barValues, function( value ) {
- if ( barValues[ value ] ) {
- formatter.format( data, ++index );
- }
- } );
-
- new google.visualization.BarChart( document.getElementById( 'plugin-version-stats' ) ).draw( data, {
- legend: {
- position: 'bottom'
- },
- chartArea: {
- left: '0',
- width: '100%',
- height: '80%',
- top: '10%'
- },
- hAxis: {
- gridlines: {
- color: 'transparent'
- }
- },
- isStacked: true
- } );
- } );
- } );
-} )( window.jQuery, window.pluginStats );
</del></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginsfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,6 +82,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'currentPlugin' => is_singular( 'plugin' ) ? get_queried_object()->post_name : '',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( get_query_var( 'plugin_admin' ) ) {
+ wp_enqueue_script( 'google-jsapi', 'https://www.google.com/jsapi', array(), false, true );
+ wp_enqueue_script( 'wporg-plugins-stats', get_template_directory_uri() . '/js/stats.js', array( 'jquery', 'google-jsapi' ), '20161019', true );
+
+
+ wp_localize_script( 'wporg-plugins-stats', 'pluginStats', array(
+ 'slug' => is_singular( 'plugin' ) ? get_queried_object()->post_name : '',
+ 'l10n' => array(
+ 'date' => __( 'Date', 'wporg-plugins' ),
+ 'downloads' => __( 'Downloads', 'wporg-plugins' ),
+ 'noData' => __( 'No data yet', 'wporg-plugins' ),
+ 'today' => __( 'Today', 'wporg-plugins' ),
+ 'yesterday' => __( 'Yesterday', 'wporg-plugins' ),
+ 'last_week' => __( 'Last Week', 'wporg-plugins' ),
+ 'all_time' => __( 'All Time', 'wporg-plugins' ),
+ ),
+ ) );
+
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $_REQUEST['react'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script( 'wporg-plugins-client', get_template_directory_uri() . '/js/theme.js', array(), false, true );
</span><span class="cx" style="display: block; padding: 0 10px"> wp_localize_script( 'wporg-plugins-client', 'app_data', array(
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginsjsstatsjsfromrev4258sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjsstatsjs"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/js/stats.js (from rev 4258, sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/stats.js)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/js/stats.js (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/js/stats.js 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,138 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+google.load( "visualization", "1", { packages: ["corechart"] } );
+
+( function( $, settings ) {
+ $( function () {
+ $.getJSON('https://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=' + settings.slug + '&limit=267&callback=?', function( downloads ) {
+ var data = new google.visualization.DataTable(),
+ count = 0,
+ sml;
+
+ data.addColumn( 'date', settings.l10n.date );
+ data.addColumn( 'number', settings.l10n.downloads );
+
+ $.each( downloads, function( key, value ) {
+ data.addRow();
+ data.setValue( count, 0, new Date( key ) );
+ data.setValue( count, 1, Number( value ) );
+ count++;
+ } );
+
+ sml = data.getNumberOfRows() < 225;
+
+ new google.visualization.LineChart( document.getElementById( 'plugin-download-stats' ) ).draw( data, {
+ colors: ['#253578'],
+ legend: { position: 'none' },
+ titlePosition: 'in',
+ axisTitlesPosition: 'in',
+ chartArea: {
+ height: 280,
+ left: ( sml ? 50 : 0 ),
+ width: ( sml ? 482 : '100%' )
+ },
+ hAxis: {
+ textStyle: { color: 'black', fontSize: 9 },
+ format: 'MMM y'
+ },
+ vAxis: {
+ format: '###,###',
+ textPosition: ( sml ? 'out' : 'in' ),
+ viewWindowMode: 'explicit',
+ viewWindow: { min: 0 }
+ },
+ bar: { groupWidth: ( data.getNumberOfRows() > 100 ? "100%" : null ) },
+ height: 350,
+ width: 532,
+ curveType: 'function'
+ } );
+ } );
+
+ $.getJSON('https://api.wordpress.org/stats/plugin/1.0/downloads.php?slug=' + settings.slug + '&historical_summary=1&callback=?', function( summary ) {
+ var $tbody = $('table#plugin-download-history-stats tbody:last-child');
+
+ for ( var summary_field in summary ) {
+ if ( ! summary.hasOwnProperty( summary_field ) ) {
+ continue;
+ }
+
+ var text = settings.l10n[summary_field];
+ var count = parseInt(summary[ summary_field ]).toLocaleString();
+
+ $newrow = $("<tr><th scope='row'></th><td>0</td></tr>");
+ $newrow.find( 'th' ).text( text );
+ $newrow.find( 'td' ).text( count );
+ $tbody.append( $newrow );
+ }
+ } );
+
+ $.getJSON( 'https://api.wordpress.org/stats/plugin/1.0/?slug=' + settings.slug + '&callback=?', function ( versions ) {
+ if ( 0 === versions.length ) {
+ $( '#plugin-version-stats' ).text( settings.l10n.noData );
+ return;
+ }
+
+ var barHeaders = [ '' ],
+ barValues = [ '' ],
+ versionList = [],
+ index = 0,
+ version, data, formatter;
+
+ // Gather and sort the list of versions.
+ $.each( versions, function( version ) {
+ versionList.push( version );
+ } );
+
+ // Sort the version list by version.
+ versionList.sort( function( a, b ) {
+ a = a.split( '.' );
+ b = b.split( '.' );
+ return ( a[0] != b[0] ) ? a[0]-b[0] : a[1]-b[1];
+ } );
+
+ // Move 'other' versions to the beginning.
+ if ( 'other' === versionList[ versionList.length - 1 ] ) {
+ versionList.unshift( versionList.pop() );
+ }
+
+ // Add all the versions
+ versionList.forEach( function( version ) {
+ barHeaders.push( version );
+ barValues.push( versions[ version ] );
+ } );
+
+ data = google.visualization.arrayToDataTable([
+ barHeaders,
+ barValues
+ ]);
+
+ // Format it as percentages
+ formatter = new google.visualization.NumberFormat( {
+ fractionDigits: 1,
+ suffix: '%'
+ } );
+
+ $.each( barValues, function( value ) {
+ if ( barValues[ value ] ) {
+ formatter.format( data, ++index );
+ }
+ } );
+
+ new google.visualization.BarChart( document.getElementById( 'plugin-version-stats' ) ).draw( data, {
+ legend: {
+ position: 'bottom'
+ },
+ chartArea: {
+ left: '0',
+ width: '100%',
+ height: '80%',
+ top: '10%'
+ },
+ hAxis: {
+ gridlines: {
+ color: 'transparent'
+ }
+ },
+ isStacked: true
+ } );
+ } );
+ } );
+} )( window.jQuery, window.pluginStats );
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginstemplatepartspluginsinglephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,9 +88,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <div>
</span><span class="cx" style="display: block; padding: 0 10px"> <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>" itemprop="downloadUrl"><?php _e( 'Download', 'wporg-plugins' ); ?></a>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php if ( true /* TODO: Logic on when to show the edit link */ ) : ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php if ( current_user_can( 'plugin_admin_view', get_post() ) ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <br>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <a class="plugin-edit" href="<?php echo esc_url( get_permalink() . 'admin/' ); ?>"><?php _e( 'Edit Plugin', 'wporg-plugins' ); ?></a>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <a class="plugin-edit" href="<?php echo esc_url( get_permalink() . 'admin/' ); ?>"><?php _e( 'Edit Plugin', 'wporg-plugins' ); ?></a>
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgpluginstemplatepartssectionadminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-admin.php 2016-10-19 02:27:58 UTC (rev 4259)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/section-admin.php 2016-10-19 02:30:54 UTC (rev 4260)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,3 +1,27 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Template part for displaying the plugin administration sections.
+ *
+ * @link https://codex.wordpress.org/Template_Hierarchy
+ *
+ * @package WordPressdotorg\Plugin_Directory\Theme
+ */
+
+namespace WordPressdotorg\Plugin_Directory\Theme;
+use WordPressdotorg\Plugin_Directory\Plugin_Directory;
+use WordPressdotorg\Plugin_Directory\Template;
+?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <div id="admin">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <h2><?php _e( 'Plugin Admin', 'wporg-plugins' ); ?></h2>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <h2><?php _e( 'Plugin Stats', 'wporg-plugins' ); ?></h2>
+
+ <h3><?php _e( 'Active versions', 'wporg-plugins' ); ?></h3>
+ <div id="plugin-version-stats" class="chart"></div>
+
+ <h3><?php _e( 'Downloads Per Day', 'wporg-plugins' ); ?></h3>
+ <div id="plugin-download-stats" class="chart"></div>
+
+ <h4><?php _e( 'Downloads history', 'wporg-plugins' ); ?></h4>
+ <table id="plugin-download-history-stats"><tbody></tbody></table>
+
+
</ins><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>