Index: trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +<?php |
| 3 | +if (!defined( 'MEDIAWIKI' )) die( "Not an entry point" ); |
| 4 | + |
| 5 | +/** |
| 6 | + * Pretty much based on UppercaseCollation from core. |
| 7 | + * |
| 8 | + * Collation that is case-insensitive, and allows specify |
| 9 | + * custom 'first-character' headings for category pages. |
| 10 | + */ |
| 11 | +class CustomHeaderCollation extends Collation { |
| 12 | + |
| 13 | + // The basic idea is we store the sortkey as three parts A^B^C |
| 14 | + // A is the capitalized first letter of the header it falls under. |
| 15 | + // B is the is the header it falls under (In whatever case the user enters) |
| 16 | + // C is the rest of the sortkey. |
| 17 | + // |
| 18 | + // The user enters something like [[category:some cat|^my header^foo]] |
| 19 | + // which gets turned into "^my header^foo\n<page name>" |
| 20 | + // which we turn into "M^my header^FOO\n<PAGE NAME>" |
| 21 | + function getSortKey( $string ) { |
| 22 | + global $wgContLang; |
| 23 | + // UppercaseCollation uses an EN lang object always instead of content lang. |
| 24 | + // I'm not sure why. To me it makes more sense to use $wgContLang. |
| 25 | + // There's minnor differences in some languages (like Turkish) |
| 26 | + |
| 27 | + $matches = array(); |
| 28 | + if ( preg_match( '/^\^([^\n^]*)\^(.*)$/Ds', $string, $matches ) ) { |
| 29 | + if ( $matches[1] === '' ) $matches[1] = ' '; |
| 30 | + $part1 = $wgContLang->firstChar( $wgContLang->uc( $matches[1] ) ); |
| 31 | + $part2 = $matches[1]; |
| 32 | + $part3 = $wgContLang->uc( $matches[2] ); |
| 33 | + |
| 34 | + } else { |
| 35 | + // Ordinay sortkey, no header info. |
| 36 | + $part3 = $wgContLang->uc( $string ); |
| 37 | + $part1 = $part2 = $wgContLang->firstChar( $part3 ); |
| 38 | + } |
| 39 | + |
| 40 | + return $part1 . '^' . $part2 . '^' . $part3; |
| 41 | + } |
| 42 | + |
| 43 | + function getFirstLetter( $string ) { |
| 44 | + global $wgContLang; |
| 45 | + |
| 46 | + # Stolen from UppercaseCollation |
| 47 | + # not sure when this could actually happen. |
| 48 | + if ( $string[0] === "\0" ) { |
| 49 | + $string = substr( $string, 1 ); |
| 50 | + } |
| 51 | + |
| 52 | + $m = array(); |
| 53 | + if ( preg_match( '/^[^\n^]*\^([^\n^]*)\^/', $string, $m ) ) { |
| 54 | + return $m[1]; |
| 55 | + } else { |
| 56 | + // Probably shouldn't happen. |
| 57 | + return $wgContLang->ucfirst( $wgContLang->firstChar( $string ) ); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
Property changes on: trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 61 | + native |
Index: trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * i18n file for CategorySortHelpers, which really doesn't have any messages to begin with. |
| 5 | + * @file |
| 6 | + * @ingroup Extensions |
| 7 | + */ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +/** English |
| 12 | + * @author Brian Wolff |
| 13 | + */ |
| 14 | +$messages['en'] = array( |
| 15 | + 'categorysortheaders-desc' => 'Allow to specify custom multi-character \'first-character\' sorting headers to list pages under in categories, using syntax like <nowiki>[[category:Foo|^Header^Invisible part of sortkey]]</nowiki>.', |
| 16 | +); |
| 17 | + |
| 18 | +$messages['qqq'] = array( |
| 19 | + 'categorysortheaders-desc' => '{{desc}}', |
| 20 | +); |
Property changes on: trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 21 | + native |
Index: trunk/extensions/CategorySortHeaders/CategorySortHeaders.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | +if (!defined( 'MEDIAWIKI' ) ) die('Not an entry point'); |
| 4 | + |
| 5 | +/** |
| 6 | + * Extension to allow specifying custom multi-character 'first-character' |
| 7 | + * sorting headers to list pages under in categories, using syntax like |
| 8 | + * [[category:Foo|^Header^Invisible part of sortkey]] or even just |
| 9 | + * [[category:Foo|^Header^]]. |
| 10 | + * |
| 11 | + * Note, this extension is incompatible with changing $wgCategoryCollation |
| 12 | + * in LocalSettings.php. It defines its own Collation that is |
| 13 | + * roughly equivalent to 'uppercase', and thus can't be used |
| 14 | + * with 'uca-default' or any other custom collation. |
| 15 | + * Additionally, this extension requires at least MediaWiki 1.17. |
| 16 | + * |
| 17 | + * To install: |
| 18 | + * Add to the bottom of LocalSettings.php: |
| 19 | + * require_once( "$IP/extensions/CategorySortHeaders/CategorySortHeaders.php" ); |
| 20 | + * Run either update.php or updateCollation.php |
| 21 | + * (update.php can be run from the web installer if need be.) |
| 22 | + * |
| 23 | + ************************************************************** |
| 24 | + * |
| 25 | + * Copyright © 2011 Brian Wolff |
| 26 | + * |
| 27 | + * This program is free software; you can redistribute it and/or modify |
| 28 | + * it under the terms of the GNU General Public License as published by |
| 29 | + * the Free Software Foundation; either version 2 of the License, or |
| 30 | + * (at your option) any later version. |
| 31 | + * |
| 32 | + * This program is distributed in the hope that it will be useful, |
| 33 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 34 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 35 | + * GNU General Public License for more details. |
| 36 | + * |
| 37 | + * You should have received a copy of the GNU General Public License along |
| 38 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 39 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 40 | + * http://www.gnu.org/copyleft/gpl.html |
| 41 | + * |
| 42 | + * @author Brian Wolff |
| 43 | + */ |
| 44 | + |
| 45 | + |
| 46 | +$wgExtensionCredits['other'][] = array( |
| 47 | + 'path' => __FILE__, |
| 48 | + 'name' => 'CategorySortHeaders', |
| 49 | + 'author' => '[http://mediawiki.org/wiki/User:Bawolff Brian Wolff]', |
| 50 | + 'descriptionmsg' => 'categorysortheaders-desc', |
| 51 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:CategorySortHeaders', |
| 52 | + 'version' => 0.1, |
| 53 | +); |
| 54 | + |
| 55 | +$dir = dirname( __FILE__ ) . '/'; |
| 56 | +$wgExtensionMessagesFiles['CategorySortHeaders'] = $dir . 'CategorySortHeaders.i18n.php'; |
| 57 | +$wgAutoloadClasses['CustomHeaderCollation'] = $dir . 'CategorySortHeaders_body.php'; |
| 58 | + |
| 59 | +$wgCategoryCollation = 'CustomHeaderCollation'; |
| 60 | + |
| 61 | + |
Property changes on: trunk/extensions/CategorySortHeaders/CategorySortHeaders.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 62 | + native |