]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-upgrader-skins.php
WordPress 4.4
[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                 /* translators: 1: Title of an update, 2: Error message */
285                 $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: %2$s');
286                 /* translators: 1: Title of an update */
287                 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
288                 /* translators: 1: Title of an update */
289                 $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>';
290                 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
291         }
292
293         /**
294          * @param string $string
295          */
296         public function feedback($string) {
297                 if ( isset( $this->upgrader->strings[$string] ) )
298                         $string = $this->upgrader->strings[$string];
299
300                 if ( strpos($string, '%') !== false ) {
301                         $args = func_get_args();
302                         $args = array_splice($args, 1);
303                         if ( $args ) {
304                                 $args = array_map( 'strip_tags', $args );
305                                 $args = array_map( 'esc_html', $args );
306                                 $string = vsprintf($string, $args);
307                         }
308                 }
309                 if ( empty($string) )
310                         return;
311                 if ( $this->in_loop )
312                         echo "$string<br />\n";
313                 else
314                         echo "<p>$string</p>\n";
315         }
316
317         /**
318          * @access public
319          */
320         public function header() {
321                 // Nothing, This will be displayed within a iframe.
322         }
323
324         /**
325          * @access public
326          */
327         public function footer() {
328                 // Nothing, This will be displayed within a iframe.
329         }
330
331         /**
332          *
333          * @param string|WP_Error $error
334          */
335         public function error($error) {
336                 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
337                         $this->error = $this->upgrader->strings[$error];
338
339                 if ( is_wp_error($error) ) {
340                         $messages = array();
341                         foreach ( $error->get_error_messages() as $emessage ) {
342                                 if ( $error->get_error_data() && is_string( $error->get_error_data() ) )
343                                         $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
344                                 else
345                                         $messages[] = $emessage;
346                         }
347                         $this->error = implode(', ', $messages);
348                 }
349                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
350         }
351
352         /**
353          * @access public
354          */
355         public function bulk_header() {
356                 $this->feedback('skin_upgrade_start');
357         }
358
359         /**
360          * @access public
361          */
362         public function bulk_footer() {
363                 $this->feedback('skin_upgrade_end');
364         }
365
366         /**
367          *
368          * @param string $title
369          */
370         public function before($title = '') {
371                 $this->in_loop = true;
372                 printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count );
373                 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>';
374                 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
375                 $this->flush_output();
376         }
377
378         /**
379          *
380          * @param string $title
381          */
382         public function after($title = '') {
383                 echo '</p></div>';
384                 if ( $this->error || ! $this->result ) {
385                         if ( $this->error ) {
386                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>';
387                         } else {
388                                 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
389                         }
390
391                         echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
392                 }
393                 if ( $this->result && ! is_wp_error( $this->result ) ) {
394                         if ( ! $this->error )
395                                 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>';
396                         echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
397                 }
398
399                 $this->reset();
400                 $this->flush_output();
401         }
402
403         /**
404          * @access public
405          */
406         public function reset() {
407                 $this->in_loop = false;
408                 $this->error = false;
409         }
410
411         /**
412          * @access public
413          */
414         public function flush_output() {
415                 wp_ob_end_flush_all();
416                 flush();
417         }
418 }
419
420 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
421         public $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
422
423         public function add_strings() {
424                 parent::add_strings();
425                 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
426         }
427
428         /**
429          *
430          * @param string $title
431          */
432         public function before($title = '') {
433                 parent::before($this->plugin_info['Title']);
434         }
435
436         /**
437          *
438          * @param string $title
439          */
440         public function after($title = '') {
441                 parent::after($this->plugin_info['Title']);
442                 $this->decrement_update_count( 'plugin' );
443         }
444
445         /**
446          * @access public
447          */
448         public function bulk_footer() {
449                 parent::bulk_footer();
450                 $update_actions =  array(
451                         'plugins_page' => '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>',
452                         'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
453                 );
454                 if ( ! current_user_can( 'activate_plugins' ) )
455                         unset( $update_actions['plugins_page'] );
456
457                 /**
458                  * Filter the list of action links available following bulk plugin updates.
459                  *
460                  * @since 3.0.0
461                  *
462                  * @param array $update_actions Array of plugin action links.
463                  * @param array $plugin_info    Array of information for the last-updated plugin.
464                  */
465                 $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
466
467                 if ( ! empty($update_actions) )
468                         $this->feedback(implode(' | ', (array)$update_actions));
469         }
470 }
471
472 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
473         public $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
474
475         public function add_strings() {
476                 parent::add_strings();
477                 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
478         }
479
480         /**
481          *
482          * @param string $title
483          */
484         public function before($title = '') {
485                 parent::before( $this->theme_info->display('Name') );
486         }
487
488         /**
489          *
490          * @param string $title
491          */
492         public function after($title = '') {
493                 parent::after( $this->theme_info->display('Name') );
494                 $this->decrement_update_count( 'theme' );
495         }
496
497         /**
498          * @access public
499          */
500         public function bulk_footer() {
501                 parent::bulk_footer();
502                 $update_actions =  array(
503                         'themes_page' => '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>',
504                         'updates_page' => '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>'
505                 );
506                 if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
507                         unset( $update_actions['themes_page'] );
508
509                 /**
510                  * Filter the list of action links available following bulk theme updates.
511                  *
512                  * @since 3.0.0
513                  *
514                  * @param array $update_actions Array of theme action links.
515                  * @param array $theme_info     Array of information for the last-updated theme.
516                  */
517                 $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
518
519                 if ( ! empty($update_actions) )
520                         $this->feedback(implode(' | ', (array)$update_actions));
521         }
522 }
523
524 /**
525  * Plugin Installer Skin for WordPress Plugin Installer.
526  *
527  * @package WordPress
528  * @subpackage Upgrader
529  * @since 2.8.0
530  */
531 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
532         public $api;
533         public $type;
534
535         /**
536          *
537          * @param array $args
538          */
539         public function __construct($args = array()) {
540                 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
541                 $args = wp_parse_args($args, $defaults);
542
543                 $this->type = $args['type'];
544                 $this->api = isset($args['api']) ? $args['api'] : array();
545
546                 parent::__construct($args);
547         }
548
549         /**
550          * @access public
551          */
552         public function before() {
553                 if ( !empty($this->api) )
554                         $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
555         }
556
557         /**
558          * @access public
559          */
560         public function after() {
561                 $plugin_file = $this->upgrader->plugin_info();
562
563                 $install_actions = array();
564
565                 $from = isset($_GET['from']) ? wp_unslash( $_GET['from'] ) : 'plugins';
566
567                 if ( 'import' == $from )
568                         $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>';
569                 else
570                         $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>';
571
572                 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
573                         $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>';
574                         unset( $install_actions['activate_plugin'] );
575                 }
576
577                 if ( 'import' == $from ) {
578                         $install_actions['importers_page'] = '<a href="' . admin_url( 'import.php' ) . '" target="_parent">' . __( 'Return to Importers' ) . '</a>';
579                 } elseif ( $this->type == 'web' ) {
580                         $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugin-install.php' ) . '" target="_parent">' . __( 'Return to Plugin Installer' ) . '</a>';
581                 } else {
582                         $install_actions['plugins_page'] = '<a href="' . self_admin_url( 'plugins.php' ) . '" target="_parent">' . __( 'Return to Plugins page' ) . '</a>';
583                 }
584
585                 if ( ! $this->result || is_wp_error($this->result) ) {
586                         unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
587                 } elseif ( ! current_user_can( 'activate_plugins' ) ) {
588                         unset( $install_actions['activate_plugin'] );
589                 }
590
591                 /**
592                  * Filter the list of action links available following a single plugin installation.
593                  *
594                  * @since 2.7.0
595                  *
596                  * @param array  $install_actions Array of plugin action links.
597                  * @param object $api             Object containing WordPress.org API plugin data. Empty
598                  *                                for non-API installs, such as when a plugin is installed
599                  *                                via upload.
600                  * @param string $plugin_file     Path to the plugin file.
601                  */
602                 $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
603
604                 if ( ! empty($install_actions) )
605                         $this->feedback(implode(' | ', (array)$install_actions));
606         }
607 }
608
609 /**
610  * Theme Installer Skin for the WordPress Theme Installer.
611  *
612  * @package WordPress
613  * @subpackage Upgrader
614  * @since 2.8.0
615  */
616 class Theme_Installer_Skin extends WP_Upgrader_Skin {
617         public $api;
618         public $type;
619
620         /**
621          *
622          * @param array $args
623          */
624         public function __construct($args = array()) {
625                 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
626                 $args = wp_parse_args($args, $defaults);
627
628                 $this->type = $args['type'];
629                 $this->api = isset($args['api']) ? $args['api'] : array();
630
631                 parent::__construct($args);
632         }
633
634         /**
635          * @access public
636          */
637         public function before() {
638                 if ( !empty($this->api) )
639                         $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version);
640         }
641
642         /**
643          * @access public
644          */
645         public function after() {
646                 if ( empty($this->upgrader->result['destination_name']) )
647                         return;
648
649                 $theme_info = $this->upgrader->theme_info();
650                 if ( empty( $theme_info ) )
651                         return;
652
653                 $name       = $theme_info->display('Name');
654                 $stylesheet = $this->upgrader->result['destination_name'];
655                 $template   = $theme_info->get_template();
656
657                 $activate_link = add_query_arg( array(
658                         'action'     => 'activate',
659                         'template'   => urlencode( $template ),
660                         'stylesheet' => urlencode( $stylesheet ),
661                 ), admin_url('themes.php') );
662                 $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
663
664                 $install_actions = array();
665
666                 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
667                         $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>';
668                 }
669                 $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>';
670
671                 if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
672                         $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>';
673
674                 if ( $this->type == 'web' )
675                         $install_actions['themes_page'] = '<a href="' . self_admin_url( 'theme-install.php' ) . '" target="_parent">' . __( 'Return to Theme Installer' ) . '</a>';
676                 elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) )
677                         $install_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
678
679                 if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) )
680                         unset( $install_actions['activate'], $install_actions['preview'] );
681
682                 /**
683                  * Filter the list of action links available following a single theme installation.
684                  *
685                  * @since 2.8.0
686                  *
687                  * @param array    $install_actions Array of theme action links.
688                  * @param object   $api             Object containing WordPress.org API theme data.
689                  * @param string   $stylesheet      Theme directory name.
690                  * @param WP_Theme $theme_info      Theme object.
691                  */
692                 $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
693                 if ( ! empty($install_actions) )
694                         $this->feedback(implode(' | ', (array)$install_actions));
695         }
696 }
697
698 /**
699  * Theme Upgrader Skin for WordPress Theme Upgrades.
700  *
701  * @package WordPress
702  * @subpackage Upgrader
703  * @since 2.8.0
704  */
705 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
706         public $theme = '';
707
708         /**
709          *
710          * @param array $args
711          */
712         public function __construct($args = array()) {
713                 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
714                 $args = wp_parse_args($args, $defaults);
715
716                 $this->theme = $args['theme'];
717
718                 parent::__construct($args);
719         }
720
721         /**
722          * @access public
723          */
724         public function after() {
725                 $this->decrement_update_count( 'theme' );
726
727                 $update_actions = array();
728                 if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
729                         $name       = $theme_info->display('Name');
730                         $stylesheet = $this->upgrader->result['destination_name'];
731                         $template   = $theme_info->get_template();
732
733                         $activate_link = add_query_arg( array(
734                                 'action'     => 'activate',
735                                 'template'   => urlencode( $template ),
736                                 'stylesheet' => urlencode( $stylesheet ),
737                         ), admin_url('themes.php') );
738                         $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
739
740                         if ( get_stylesheet() == $stylesheet ) {
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">' . __( 'Customize' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize &#8220;%s&#8221;' ), $name ) . '</span></a>';
743                                 }
744                         } elseif ( current_user_can( 'switch_themes' ) ) {
745                                 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
746                                         $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>';
747                                 }
748                                 $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>';
749                         }
750
751                         if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() )
752                                 unset( $update_actions['preview'], $update_actions['activate'] );
753                 }
754
755                 $update_actions['themes_page'] = '<a href="' . self_admin_url( 'themes.php' ) . '" target="_parent">' . __( 'Return to Themes page' ) . '</a>';
756
757                 /**
758                  * Filter the list of action links available following a single theme update.
759                  *
760                  * @since 2.8.0
761                  *
762                  * @param array  $update_actions Array of theme action links.
763                  * @param string $theme          Theme directory name.
764                  */
765                 $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
766
767                 if ( ! empty($update_actions) )
768                         $this->feedback(implode(' | ', (array)$update_actions));
769         }
770 }
771
772 /**
773  * Translation Upgrader Skin for WordPress Translation Upgrades.
774  *
775  * @package WordPress
776  * @subpackage Upgrader
777  * @since 3.7.0
778  */
779 class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
780         public $language_update = null;
781         public $done_header = false;
782         public $done_footer = false;
783         public $display_footer_actions = true;
784
785         /**
786          *
787          * @param array $args
788          */
789         public function __construct( $args = array() ) {
790                 $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false );
791                 $args = wp_parse_args( $args, $defaults );
792                 if ( $args['skip_header_footer'] ) {
793                         $this->done_header = true;
794                         $this->done_footer = true;
795                         $this->display_footer_actions = false;
796                 }
797                 parent::__construct( $args );
798         }
799
800         /**
801          * @access public
802          */
803         public function before() {
804                 $name = $this->upgrader->get_name_for_update( $this->language_update );
805
806                 echo '<div class="update-messages lp-show-latest">';
807
808                 printf( '<h2>' . __( 'Updating translations for %1$s (%2$s)&#8230;' ) . '</h2>', $name, $this->language_update->language );
809         }
810
811         /**
812          *
813          * @param string|WP_Error $error
814          */
815         public function error( $error ) {
816                 echo '<div class="lp-error">';
817                 parent::error( $error );
818                 echo '</div>';
819         }
820
821         /**
822          * @access public
823          */
824         public function after() {
825                 echo '</div>';
826         }
827
828         /**
829          * @access public
830          */
831         public function bulk_footer() {
832                 $this->decrement_update_count( 'translation' );
833                 $update_actions = array();
834                 $update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" target="_parent">' . __( 'Return to WordPress Updates page' ) . '</a>';
835
836                 /**
837                  * Filter the list of action links available following a translations update.
838                  *
839                  * @since 3.7.0
840                  *
841                  * @param array $update_actions Array of translations update links.
842                  */
843                 $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
844
845                 if ( $update_actions && $this->display_footer_actions )
846                         $this->feedback( implode( ' | ', $update_actions ) );
847         }
848 }
849
850 /**
851  * Upgrader Skin for Automatic WordPress Upgrades
852  *
853  * This skin is designed to be used when no output is intended, all output
854  * is captured and stored for the caller to process and log/email/discard.
855  *
856  * @package WordPress
857  * @subpackage Upgrader
858  * @since 3.7.0
859  */
860 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
861         protected $messages = array();
862
863         /**
864          *
865          * @param bool   $error
866          * @param string $context
867          * @param bool   $allow_relaxed_file_ownership
868          * @return bool
869          */
870         public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
871                 if ( $context ) {
872                         $this->options['context'] = $context;
873                 }
874                 // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
875                 // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
876                 ob_start();
877                 $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
878                 ob_end_clean();
879                 return $result;
880         }
881
882         /**
883          * @access public
884          *
885          * @return array
886          */
887         public function get_upgrade_messages() {
888                 return $this->messages;
889         }
890
891         /**
892          * @param string|array|WP_Error $data
893          */
894         public function feedback( $data ) {
895                 if ( is_wp_error( $data ) ) {
896                         $string = $data->get_error_message();
897                 } elseif ( is_array( $data ) ) {
898                         return;
899                 } else {
900                         $string = $data;
901                 }
902                 if ( ! empty( $this->upgrader->strings[ $string ] ) )
903                         $string = $this->upgrader->strings[ $string ];
904
905                 if ( strpos( $string, '%' ) !== false ) {
906                         $args = func_get_args();
907                         $args = array_splice( $args, 1 );
908                         if ( ! empty( $args ) )
909                                 $string = vsprintf( $string, $args );
910                 }
911
912                 $string = trim( $string );
913
914                 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
915                 $string = wp_kses( $string, array(
916                         'a' => array(
917                                 'href' => true
918                         ),
919                         'br' => true,
920                         'em' => true,
921                         'strong' => true,
922                 ) );
923
924                 if ( empty( $string ) )
925                         return;
926
927                 $this->messages[] = $string;
928         }
929
930         /**
931          * @access public
932          */
933         public function header() {
934                 ob_start();
935         }
936
937         /**
938          * @access public
939          */
940         public function footer() {
941                 $output = ob_get_clean();
942                 if ( ! empty( $output ) )
943                         $this->feedback( $output );
944         }
945 }