* Show a link to [[Special:Whatlinkshere]] in case there are more imagelinks on ImagePage
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 9 May 2008 11:31:00 +0000 (11:31 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 9 May 2008 11:31:00 +0000 (11:31 +0000)
* Cleanup ImagePage code

includes/ImagePage.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 0ba2198..c77c077 100644 (file)
@@ -521,31 +521,45 @@ EOT
        function imageLinks()
        {
                global $wgUser, $wgOut;
+               
+               $limit = 100;
 
                $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
 
                $dbr = wfGetDB( DB_SLAVE );
-               $page = $dbr->tableName( 'page' );
-               $imagelinks = $dbr->tableName( 'imagelinks' );
 
-               $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
-                 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
-               $sql = $dbr->limitResult($sql, 500, 0);
-               $res = $dbr->query( $sql, "ImagePage::imageLinks" );
+               $res = $dbr->select(
+                       array( 'imagelinks', 'page' ),
+                       array( 'page_namespace', 'page_title' ),
+                       array( 'il_to' => $this->mTitle->getDBkey(), 'il_from = page_id' ),
+                       __METHOD__,
+                       array( 'LIMIT' => $limit + 1)   
+               );
 
                if ( 0 == $dbr->numRows( $res ) ) {
-                       $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
+                       $wgOut->addHtml( Xml::element('p', null ,wfMsg( "nolinkstoimage" ) )."\n" );
                        return;
                }
-               $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) .  "</p>\n<ul>" );
+               $wgOut->addHTML( Xml::element('p', null, wfMsg( 'linkstoimage' ) )."\n" );
+               $wgOut->addHTML( Xml::openElement( 'ul' ));
 
                $sk = $wgUser->getSkin();
-               while ( $s = $dbr->fetchObject( $res ) ) {
-                       $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
-                       $link = $sk->makeKnownLinkObj( $name, "" );
-                       $wgOut->addHTML( "<li>{$link}</li>\n" );
+               $count = 0;
+               while ( $s = $res->fetchObject() ) {
+                       $count++;
+                       if ( $count <= $limit ) {
+                               // We have not yet reached the extra one that tells us there is more to fetch
+                               $name = Title::makeTitle( $s->page_namespace, $s->page_title );
+                               $link = $sk->makeKnownLinkObj( $name, "" );
+                               $wgOut->addHTML( "<li>{$link}</li>\n" );
+                       }
                }
                $wgOut->addHTML( "</ul>\n" );
+               $res->free();
+               
+               // Add a links to [[Special:Whatlinkshere]]
+               if ( $count > $limit )
+                       $wgOut->addWikiText( wfMsg( 'morelinkstoimage', $this->mTitle->getPrefixedDBkey() ) );
        }
        
        function imageRedirects() 
@@ -561,7 +575,8 @@ EOT
                                'rd_title' => $this->mTitle->getDBkey(),
                                'page_namespace' => NS_IMAGE,
                                'rd_from = page_id'
-                       )
+                       ),
+                       __METHOD__
                );
                
 
index 8198f81..cd75dec 100644 (file)
@@ -1710,6 +1710,7 @@ A click on a column header changes the sorting.',
 'imagelinks'                     => 'Links',
 'linkstoimage'                   => 'The following pages link to this file:',
 'nolinkstoimage'                 => 'There are no pages that link to this file.',
+'morelinkstoimage'                              => 'View [[Special:Whatlinkshere/$1|more links]] to this file.',
 'redirectstofile'                => 'The following files redirect to this file:',
 'sharedupload'                   => 'This file is a shared upload and may be used by other projects.',
 'shareduploadwiki'               => 'Please see the $1 for further information.',
index fbfae95..a301439 100644 (file)
@@ -1050,6 +1050,7 @@ $wgMessageStructure = array(
                'imagelinks',
                'linkstoimage',
                'nolinkstoimage',
+               'morelinkstoimage',
                'redirectstofile',
                'sharedupload',
                'shareduploadwiki',