Index: trunk/extensions/Babel/Babel.class.php |
— | — | @@ -612,6 +612,8 @@ |
613 | 613 | // Add category wikitext to box tower. |
614 | 614 | $r .= "[[Category:{$this->_addFixes( $code,'category' )}|$level{$wgUser->getName()}]]"; |
615 | 615 | |
| 616 | + BabelAutoCreate::create( $this->_addFixes( "$code",'category' ), $this->_nameCode( $code ) ); |
| 617 | + |
616 | 618 | } |
617 | 619 | |
618 | 620 | // Add to level categories, only adding it to the level 0 |
— | — | @@ -621,6 +623,8 @@ |
622 | 624 | // Add category wikitext to box tower. |
623 | 625 | $r .= "[[Category:{$this->_addFixes( "$code-$level",'category' )}|{$wgUser->getName()}]]"; |
624 | 626 | |
| 627 | + BabelAutoCreate::create( $this->_addFixes( "$code-$level",'category' ), $level, $this->_nameCode( $code ) ); |
| 628 | + |
625 | 629 | } |
626 | 630 | |
627 | 631 | // Return categories. |
— | — | @@ -667,7 +671,7 @@ |
668 | 672 | if( class_exists( 'LanguageNames' ) ) { |
669 | 673 | $names = LanguageNames::getNames( $code ); |
670 | 674 | } else { |
671 | | - $names = $nativeNames; |
| 675 | + $names = Language::getLanguageNames(); |
672 | 676 | } |
673 | 677 | |
674 | 678 | if( array_key_exists( strtolower( $code ), $names ) ) { |
— | — | @@ -741,7 +745,7 @@ |
742 | 746 | if( class_exists( 'LanguageNames' ) ) { |
743 | 747 | $names = LanguageNames::getNames( $code ); |
744 | 748 | } else { |
745 | | - $names = $nativeNames; |
| 749 | + $names = Language::getLanguageNames(); |
746 | 750 | } |
747 | 751 | |
748 | 752 | if( array_key_exists( strtolower( $code ), $names ) ) { |
Index: trunk/extensions/Babel/Babel.i18n.php |
— | — | @@ -16,6 +16,11 @@ |
17 | 17 | 'babel-desc' => 'Adds the <tt>#babel</tt> parser function to allow automated generation of a babel userbox column with the ability to include custom templates', |
18 | 18 | 'babel-url' => 'Project:Babel', |
19 | 19 | |
| 20 | + 'babel-autocreate-abort' => 'The username you specified is used for Babel category auto-creation and cannot be registered.', |
| 21 | + 'babel-autocreate-reason' => 'Automatically creating Babel category page.', |
| 22 | + 'babel-autocreate-text-levels' => 'Users in this category indicate they have skill level $1 for language $2.', |
| 23 | + 'babel-autocreate-text-main' => 'Users in this category indicate they have knowlege of language $1.', |
| 24 | + |
20 | 25 | 'babel-directionality' => 'ltr', # Optional. |
21 | 26 | |
22 | 27 | 'babel-0' => 'This user has [[$1|no]] knowledge of [[$2|$3]] (or understands it with considerable difficulty).', |
Index: trunk/extensions/Babel/Babel.php |
— | — | @@ -37,18 +37,21 @@ |
38 | 38 | |
39 | 39 | // Register required hooks. |
40 | 40 | $wgHooks[ 'LanguageGetMagic' ][] = 'BabelStatic::Magic'; |
| 41 | +$wgHooks[ 'AbortNewAccount' ][] = 'BabelAutoCreate::RegisterAbort'; |
41 | 42 | |
42 | 43 | // Register internationalisation file. |
43 | 44 | $wgExtensionMessagesFiles[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.i18n.php'; |
44 | 45 | |
45 | 46 | // Register autoload classes. |
46 | | -$wgAutoloadClasses[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.class.php'; |
47 | | -$wgAutoloadClasses[ 'BabelStatic' ] = dirname( __FILE__ ) . '/BabelStatic.class.php'; |
| 47 | +$wgAutoloadClasses[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.class.php'; |
| 48 | +$wgAutoloadClasses[ 'BabelStatic' ] = dirname( __FILE__ ) . '/BabelStatic.class.php'; |
| 49 | +$wgAutoloadClasses[ 'BabelAutoCreate' ] = dirname( __FILE__ ) . '/BabelAutoCreate.class.php'; |
48 | 50 | |
49 | 51 | // Configuration setttings. |
50 | 52 | $wgBabelUseLevelZeroCategory = false; |
51 | 53 | $wgBabelUseSimpleCategories = false; |
52 | 54 | $wgBabelUseMainCategories = true; |
| 55 | +$wgBabelAutoCreateUsername = 'Babel AutoCreate'; |
53 | 56 | $wgLanguageCodesFiles = array(); |
54 | 57 | $wgLanguageCodesFiles[ 'ISO_639_1' ] = dirname( __FILE__ ) . '/codes/ISO_639_1.php'; |
55 | 58 | $wgLanguageCodesFiles[ 'ISO_639_3' ] = dirname( __FILE__ ) . '/codes/ISO_639_3.php'; |
\ No newline at end of file |
Index: trunk/extensions/Babel/BabelAutoCreate.class.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class BabelAutoCreate { |
| 5 | + static $user = false; |
| 6 | + public static function RegisterAbort( User $user, &$message ) { |
| 7 | + global $wgBabelAutoCreateUsername; |
| 8 | + wfLoadExtensionMessages( 'Babel' ); |
| 9 | + $message = wfMsg( 'babel-autocreate-abort' ); |
| 10 | + return !( $user->getName() === $wgBabelAutoCreateUsername ); |
| 11 | + } |
| 12 | + public static function create( $category, $language, $level = null ) { |
| 13 | + global $wgUser; |
| 14 | + $title = Title::newFromText( $category, NS_CATEGORY ); |
| 15 | + if( $title === null || $title->exists() ) return; |
| 16 | + $olduser = $wgUser; |
| 17 | + $wgUser = self::user(); |
| 18 | + if( $level === null ) { |
| 19 | + $text = wfMsgForContent( 'babel-autocreate-text-main', $language ); |
| 20 | + } else { |
| 21 | + $text = wfMsgForContent( 'babel-autocreate-text-levels', $language, $level ); |
| 22 | + } |
| 23 | + $article = new Article( $title ); |
| 24 | + $article->doEdit( $text, wfMsgForContent( 'babel-autocreate-reason' ), EDIT_SUPPRESS_RC ); |
| 25 | + $wgUser = $olduser; |
| 26 | + } |
| 27 | + public static function user() { |
| 28 | + global $wgBabelAutoCreateUsername; |
| 29 | + if( !self::$user ) { |
| 30 | + self::$user = User::newFromName( $wgBabelAutoCreateUsername, false ); |
| 31 | + if( !self::$user->isLoggedIn() ) self::$user->addToDatabase(); |
| 32 | + } |
| 33 | + return self::$user; |
| 34 | + } |
| 35 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Babel/BabelAutoCreate.class.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 36 | + native |