Make WordPress Core

Ticket #7875: 7875.10.diff

File 7875.10.diff, 8.3 KB (added by DD32, 13 years ago)
  • wp-admin/includes/class-wp-upgrader.php

     
    11<?php
    22/**
    3  * This file is an attempt at an abstracted version of the plugin/theme/core installer/upgrader which can be used interchangably for all uses needed within WordPress.
    4  * It is designed to be as flexible as possible, but some logic may seem rather, crazy to say the least.
    5  * Yes, this header is designed to be replaced before commiting, Hopefully i'll get some proper documentation in here.
     3 * A File upgrader class for WordPress.
    64 *
    7  * This File obviously needs some new PHPDoc, However:
    8  * Tested:
    9  *   Theme/Plugin Upgrades/Installs
    10  *   Core Upgrade
    11  *   FTP Extension, FTP Sockets, Direct.
    12  * Untested:
    13  *   SSH2 Layer - Needs a good cleanup.
     5 * This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes.
    146 *
    15  * TODO: Remove this commentblock and replace with some better docs.
     7 * @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions
     8 *
     9 * @package WordPress
     10 * @subpackage Upgrader
     11 * @since 2.8.0
    1612 */
    1713
     14/**
     15 * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file.
     16 *
     17 * @TODO More Detailed docs, for methods as well.
     18 *
     19 * @package WordPress
     20 * @subpackage Upgrader
     21 * @since 2.8.0
     22 */
    1823class WP_Upgrader {
    1924        var $strings = array();
    2025        var $skin = null;
     
    2833                        $this->skin = new WP_Upgrader_Skin();
    2934                else
    3035                        $this->skin = $skin;
     36        }
     37       
     38        function init() {
    3139                $this->skin->set_upgrader($this);
     40                $this->generic_strings();
    3241        }
    3342
    3443        function generic_strings() {
     
    323332
    324333}
    325334
     335/**
     336 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
     337 *
     338 * @TODO More Detailed docs, for methods as well.
     339 *
     340 * @package WordPress
     341 * @subpackage Upgrader
     342 * @since 2.8.0
     343 */
    326344class Plugin_Upgrader extends WP_Upgrader {
    327345
    328346        var $result;
    329347
    330348        function upgrade_strings() {
    331                 $this->generic_strings();
    332349                $this->strings['up_to_date'] = __('The plugin is at the latest version.');
    333350                $this->strings['no_package'] = __('Upgrade package not available.');
    334351                $this->strings['downloading_package'] = __('Downloading update from %s.');
     
    341358        }
    342359
    343360        function install_strings() {
    344                 $this->generic_strings();
    345361                $this->strings['no_package'] = __('Install package not available.');
    346362                $this->strings['downloading_package'] = __('Downloading install package from %s.');
    347363                $this->strings['unpack_package'] = __('Unpacking the package.');
     
    352368
    353369        function install($package) {
    354370
     371                $this->init();
    355372                $this->install_strings();
    356373
    357374                $this->run(array(
     
    369386
    370387        function upgrade($plugin) {
    371388
     389                $this->init();
    372390                $this->upgrade_strings();
    373391
    374392                $current = get_transient( 'update_plugins' );
     
    469487        }
    470488}
    471489
    472 
     490/**
     491 * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
     492 *
     493 * @TODO More Detailed docs, for methods as well.
     494 *
     495 * @package WordPress
     496 * @subpackage Upgrader
     497 * @since 2.8.0
     498 */
    473499class Theme_Upgrader extends WP_Upgrader {
    474500
    475501        var $result;
    476502
    477503        function upgrade_strings() {
    478                 $this->generic_strings();
    479504                $this->strings['up_to_date'] = __('The theme is at the latest version.');
    480505                $this->strings['no_package'] = __('Upgrade package not available.');
    481506                $this->strings['downloading_package'] = __('Downloading update from %s.');
     
    487512        }
    488513
    489514        function install_strings() {
    490                 $this->generic_strings();
    491515                $this->strings['no_package'] = __('Install package not available.');
    492516                $this->strings['downloading_package'] = __('Downloading install package from %s.');
    493517                $this->strings['unpack_package'] = __('Unpacking the package.');
     
    497521        }
    498522
    499523        function install($package) {
    500 
     524               
     525                $this->init();
    501526                $this->install_strings();
    502527
    503528                $options = array(
     
    523548
    524549        function upgrade($theme) {
    525550
     551                $this->init();
    526552                $this->upgrade_strings();
    527553
    528554                // Is an update available?
     
    616642
    617643}
    618644
    619 //Untested.
     645/**
     646 * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
     647 *
     648 * @TODO More Detailed docs, for methods as well.
     649 *
     650 * @package WordPress
     651 * @subpackage Upgrader
     652 * @since 2.8.0
     653 */
    620654class Core_Upgrader extends WP_Upgrader {
    621655
    622656        function upgrade_strings() {
    623                 $this->generic_strings();
    624657                $this->strings['up_to_date'] = __('WordPress is at the latest version.');
    625658                $this->strings['no_package'] = __('Upgrade package not available.');
    626659                $this->strings['downloading_package'] = __('Downloading update from %s.');
     
    630663
    631664        function upgrade($current) {
    632665                global $wp_filesystem;
     666
     667                $this->init();
    633668                $this->upgrade_strings();
    634669
    635 
    636670                if ( !empty($feedback) )
    637671                        add_filter('update_feedback', $feedback);
    638672
     
    668702
    669703}
    670704
    671 
    672705/**
    673  * Skin stuff here.
    674  * ============================================
    675  * ============================================
    676  * ============================================
     706 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
     707 *
     708 * @TODO More Detailed docs, for methods as well.
     709 *
     710 * @package WordPress
     711 * @subpackage Upgrader
     712 * @since 2.8.0
    677713 */
    678 
    679714class WP_Upgrader_Skin {
    680715
    681716        var $upgrader;
     
    732767        }
    733768
    734769        function feedback($string) {
    735                 if ( isset( $this->upgrader->strings[$string]) )
     770                if ( isset( $this->upgrader->strings[$string] ) )
    736771                        $string = $this->upgrader->strings[$string];
    737772
    738773                if ( strpos($string, '%') !== false ) {
     
    750785
    751786}
    752787
     788/**
     789 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
     790 *
     791 * @TODO More Detailed docs, for methods as well.
     792 *
     793 * @package WordPress
     794 * @subpackage Upgrader
     795 * @since 2.8.0
     796 */
    753797class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
    754798        var $plugin = '';
    755799        var $plugin_active = false;
     
    790834        }
    791835}
    792836
    793 
     837/**
     838 * Plugin Installer Skin for WordPress Plugin Installer.
     839 *
     840 * @TODO More Detailed docs, for methods as well.
     841 *
     842 * @package WordPress
     843 * @subpackage Upgrader
     844 * @since 2.8.0
     845 */
    794846class Plugin_Installer_Skin extends WP_Upgrader_Skin {
    795847        var $api;
    796848        var $type;
     
    829881
    830882
    831883                if ( ! $this->result || is_wp_error($this->result) )
    832                         unset( $update_actions['activate_plugin'] );
     884                        unset( $install_actions['activate_plugin'] );
    833885
    834886                $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
    835887                if ( ! empty($install_actions) )
     
    837889        }
    838890}
    839891
     892/**
     893 * Theme Installer Skin for the WordPress Theme Installer.
     894 *
     895 * @TODO More Detailed docs, for methods as well.
     896 *
     897 * @package WordPress
     898 * @subpackage Upgrader
     899 * @since 2.8.0
     900 */
    840901class Theme_Installer_Skin extends WP_Upgrader_Skin {
    841902        var $api;
    842903        var $type;
     
    885946                        $install_actions['themes_page'] = '<a href="' . admin_url('themes.php') . '" title="' . attribute_escape(__('Themes page')) . '" target="_parent">' . __('Return to Themes page') . '</a>';
    886947
    887948                if ( ! $this->result || is_wp_error($this->result) )
    888                         unset( $update_actions['activate'], $update_actions['preview'] );
     949                        unset( $install_actions['activate'], $install_actions['preview'] );
    889950
    890951                $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
    891952                if ( ! empty($install_actions) )
     
    893954        }
    894955}
    895956
     957/**
     958 * Theme Upgrader Skin for WordPress Theme Upgrades.
     959 *
     960 * @TODO More Detailed docs, for methods as well.
     961 *
     962 * @package WordPress
     963 * @subpackage Upgrader
     964 * @since 2.8.0
     965 */
    896966class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
    897967        var $theme = '';
    898968
     
    9381008        }
    9391009}
    9401010
     1011/**
     1012 * Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if its a local file to the Upgrade/Installer functions.
     1013 *
     1014 * @TODO More Detailed docs, for methods as well.
     1015 *
     1016 * @package WordPress
     1017 * @subpackage Upgrader
     1018 * @since 2.8.0
     1019 */
    9411020class File_Upload_Upgrader {
    9421021        var $package;
    9431022        var $filename;