r30812 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30811‎ | r30812 | r30813 >
Date:23:06, 10 February 2008
Author:grondin
Status:old
Tags:
Comment:
Major release of Import User extension
* Add internationalization extension description message in [[Special:Version]]
* Create internationalization file
* Add more message
Adding Import User to Translate tool extension
Modified paths:
  • /trunk/extensions/ImportUsers/SpecialImportUsers.i18n.php (added) (history)
  • /trunk/extensions/ImportUsers/SpecialImportUsers.php (modified) (history)
  • /trunk/extensions/ImportUsers/SpecialImportUsers_body.php (added) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ImportUsers/SpecialImportUsers_body.php
@@ -0,0 +1,87 @@
 2+<?php
 3+if( !defined( 'MEDIAWIKI' ) ) {
 4+ echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
 5+ exit( 1 );
 6+}
 7+
 8+class SpecialImportUsers extends SpecialPage {
 9+
 10+ function SpecialImportUsers() {
 11+ SpecialPage::SpecialPage('ImportUsers' , 'import_users' );
 12+ wfLoadExtensionMessages('ImportUsers');
 13+ }
 14+
 15+ function execute( $par ) {
 16+ global $wgOut, $wgUser;
 17+ $wgOut->setArticleRelated( false );
 18+ if( !$wgUser->isAllowed( 'import_users' ) ) {
 19+ $wgOut->permissionRequired( 'import_users' );
 20+ return;
 21+ }
 22+ $wgOut->setPagetitle( wfMsg( 'importusers' ) );
 23+ if (IsSet($_FILES['users_file'])) {
 24+ $wgOut->addHTML( $this->AnalizeUsers($_FILES['users_file'],IsSet($_POST['replace_present'])) );
 25+ } else {
 26+ $wgOut->addHTML( $this->MakeForm() );
 27+ }
 28+ }
 29+
 30+ function MakeForm() {
 31+ $titleObj = Title::makeTitle( NS_SPECIAL, 'ImportUsers' );
 32+ $action = $titleObj->escapeLocalURL();
 33+ $output ='<form enctype="multipart/form-data" method="post" action="'.$action.'">';
 34+ $output.='<dl><dt>'. wfMsg('importusers-form-file') .'</dt><dd>'. wfMsg('importusers-login-name'). ', '. wfMsg('importusers-password') . ', ' . wfMsg('importusers-email') . ', ' . wfMsg('importusers-realname') . '.</dd></dl>';
 35+ $output.='<fieldset><legend>' . wfMsg('importusers-uploadfile') . '</legend>';
 36+ $output.='<table border=0 a-valign=center width=100%>';
 37+ $output.='<tr><td align=right width=160>'.wfMsg( 'importusers-form-caption' ).': </td><td><input name="users_file" type="file" size=40 /></td></tr>';
 38+ $output.='<tr><td align=right></td><td><input name="replace_present" type="checkbox" />'.wfMsg( 'importusers-form-replace-present' ).'</td></tr>';
 39+ $output.='<tr><td align=right></td><td><input type="submit" value="'.wfMsg( 'importusers-form-button' ).'" /></td></tr>';
 40+ $output.='</table>';
 41+ $output.='</fieldset>';
 42+ $output.='</form>';
 43+ return $output;
 44+ }
 45+
 46+ function AnalizeUsers($fileinfo,$replace_present) {
 47+ global $IP, $wgOut;
 48+ require_once "$IP/includes/User.php";
 49+ $summary=array('all'=>0,'added'=>0,'updated'=>0);
 50+ $filedata=explode("\n",rtrim(file_get_contents($fileinfo['tmp_name'])));
 51+ $output='<h2>'.wfMsg( 'importusers-log' ).'</h2>';
 52+ foreach ($filedata as $line=>$newuserstr) {
 53+ $newuserarray=explode(',', trim( $newuserstr ) );
 54+ if (count($newuserarray)<2) {
 55+ $output.=sprintf(wfMsg( 'importusers-user-invalid-format' ) ,$line+1 ).'<br />';
 56+ continue;
 57+ }
 58+ if (!IsSet($newuserarray[2])) $newuserarray[2]='';
 59+ if (!IsSet($newuserarray[3])) $newuserarray[3]='';
 60+ $NextUser=User::newFromName( $newuserarray[0] );
 61+ $NextUser->setEmail( $newuserarray[2] );
 62+ $NextUser->setRealName( $newuserarray[3] );
 63+ $uid=$NextUser->idForName();
 64+ if ($uid===0) {
 65+ $NextUser->addToDatabase();
 66+ $NextUser->setPassword( $newuserarray[1] );
 67+ $NextUser->saveSettings();
 68+ $output.=sprintf(wfMsg( 'importusers-user-added' ) ,$newuserarray[0] ).'<br />';
 69+ $summary['added']++;
 70+ }
 71+ else {
 72+ if ($replace_present) {
 73+ $NextUser->setPassword( $newuserarray[1] );
 74+ $NextUser->saveSettings();
 75+ $output.=sprintf( wfMsg( 'importusers-user-present-update' ) ,$newuserarray[0] ).'<br />';
 76+ $summary['updated']++;
 77+ }
 78+ else $output.=sprintf(wfMsg( 'importusers-user-present-no-update' ) ,$newuserarray[0] ).'<br />';
 79+ }
 80+ $summary['all']++;
 81+ }
 82+ $output.='<b>'.wfMsg( 'importusers-log-summary' ).'</b><br />';
 83+ $output.=wfMsg( 'importusers-log-summary-all' ).' : '.$summary['all'].'<br />';
 84+ $output.=wfMsg( 'importusers-log-summary-added' ).' : '.$summary['added'].'<br />';
 85+ $output.=wfMsg( 'importusers-log-summary-updated' ).' : '.$summary['updated'];
 86+ return $output;
 87+ }
 88+ }
Property changes on: trunk/extensions/ImportUsers/SpecialImportUsers_body.php
___________________________________________________________________
Added: svn:eol-style
189 + native
Index: trunk/extensions/ImportUsers/SpecialImportUsers.i18n.php
@@ -0,0 +1,54 @@
 2+<?php
 3+/**Internationalization messages file for
 4+ *Import User extension
 5+ *
 6+ * @addtogroup Extensions
 7+*/
 8+
 9+$messages = array();
 10+
 11+$messages['en'] = array(
 12+ 'importusers' => 'Import Users' ,
 13+ 'importusers-desc' => 'Imports users in bulk from CSV-file; encoding: UTF-8',
 14+ 'importusers-uploadfile' => 'Upload file',
 15+ 'importusers-form-caption' => 'Input CSV-file (UTF-8)' ,
 16+ 'importusers-form-file' => 'User file format (csv): ',
 17+ 'importusers-form-replace-present' => 'Replace existing users' ,
 18+ 'importusers-form-button' => 'Import' ,
 19+ 'importusers-user-added' => 'User <b>%s</b> has been added.' ,
 20+ 'importusers-user-present-update' => 'User <b>%s</b> already exists. Updated.' ,
 21+ 'importusers-user-present-not-update' => 'User <b>%s</b> already exists. Did not update.' ,
 22+ 'importusers-user-invalid-format' => 'User data in the line #%s has invalid format or is blank. Skipped.' ,
 23+ 'importusers-log' => 'Import log' ,
 24+ 'importusers-log-summary' => 'Summary' ,
 25+ 'importusers-log-summary-all' => 'All' ,
 26+ 'importusers-log-summary-added' => 'Added' ,
 27+ 'importusers-log-summary-updated' => 'Updated',
 28+ 'importusers-login-name' => 'Login name',
 29+ 'importusers-password' => 'password',
 30+ 'importusers-email' => 'email',
 31+ 'importusers-realname' => 'real name',
 32+);
 33+
 34+$messages['fr'] = array(
 35+ 'importusers' => 'Importer des utilisateurs' ,
 36+ 'importusers-desc' => 'Importe des utilisateurs en bloc depuis un fichier CVS ; encodage : UTF-8.',
 37+ 'importusers-uploadfile' => 'Importer le fichier',
 38+ 'importusers-form-caption' => 'Entrez un fichier CVS (UTF-8)' ,
 39+ 'importusers-form-file' => 'Format du fichier utilisateur (csv) : ',
 40+ 'importusers-form-replace-present' => 'Remplace les utilisateurs existants' ,
 41+ 'importusers-form-button' => 'Importer' ,
 42+ 'importusers-user-added' => 'L’utilisateur <b>%s</b> a été ajouté.' ,
 43+ 'importusers-user-present-update' => 'l’utilisateur <b>%s</b> existe déjà. Mise à jour effectuée.' ,
 44+ 'importusers-user-present-not-update' => 'L’utilisateur <b>%s</b> existe déjà. Non mis à jour.' ,
 45+ 'importusers-user-invalid-format' => 'Les données utilisateur dans la ligne #%s sont dans un mauvais format ou bien sont inexistantes. Aucune action.' ,
 46+ 'importusers-log' => 'Journal des imports' ,
 47+ 'importusers-log-summary' => 'Sommaire' ,
 48+ 'importusers-log-summary-all' => 'Total' ,
 49+ 'importusers-log-summary-added' => 'Ajouté' ,
 50+ 'importusers-log-summary-updated' => 'Mise à jour',
 51+ 'importusers-login-name' => 'Nom du pseudo',
 52+ 'importusers-password' => 'mot de passe',
 53+ 'importusers-email' => 'adresse courriel',
 54+ 'importusers-realname' => 'nom réel',
 55+);
Property changes on: trunk/extensions/ImportUsers/SpecialImportUsers.i18n.php
___________________________________________________________________
Added: svn:eol-style
156 + native
Index: trunk/extensions/ImportUsers/SpecialImportUsers.php
@@ -12,117 +12,21 @@
1313 if (!defined('MEDIAWIKI')) die();
1414 require_once "$IP/includes/SpecialPage.php";
1515
16 -$wgExtensionFunctions[] = 'wfSpecialImportUsers';
 16+if ( !function_exists( 'extAddSpecialPage' ) ) {
 17+ require( dirname(__FILE__) . '/../ExtensionFunctions.php' );
 18+}
 19+
1720 $wgExtensionCredits['specialpage'][] = array(
18 - 'name' => 'Import Users',
19 - 'author' => 'Yuriy Ilkiv, Rouslan Zenetl',
20 - 'url' => 'http://www.mediawiki.org/wiki/Extension:ImportUsers',
21 - 'description' => 'Imports users in bulk from CSV-file; encoding: UTF-8',
 21+ 'name' => 'Import Users',
 22+ 'author' => 'Yuriy Ilkiv, Rouslan Zenetl',
 23+ 'version' => '2008-02-10',
 24+ 'url' => 'http://www.mediawiki.org/wiki/Extension:ImportUsers',
 25+ 'description' => 'Imports users in bulk from CSV-file; encoding: UTF-8',
 26+ 'descriptionmsg' => 'importusers-desc',
2227 );
2328
2429 $wgAvailableRights[] = 'import_users';
2530 $wgGroupPermissions['bureaucrat']['import_users'] = true;
26 -
27 -function wfSpecialImportUsers() {
28 - global $IP, $wgMessageCache;
29 -
30 - $wgMessageCache->addMessages(
31 - array(
32 - 'importusers' => 'Import Users' ,
33 - 'importusers_form_caption' => 'Input CSV-file (UTF-8)' ,
34 - 'importusers_form_replace_present' => 'Replace existing users' ,
35 - 'importusers_form_button' => 'Import' ,
36 - 'importusers_user_added' => 'User <b>%s</b> has been added.' ,
37 - 'importusers_user_present_update' => 'User <b>%s</b> already exists. Updated.' ,
38 - 'importusers_user_present_not_update' => 'User <b>%s</b> already exists. Did not update.' ,
39 - 'importusers_user_invalid_format' => 'User data in the line #%s has invalid format or is blank. Skipped.' ,
40 - 'importusers_log' => 'Import log' ,
41 - 'importusers_log_summary' => 'Summary' ,
42 - 'importusers_log_summary_all' => 'All' ,
43 - 'importusers_log_summary_added' => 'Added' ,
44 - 'importusers_log_summary_updated' => 'Updated' ));
45 -
46 - class SpecialImportUsers extends SpecialPage {
47 -
48 - function SpecialImportUsers() {
49 - SpecialPage::SpecialPage('ImportUsers' , 'import_users' );
50 - }
51 -
52 - function execute( $par ) {
53 - global $wgOut, $wgUser;
54 - $wgOut->setArticleRelated( false );
55 - if( !$wgUser->isAllowed( 'import_users' ) ) {
56 - $wgOut->permissionRequired( 'import_users' );
57 - return;
58 - }
59 - $wgOut->setPagetitle( wfMsg( 'importusers' ) );
60 - if (IsSet($_FILES['users_file'])) {
61 - $wgOut->addHTML( $this->AnalizeUsers($_FILES['users_file'],IsSet($_POST['replace_present'])) );
62 - } else {
63 - $wgOut->addHTML( $this->MakeForm() );
64 - }
65 - }
66 -
67 - function MakeForm() {
68 - $titleObj = Title::makeTitle( NS_SPECIAL, 'ImportUsers' );
69 - $action = $titleObj->escapeLocalURL();
70 - $output ='<form enctype="multipart/form-data" method="post" action="'.$action.'">';
71 - $output.='<dl><dt>User file format (csv): </dt><dd>&amp;lt;login-name&amp;gt;,&amp;lt;password&amp;gt;,&amp;lt;email&amp;gt;,&amp;lt;real-name&amp;gt;</dd></dl>';
72 - $output.='<fieldset><legend>Upload file</legend>';
73 - $output.='<table border=0 a-valign=center width=100%>';
74 - $output.='<tr><td align=right width=160>'.wfMsg( 'importusers_form_caption' ).': </td><td><input name="users_file" type="file" size=40 /></td></tr>';
75 - $output.='<tr><td align=right></td><td><input name="replace_present" type="checkbox" />'.wfMsg( 'importusers_form_replace_present' ).'</td></tr>';
76 - $output.='<tr><td align=right></td><td><input type="submit" value="'.wfMsg( 'importusers_form_button' ).'" /></td></tr>';
77 - $output.='</table>';
78 - $output.='</fieldset>';
79 - $output.='</form>';
80 - return $output;
81 - }
82 -
83 - function AnalizeUsers($fileinfo,$replace_present) {
84 - global $IP, $wgOut;
85 - require_once "$IP/includes/User.php";
86 - $summary=array('all'=>0,'added'=>0,'updated'=>0);
87 - $filedata=explode("\n",rtrim(file_get_contents($fileinfo['tmp_name'])));
88 - $output='<h2>'.wfMsg( 'importusers_log' ).'</h2>';
89 - foreach ($filedata as $line=>$newuserstr) {
90 - $newuserarray=explode(',', trim( $newuserstr ) );
91 - if (count($newuserarray)<2) {
92 - $output.=sprintf(wfMsg( 'importusers_user_invalid_format' ) ,$line+1 ).'<br />';
93 - continue;
94 - }
95 - if (!IsSet($newuserarray[2])) $newuserarray[2]='';
96 - if (!IsSet($newuserarray[3])) $newuserarray[3]='';
97 - $NextUser=User::newFromName( $newuserarray[0] );
98 - $NextUser->setEmail( $newuserarray[2] );
99 - $NextUser->setRealName( $newuserarray[3] );
100 - $uid=$NextUser->idForName();
101 - if ($uid===0) {
102 - $NextUser->addToDatabase();
103 - $NextUser->setPassword( $newuserarray[1] );
104 - $NextUser->saveSettings();
105 - $output.=sprintf(wfMsg( 'importusers_user_added' ) ,$newuserarray[0] ).'<br />';
106 - $summary['added']++;
107 - }
108 - else {
109 - if ($replace_present) {
110 - $NextUser->setPassword( $newuserarray[1] );
111 - $NextUser->saveSettings();
112 - $output.=sprintf( wfMsg( 'importusers_user_present_update' ) ,$newuserarray[0] ).'<br />';
113 - $summary['updated']++;
114 - }
115 - else $output.=sprintf(wfMsg( 'importusers_user_present_not_update' ) ,$newuserarray[0] ).'<br />';
116 - }
117 - $summary['all']++;
118 - }
119 - $output.='<b>'.wfMsg( 'importusers_log_summary' ).'</b><br />';
120 - $output.=wfMsg( 'importusers_log_summary_all' ).': '.$summary['all'].'<br />';
121 - $output.=wfMsg( 'importusers_log_summary_added' ).': '.$summary['added'].'<br />';
122 - $output.=wfMsg( 'importusers_log_summary_updated' ).': '.$summary['updated'];
123 - return $output;
124 - }
125 -
126 - }
127 -
128 - SpecialPage::addPage (new SpecialImportUsers());
129 -}
 31+$dir = dirname(__FILE__) . '/';
 32+extAddSpecialPage( $dir . 'SpecialImportUsers_body.php', 'ImportUsers', 'SpecialImportUsers' );
 33+$wgExtensionMessagesFiles['ImportUsers'] = $dir . 'SpecialImportUsers.i18n.php';
Index: trunk/extensions/Translate/Translate.php
@@ -142,6 +142,7 @@
143143 'ext-icon' => 'IconMessageGroup',
144144 'ext-imagemap' => 'ImageMapMessageGroup',
145145 'ext-importfreeimages' => 'ImportFreeImagesMessageGroup',
 146+'ext-importusers' => 'ImportUsersMessageGroup',
146147 'ext-inputbox' => 'InputBoxMessageGroup',
147148 'ext-inspectcache' => 'InspectCacheMessageGroup',
148149 'ext-intersection' => 'IntersectionMessageGroup',
Index: trunk/extensions/Translate/MessageGroups.php
@@ -1219,6 +1219,14 @@
12201220 protected $messageFile = 'ImportFreeImages/ImportFreeImages.i18n.php';
12211221 }
12221222
 1223+class ImportUsersMessageGroup extends ExtensionMessageGroup {
 1224+ protected $label = 'Import Users';
 1225+ protected $id = 'ext-importusers';
 1226+
 1227+ protected $arrName = 'messages';
 1228+ protected $messageFile = 'ImportUsers/SpecialImportUsers.i18n.php';
 1229+}
 1230+
12231231 class InputBoxMessageGroup extends ExtensionMessageGroup {
12241232 protected $label = 'Input Box';
12251233 protected $id = 'ext-inputbox';

Status & tagging log