http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90760
Revision: 90760
Author: bawolff
Date: 2011-06-25 07:27:12 +0000 (Sat, 25 Jun 2011)
Log Message:
-----------
New extension: CategorySortHeaders, to make custom headers instead of just the
first character of sortkey
depends on r90759
Added Paths:
-----------
trunk/extensions/CategorySortHeaders/
trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php
trunk/extensions/CategorySortHeaders/CategorySortHeaders.php
trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php
Added: trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php
===================================================================
--- trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php
(rev 0)
+++ trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php
2011-06-25 07:27:12 UTC (rev 90760)
@@ -0,0 +1,19 @@
+<?php
+/**
+ * i18n file for CategorySortHelpers, which really doesn't have any messages
to begin with.
+ * @file
+ * @ingroup Extensions
+ */
+
+$messages = array();
+
+/** English
+ * @author Brian Wolff
+ */
+$messages['en'] = array(
+ '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>.',
+);
+
+$messages['qqq'] = array(
+ 'categorysortheaders-desc' => '{{desc}}',
+);
Property changes on:
trunk/extensions/CategorySortHeaders/CategorySortHeaders.i18n.php
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/extensions/CategorySortHeaders/CategorySortHeaders.php
===================================================================
--- trunk/extensions/CategorySortHeaders/CategorySortHeaders.php
(rev 0)
+++ trunk/extensions/CategorySortHeaders/CategorySortHeaders.php
2011-06-25 07:27:12 UTC (rev 90760)
@@ -0,0 +1,60 @@
+<?php
+if (!defined( 'MEDIAWIKI' ) ) die('Not an entry point');
+
+/**
+ * Extension to allow specifying custom multi-character 'first-character'
+ * sorting headers to list pages under in categories, using syntax like
+ * [[category:Foo|^Header^Invisible part of sortkey]] or even just
+ * [[category:Foo|^Header^]].
+ *
+ * Note, this extension is incompatible with changing $wgCategoryCollation
+ * in LocalSettings.php. It defines its own Collation that is
+ * roughly equivalent to 'uppercase', and thus can't be used
+ * with 'uca-default' or any other custom collation.
+ * Additionally, this extension requires at least MediaWiki 1.17.
+ *
+ * To install:
+ * Add to the bottom of LocalSettings.php:
+ * require_once(
"$IP/extensions/CategorySortHeaders/CategorySortHeaders.php" );
+ * Run either update.php or updateCollation.php
+ * (update.php can be run from the web installer if need be.)
+ *
+ **************************************************************
+ *
+ * Copyright © 2011 Brian Wolff
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @author Brian Wolff
+ */
+
+
+$wgExtensionCredits['other'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'CategorySortHeaders',
+ 'author' => '[http://mediawiki.org/wiki/User:Bawolff Brian Wolff]',
+ 'descriptionmsg' => 'categorysortheaders-desc',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:CategorySortHeaders',
+ 'version' => 0.1,
+);
+
+$dir = dirname( __FILE__ ) . '/';
+$wgExtensionMessagesFiles['CategorySortHeaders'] = $dir .
'CategorySortHeaders.i18n.php';
+$wgAutoloadClasses['CustomHeaderCollation'] = $dir .
'CategorySortHeaders_body.php';
+
+$wgCategoryCollation = 'CustomHeaderCollation';
+
+
Property changes on:
trunk/extensions/CategorySortHeaders/CategorySortHeaders.php
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php
===================================================================
--- trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php
(rev 0)
+++ trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php
2011-06-25 07:27:12 UTC (rev 90760)
@@ -0,0 +1,59 @@
+<?php
+if (!defined( 'MEDIAWIKI' )) die( "Not an entry point" );
+
+/**
+ * Pretty much based on UppercaseCollation from core.
+ *
+ * Collation that is case-insensitive, and allows specify
+ * custom 'first-character' headings for category pages.
+ */
+class CustomHeaderCollation extends Collation {
+
+ // The basic idea is we store the sortkey as three parts A^B^C
+ // A is the capitalized first letter of the header it falls under.
+ // B is the is the header it falls under (In whatever case the user
enters)
+ // C is the rest of the sortkey.
+ //
+ // The user enters something like [[category:some cat|^my header^foo]]
+ // which gets turned into "^my header^foo\n<page name>"
+ // which we turn into "M^my header^FOO\n<PAGE NAME>"
+ function getSortKey( $string ) {
+ global $wgContLang;
+ // UppercaseCollation uses an EN lang object always instead of
content lang.
+ // I'm not sure why. To me it makes more sense to use
$wgContLang.
+ // There's minnor differences in some languages (like Turkish)
+
+ $matches = array();
+ if ( preg_match( '/^\^([^\n^]*)\^(.*)$/Ds', $string, $matches )
) {
+ if ( $matches[1] === '' ) $matches[1] = ' ';
+ $part1 = $wgContLang->firstChar( $wgContLang->uc(
$matches[1] ) );
+ $part2 = $matches[1];
+ $part3 = $wgContLang->uc( $matches[2] );
+
+ } else {
+ // Ordinay sortkey, no header info.
+ $part3 = $wgContLang->uc( $string );
+ $part1 = $part2 = $wgContLang->firstChar( $part3 );
+ }
+
+ return $part1 . '^' . $part2 . '^' . $part3;
+ }
+
+ function getFirstLetter( $string ) {
+ global $wgContLang;
+
+ # Stolen from UppercaseCollation
+ # not sure when this could actually happen.
+ if ( $string[0] === "\0" ) {
+ $string = substr( $string, 1 );
+ }
+
+ $m = array();
+ if ( preg_match( '/^[^\n^]*\^([^\n^]*)\^/', $string, $m
) ) {
+ return $m[1];
+ } else {
+ // Probably shouldn't happen.
+ return $wgContLang->ucfirst(
$wgContLang->firstChar( $string ) );
+ }
+ }
+}
Property changes on:
trunk/extensions/CategorySortHeaders/CategorySortHeaders_body.php
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs