Manual:Kancalar/GetPreferences

This page is a translated version of the page Manual:Hooks/GetPreferences and the translation is 96% complete.
Outdated translations are marked like this.
GetPreferences
sürüm 1.16.0 sürümünden mevcuttur
Kullanıcı tercihlerini değiştirin.
İşlevi tanımlayın:
public static function onGetPreferences( User $user, array &$preferences ) { ... }
Ek kancası extension.json sürümünde:
{
	"Hooks": {
		"GetPreferences": "MediaWiki\\Extension\\MyExtension\\Hooks::onGetPreferences"
	}
}
Çağrıdan: Dosya(lar): preferences/DefaultPreferencesFactory.php
Arayüz: GetPreferencesHook.php

Kancaların takılmasıyla ilgili daha fazla bilgi için Manual:Hooks sayfasına bakın.
Bu kancayı kullanan uzantı örnekleri için Category:GetPreferences extensions/tr sayfasına bakın.

Kullanım

Parametreler

Parametre/Seçenek Açıklama
$user Tercihleri ​​değiştirilen kullanıcı
&$preferences Bir HTMLForm nesnesine beslenecek tercihler açıklama dizisi

Örnek

In extension.json:

"Hooks": {
  "GetPreferences": [ "MediaWiki\\Extension\\ExampleExtension\\Hooks::onGetPreferences" ]
}

In includes/Hooks.php:

namespace MediaWiki\Extension\ExampleExtension;

class Hooks {
	/**
	 * @param User $user
	 * @param array $preferences
	 */
	public static function onGetPreferences( $user, &$preferences ) {
		// A checkbox
		$preferences['mypref'] = [
			'type' => 'toggle',
			'label-message' => 'tog-mypref', // a system message
			'section' => 'personal/info',
		];

		// A set of radio buttons. Notice that in the 'options' array,
		// the keys are the text (not system messages), and the values are the HTML values.
		// They keys/values might be the opposite of what you expect. PHP's array_flip()
		// can be helpful here.
		$preferences['mypref2'] = [
			'type' => 'radio',
			'label-message' => 'tog-mypref2', // a system message
			'section' => 'personal/info',
			// Array of options. Key = text to display. Value = HTML <option> value.
			'options' => [
				'Pick me please' => 'choice1',
				'No, pick me!' => 'choice2',
				'Seriously, pick me right now' => 'choice3',
			],
			'default' => 'choice1',  // A 'default' key is required!
			'help-message' => 'tog-help-mypref2', // a system message (optional)
		];
	}
}

Sekmeler ve bölümler

section dizi anahtarı, tercihlerinizi Preferences sayfasının hangi sekme ve bölümünün içerdiğini belirtir. section değeriniz foo/bar ise, bu, tercihinizin bar bölümündeki (prefs-bar sistem mesajı ile adlandırılmış) foo sekmesinde (prefs-foo sistem mesajı ile adlandırılmış) görüneceği anlamına gelir. Böyle bir sekme veya bölüm yoksa, otomatik olarak oluşturulur.

Varsayılan sekmeler listesi

Tanımlayıcı Şunu görüntüler
personal Kullanıcı bilgileri
rendering Görünüm
editing Sayfa yazma alanı
rc Son değişiklikler
watchlist İzleme listesi
misc Diğer ayarlar

Desteklenen türler

Görünür türler

type, info, multiselect, radio vb. dahil olmak üzere includes/htmlform/HTMLForm.php dosyasındaki HTMLForm::$typeMappings dizisinde bulunan çeşitli değerleri alabilir.

Tercihlerin çoğu HTMLFormField tarafından kullanılan formatta saklanır, ancak 'type' => 'usersmultiselect' olması durumunda, yeni satırla ayrılmış kullanıcı adları listesinden (form widget'ının çalıştığı şey budur) ve yeni satırla ayrılmış kullanıcı kimliklerinin listesi (veritabanında depolanan budur) bir kullanıcı adları listesinden bir dönüşüm gerçekleştirilmelidir. Bunun örnekleri için email-blacklist (çekirdek olarak) veya echo-notifications-blacklist (Echo olarak) tedavisine bakın.

Floats

For float types, you can set min and max, which will be validated on save.

API tercihleri

API tercihleri ​​'api' türünü kullanır. Special:Preferences sayfasında görüntülenmezler. They are usually set via custom front-end interfaces that call the API.

Note that you should not use 'type' => 'hidden' for API preferences (that type exists for HTML forms, not preferences).

Varsayılan tercihler

Bir tercihin varsayılan değerini (yani, henüz tercihlerini özelleştirmemiş yeni bir kullanıcı için ayarlanan değer) ayarlamak için, ayarı $wgDefaultUserOptions küresel değişkenine ekleyin. Kancada $preferences için kullandığınız anahtar adını kullanın.

Alternatif olarak, bir uzantı yazıyorsanız, extensions.json dosyasının DefaultUserOptions bölümüne ekleyebilirsiniz.