Index: trunk/extensions/Translate/tag/TranslatablePage.php |
— | — | @@ -448,27 +448,34 @@ |
449 | 449 | |
450 | 450 | // Returns false if not found |
451 | 451 | protected function getTag( $tag, $dbt = DB_SLAVE ) { |
452 | | - $db = wfGetDB( $dbt ); |
453 | 452 | |
454 | | - $id = $this->getTagId( $tag ); |
455 | | - |
456 | 453 | if ( !$this->getTitle()->exists() ) { |
457 | 454 | return false; |
458 | 455 | } |
459 | 456 | |
| 457 | + static $cache = array(); |
| 458 | + $aid = $this->getTitle()->getArticleId(); |
| 459 | + |
| 460 | + if ( isset( $cache[$aid][$tag] ) ) { |
| 461 | + return $cache[$aid][$tag]; |
| 462 | + } |
| 463 | + |
| 464 | + $db = wfGetDB( $dbt ); |
| 465 | + $id = $this->getTagId( $tag ); |
| 466 | + |
460 | 467 | $fields = 'rt_revision'; |
461 | 468 | $conds = array( |
462 | | - 'rt_page' => $this->getTitle()->getArticleId(), |
| 469 | + 'rt_page' => $aid, |
463 | 470 | 'rt_type' => $id, |
464 | 471 | ); |
465 | 472 | |
466 | 473 | $options = array( 'ORDER BY' => 'rt_revision DESC' ); |
467 | 474 | |
468 | | - $tag = $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options ); |
469 | | - if ( $tag !== false ) { |
470 | | - return intval( $tag ); |
| 475 | + $tagRevision = $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options ); |
| 476 | + if ( $tagRevision !== false ) { |
| 477 | + return $cache[$aid][$tag] = intval( $tagRevision ); |
471 | 478 | } else { |
472 | | - return false; |
| 479 | + return $cache[$aid][$tag] = false; |
473 | 480 | } |
474 | 481 | } |
475 | 482 | |
— | — | @@ -634,7 +641,7 @@ |
635 | 642 | return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options ); |
636 | 643 | } |
637 | 644 | |
638 | | - protected function getTagId( $tag ) { |
| 645 | + protected static function getTagId( $tag ) { |
639 | 646 | $validTags = array( 'tp:mark', 'tp:tag', 'tp:transver' ); |
640 | 647 | if ( !in_array( $tag, $validTags ) ) { |
641 | 648 | throw new MWException( "Invalid tag $tag requested" ); |
— | — | @@ -699,6 +706,45 @@ |
700 | 707 | protected static function changeTitleText( Title $title, $text ) { |
701 | 708 | return Title::makeTitleSafe( $title->getNamespace(), $text ); |
702 | 709 | } |
| 710 | + |
| 711 | + public static function isSourcePage( Title $title ) { |
| 712 | + static $cache = null; |
| 713 | + |
| 714 | + $cacheObj = wfGetCache( CACHE_ANYTHING ); |
| 715 | + $cacheKey = wfMemcKey( 'pagetranslation', 'sourcepages' ); |
| 716 | + |
| 717 | + if ( $cache === null ) { |
| 718 | + $cache = $cacheObj->get( $cacheKey ); |
| 719 | + } |
| 720 | + if ( !is_array( $cache ) ) { |
| 721 | + $cache = self::getTranslatablePages(); |
| 722 | + $cacheObj->set( $cacheKey, $cache, 60 * 5 ); |
| 723 | + } |
| 724 | + |
| 725 | + return in_array( $title->getArticleId(), $cache ); |
| 726 | + } |
| 727 | + |
| 728 | + /// List of page ids where the latest revision is either tagged or marked |
| 729 | + public static function getTranslatablePages() { |
| 730 | + $dbr = wfGetDB( DB_SLAVE ); |
| 731 | + |
| 732 | + $tables = array( 'revtag', 'page' ); |
| 733 | + $fields = 'rt_page'; |
| 734 | + $conds = array( |
| 735 | + 'rt_page = page_id', |
| 736 | + 'rt_revision = page_latest', |
| 737 | + 'rt_type' => array( self::getTagId( 'tp:mark' ), self::getTagId( 'tp:tag' ) ), |
| 738 | + ); |
| 739 | + $options = array( 'GROUP BY' => 'rt_page' ); |
| 740 | + |
| 741 | + $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options ); |
| 742 | + $results = array(); |
| 743 | + foreach ( $res as $row ) { |
| 744 | + $results[] = $row->rt_page; |
| 745 | + } |
| 746 | + |
| 747 | + return $results; |
| 748 | + } |
703 | 749 | } |
704 | 750 | |
705 | 751 | /** |
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php |
— | — | @@ -373,20 +373,21 @@ |
374 | 374 | } |
375 | 375 | |
376 | 376 | public static function header( Title $title ) { |
377 | | - $page = TranslatablePage::newFromTitle( $title ); |
378 | | - $marked = $page->getMarkedTag(); |
379 | | - $ready = $page->getReadyTag(); |
380 | | - |
381 | | - if ( $marked || $ready ) { |
382 | | - self::sourcePageHeader( $page, $marked, $ready ); |
383 | | - } else { |
| 377 | + if ( TranslatablePage::isSourcePage( $title ) ) { |
| 378 | + self::sourcePageHeader( $title ); |
| 379 | + } elseif ( TranslatablePage::isTranslationPage( $title ) ) { |
384 | 380 | self::translationPageHeader( $title ); |
385 | 381 | } |
386 | 382 | } |
387 | 383 | |
388 | | - protected static function sourcePageHeader( TranslatablePage $page, $marked, $ready ) { |
| 384 | + protected static function sourcePageHeader( Title $title ) { |
389 | 385 | global $wgUser, $wgLang; |
390 | 386 | |
| 387 | + $page = TranslatablePage::newFromTitle( $title ); |
| 388 | + |
| 389 | + $marked = $page->getMarkedTag(); |
| 390 | + $ready = $page->getReadyTag(); |
| 391 | + |
391 | 392 | $title = $page->getTitle(); |
392 | 393 | $sk = $wgUser->getSkin(); |
393 | 394 | |