Ticket #12362: 11644.code_cleanup_wpdb-3nd_iteration.patch
File 11644.code_cleanup_wpdb-3nd_iteration.patch, 10.1 KB (added by , 15 years ago) |
---|
-
wordpress/wp-includes/wp-db.php
169 169 * {@internal Missing Description}} 170 170 * 171 171 * @since 3.0.0 172 * @access p ublic172 * @access private 173 173 * @var int 174 174 */ 175 175 var $blogid = 0; … … 178 178 * {@internal Missing Description}} 179 179 * 180 180 * @since 3.0.0 181 * @access p ublic181 * @access private 182 182 * @var int 183 183 */ 184 184 var $siteid = 0; … … 470 470 * the actual setting up of the class properties and connection 471 471 * to the database. 472 472 * 473 * NOTE: register_shutdown_function prevents this object from unloading 474 * 473 475 * @since 2.0.8 474 476 * 475 477 * @param string $dbuser MySQL database user … … 533 535 /** 534 536 * PHP5 style destructor and will run when database object is destroyed. 535 537 * 538 * 539 * Please see {@link __construct() class constructor} and the 540 * {@link register_shutdown_function() register_shutdown_function()}. for 541 * more details. 542 * 543 * @link http://www.php.net/__destruct 544 * @link http://www.php.net/register_shutdown_function 545 * 536 546 * @since 2.0.8 537 547 * @return bool true 538 548 */ … … 567 577 return $old_prefix; 568 578 569 579 $this->prefix = $this->get_blog_prefix( $this->blogid ); 570 571 foreach ( (array) $this->tables( 'blog') as $table => $prefixed_table )580 581 foreach ( array_merge( $this->tables( 'blog' ), $this->tables( 'old' ) ) as $table => $prefixed_table ) 572 582 $this->$table = $prefixed_table; 573 583 574 foreach ( (array) $this->tables( 'old' ) as $table => $prefixed_table )575 $this->$table = $prefixed_table;576 577 584 return $old_prefix; 578 585 } 579 586 … … 586 593 * @param int $site_id Optional. 587 594 * @return string previous blog id 588 595 */ 589 function set_blog_id( $blog_id, $site_id = 0) {596 function set_blog_id( $blog_id, $site_id = '' ) { 590 597 if ( ! empty( $site_id ) ) 591 598 $this->siteid = $site_id; 592 599 … … 594 601 $this->blogid = $blog_id; 595 602 596 603 $this->prefix = $this->get_blog_prefix( $this->blogid ); 597 598 foreach ( $this->tables( 'blog') as $table => $prefixed_table )604 605 foreach ( array_merge( $this->tables( 'blog' ), $this->tables( 'old' ) ) as $table => $prefixed_table ) 599 606 $this->$table = $prefixed_table; 600 607 601 foreach ( $this->tables( 'old' ) as $table => $prefixed_table )602 $this->$table = $prefixed_table;603 604 608 return $old_blog_id; 605 609 } 606 610 … … 630 634 * override the WordPress users and usersmeta tables that would otherwise 631 635 * be determined by the prefix. 632 636 * 637 * Scope / Table identifiers: 638 * all ........ global and blog tables. 639 * blog ....... blog tables 640 * blog+old ... blog and old (deprecated) tables 641 * global ..... global tables 642 * ms_global .. multisite global tables, regardless if current installation is multisite. 643 * old ........ old (depreacted) tables 644 * 645 * @access public 633 646 * @since 3.0.0 634 647 * @uses wpdb::$tables 635 648 * @uses wpdb::$old_tables … … 637 650 * @uses wpdb::$ms_global_tables 638 651 * @uses is_multisite() 639 652 * 640 * @param string $scope Can be all, global, ms_global, blog, or old tables. Defaults to all.653 * @param string $scope Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all. 641 654 * 'all' returns 'all' and 'global' tables. No old tables are returned. 642 655 * 'global' returns the global tables for the installation, returning multisite tables only if running multisite. 643 656 * 'ms_global' returns the multisite global tables, regardless if current installation is multisite. 644 657 * 'blog' returns the blog-level tables for the queried blog. 645 658 * 'old' returns tables which are deprecated. 646 * @param bool $prefix Whether to include table prefixes. Default true. If blog659 * @param bool $prefix Optional. Whether to include table prefixes. Default true. If blog 647 660 * prefix is requested, then the custom users and usermeta tables will be mapped. 648 * @param int $blog_id The blog_id to prefix. Defaults to wpdb::blogid. Used only when prefix is requested.661 * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::blogid. Used only when prefix is requested. 649 662 * @return array Table names. When a prefix is requested, the key is the unprefixed table name. 650 663 */ 651 664 function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { 665 652 666 switch ( $scope ) { 653 case 'old' : 654 $tables = $this->old_tables; 667 case 'all' : 668 $tables = array_merge( $this->global_tables, $this->tables ); 669 if ( is_multisite() ) 670 $tables = array_merge( $tables, $this->ms_global_tables ); 655 671 break; 656 672 case 'blog' : 657 673 $tables = $this->tables; 658 674 break; 659 case ' ms_global':660 $tables = $this->ms_global_tables;675 case 'blog+old': 676 $tables = array_merge( $this->tables, $this->old_tables ); 661 677 break; 662 678 case 'global' : 663 679 $tables = $this->global_tables; 664 680 if ( is_multisite() ) 665 681 $tables = array_merge( $tables, $this->ms_global_tables ); 666 682 break; 667 case 'all' : 668 $tables = array_merge( $this->global_tables, $this->tables ); 669 if ( is_multisite() ) 670 $tables = array_merge( $tables, $this->ms_global_tables ); 683 case 'ms_global' : 684 $tables = $this->ms_global_tables; 671 685 break; 686 case 'old' : 687 $tables = $this->old_tables; 688 break; 689 default: 690 $tables = array(); 672 691 } 673 692 674 if ( $prefix ) {693 if ( count( $tables ) && $prefix ) { 675 694 if ( ! $blog_id ) 676 695 $blog_id = $this->blogid; 696 677 697 $blog_prefix = $this->get_blog_prefix( $blog_id ); 678 698 $base_prefix = $this->base_prefix; 679 699 $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); 680 foreach ( $tables as $k => $table ) { 700 foreach ( $tables as $k => $table ) { 681 701 if ( in_array( $table, $global_tables ) ) 682 702 $tables[ $table ] = $base_prefix . $table; 683 703 else … … 725 745 /** 726 746 * Weak escape 727 747 * 728 * @uses addslashes() 748 * An alias to addslashes(). 749 * 750 * @see addslashes() 729 751 * @since {@internal Version Unknown}} 730 752 * @access private 731 753 * … … 739 761 /** 740 762 * Real escape 741 763 * 742 * @uses mysql_real_escape_string() 743 * @uses addslashes() 764 * Escape via mysql_real_escape_string() or addslashes() 765 * 766 * @see mysql_real_escape_string() 767 * @see addslashes() 744 768 * @since 2.8 745 769 * @access private 746 770 * … … 786 810 * Works on arrays. 787 811 * 788 812 * @since 0.71 789 * @param 813 * @param string|array $data to escape 790 814 * @return string|array escaped as query safe string 791 815 */ 792 816 function escape( $data ) { … … 809 833 * 810 834 * @uses wpdb::_real_escape() 811 835 * @since 2.3.0 812 * @param 836 * @param string $string to escape 813 837 * @return void 814 838 */ 815 839 function escape_by_ref( &$string ) { … … 837 861 * Both %d and %s should be left unquoted in the query string. 838 862 * 839 863 * <code> 840 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 )864 * wpdb::prepare( 'SELECT * FROM `table` WHERE `column` = %s AND `field` = %d', 'foo', 1337 ) 841 865 * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); 842 866 * </code> 843 867 * … … 864 888 $args = $args[0]; 865 889 $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it 866 890 $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting 867 $query = preg_replace('|(?<!%)%s|', "'%s'", $query); // quote the strings, avoiding escaped strings like %%s891 $query = str_replace( '%s', "'%s'", $query ); // quote the strings 868 892 array_walk( $args, array( &$this, 'escape_by_ref' ) ); 869 893 return @vsprintf( $query, $args ); 870 894 } … … 893 917 else 894 918 $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR*/'WordPress database error %1$s for query %2$s'/*/WP_I18N_DB_QUERY_ERROR*/, $str, $this->last_query); 895 919 896 if ( function_exists('error_log') && $log_file = @ini_get('error_log') && ( 'syslog' == $log_file || is_writable( $log_file ) ) ) 897 @error_log( $error_str, 0 ); 920 if ( function_exists( 'error_log' ) 921 && ! ( $log_file = @ini_get( 'error_log' ) ) 922 && ( 'syslog' != $log_file ) 923 && @is_writable( $log_file ) ) 924 @error_log( $error_str ); 898 925 899 // Is error output turned on or not..926 // Show Errors ? 900 927 if ( ! $this->show_errors ) 901 928 return false; 902 929 … … 1033 1060 if ( ! $this->ready ) 1034 1061 return false; 1035 1062 1036 // some queries are made before the plugins have been loaded, and thus cannot be filtered with this method1037 1063 if ( function_exists( 'apply_filters' ) ) 1038 1064 $query = apply_filters( 'query', $query ); 1039 1065 … … 1127 1153 * 1128 1154 * @since 2.5.0 1129 1155 * @see wpdb::prepare() 1130 * @see wpdb::$field_types1131 * @see wp_set_wpdb_vars()1132 1156 * 1133 1157 * @param string $table table name 1134 1158 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). … … 1158 1182 * Update a row in the table 1159 1183 * 1160 1184 * <code> 1161 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar'), array( 'ID' => 1 ) )1185 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ) ) 1162 1186 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) 1163 1187 * </code> 1164 1188 * … … 1456 1480 * @see wpdb::db_version() 1457 1481 * 1458 1482 * @param string $db_cap the feature 1459 * @param false|string|resource $dbh_or_table. Not implemented.1460 1483 * @return bool 1461 1484 */ 1462 1485 function has_cap( $db_cap ) { … … 1489 1512 foreach ( $trace as $call ) { 1490 1513 if ( isset( $call['class'] ) && __CLASS__ == $call['class'] ) 1491 1514 continue; // Filter out wpdb calls. 1515 $caller[] = isset( $call['class'] ) ? "{$call['class']}->{$call['function']}" : $call['function']; 1492 1516 } 1493 $caller = join( ', ', $caller );1494 1517 1495 return $caller;1518 return join( ', ', $caller ); 1496 1519 } 1497 1520 1498 1521 /** 1499 1522 * The database version number. 1500 1523 * 1501 * @param false|string|resource $dbh_or_table. Not implemented.1502 1524 * @return false|string false on failure, version number on success 1503 1525 */ 1504 1526 function db_version() { … … 1514 1536 */ 1515 1537 $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 1516 1538 } 1517 ?> 1539 ?> 1540 No newline at end of file