Index: trunk/phase3/CREDITS |
— | — | @@ -120,6 +120,7 @@ |
121 | 121 | * Lejonel |
122 | 122 | * liangent |
123 | 123 | * Louperivois |
| 124 | +* Luca Fulchir |
124 | 125 | * Lucas Garczewski |
125 | 126 | * Luigi Corsaro |
126 | 127 | * Lupo |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -624,15 +624,69 @@ |
625 | 625 | } |
626 | 626 | |
627 | 627 | function tableName( $name, $format = 'quoted' ) { |
628 | | - # Replace reserved words with better ones |
629 | | - switch( $name ) { |
| 628 | + global $wgSharedDB, $wgSharedTables, $wgDBmwSchema; |
| 629 | + # Skip quoted tablenames. |
| 630 | + if ( $this->isQuotedIdentifier( $name ) ) { |
| 631 | + return $name; |
| 632 | + } |
| 633 | + # Lets test for any bits of text that should never show up in a table |
| 634 | + # name. Basically anything like JOIN or ON which are actually part of |
| 635 | + # SQL queries, but may end up inside of the table value to combine |
| 636 | + # sql. Such as how the API is doing. |
| 637 | + # Note that we use a whitespace test rather than a \b test to avoid |
| 638 | + # any remote case where a word like on may be inside of a table name |
| 639 | + # surrounded by symbols which may be considered word breaks. |
| 640 | + if ( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) { |
| 641 | + return $name; |
| 642 | + } |
| 643 | + # Split database and table into proper variables. |
| 644 | + # We reverse the explode so that schema.table and table both output |
| 645 | + # the correct table. |
| 646 | + $dbDetails = array_reverse( explode( '.', $name, 2 ) ); |
| 647 | + if ( isset( $dbDetails[1] ) ) { |
| 648 | + list( $table, $schema ) = $dbDetails; |
| 649 | + } else { |
| 650 | + list( $table ) = $dbDetails; |
| 651 | + } |
| 652 | + if ( $format != 'quoted' ) { |
| 653 | + switch( $name ) { |
| 654 | + case 'user': |
| 655 | + return 'mwuser'; |
| 656 | + case 'text': |
| 657 | + return 'pagecontent'; |
| 658 | + default: |
| 659 | + return $table; |
| 660 | + } |
| 661 | + } |
| 662 | + if ( !isset( $schema )) { |
| 663 | + $schema = "\"{$wgDBmwSchema}\"."; |
| 664 | + } else { |
| 665 | + # keep old schema, but quote it. |
| 666 | + $schema = "\"{$schema}\"."; |
| 667 | + } |
| 668 | + # during installation wgDBmwSchema is not set, so we would end up quering |
| 669 | + # ""."table" => error. Erase the first part if wgDBmwSchema is empty |
| 670 | + if ( $schema == "\"\"." ) { |
| 671 | + $schema = ""; |
| 672 | + } |
| 673 | + if ( isset( $wgSharedDB ) # We have a shared database (=> schema) |
| 674 | + && isset( $wgSharedTables ) |
| 675 | + && is_array( $wgSharedTables ) |
| 676 | + && in_array( $table, $wgSharedTables ) ) { # A shared table is selected |
| 677 | + $schema = "\"{$wgSharedDB}\"."; |
| 678 | + } |
| 679 | + switch ( $table ) { |
630 | 680 | case 'user': |
631 | | - return 'mwuser'; |
| 681 | + $table = "{$schema}\"mwuser\""; |
| 682 | + break; |
632 | 683 | case 'text': |
633 | | - return 'pagecontent'; |
| 684 | + $table = "{$schema}\"pagecontent\""; |
| 685 | + break; |
634 | 686 | default: |
635 | | - return parent::tableName( $name, $format ); |
| 687 | + $table = "{$schema}\"$table\""; |
| 688 | + break; |
636 | 689 | } |
| 690 | + return $table; |
637 | 691 | } |
638 | 692 | |
639 | 693 | /** |