Changeset 494

Show
Ignore:
Timestamp:
04/26/08 00:18:34 (9 months ago)
Author:
padams
Message:

- refatored wordpress plugin to use factory to create OWA instance so that it works with wordpress 2.5 and is better insulated from changes to
how WP loads plugins.

- Added return value to loadmessages method in mediawiki plugin (thanks to Cary Collett)

- altered check in factory instance in other plugins to use empty instead of isset function

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/module.inc

    r483 r494  
    3030        static $owa; 
    3131 
    32         if( isset($owa)): 
     32        if(!empty($owa)): 
    3333                return $owa; 
    3434        else: 
  • trunk/mw_plugin.php

    r469 r494  
    8787        static $owa; 
    8888         
    89         if( isset($owa)): 
     89        if(!empty($owa)): 
    9090                return $owa; 
    9191        else: 
     
    347347                                   $wgMessageCache->addMessages( $langMessages, $lang ); 
    348348                        } 
     349                         
     350                        return true; 
    349351        } 
    350352         
  • trunk/public/wp.php

    r367 r494  
    3434// Initialize owa admin 
    3535//$owa_wp = &new owa_wp; 
    36  
     36$owa_wp = owa_factory(); 
    3737// run controller or view and echo page content 
    3838echo $owa_wp->handleRequestFromURL(); 
  • trunk/wp_plugin.php

    r473 r494  
    2727 
    2828require_once('owa_env.php'); 
    29 require_once(OWA_BASE_CLASSES_DIR.'owa_wp.php'); 
     29 
    3030 
    3131 
     
    5252// Public folder URI 
    5353define('OWA_PUBLIC_URL', '../wp-content/plugins/owa/public/'); 
     54/* 
    5455 
    5556// Build the OWA wordpress specific config overrides array 
     
    7778$owa_config['site_id'] = md5(get_settings('siteurl')); 
    7879$owa_config['is_embedded'] = 'true'; 
    79  
     80*/ 
     81 
     82/* 
    8083// Needed to avoid a fetch of configuration from db during installation 
    8184if (($_GET['action'] == 'activate') && ($_GET['plugin'] == 'owa/wp_plugin.php')): 
    8285        $owa_config['do_not_fetch_config_from_db'] = true; 
    8386endif; 
     87*/ 
    8488 
    8589// Create new instance of OWA passing in the Wordpres specific config overrides 
    86 $owa_wp = &new owa_wp($owa_config); 
     90//$owa_wp = &new owa_wp($owa_config); 
    8791 
    8892// Filter and Action hook assignments 
    89 add_action('init', 'owa_set_user_level'); 
     93//add_action('init', 'owa_set_user_level'); 
    9094add_action('template_redirect', 'owa_main'); 
    9195add_action('wp_footer', 'owa_footer'); 
    9296add_filter('the_permalink_rss', 'owa_post_link'); 
    93 add_action('init', array(&$owa_wp, 'handleSpecialActionRequest')); 
     97add_action('init', 'owa_handleSpecialActionRequest'); 
    9498add_filter('bloginfo_url', 'add_feed_sid'); 
    9599add_action('admin_menu', 'owa_dashboard_menu'); 
    96 add_action('comment_post', array(&$owa_wp, 'logComment')); 
     100add_action('comment_post', 'owa_logComment'); 
    97101add_action('admin_menu', 'owa_options_menu'); 
    98102add_action('activate_owa/wp_plugin.php', 'owa_install'); // Installation hook 
     
    100104///////////////////////////////////////////////////////////////////////////////// 
    101105 
     106function owa_factory($params = array()) { 
     107         
     108        static $owa; 
     109 
     110        if(!empty($owa)): 
     111                return $owa; 
     112        else: 
     113         
     114                require_once(OWA_BASE_CLASSES_DIR.'owa_wp.php'); 
     115                 
     116                // Build the OWA wordpress specific config overrides array 
     117                $owa_config = $params; 
     118                 
     119                // OWA DATABASE CONFIGURATION  
     120                // Will use Wordpress config unless there is a config file present. 
     121                // OWA uses this to setup it's own DB connection seperate from the one 
     122                // that Wordpress uses. 
     123                $owa_config['db_type'] = 'mysql'; 
     124                $owa_config['db_name'] = DB_NAME; 
     125                $owa_config['db_host'] = DB_HOST; 
     126                $owa_config['db_user'] = DB_USER; 
     127                $owa_config['db_password'] = DB_PASSWORD; 
     128                 
     129                $owa_config['report_wrapper'] = 'wrapper_wordpress.tpl'; 
     130                $owa_config['images_url'] = OWA_PUBLIC_URL.'i/';//'../wp-content/plugins/owa/public/i/'; 
     131                $owa_config['images_absolute_url'] = get_bloginfo('url').'/wp-content/plugins/owa/public/i/';//'../wp-content/plugins/owa/public/i/'; 
     132                $owa_config['main_url'] = '../wp-admin/index.php?page=owa/public/wp.php'; 
     133                $owa_config['main_absolute_url'] = get_bloginfo('url').'/wp-admin/index.php?page=owa/public/wp.php'; 
     134                $owa_config['action_url'] = get_bloginfo('url').'/index.php?owa_specialAction'; 
     135                $owa_config['log_url'] = get_bloginfo('url').'/index.php?owa_logAction=1'; 
     136                $owa_config['link_template'] = '%s&%s'; 
     137                $owa_config['authentication'] = 'wordpress'; 
     138                $owa_config['site_id'] = md5(get_settings('siteurl')); 
     139                $owa_config['is_embedded'] = 'true'; 
     140         
     141                $owa = new owa_wp($owa_config); 
     142                 
     143                global $user_level, $user_login, $user_ID, $user_email, $user_identity, $user_pass_md5; 
     144         
     145                $owa->params['caller']['wordpress']['user_data'] = array( 
     146         
     147                'user_level'    => $user_level,  
     148                'user_ID'               => $user_ID, 
     149                'user_login'    => $user_login, 
     150                'user_email'    => $user_email, 
     151                'user_identity' => $user_identity, 
     152                'user_password' => 'xxxxxxxxx'); 
     153                 
     154                $owa->params['u'] = $user_login; 
     155                $owa->params['p'] = 'xxxxxxxxx'; 
     156         
     157                return $owa; 
     158                 
     159        endif; 
     160} 
     161 
     162function owa_handleSpecialActionRequest() { 
     163 
     164        $owa_wp = owa_factory(); 
     165        return $owa_wp->handleSpecialActionRequest(); 
     166} 
     167 
     168function owa_logComment() { 
     169 
     170        $owa_wp = owa_factory(); 
     171        return $owa_wp->logComment(); 
     172} 
     173 
     174 
     175 
    102176/** 
    103177 * Prints helper page tags to the footers of templates. 
     
    106180function owa_footer() { 
    107181         
    108         global $owa_wp; 
     182        $owa_wp = owa_factory(); 
    109183         
    110184        $owa_wp->placeHelperPageTags(); 
     
    113187        return; 
    114188         
    115 } 
    116  
    117  
    118 /** 
    119  * Sets the user level in caller params for use in OWA's auth module. 
    120  * 
    121  */ 
    122 function owa_set_user_level() { 
    123          
    124         global $owa_wp, $user_level, $user_login, $user_ID, $user_email, $user_identity, $user_pass_md5; 
    125          
    126         $owa_wp->params['caller']['wordpress']['user_data'] = array( 
    127          
    128         'user_level'    => $user_level,  
    129         'user_ID'               => $user_ID, 
    130         'user_login'    => $user_login, 
    131         'user_email'    => $user_email, 
    132         'user_identity' => $user_identity, 
    133         'user_password' => 'xxxxxxxxx'); 
    134          
    135         $owa_wp->params['u'] = $user_login; 
    136         $owa_wp->params['p'] = 'xxxxxxxxx'; 
    137          
    138         return;  
    139 } 
    140          
     189}        
    141190 
    142191/** 
     
    146195function owa_main() { 
    147196         
    148         global $user_level, $owa_wp; 
     197        global $user_level; 
     198         
     199        $owa_wp = owa_factory(); 
    149200         
    150201        // Don't log if the page request is a preview - Wordpress 2.x or greater 
     
    175226function owa_log() { 
    176227 
    177         global $owa_wp; 
     228        $owa_wp = owa_factory(); 
    178229         
    179230        // WORDPRESS SPECIFIC DATA // 
     
    282333function add_feed_sid($binfo) { 
    283334         
    284         global $owa_wp; 
     335        $owa_wp = owa_factory(); 
    285336         
    286337        $test = strpos($binfo, "feed="); 
     
    307358function owa_post_link($link) { 
    308359 
    309         global $owa_wp; 
     360        $owa_wp = owa_factory(); 
    310361 
    311362        return $owa_wp->add_link_tracking($link); 
     
    320371 
    321372        global $user_level; 
    322         global $owa_wp; 
     373         
     374        $params = array(); 
     375        $params['do_not_fetch_config_from_db'] = true; 
     376 
     377        $owa_wp = owa_factory($params); 
    323378         
    324379        //check to see if the user has permissions to install or not... 
     
    364419function owa_dashboard_report() { 
    365420         
    366         global $owa_wp; 
     421        $owa_wp = owa_factory(); 
    367422         
    368423        $params = array(); 
     
    393448function owa_options_page() { 
    394449         
    395         global $owa_wp; 
     450        $owa_wp = owa_factory(); 
    396451         
    397452        $params = array();