r14418 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14417‎ | r14418 | r14419 >
Date:03:41, 27 May 2006
Author:robchurch
Status:old
Tags:
Comment:
* Add reminder to profile
* Implement sorting using natsort()
Modified paths:
  • /trunk/extensions/Sort/Sort.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Sort/Sort.php
@@ -15,6 +15,10 @@
1616 * @author Rob Church <robchur@gmail.com>
1717 * @copyright © 2006 Rob Church
1818 * @licence GNU General Public Licence 2.0
 19+ *
 20+ * @todo Profile this to see how it copes with larger lists; might need to
 21+ * re-think a sizeable portion of the main sort function so we don't
 22+ * flood the application server(s) with multiple parse operations
1923 */
2024
2125 if( defined( 'MEDIAWIKI' ) ) {
@@ -59,23 +63,21 @@
6064 $raw = explode( "\n", $text );
6165 $lines = array();
6266 foreach( $raw as $line ) {
63 - if( trim( $line ) != '' ) {
 67+ if( trim( $line ) != '' ) {
6468 $html = $this->parse( $line );
65 - $lines[ $this->stripHtml( $html ) ] = $html;
 69+ $lines[ $html ] = $this->stripHtml( $html );
6670 }
6771 }
68 - if( $this->order == 'desc' ) {
69 - krsort( $lines );
70 - } else {
71 - ksort( $lines );
72 - }
 72+ natsort( $lines );
 73+ if( $this->order == 'desc' )
 74+ $lines = array_reverse( $lines, true );
7375 return $lines;
7476 }
7577
7678 function makeList( $sorted ) {
7779 $tag = $this->class == 'ol' ? 'ol' : 'ul';
78 - foreach( $sorted as $item )
79 - $list[] = wfOpenElement( 'li' ) . $item . wfCloseElement( 'li' );
 80+ foreach( $sorted as $html => $text )
 81+ $list[] = wfOpenElement( 'li' ) . $html . wfCloseElement( 'li' );
8082 return wfOpenElement( $tag ) . implode( "\n", $list ) . wfCloseElement( $tag );
8183 }
8284

Status & tagging log