Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/blogs-gentoo:master commit in: plugins/akismet/
Date: Mon, 20 Nov 2017 21:52:53
Message-Id: 1511214547.056e9aabd5b356b57e66575340e47acf5901b65b.blueness@gentoo
1 commit: 056e9aabd5b356b57e66575340e47acf5901b65b
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Mon Nov 20 21:49:07 2017 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Mon Nov 20 21:49:07 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/blogs-gentoo.git/commit/?id=056e9aab
7
8 Update akismet 4.0.1
9
10 Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>
11
12 plugins/akismet/akismet.php | 4 +-
13 plugins/akismet/class.akismet-admin.php | 24 +++++++++---
14 plugins/akismet/class.akismet.php | 66 ++++++++++++++++++++++++++-------
15 plugins/akismet/readme.txt | 15 ++++++--
16 4 files changed, 85 insertions(+), 24 deletions(-)
17
18 diff --git a/plugins/akismet/akismet.php b/plugins/akismet/akismet.php
19 index 56babcb..c29057e 100644
20 --- a/plugins/akismet/akismet.php
21 +++ b/plugins/akismet/akismet.php
22 @@ -6,7 +6,7 @@
23 Plugin Name: Akismet Anti-Spam
24 Plugin URI: https://akismet.com/
25 Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
26 -Version: 4.0
27 +Version: 4.0.1
28 Author: Automattic
29 Author URI: https://automattic.com/wordpress-plugins/
30 License: GPLv2 or later
31 @@ -37,7 +37,7 @@ if ( !function_exists( 'add_action' ) ) {
32 exit;
33 }
34
35 -define( 'AKISMET_VERSION', '4.0' );
36 +define( 'AKISMET_VERSION', '4.0.1' );
37 define( 'AKISMET__MINIMUM_WP_VERSION', '4.0' );
38 define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
39 define( 'AKISMET_DELETE_LIMIT', 100000 );
40
41 diff --git a/plugins/akismet/class.akismet-admin.php b/plugins/akismet/class.akismet-admin.php
42 index bc00260..926b3c7 100644
43 --- a/plugins/akismet/class.akismet-admin.php
44 +++ b/plugins/akismet/class.akismet-admin.php
45 @@ -92,10 +92,10 @@ class Akismet_Admin {
46
47 public static function load_menu() {
48 if ( class_exists( 'Jetpack' ) ) {
49 - $hook = add_submenu_page( 'jetpack', __( 'Akismet' , 'akismet'), __( 'Akismet' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
50 + $hook = add_submenu_page( 'jetpack', __( 'Akismet Anti-Spam' , 'akismet'), __( 'Akismet Anti-Spam' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
51 }
52 else {
53 - $hook = add_options_page( __('Akismet', 'akismet'), __('Akismet', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
54 + $hook = add_options_page( __('Akismet Anti-Spam', 'akismet'), __('Akismet Anti-Spam', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
55 }
56
57 if ( $hook ) {
58 @@ -1061,8 +1061,22 @@ class Akismet_Admin {
59 if ( !$xml->isError() ) {
60 $responses = $xml->getResponse();
61 if ( count( $responses ) > 1 ) {
62 - $api_key = array_shift( $responses[0] );
63 - $user_id = (int) array_shift( $responses[1] );
64 + // Due to a quirk in how Jetpack does multi-calls, the response order
65 + // can't be trusted to match the call order. It's a good thing our
66 + // return values can be mostly differentiated from each other.
67 + $first_response_value = array_shift( $responses[0] );
68 + $second_response_value = array_shift( $responses[1] );
69 +
70 + // If WPCOM ever reaches 100 billion users, this will fail. :-)
71 + if ( preg_match( '/^[a-f0-9]{12}$/i', $first_response_value ) ) {
72 + $api_key = $first_response_value;
73 + $user_id = (int) $second_response_value;
74 + }
75 + else {
76 + $api_key = $second_response_value;
77 + $user_id = (int) $first_response_value;
78 + }
79 +
80 return compact( 'api_key', 'user_id' );
81 }
82 }
83 @@ -1100,4 +1114,4 @@ class Akismet_Admin {
84
85 return $all_plugins;
86 }
87 -}
88 \ No newline at end of file
89 +}
90
91 diff --git a/plugins/akismet/class.akismet.php b/plugins/akismet/class.akismet.php
92 index 02d994d..32b23ea 100644
93 --- a/plugins/akismet/class.akismet.php
94 +++ b/plugins/akismet/class.akismet.php
95 @@ -37,6 +37,7 @@ class Akismet {
96 add_action( 'admin_head-edit-comments.php', array( 'Akismet', 'load_form_js' ) );
97 add_action( 'comment_form', array( 'Akismet', 'load_form_js' ) );
98 add_action( 'comment_form', array( 'Akismet', 'inject_ak_js' ) );
99 + add_filter( 'script_loader_tag', array( 'Akismet', 'set_form_js_async' ), 10, 3 );
100
101 add_filter( 'comment_moderation_recipients', array( 'Akismet', 'disable_moderation_emails_if_unreachable' ), 1000, 2 );
102 add_filter( 'pre_comment_approved', array( 'Akismet', 'last_comment_status' ), 10, 2 );
103 @@ -533,24 +534,36 @@ class Akismet {
104 if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
105 return;
106
107 - global $current_user;
108 - $reporter = '';
109 - if ( is_object( $current_user ) )
110 - $reporter = $current_user->user_login;
111 -
112 // Assumption alert:
113 // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
114 // is changed automatically by another plugin. Unfortunately WordPress doesn't provide an unambiguous way to
115 // determine why the transition_comment_status action was triggered. And there are several different ways by which
116 // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
117 // We'll assume that this is an explicit user action if certain POST/GET variables exist.
118 - if ( ( isset( $_POST['status'] ) && in_array( $_POST['status'], array( 'spam', 'unspam' ) ) ) ||
119 - ( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 ) ||
120 - ( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 ) ||
121 - ( isset( $_POST['comment_status'] ) && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) ) ||
122 - ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment', ) ) ) ||
123 - ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) ) ||
124 - ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) ) // Moderation via WP.com notifications/WP app/etc.
125 + if (
126 + // status=spam: Marking as spam via the REST API or...
127 + // status=unspam: I'm not sure. Maybe this used to be used instead of status=approved? Or the UI for removing from spam but not approving has been since removed?...
128 + // status=approved: Unspamming via the REST API (Calypso) or...
129 + ( isset( $_POST['status'] ) && in_array( $_POST['status'], array( 'spam', 'unspam', 'approved', ) ) )
130 + // spam=1: Clicking "Spam" underneath a comment in wp-admin and allowing the AJAX request to happen.
131 + || ( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 )
132 + // unspam=1: Clicking "Not Spam" underneath a comment in wp-admin and allowing the AJAX request to happen. Or, clicking "Undo" after marking something as spam.
133 + || ( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 )
134 + // comment_status=spam/unspam: It's unclear where this is happening.
135 + || ( isset( $_POST['comment_status'] ) && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) )
136 + // action=spam: Choosing "Mark as Spam" from the Bulk Actions dropdown in wp-admin (or the "Spam it" link in notification emails).
137 + // action=unspam: Choosing "Not Spam" from the Bulk Actions dropdown in wp-admin.
138 + // action=spamcomment: Following the "Spam" link below a comment in wp-admin (not allowing AJAX request to happen).
139 + // action=unspamcomment: Following the "Not Spam" link below a comment in wp-admin (not allowing AJAX request to happen).
140 + || ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment', ) ) )
141 + // action=editedcomment: Editing a comment via wp-admin (and possibly changing its status).
142 + || ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) )
143 + // for=jetpack: Moderation via the WordPress app, Calypso, anything powered by the Jetpack connection.
144 + || ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) && ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) )
145 + // Certain WordPress.com API requests
146 + || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST )
147 + // WordPress.org REST API requests
148 + || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
149 ) {
150 if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
151 return self::submit_spam_comment( $comment->comment_ID );
152 @@ -1104,6 +1117,19 @@ class Akismet {
153 wp_enqueue_script( 'akismet-form' );
154 }
155
156 + /**
157 + * Mark form.js as async. Because nothing depends on it, it can run at any time
158 + * after it's loaded, and the browser won't have to wait for it to load to continue
159 + * parsing the rest of the page.
160 + */
161 + public static function set_form_js_async( $tag, $handle, $src ) {
162 + if ( 'akismet-form' !== $handle ) {
163 + return $tag;
164 + }
165 +
166 + return preg_replace( '/^<script /i', '<script async="async" ', $tag );
167 + }
168 +
169 public static function inject_ak_js( $fields ) {
170 echo '<p style="display: none;">';
171 echo '<input type="hidden" id="ak_js" name="ak_js" value="' . mt_rand( 0, 250 ) . '"/>';
172 @@ -1184,7 +1210,21 @@ p {
173 * @static
174 */
175 public static function plugin_deactivation( ) {
176 - return self::deactivate_key( self::get_api_key() );
177 + self::deactivate_key( self::get_api_key() );
178 +
179 + // Remove any scheduled cron jobs.
180 + $akismet_cron_events = array(
181 + 'akismet_schedule_cron_recheck',
182 + 'akismet_scheduled_delete',
183 + );
184 +
185 + foreach ( $akismet_cron_events as $akismet_cron_event ) {
186 + $timestamp = wp_next_scheduled( $akismet_cron_event );
187 +
188 + if ( $timestamp ) {
189 + wp_unschedule_event( $timestamp, $akismet_cron_event );
190 + }
191 + }
192 }
193
194 /**
195
196 diff --git a/plugins/akismet/readme.txt b/plugins/akismet/readme.txt
197 index a1bd5b6..0280880 100644
198 --- a/plugins/akismet/readme.txt
199 +++ b/plugins/akismet/readme.txt
200 @@ -1,9 +1,9 @@
201 -=== Akismet ===
202 -Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eoigal, cfinke, automattic, jgs
203 +=== Akismet Anti-Spam ===
204 +Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eoigal, cfinke, automattic, jgs, procifer
205 Tags: akismet, comments, spam, antispam, anti-spam, anti spam, comment moderation, comment spam, contact form spam, spam comments
206 Requires at least: 4.0
207 -Tested up to: 4.8.1
208 -Stable tag: 4.0
209 +Tested up to: 4.9
210 +Stable tag: 4.0.1
211 License: GPLv2 or later
212
213 Akismet checks your comments and contact form submissions against our global database of spam to protect you and your site from malicious content.
214 @@ -30,6 +30,13 @@ Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.co
215
216 == Changelog ==
217
218 += 4.0.1 =
219 +*Release Date - 6 November 2017*
220 +
221 +* Fixed a bug that could prevent some users from connecting Akismet via their Jetpack connection.
222 +* Ensured that any pending Akismet-related events are unscheduled if the plugin is deactivated.
223 +* Allow some JavaScript to be run asynchronously to avoid affecting page render speeds.
224 +
225 = 4.0 =
226 *Release Date - 19 September 2017*