]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-upgrader-skins.php
WordPress 4.3
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-upgrader-skins.php
1 <?php
2 /**
3  * The User Interface "Skins" for the WordPress File Upgrader
4  *
5  * @package WordPress
6  * @subpackage Upgrader
7  * @since 2.8.0
8  */
9
10 /**
11  * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
12  *
13  * @package WordPress
14  * @subpackage Upgrader
15  * @since 2.8.0
16  */
17 class WP_Upgrader_Skin {
18
19         public $upgrader;
20         public $done_header = false;
21         public $done_footer = false;
22         public $result = false;
23         public $options = array();
24
25         /**
26          *
27          * @param array $args
28          */
29         public function __construct($args = array()) {
30                 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
31                 $this->options = wp_parse_args($args, $defaults);
32         }
33
34         /**
35          * @param WP_Upgrader $upgrader
36          */
37         public function set_upgrader(&$upgrader) {
38                 if ( is_object($upgrader) )
39                         $this->upgrader =& $upgrader;
40                 $this->add_strings();
41         }
42
43         /**
44          * @access public
45          */
46         public function add_strings() {
47         }
48
49         /**
50          *
51          * @param string|false|WP_Error $result
52          */
53         public function set_result($result) {
54                 $this->result = $result;
55         }
56
57         /**
58          *
59          * @param bool   $error
60          * @param string $context
61          * @param bool   $allow_relaxed_file_ownership
62          * @return type
63          */
64         public function request_filesystem_credentials( $error = false, $context = false, $allow_relaxed_file_ownership = false ) {
65                 $url = $this->options['url'];
66                 if ( ! $context ) {
67                         $context = $this->options['context'];
68                 }
69                 if ( !empty($this->options['nonce']) ) {
70                         $url = wp_nonce_url($url, $this->options['nonce']);
71                 }
72
73                 $extra_fields = array();
74
75                 return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
76         }
77
78         /**
79          * @access public
80          */
81         public function header() {
82                 if ( $this->done_header ) {
83                         return;
84                 }
85                 $this->done_header = true;
86                 echo '<div class="wrap">';
87                 echo '<h1>' . $this->options['title'] . '</h1>';
88         }
89
90         /**
91          * @access public
92          */
93         public function footer() {
94                 if ( $this->done_footer ) {
95                         return;
96                 }
97                 $this->done_footer = true;
98                 echo '</div>';
99         }
100
101         /**
102          *
103          * @param string|WP_Error $errors
104          */
105         public function error($errors) {
106                 if ( ! $this->done_header )
107                         $this->header();
108                 if ( is_string($errors) ) {
109                         $this->feedback($errors);
110                 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
111                         foreach ( $errors->get_error_messages() as $message ) {
112                                 if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
113                                         $this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
114                                 else
115                                         $this->feedback($message);
116                         }
117                 }
118         }
119
120         /**
121          *
122          * @param string $string
123          */
124         public function feedback($string) {
125                 if ( isset( $this->upgrader->strings[$string] ) )
126                         $string = $this->upgrader->strings[$string];
127
128                 if ( strpos($string, '%') !== false ) {
129                         $args = func_get_args();
130                         $args = array_splice($args, 1);
131                         if ( $args ) {
132                                 $args = array_map( 'strip_tags', $args );
133                                 $args = array_map( 'esc_html', $args );
134                                 $string = vsprintf($string, $args);
135                         }
136                 }
137                 if ( empty($string) )
138                         return;
139                 show_message($string);
140         }
141
142         /**
143          * @access public
144          */
145         public function before() {}
146
147         /**
148          * @access public
149          */
150         public function after() {}
151
152         /**
153          * Output JavaScript that calls function to decrement the update counts.
154          *
155          * @since 3.9.0
156          *
157          * @param string $type Type of update count to decrement. Likely values include 'plugin',
158          *                     'theme', 'translation', etc.
159          */
160         protected function decrement_update_count( $type ) {
161                 if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
162                         return;
163                 }
164
165                 if ( defined( 'IFRAME_REQUEST' ) ) {
166                         echo '<script type="text/javascript">
167                                         if ( window.postMessage && JSON ) {
168                                                 window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
169                                         }
170                                 </script>';
171                 } else {
172                         echo '<script type="text/javascript">
173                                         (function( wp ) {
174                                                 if ( wp && wp.updates.decrementCount ) {
175                                                         wp.updates.decrementCount( "' . $type . '" );
176                                                 }
177                                         })( window.wp );
178                                 </script>';
179                 }
180         }
181
182         /**
183          * @access public
184          */
185         public function bulk_header() {}
186
187         /**
188          * @access public
189          */
190         public function bulk_footer() {}
191 }
192
193 /**
194  * Plugin Upgrader Skin for WordPress Plugin Upgrades.
195  *
196  * @package WordPress
197  * @subpackage Upgrader
198  * @since 2.8.0
199  */
200 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
201         public $plugin = '';
202         public $plugin_active = false;
203         public $plugin_network_active = false;
204
205         /**
206          *
207          * @param array $args
208          */
209         public function __construct( $args = array() ) {
210                 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
211                 $args = wp_parse_args($args, $defaults);
212
213                 $this->plugin = $args['plugin'];
214
215                 $this->plugin_active = is_plugin_active( $this->plugin );
216                 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
217
218                 parent::__construct($args);
219         }
220
221         /**
222          * @access public
223          */
224         public function after() {
225                 $this->plugin = $this->upgrader->plugin_info();
226                 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
227                         echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) .'"></iframe>';
228                 }
229
230                 $this->decrement_update_count( 'plugin' );
231
232                 $update_actions =  array(
233                         'activate_plugin' => '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>',
234                         'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>'
235                 );
236                 if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) )
237                         unset( $update_actions['activate_plugin'] );
238
239                 /**
240                  * Filter the list of action links available following a single plugin update.
241                  *
242                  * @since 2.7.0
243                  *
244                  * @param array  $update_actions Array of plugin action links.
245                  * @param string $plugin         Path to the plugin file.
246                  */
247                 $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
248
249                 if ( ! empty($update_actions) )
250                         $this->feedback(implode(' | ', (array)$update_actions));
251         }
252 }
253
254 /**
255  * Plugin Upgrader Skin for WordPress Plugin Upgrades.
256  *
257  * @package WordPress
258  * @subpackage Upgrader
259  * @since 3.0.0
260  */
261 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
262         public $in_loop = false;
263         /**
264          * @var string|false
265          */
266         public $error = false;
267
268         /**
269          *
270          * @param array $args
271          */
272         public function __construct($args = array()) {
273                 $defaults = array( 'url' => '', 'nonce' => '' );
274                 $args = wp_parse_args($args, $defaults);
275
276                 parent::__construct($args);
277         }
278
279         /**
280          * @access public
281          */
282         public function add_strings() {
283                 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.');
284                 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>');
285                 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
286                 $this->upgrader->strings['skin_update_successful'] = __( '%1$s updated successfully.' ) . ' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>' . __( 'Show Details' ) . '</span><span class="hidden">' . __( 'Hide Details' ) . '</span></a>';
287                 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
288         }
289
290         /**
291          * @param string $string
292          */
293         public function feedback($string) {
294                 if ( isset( $this->upgrader->strings[$string] ) )
295                         $string = $this->upgrader->strings[$string];
296
297                 if ( strpos($string, '%') !== false ) {
298                         $args = func_get_args();
299                         $args = array_splice($args, 1);
300                         if ( $args ) {
301                                 $args = array_map( 'strip_tags', $args );
302                                 $args = array_map( 'esc_html', $args );
303                                 $string = vsprintf($string, $args);
304                         }
305                 }
306                 if ( empty($string) )
307                         return;
308                 if ( $this->in_loop )
309                         echo "$string<br />\n";
310                 else
311                         echo "<p>$string</p>\n";
312         }
313
314         /**
315          * @access public
316          */
317         public function header() {
318                 // Nothing, This will be displayed within a iframe.
319         }
320
321         /**
322          * @access public
323          */
324         public function footer() {
325                 // Nothing, This will be displayed within a iframe.
326         }
327
328         /**
329          *
330          * @param string|WP_Error $error
331          */
332         public function error($error) {
333                 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
334                         $this->error = $this->upgrader->strings[$error];
335
336                 if ( is_wp_error($error) ) {
337                         $messages = array();
338                         foreach ( $error->get_error_messages() as $emessage ) {
339                                 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
340                                         $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
341                                 else
342                                         $messages[] = $emessage;
343                         }
344                         $this->error = implode(', ', $messages);
345                 }
346                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
347         }
348
349         /**
350          * @access public
351          */
352         public function bulk_header() {
353                 $this->feedback('skin_upgrade_start');
354         }
355
356         /**
357          * @access public
358          */
359         public function bulk_footer() {
360                 $this->feedback('skin_upgrade_end');
361         }
362
363         /**
364          *
365          * @param string $title
366          */
367         public function before($title = '') {
368                 $this->in_loop = true;
369                 printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h4>',  $title, $this->upgrader->update_current, $this->upgrader->update_count);
370                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
371                 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
372                 $this->flush_output();
373         }
374
375         /**
376          *
377          * @param string $title
378          */
379         public function after($title = '') {
380                 echo '</p></div>';
381                 if ( $this->error || ! $this->result ) {
382                         if ( $this->error )
383                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
384                         else
385                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
386
387                         echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
388                 }
389                 if ( $this->result && ! is_wp_error( $this->result ) ) {
390                         if ( ! $this->error )
391                                 echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
392                         echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
393                 }
394
395                 $this->reset();
396                 $this->flush_output();
397         }
398
399         /**
400          * @access public
401          */
402         public function reset() {
403                 $this->in_loop = false;
404                 $this->error = false;
405         }
406
407         /**
408          * @access public
409          */
410         public function flush_output() {
411                 wp_ob_end_flush_all();
412                 flush();
413         }
414 }
415
416 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
417         public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
418
419         public function add_strings() {
420                 parent::add_strings();
421                 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
422         }
423
424         /**
425          *
426          * @param string $title
427          */
428         public function before($title = '') {
429                 parent::before($this->plugin_info['Title']);
430         }
431
432         /**
433          *
434          * @param string $title
435          */
436         public function after($title = '') {
437                 parent::after($this->plugin_info['Title']);
438                 $this->decrement_update_count( 'plugin' );
439         }
440
441         /**
442          * @access public
443          */
444         public function bulk_footer() {
445                 parent::bulk_footer();
446                 $update_actions =  array(
447                         'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>',
448                         'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
449                 );
450                 if ( ! current_user_can( 'activate_plugins' ) )
451                         unset( $update_actions['plugins_page'] );
452
453                 /**
454                  * Filter the list of action links available following bulk plugin updates.
455                  *
456                  * @since 3.0.0
457                  *
458                  * @param array $update_actions Array of plugin action links.
459                  * @param array $plugin_info    Array of information for the last-updated plugin.
460                  */
461                 $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
462
463                 if ( ! empty($update_actions) )
464                         $this->feedback(implode(' | ', (array)$update_actions));
465         }
466 }
467
468 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
469         public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
470
471         public function add_strings() {
472                 parent::add_strings();
473                 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
474         }
475
476         /**
477          *
478          * @param string $title
479          */
480         public function before($title = '') {
481                 parent::before( $this->theme_info->display('Name') );
482         }
483
484         /**
485          *
486          * @param string $title
487          */
488         public function after($title = '') {
489                 parent::after( $this->theme_info->display('Name') );
490                 $this->decrement_update_count( 'theme' );
491         }
492
493         /**
494          * @access public
495          */
496         public function bulk_footer() {
497                 parent::bulk_footer();
498                 $update_actions =  array(
499                         'themes_page' => '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>',
500                         'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
501                 );
502                 if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
503                         unset( $update_actions['themes_page'] );
504
505                 /**
506                  * Filter the list of action links available following bulk theme updates.
507                  *
508                  * @since 3.0.0
509                  *
510                  * @param array $update_actions Array of theme action links.
511                  * @param array $theme_info     Array of information for the last-updated theme.
512                  */
513                 $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
514
515                 if ( ! empty($update_actions) )
516                         $this->feedback(implode(' | ', (array)$update_actions));
517         }
518 }
519
520 /**
521  * Plugin Installer Skin for WordPress Plugin Installer.
522  *
523  * @package WordPress
524  * @subpackage Upgrader
525  * @since 2.8.0
526  */
527 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
528         public $api;
529         public $type;
530
531         /**
532          *
533          * @param array $args
534          */
535         public function __construct($args = array()) {
536                 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
537                 $args = wp_parse_args($args, $defaults);
538
539                 $this->type = $args['type'];
540                 $this->api = isset($args['api']) ? $args['api'] : array();
541
542                 parent::__construct($args);
543         }
544
545         /**
546          * @access public
547          */
548         public function before() {
549                 if ( !empty($this->api) )
550                         $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
551         }
552
553         /**
554          * @access public
555          */
556         public function after() {
557                 $plugin_file = $this->upgrader->plugin_info();
558
559                 $install_actions = array();
560
561                 $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
562
563                 if ( 'import' == $from )
564                         $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin &amp; Run Importer' ) . '</a>';
565                 else
566                         $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>';
567
568                 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
569                         $install_actions['network_activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" target="_parent">' . __( 'Network Activate' ) . '</a>';
570                         unset( $install_actions['activate_plugin'] );
571                 }
572
573                 if ( 'import' == $from ) {
574                         $install_actions['importers_page'] = '<a href="' . admin_url( 'import.php' ) . '" target="_parent">' . __( 'Return to Importers' ) . '</a>';
575                 } elseif ( $this->type == 'web' ) {
576                         $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '" target="_parent">' . __( 'Return to Plugin Installer' ) . '</a>';
577                 } else {
578                         $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>';
579                 }
580
581                 if ( ! $this->result || is_wp_error($this->result) ) {
582                         unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
583                 } elseif ( ! current_user_can( 'activate_plugins' ) ) {
584                         unset( $install_actions['activate_plugin'] );
585                 }
586
587                 /**
588                  * Filter the list of action links available following a single plugin installation.
589                  *
590                  * @since 2.7.0
591                  *
592                  * @param array  $install_actions Array of plugin action links.
593                  * @param object $api             Object containing WordPress.org API plugin data. Empty
594                  *                                for non-API installs, such as when a plugin is installed
595                  *                                via upload.
596                  * @param string $plugin_file     Path to the plugin file.
597                  */
598                 $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
599
600                 if ( ! empty($install_actions) )
601                         $this->feedback(implode(' | ', (array)$install_actions));
602         }
603 }
604
605 /**
606  * Theme Installer Skin for the WordPress Theme Installer.
607  *
608  * @package WordPress
609  * @subpackage Upgrader
610  * @since 2.8.0
611  */
612 class Theme_Installer_Skin extends WP_Upgrader_Skin {
613         public $api;
614         public $type;
615
616         /**
617          *
618          * @param array $args
619          */
620         public function __construct($args = array()) {
621                 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
622                 $args = wp_parse_args($args, $defaults);
623
624                 $this->type = $args['type'];
625                 $this->api = isset($args['api']) ? $args['api'] : array();
626
627                 parent::__construct($args);
628         }
629
630         /**
631          * @access public
632          */
633         public function before() {
634                 if ( !empty($this->api) )
635                         $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
636         }
637
638         /**
639          * @access public
640          */
641         public function after() {
642                 if ( empty($this->upgrader->result['destination_name']) )
643                         return;
644
645                 $theme_info = $this->upgrader->theme_info();
646                 if ( empty( $theme_info ) )
647                         return;
648
649                 $name       = $theme_info->display('Name');
650                 $stylesheet = $this->upgrader->result['destination_name'];
651                 $template   = $theme_info->get_template();
652
653                 $activate_link = add_query_arg( array(
654                         'action'     => 'activate',
655                         'template'   => urlencode( $template ),
656                         'stylesheet' => urlencode( $stylesheet ),
657                 ), admin_url('themes.php') );
658                 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
659
660                 $install_actions = array();
661
662                 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
663                         $install_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
664                 }
665                 $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
666
667                 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
668                         $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
669
670                 if ( $this->type == 'web' )
671                         $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
672                 elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
673                         $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
674
675                 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
676                         unset( $install_actions['activate'], $install_actions['preview'] );
677
678                 /**
679                  * Filter the list of action links available following a single theme installation.
680                  *
681                  * @since 2.8.0
682                  *
683                  * @param array    $install_actions Array of theme action links.
684                  * @param object   $api             Object containing WordPress.org API theme data.
685                  * @param string   $stylesheet      Theme directory name.
686                  * @param WP_Theme $theme_info      Theme object.
687                  */
688                 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
689                 if ( ! empty($install_actions) )
690                         $this->feedback(implode(' | ', (array)$install_actions));
691         }
692 }
693
694 /**
695  * Theme Upgrader Skin for WordPress Theme Upgrades.
696  *
697  * @package WordPress
698  * @subpackage Upgrader
699  * @since 2.8.0
700  */
701 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
702         public $theme = '';
703
704         /**
705          *
706          * @param array $args
707          */
708         public function __construct($args = array()) {
709                 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
710                 $args = wp_parse_args($args, $defaults);
711
712                 $this->theme = $args['theme'];
713
714                 parent::__construct($args);
715         }
716
717         /**
718          * @access public
719          */
720         public function after() {
721                 $this->decrement_update_count( 'theme' );
722
723                 $update_actions = array();
724                 if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
725                         $name       = $theme_info->display('Name');
726                         $stylesheet = $this->upgrader->result['destination_name'];
727                         $template   = $theme_info->get_template();
728
729                         $activate_link = add_query_arg( array(
730                                 'action'     => 'activate',
731                                 'template'   => urlencode( $template ),
732                                 'stylesheet' => urlencode( $stylesheet ),
733                         ), admin_url('themes.php') );
734                         $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
735
736                         if ( get_stylesheet() == $stylesheet ) {
737                                 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
738                                         $update_actions['preview']  = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
739                                 }
740                         } elseif ( current_user_can( 'switch_themes' ) ) {
741                                 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
742                                         $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) . '</span></a>';
743                                 }
744                                 $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate &#8220;%s&#8221;' ), $name ) . '</span></a>';
745                         }
746
747                         if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
748                                 unset( $update_actions['preview'], $update_actions['activate'] );
749                 }
750
751                 $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
752
753                 /**
754                  * Filter the list of action links available following a single theme update.
755                  *
756                  * @since 2.8.0
757                  *
758                  * @param array  $update_actions Array of theme action links.
759                  * @param string $theme          Theme directory name.
760                  */
761                 $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
762
763                 if ( ! empty($update_actions) )
764                         $this->feedback(implode(' | ', (array)$update_actions));
765         }
766 }
767
768 /**
769  * Translation Upgrader Skin for WordPress Translation Upgrades.
770  *
771  * @package WordPress
772  * @subpackage Upgrader
773  * @since 3.7.0
774  */
775 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
776         public $language_update = null;
777         public $done_header = false;
778         public $done_footer = false;
779         public $display_footer_actions = true;
780
781         /**
782          *
783          * @param array $args
784          */
785         public function __construct( $args = array() ) {
786                 $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
787                 $args = wp_parse_args( $args, $defaults );
788                 if ( $args['skip_header_footer'] ) {
789                         $this->done_header = true;
790                         $this->done_footer = true;
791                         $this->display_footer_actions = false;
792                 }
793                 parent::__construct( $args );
794         }
795
796         /**
797          * @access public
798          */
799         public function before() {
800                 $name = $this->upgrader->get_name_for_update( $this->language_update );
801
802                 echo '<div class="update-messages lp-show-latest">';
803
804                 printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h4>', $name, $this->language_update->language );
805         }
806
807         /**
808          *
809          * @param string|WP_Error $error
810          */
811         public function error( $error ) {
812                 echo '<div class="lp-error">';
813                 parent::error( $error );
814                 echo '</div>';
815         }
816
817         /**
818          * @access public
819          */
820         public function after() {
821                 echo '</div>';
822         }
823
824         /**
825          * @access public
826          */
827         public function bulk_footer() {
828                 $this->decrement_update_count( 'translation' );
829                 $update_actions = array();
830                 $update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>';
831
832                 /**
833                  * Filter the list of action links available following a translations update.
834                  *
835                  * @since 3.7.0
836                  *
837                  * @param array $update_actions Array of translations update links.
838                  */
839                 $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
840
841                 if ( $update_actions && $this->display_footer_actions )
842                         $this->feedback( implode( ' | ', $update_actions ) );
843         }
844 }
845
846 /**
847  * Upgrader Skin for Automatic WordPress Upgrades
848  *
849  * This skin is designed to be used when no output is intended, all output
850  * is captured and stored for the caller to process and log/email/discard.
851  *
852  * @package WordPress
853  * @subpackage Upgrader
854  * @since 3.7.0
855  */
856 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
857         protected $messages = array();
858
859         /**
860          *
861          * @param bool   $error
862          * @param string $context
863          * @param bool   $allow_relaxed_file_ownership
864          * @return bool
865          */
866         public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
867                 if ( $context ) {
868                         $this->options['context'] = $context;
869                 }
870                 // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
871                 // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
872                 ob_start();
873                 $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
874                 ob_end_clean();
875                 return $result;
876         }
877
878         /**
879          * @access public
880          *
881          * @return array
882          */
883         public function get_upgrade_messages() {
884                 return $this->messages;
885         }
886
887         /**
888          * @param string|array|WP_Error $data
889          */
890         public function feedback( $data ) {
891                 if ( is_wp_error( $data ) ) {
892                         $string = $data->get_error_message();
893                 } elseif ( is_array( $data ) ) {
894                         return;
895                 } else {
896                         $string = $data;
897                 }
898                 if ( ! empty( $this->upgrader->strings[ $string ] ) )
899                         $string = $this->upgrader->strings[ $string ];
900
901                 if ( strpos( $string, '%' ) !== false ) {
902                         $args = func_get_args();
903                         $args = array_splice( $args, 1 );
904                         if ( ! empty( $args ) )
905                                 $string = vsprintf( $string, $args );
906                 }
907
908                 $string = trim( $string );
909
910                 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
911                 $string = wp_kses( $string, array(
912                         'a' => array(
913                                 'href' => true
914                         ),
915                         'br' => true,
916                         'em' => true,
917                         'strong' => true,
918                 ) );
919
920                 if ( empty( $string ) )
921                         return;
922
923                 $this->messages[] = $string;
924         }
925
926         /**
927          * @access public
928          */
929         public function header() {
930                 ob_start();
931         }
932
933         /**
934          * @access public
935          */
936         public function footer() {
937                 $output = ob_get_clean();
938                 if ( ! empty( $output ) )
939                         $this->feedback( $output );
940         }
941 }