r42666 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42665‎ | r42666 | r42667 >
Date:18:32, 27 October 2008
Author:minuteelectron
Status:old (Comments)
Tags:
Comment:
* Add category auto creation to Babel extension.
Modified paths:
  • /trunk/extensions/Babel/Babel.class.php (modified) (history)
  • /trunk/extensions/Babel/Babel.i18n.php (modified) (history)
  • /trunk/extensions/Babel/Babel.php (modified) (history)
  • /trunk/extensions/Babel/BabelAutoCreate.class.php (added) (history)

Diff [purge]

Index: trunk/extensions/Babel/Babel.class.php
@@ -612,6 +612,8 @@
613613 // Add category wikitext to box tower.
614614 $r .= "[[Category:{$this->_addFixes( $code,'category' )}|$level{$wgUser->getName()}]]";
615615
 616+ BabelAutoCreate::create( $this->_addFixes( "$code",'category' ), $this->_nameCode( $code ) );
 617+
616618 }
617619
618620 // Add to level categories, only adding it to the level 0
@@ -621,6 +623,8 @@
622624 // Add category wikitext to box tower.
623625 $r .= "[[Category:{$this->_addFixes( "$code-$level",'category' )}|{$wgUser->getName()}]]";
624626
 627+ BabelAutoCreate::create( $this->_addFixes( "$code-$level",'category' ), $level, $this->_nameCode( $code ) );
 628+
625629 }
626630
627631 // Return categories.
@@ -667,7 +671,7 @@
668672 if( class_exists( 'LanguageNames' ) ) {
669673 $names = LanguageNames::getNames( $code );
670674 } else {
671 - $names = $nativeNames;
 675+ $names = Language::getLanguageNames();
672676 }
673677
674678 if( array_key_exists( strtolower( $code ), $names ) ) {
@@ -741,7 +745,7 @@
742746 if( class_exists( 'LanguageNames' ) ) {
743747 $names = LanguageNames::getNames( $code );
744748 } else {
745 - $names = $nativeNames;
 749+ $names = Language::getLanguageNames();
746750 }
747751
748752 if( array_key_exists( strtolower( $code ), $names ) ) {
Index: trunk/extensions/Babel/Babel.i18n.php
@@ -16,6 +16,11 @@
1717 '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',
1818 'babel-url' => 'Project:Babel',
1919
 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+
2025 'babel-directionality' => 'ltr', # Optional.
2126
2227 '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 @@
3838
3939 // Register required hooks.
4040 $wgHooks[ 'LanguageGetMagic' ][] = 'BabelStatic::Magic';
 41+$wgHooks[ 'AbortNewAccount' ][] = 'BabelAutoCreate::RegisterAbort';
4142
4243 // Register internationalisation file.
4344 $wgExtensionMessagesFiles[ 'Babel' ] = dirname( __FILE__ ) . '/Babel.i18n.php';
4445
4546 // 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';
4850
4951 // Configuration setttings.
5052 $wgBabelUseLevelZeroCategory = false;
5153 $wgBabelUseSimpleCategories = false;
5254 $wgBabelUseMainCategories = true;
 55+$wgBabelAutoCreateUsername = 'Babel AutoCreate';
5356 $wgLanguageCodesFiles = array();
5457 $wgLanguageCodesFiles[ 'ISO_639_1' ] = dirname( __FILE__ ) . '/codes/ISO_639_1.php';
5558 $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
136 + native

Comments

#Comment by Aaron Schulz (talk | contribs)   21:01, 31 October 2008

doEdit() has a $user param

#Comment by Aaron Schulz (talk | contribs)   16:36, 1 November 2008

Fixed in r42993

Status & tagging log