Index: trunk/extensions/Sort/Sort.php |
— | — | @@ -15,6 +15,10 @@ |
16 | 16 | * @author Rob Church <robchur@gmail.com> |
17 | 17 | * @copyright © 2006 Rob Church |
18 | 18 | * @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 |
19 | 23 | */ |
20 | 24 | |
21 | 25 | if( defined( 'MEDIAWIKI' ) ) { |
— | — | @@ -59,23 +63,21 @@ |
60 | 64 | $raw = explode( "\n", $text ); |
61 | 65 | $lines = array(); |
62 | 66 | foreach( $raw as $line ) { |
63 | | - if( trim( $line ) != '' ) { |
| 67 | + if( trim( $line ) != '' ) { |
64 | 68 | $html = $this->parse( $line ); |
65 | | - $lines[ $this->stripHtml( $html ) ] = $html; |
| 69 | + $lines[ $html ] = $this->stripHtml( $html ); |
66 | 70 | } |
67 | 71 | } |
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 ); |
73 | 75 | return $lines; |
74 | 76 | } |
75 | 77 | |
76 | 78 | function makeList( $sorted ) { |
77 | 79 | $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' ); |
80 | 82 | return wfOpenElement( $tag ) . implode( "\n", $list ) . wfCloseElement( $tag ); |
81 | 83 | } |
82 | 84 | |