Index: trunk/extensions/SemanticMediaWiki/includes/SMW_InlineQueries.php |
— | — | @@ -488,17 +488,23 @@ |
489 | 489 | // using a simple SQL query instead) |
490 | 490 | // Also, redirects are not taken into account for sub-queries |
491 | 491 | // anymore now. |
492 | | - foreach ($values as $idx => $v) { |
493 | | - $values[$idx] = smwfNormalTitleDBKey($v); |
494 | | - } |
495 | | - $values = $this->normalizeRedirects($values); |
496 | | - // search for values |
| 492 | + $vtitles = array(); |
497 | 493 | foreach ($values as $v) { |
498 | 494 | $vtitle = Title::newFromText($v); |
499 | | - if (NULL != $vtitle) { |
500 | | - $or_conditions[] = "$curtable.object_title=" . $this->dbr->addQuotes($vtitle->getDBKey()) . " AND $curtable.object_namespace=" . $vtitle->getNamespace(); |
| 495 | + if (NULL != $vtitle) { |
| 496 | + $id = $vtitle->getArticleID(); // create index for title |
| 497 | + if (0 == $id) $id = $vtitle->getPrefixedText(); |
| 498 | + $vtitles[$vtitle->getArticleID()] = $vtitle; //convert values to titles |
501 | 499 | } |
502 | 500 | } |
| 501 | + $vtitles = $this->normalizeRedirects($vtitles); |
| 502 | + |
| 503 | + // search for values |
| 504 | + foreach ($vtitles as $vtitle) { |
| 505 | + //if (NULL != $vtitle) { |
| 506 | + $or_conditions[] = "$curtable.object_title=" . $this->dbr->addQuotes($vtitle->getDBKey()) . " AND $curtable.object_namespace=" . $vtitle->getNamespace(); |
| 507 | + //} |
| 508 | + } |
503 | 509 | } |
504 | 510 | if ($relation == $this->mSort) { |
505 | 511 | $result->mOrderBy = "$curtable.object_title"; |
— | — | @@ -601,7 +607,7 @@ |
602 | 608 | } |
603 | 609 | |
604 | 610 | /** |
605 | | - * Turns an array of articles into an array of all these articles and |
| 611 | + * Turns an array of article titles into an array of all these articles and |
606 | 612 | * the transitive closure of all redirects from and to this articles. |
607 | 613 | * Or, simply said: it gets all aliases of what you put in. |
608 | 614 | * |
— | — | @@ -610,61 +616,77 @@ |
611 | 617 | * plugable SQL-query to compute one-step back-and-forth redirects without any |
612 | 618 | * materialisation. |
613 | 619 | */ |
614 | | - private function normalizeRedirects(&$articles) { |
| 620 | + private function normalizeRedirects(&$titles) { |
615 | 621 | global $smwgIQRedirectNormalization; |
616 | 622 | if (!$smwgIQRedirectNormalization) { |
617 | | - return $articles; |
| 623 | + return $titles; |
618 | 624 | } |
619 | | - $stable = FALSE; |
620 | | - $check_articles = array_diff( $articles , array() ); // Copies the array |
621 | | - while (!$stable) { |
622 | | - $new_articles = array(); |
623 | | - foreach ( $check_articles as $article ) { |
| 625 | + |
| 626 | + print "STARTING NORMALIZATION FOR:<br />\n"; |
| 627 | + foreach ($titles as $title) print "+ " . $title->getPrefixedText(); |
| 628 | + print "<br />\n"; |
| 629 | + |
| 630 | + $stable = 0; |
| 631 | + $check_titles = array_diff( $titles , array() ); // Copies the array |
| 632 | + while ($stable<30) { // emergency stop after 30 iterations |
| 633 | + $stable++; |
| 634 | + $new_titles = array(); |
| 635 | + foreach ( $check_titles as $title ) { |
624 | 636 | // there... |
625 | | - $res = $this->dbr->select( |
626 | | - array( 'page' , 'pagelinks' ), |
627 | | - array( 'pl_title' ), |
628 | | - array( 'page_title = ' . $this->dbr->addQuotes( $article ), |
| 637 | + |
| 638 | + print "1 "; |
| 639 | + if ( 0 != $title->getArticleID() ) { |
| 640 | + $res = $this->dbr->select( |
| 641 | + array( 'page' , 'pagelinks' ), |
| 642 | + array( 'pl_title', 'pl_namespace'), |
| 643 | + array( 'page_id = ' . $title->getArticleID(), |
629 | 644 | 'page_is_redirect = 1', |
630 | 645 | 'page_id = pl_from' ) , |
631 | 646 | "SMW::NormalizeRedirects" ); |
632 | | - if ( $res ) { |
633 | 647 | while ( $res && $row = $this->dbr->fetchRow( $res )) { |
634 | | - if ( array_key_exists( 'pl_title', $row) ) { |
635 | | - $new_article = $row[ 'pl_title' ]; |
636 | | - if (!in_array( $new_article , $articles)) { |
637 | | - $new_articles[] = $new_article; |
| 648 | + $new_title = Title::newFromText($row['pl_title'], $row['pl_namespace']); |
| 649 | + if (NULL != $new_title) { |
| 650 | + $id = $new_title->getArticleID(); |
| 651 | + if (0 == $id) $id = $new_title->getPrefixedText(); |
| 652 | + if (!array_key_exists( $id , $titles)) { |
| 653 | + $titles[$id] = $new_title; |
| 654 | + $new_titles[] = $new_title; |
| 655 | + print "+ " . $new_title->getPrefixedText() . "(" . $new_title->getArticleID() . ") "; |
638 | 656 | } |
639 | 657 | } |
640 | 658 | } |
| 659 | + $this->dbr->freeResult( $res ); |
641 | 660 | } |
642 | | - $this->dbr->freeResult( $res ); |
643 | | - |
| 661 | + |
| 662 | + print "<br />\n"; |
| 663 | + print "2 "; |
644 | 664 | // ... and back again |
645 | 665 | $res = $this->dbr->select( |
646 | 666 | array( 'page' , 'pagelinks' ), |
647 | | - array( 'page_title' ), |
648 | | - array( 'pl_title = '. $this->dbr->addQuotes( $article ), |
649 | | - 'page_is_redirect = 1', |
650 | | - 'page_id = pl_from' ) , |
651 | | - "SMW::NormalizeRedirects" ); |
652 | | - if ( $res ) { |
653 | | - while ( $res && $row = $this->dbr->fetchRow( $res )) { |
654 | | - if ( array_key_exists( 'page_title', $row) ) { |
655 | | - $new_article = $row[ 'page_title' ]; |
656 | | - if (!in_array( $new_article , $articles)) { |
657 | | - $new_articles[] = $new_article; |
658 | | - } |
659 | | - } |
| 667 | + array( 'page_id' ), |
| 668 | + array( 'pl_title = ' . $this->dbr->addQuotes( $title->getDBkey() ), |
| 669 | + 'pl_namespace = ' . $this->dbr->addQuotes( $title->getNamespace() ), |
| 670 | + 'page_is_redirect = 1', |
| 671 | + 'page_id = pl_from' ) , |
| 672 | + "SMW::NormalizeRedirects" ); |
| 673 | + while ( $res && $row = $this->dbr->fetchRow( $res )) { |
| 674 | + $new_title = Title::newFromID( $row['page_id'] ); |
| 675 | + if (!array_key_exists( $row['page_id'] , $titles)) { |
| 676 | + $titles[$row['page_id']] = $new_title; |
| 677 | + $new_titles[] = $new_title; |
| 678 | + print "+ " . $new_title->getPrefixedText() . "(" . $new_title->getArticleID() . ") "; |
660 | 679 | } |
661 | 680 | } |
662 | 681 | $this->dbr->freeResult( $res ); |
663 | 682 | } |
664 | | - $stable = (count($new_articles)==0); |
665 | | - $articles = array_merge( $articles, $new_articles ); |
666 | | - $check_articles = array_diff( $new_articles , array() ); |
| 683 | + if (count($new_titles)==0) |
| 684 | + $stable= 500; // stop |
| 685 | + else |
| 686 | + $check_titles = array_diff( $new_titles , array() ); |
| 687 | +// foreach ($new_titles as $title) print "+ " . $title->getPrefixedText(); |
| 688 | + print "<br />\n"; |
667 | 689 | } |
668 | | - return $articles; |
| 690 | + return $titles; |
669 | 691 | } |
670 | 692 | |
671 | 693 | /** |