http://www.mediawiki.org/wiki/Special:Code/MediaWiki/68719
Revision: 68719 Author: raymond Date: 2010-06-29 13:38:55 +0000 (Tue, 29 Jun 2010) Log Message: ----------- * 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 Modified Paths: -------------- trunk/phase3/RELEASE-NOTES trunk/phase3/includes/ImagePage.php Modified: trunk/phase3/RELEASE-NOTES =================================================================== --- trunk/phase3/RELEASE-NOTES 2010-06-29 11:34:25 UTC (rev 68718) +++ trunk/phase3/RELEASE-NOTES 2010-06-29 13:38:55 UTC (rev 68719) @@ -94,6 +94,7 @@ * (bug 21475) \mathtt and \textsf can now be used in <math> * 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 Modified: trunk/phase3/includes/ImagePage.php =================================================================== --- trunk/phase3/includes/ImagePage.php 2010-06-29 11:34:25 UTC (rev 68718) +++ trunk/phase3/includes/ImagePage.php 2010-06-29 13:38:55 UTC (rev 68719) @@ -629,9 +629,8 @@ ); $count = $dbr->numRows( $res ); if ( $count == 0 ) { - $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" ); - $wgOut->addWikiMsg( 'nolinkstoimage' ); - $wgOut->addHTML( "</div>\n" ); + $wgOut->addHTML( Html::rawElement( 'div', array ( 'id' => 'mw-imagepage-nolinkstoimage' ), + wfMsg( 'nolinkstoimage' ) ) ) . "\n"; return; } @@ -646,30 +645,46 @@ ); } - $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" ); + $wgOut->addHTML( Html::openElement( 'ul', array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" ); $sk = $wgUser->getSkin(); $count = 0; + $elements = array(); while ( $s = $res->fetchObject() ) { $count++; if ( $count <= $limit ) { // We have not yet reached the extra one that tells us there is more to fetch - $link = $sk->link( - Title::makeTitle( $s->page_namespace, $s->page_title ), - null, - array(), - array(), - array( 'known', 'noclasses' ) - ); - $wgOut->addHTML( "<li>{$link}</li>\n" ); + $elements[] = $s; } } - $wgOut->addHTML( "</ul>\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( "</div>\n" ); + } + $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" ); } protected function imageRedirects() { @@ -796,6 +811,22 @@ $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; + } + } } /** _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs