From: Raimond Spekking Date: Tue, 29 Jun 2010 13:38:55 +0000 (+0000) Subject: * Bug 8507 - Group file links by namespace:title on image pages X-Git-Tag: 1.31.0-rc.0~36346 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=7f0a8cf88ac81012ec01c2fe0ec6e3fed2ce008c;p=lhc%2Fweb%2Fwiklou.git * Bug 8507 - Group file links by namespace:title on image pages * Use proper Html::functions * Add namespace specific CSS Id to the li elements to allow styling per namespace --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 4e56a6852f..97fa093b48 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -94,6 +94,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 21475) \mathtt and \textsf can now be used in * texvc is now run via ulimit4.sh, to limit execution time. * SQLite now supports $wgSharedDB. +* (bug 8507) Group file links by namespace:title on image pages === Bug fixes in 1.17 === * (bug 17560) Half-broken deletion moved image files to deletion archive diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 07bc7d29d9..48221e12e4 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -629,9 +629,8 @@ EOT ); $count = $dbr->numRows( $res ); if ( $count == 0 ) { - $wgOut->addHTML( "
\n" ); - $wgOut->addWikiMsg( 'nolinkstoimage' ); - $wgOut->addHTML( "
\n" ); + $wgOut->addHTML( Html::rawElement( 'div', array ( 'id' => 'mw-imagepage-nolinkstoimage' ), + wfMsg( 'nolinkstoimage' ) ) ) . "\n"; return; } @@ -646,30 +645,46 @@ EOT ); } - $wgOut->addHTML( "\n" ); + + // Sort the list by namespace:title + usort ( $elements, array( $this, 'compare' ) ); + + // Create links for every element + foreach( $elements as $element ) { + $link = $sk->link( + Title::makeTitle( $element->page_namespace, $element->page_title ), + null, + array(), + array(), + array( 'known', 'noclasses' ) + ); + $wgOut->addHTML( Html::rawElement( + 'li', + array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ), + $link + ) . "\n" + ); + + }; + $wgOut->addHTML( Html::closeElement( 'ul' ) . "\n" ); $res->free(); // Add a links to [[Special:Whatlinkshere]] - if ( $count > $limit ) + if ( $count > $limit ) { $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle->getPrefixedDBkey() ); - $wgOut->addHTML( "\n" ); + } + $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" ); } protected function imageRedirects() { @@ -796,6 +811,22 @@ EOT $wgOut->addWikiText( $description ); } + + /** + * Callback for usort() to do link sorts by (namespace, title) + * Function copied from Title::compare() + * + * @param $a object page to compare with + * @param $b object page to compare with + * @return Integer: result of string comparison, or namespace comparison + */ + protected function compare( $a, $b ) { + if ( $a->page_namespace == $b->page_namespace ) { + return strcmp( $a->page_title, $b->page_title ); + } else { + return $a->page_namespace - $b->page_namespace; + } + } } /**