Extension talk:CustomUserCreateForm/de

From mediawiki.org
MediaWiki extensions

Anmerkung[edit]

Die beiden Klassen Usercreate und Userlogin wurden in 2 Dateien aufgeteilt und heißen jetzt: Usercreate.php und Userlogin.php

Wie ein benutzerdefiniertes Feld hinzu gefügt wird[edit]

Zunächst wurde dies durch Mediawiki 1.17.0 und CustomUserCreateForm möglich gemacht.
Lasse uns starten.

Vorbereitung[edit]

Alle Arbeiten nach Extension:CustomUserCreateForm wurden durchgeführt.

Felder zum Anmeldeformular hinzufügen[edit]

Datei: extensions/customUserCreateForm/templates/customUsercreate.php
Process:

  • Füge folgende Zeilen irgendwo in der Mitte der Execute Methode der customUsercreateTemplate Klasse ein.
$this->addInputItem('fieldname', 'default value', 'input type', 'Left column message');

Beispiel:

	function execute() {

		$this->addInputItem ('user_street', '', 'text', 'Strasse:');
		$this->addInputItem ('user_city', '', 'text', 'Wohnort:');
        
		if( $this->data['message'] ) {


Die durch die neuen Felder erzeugt Daten, in die Datenbank speichern[edit]

Datei: extensions/customUserCreateForm/customUserCreateForm.php
Prozess:

  • Ein neuen AddNewAccount Anker am Anfang der Datei einfügen:
  • Eine neue Funktion einfügen mit dem Namen von der AddNewAccount Anker Registrierung. Alle Daten der zusätzlichen Felder werden über der globalen Variable wgRequest eingelesen.
  • Aktuelle User ID mit $user->getID() einlesen.
  • Mit der Funktion wfGetDB (DB_MASTER) wird ein Objekt $dbw für die Datenbank geholt.
  • $dbw->insert( 'user_properties' speichert die Daten in die Tabelle user_properties.
  • Die Tabelle besteht aus den Feldern up_user, up_property, up_value und werden mit einem Array übergeben.

Beispiel:

$wgHooks['AddNewAccount'][] = 'customUserSaveToDB';

function customUserSaveToDB( $user, $byuser)
{
	global $wgRequest;
        $user_id = $user->getID();
	$dbw = wfGetDB( DB_MASTER );
        $dbw->insert( 'user_properties', array(
                'up_user'     => $user_id,
                'up_property' => 'user_street',
                'up_value'    =>  $wgRequest->getText( 'user_street')
        ));
        $dbw->insert( 'user_properties', array(
                'up_user'     => $user_id,
                'up_property' => 'user_city',
                'up_value'    =>  $wgRequest->getText( 'user_city')
        ));
 	return true;
}


Add new data to Special:Preferences page[edit]

File: templates/customUserCreateForm.php
Process: q

  • Add a new GetPreferences hook at the top of the file:
  • Create a new function that will handle the custom user preferences section with the same name as stated on the GetPreferences hook registration.
  • Call the data in the user_properties table by using the preferences variable

Example:

$wgHooks['GetPreferences'][] = 'customUserPreferences';

function customUserPreferences ($user, &$preferences)
{
    $preferences['city'] = array(
    	'type' => 'text',
        'label-message' => 'customUserCity', // a system message
        'section' => 'personal/info',
	);

	// Required return value of a hook function.
    return true;
}


Create the custom system messages for the new fields[edit]

  • For each new property in the preferences, visit the MediaWiki:systemMessageForTheProperty article of your wiki and edit it by adding the name of the field you wish to appear next to the preferences box field.

Get data from the database[edit]

The SQL query for getting the data from the database should go as following:

SELECT user_name, user_email, up_user, up_property, CONVERT(up_value USING utf8) AS yourFieldName FROM user_properties
JOIN user ON user.user_id=user_properties.up_user
WHERE up_property IN ('field1','field2',...) AND (up_value IS NOT NULL AND (TRIM(up_value) != ''))
ORDER BY user_name DESC

That should be all! Enjoy your new customized registration tool
--Fladei (talk) 20:01, 15 April 2012 (UTC)Reply

If you wish to inject text into the UI this DOES NOT WORK. FIX IS INCLUDED[edit]

The function prototype needs to be:

function customUserCreateForm(&$template) {

NOT

 
function customUserCreateForm($template) {

$template needs to be passed by reference because the execute() function that renders the content is call after the hooks are exected.


-Michael Lapinski -mtl[attt]mit[dot]edu

Extension NOT clear[edit]

Can you please provide more about how does this extension work and how to create new columns in database if i want to add birth date and country ' ANY ADVICE PLEASE

Is this extension still supported[edit]

Is this extension still supported please let us know


Übersetzt: Gieselkalk (talk) 23:16, 18 July 2012 (UTC)Reply