Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -3508,8 +3508,6 @@ |
3509 | 3509 | # Register the file as a dependency... |
3510 | 3510 | $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 ); |
3511 | 3511 | if ( $file && !$title->equals( $file->getTitle() ) ) { |
3512 | | - # We fetched a rev from a different title; register it too... |
3513 | | - $this->mOutput->addImage( $file->getTitle()->getDBkey(), $time, $sha1 ); |
3514 | 3512 | # Update fetched file title |
3515 | 3513 | $title = $file->getTitle(); |
3516 | 3514 | } |
Index: trunk/phase3/includes/ImagePage.php |
— | — | @@ -140,7 +140,6 @@ |
141 | 141 | $this->imageDupes(); |
142 | 142 | # TODO! FIXME! For some freaky reason, we can't redirect to foreign images. |
143 | 143 | # Yet we return metadata about the target. Definitely an issue in the FileRepo |
144 | | - $this->imageRedirects(); |
145 | 144 | $this->imageLinks(); |
146 | 145 | |
147 | 146 | # Allow extensions to add something after the image links |
— | — | @@ -660,21 +659,45 @@ |
661 | 660 | } |
662 | 661 | } |
663 | 662 | |
| 663 | + protected function queryImageLinks( $target, $limit ) { |
| 664 | + $dbr = wfGetDB( DB_SLAVE ); |
| 665 | + |
| 666 | + return $dbr->select( |
| 667 | + array( 'imagelinks', 'page' ), |
| 668 | + array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ), |
| 669 | + array( 'il_to' => $target, 'il_from = page_id' ), |
| 670 | + __METHOD__, |
| 671 | + array( 'LIMIT' => $limit + 1 ) |
| 672 | + ); |
| 673 | + } |
| 674 | + |
664 | 675 | protected function imageLinks() { |
665 | 676 | global $wgUser, $wgOut, $wgLang; |
666 | 677 | |
667 | 678 | $limit = 100; |
| 679 | + |
| 680 | + $res = $this->queryImageLinks( $this->mTitle->getDbKey(), $limit + 1); |
| 681 | + $rows = array(); |
| 682 | + $redirects = array(); |
| 683 | + foreach ( $res as $row ) { |
| 684 | + if ( $row->page_is_redirect ) { |
| 685 | + $redirects[$row->page_title] = array(); |
| 686 | + } |
| 687 | + $rows[] = $row; |
| 688 | + } |
| 689 | + $count = count( $rows ); |
| 690 | + |
| 691 | + $hasMore = $count > $limit; |
| 692 | + if ( !$hasMore && count( $redirects ) ) { |
| 693 | + $res = $this->queryImageLinks( array_keys( $redirects ), |
| 694 | + $limit - count( $rows ) + 1 ); |
| 695 | + foreach ( $res as $row ) { |
| 696 | + $redirects[$row->il_to][] = $row; |
| 697 | + $count++; |
| 698 | + } |
| 699 | + $hasMore = ( $res->numRows() + count( $rows ) ) > $limit; |
| 700 | + } |
668 | 701 | |
669 | | - $dbr = wfGetDB( DB_SLAVE ); |
670 | | - |
671 | | - $res = $dbr->select( |
672 | | - array( 'imagelinks', 'page' ), |
673 | | - array( 'page_namespace', 'page_title' ), |
674 | | - array( 'il_to' => $this->mTitle->getDBkey(), 'il_from = page_id' ), |
675 | | - __METHOD__, |
676 | | - array( 'LIMIT' => $limit + 1 ) |
677 | | - ); |
678 | | - $count = $dbr->numRows( $res ); |
679 | 702 | if ( $count == 0 ) { |
680 | 703 | $wgOut->wrapWikiMsg( |
681 | 704 | Html::rawElement( 'div', |
— | — | @@ -685,7 +708,7 @@ |
686 | 709 | } |
687 | 710 | |
688 | 711 | $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" ); |
689 | | - if ( $count <= $limit - 1 ) { |
| 712 | + if ( !$hasMore ) { |
690 | 713 | $wgOut->addWikiMsg( 'linkstoimage', $count ); |
691 | 714 | } else { |
692 | 715 | // More links than the limit. Add a link to [[Special:Whatlinkshere]] |
— | — | @@ -701,25 +724,44 @@ |
702 | 725 | ); |
703 | 726 | $sk = $wgUser->getSkin(); |
704 | 727 | $count = 0; |
705 | | - $elements = array(); |
706 | | - foreach ( $res as $s ) { |
707 | | - $count++; |
708 | | - if ( $count <= $limit ) { |
709 | | - // We have not yet reached the extra one that tells us there is more to fetch |
710 | | - $elements[] = $s; |
711 | | - } |
712 | | - } |
713 | 728 | |
714 | 729 | // Sort the list by namespace:title |
715 | | - usort( $elements, array( $this, 'compare' ) ); |
| 730 | + usort( $rows, array( $this, 'compare' ) ); |
716 | 731 | |
717 | 732 | // Create links for every element |
718 | | - foreach( $elements as $element ) { |
| 733 | + $currentCount = 0; |
| 734 | + foreach( $rows as $element ) { |
| 735 | + $currentCount++; |
| 736 | + if ( $currentCount > $limit ) { |
| 737 | + break; |
| 738 | + } |
| 739 | + |
719 | 740 | $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) ); |
| 741 | + if ( !isset( $redirects[$element->page_title] ) ) { |
| 742 | + $liContents = $link; |
| 743 | + } else { |
| 744 | + $ul = "<ul class='mw-imagepage-redirectstofile'>\n"; |
| 745 | + foreach ( $redirects[$element->page_title] as $row ) { |
| 746 | + $currentCount++; |
| 747 | + if ( $currentCount > $limit ) { |
| 748 | + break; |
| 749 | + } |
| 750 | + |
| 751 | + $link2 = $sk->linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) ); |
| 752 | + $ul .= Html::rawElement( |
| 753 | + 'li', |
| 754 | + array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ), |
| 755 | + $link2 |
| 756 | + ) . "\n"; |
| 757 | + } |
| 758 | + $ul .= '</ul>'; |
| 759 | + $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( |
| 760 | + $link, $ul )->parse(); |
| 761 | + } |
720 | 762 | $wgOut->addHTML( Html::rawElement( |
721 | 763 | 'li', |
722 | 764 | array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ), |
723 | | - $link |
| 765 | + $liContents |
724 | 766 | ) . "\n" |
725 | 767 | ); |
726 | 768 | |
— | — | @@ -733,35 +775,7 @@ |
734 | 776 | } |
735 | 777 | $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" ); |
736 | 778 | } |
737 | | - |
738 | | - protected function imageRedirects() { |
739 | | - global $wgUser, $wgOut, $wgLang; |
740 | 779 | |
741 | | - $redirects = $this->getTitle()->getRedirectsHere( NS_FILE ); |
742 | | - if ( count( $redirects ) == 0 ) { |
743 | | - return; |
744 | | - } |
745 | | - |
746 | | - $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" ); |
747 | | - $wgOut->addWikiMsg( 'redirectstofile', |
748 | | - $wgLang->formatNum( count( $redirects ) ) |
749 | | - ); |
750 | | - $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" ); |
751 | | - |
752 | | - $sk = $wgUser->getSkin(); |
753 | | - foreach ( $redirects as $title ) { |
754 | | - $link = $sk->link( |
755 | | - $title, |
756 | | - null, |
757 | | - array(), |
758 | | - array( 'redirect' => 'no' ), |
759 | | - array( 'known', 'noclasses' ) |
760 | | - ); |
761 | | - $wgOut->addHTML( "<li>{$link}</li>\n" ); |
762 | | - } |
763 | | - $wgOut->addHTML( "</ul></div>\n" ); |
764 | | - } |
765 | | - |
766 | 780 | protected function imageDupes() { |
767 | 781 | global $wgOut, $wgUser, $wgLang; |
768 | 782 | |
Index: trunk/phase3/languages/messages/MessagesQqq.php |
— | — | @@ -1901,8 +1901,10 @@ |
1902 | 1902 | |
1903 | 1903 | * $1: limit. At the moment hardcoded at 100 |
1904 | 1904 | * $2: filename', |
| 1905 | +'linkstoimage-redirect' => 'Item in the "the following pages link to this file" section on a file page if the item is a redirect. |
| 1906 | +* $1: an HTML link to the file |
| 1907 | +* $2: the list of files that link to the redirect (may be empty)', |
1905 | 1908 | 'nolinkstoimage' => 'Displayed on image description pages, see for exampe [[:Image:Tournesol.png#filelinks]].', |
1906 | | -'redirectstofile' => 'Used on file description pages after the list of pages which used this file', |
1907 | 1909 | 'duplicatesoffile' => 'Shown on file description pages when a file is duplicated |
1908 | 1910 | |
1909 | 1911 | * $1: Number of identical files |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2333,7 +2333,7 @@ |
2334 | 2334 | A [[Special:WhatLinksHere/$2|full list]] is available.', |
2335 | 2335 | 'nolinkstoimage' => 'There are no pages that link to this file.', |
2336 | 2336 | 'morelinkstoimage' => 'View [[Special:WhatLinksHere/$1|more links]] to this file.', |
2337 | | -'redirectstofile' => 'The following {{PLURAL:$1|file redirects|$1 files redirect}} to this file:', |
| 2337 | +'linkstoimage-redirect' => '$1 (file redirect) $2', |
2338 | 2338 | 'duplicatesoffile' => 'The following {{PLURAL:$1|file is a duplicate|$1 files are duplicates}} of this file ([[Special:FileDuplicateSearch/$2|more details]]):', |
2339 | 2339 | 'sharedupload' => 'This file is from $1 and may be used by other projects.', |
2340 | 2340 | 'sharedupload-desc-there' => 'This file is from $1 and may be used by other projects. |