มอดูล:Labelled list hatnote/doc

จากวิกิพีเดีย สารานุกรมเสรี

มอดูลนี้มีฟังก์ชันจำนวนหนึ่งที่ช่วยสร้างแฮตโน้ตให้อยู่ในรูปแบบที่มีป้ายกำกับวางอยู่ตรงตำแหน่งด้านหน้าของรายการของหน้า ในลักษณะนี้

การใช้งาน[แก้]

labelledList[แก้]

การเรียกใช้ (invoke) ฟังก์ชัน labelledList() ก็เพียงพอต่อใช้งานแม่แบบส่วนใหญ่ได้ ดังนี้

{{#invoke:Labelled list hatnote|labelledList|ป้ายที่ใช้ได้ทั่วไป}}

ตัวอย่างเช่น ถ้าระบุตรง "ป้ายที่ใช้ได้ทั่วไป" เป็น "ดูเพิ่มที่" จะให้ผลลัพธ์แบบแม่แบบ {{ดูเพิ่ม}}

หรือ

{{#invoke:Labelled list hatnote|labelledList|ป้ายกำกับเอกพจน์|ป้ายกำกับพหูพจน์}}

เนื่องด้วยสคริปต์ลูอามอดูลนี้ได้รับการคัดลอกมาจากวิกิพีเดียภาษาอังกฤษ จึงจำเป็นต้องระบุพารามิเตอร์ด้วยข้อความที่เหมือนกันสองครั้ง ตัวอย่างการนำไปใช้งาน เช่น ถ้าระบุตรง "ป้ายกำกับเอกพจน์" กับ "ป้ายกำกับพหูพจน์" เป็น "บทความหลัก" กับ "บทความหลัก" จะให้ผลลัพธ์ในลักษณะเดียวกับแม่แบบ {{หลัก}} (เฉพาะส่วนของการทำงานในเนมสเปซหลัก)

ส่วนการระบุป้ายที่ 3 และ 4 จะใช้ในกรณีที่มีหน้าเป้าหมายที่อยู่นอกเนมสเปซบทความ ดังเช่นในแม่แบบ {{หลัก}} ดังนี้

{{#invoke:Labelled list hatnote|labelledList|บทความหลัก|บทความหลัก|หน้าหลัก|หน้าหลัก}}

preprocessDisplays[แก้]

The preprocessDisplays() function takes a raw list of arguments and combines in any display arguments. For example, {{see also|1|l1=One}} initially has the arguments table {'1', ['l1'] = 'One'}; this table would combine those into the table {'1|One'}. It overrides manual piping (e.g. {{see also|1{{!}}2|l1=One}}{'1|One'}) and compresses sparse arrays if a parameter is skipped or left empty.

ตัวอย่าง:

local mLabelledList = require('Module:Labelled list hatnote')
local pages = mLabelledList.preprocessDisplays(args)

_labelledList[แก้]

For modules that need to modify the functionality slightly while still using it, _labelledList() provides some flexibility. It takes three parameters:

  1. A pages list, preferably preprocessed and compressed by preprocessDisplays
  2. A labels table, where the first item is the singular or universal label, and the second either a plural label or a copy of the first.
  3. An options table, preferably containing:
    • a template string with the full title of the template. Defaults to the title of this module.
    • a category string (or nil) as taken by makeWikitextError from Module:Hatnote, to optionally disable error categories
    • a selfref string (or nil) as taken by _hatnote to enable the selfref option

Example:

local mLabelledList = require('Module:Labelled list hatnote')
return mLabelledList._labelledList(pages, labels, options)

ข้อผิดพลาด[แก้]

หากไม่มีการระบุชื่อหน้าลงในพารามิเตอร์ในแม่แบบที่นำมอดูลนี้ไปใช้ มอดูลนี้จะส่งผลให้แม่แบบสร้างข้อความแสดงข้อผิดพลาด และโดยปกติแล้ว ข้อความแสดงข้อผิดพลาดนี้จะสร้างลิงก์เพื่อนำผู้ใช้ไปยังส่วน "ข้อผิดพลาด" ในเอกสารประกอบแม่แบบนั้น ๆ ด้วย อย่างไรก็ตาม ถ้าปัญหาอยู่ที่ตัวแม่แบบเอง กล่าวคือ ตัวแม่แบบที่นำมอดูลไปใช้โดยใช้ฟังก์ชัน _labelledList() แต่ไม่ได้กำหนดในส่วนของ template ในตารางตัวเลือก (options table) ลิงก์จะนำผู้ใช้กลับมายังที่นี่โดยตรง ข้อผิดพลาดข้างต้นสามารถแก้ไขได้โดยระบุชื่อของหน้าให้กับพารามิเตอร์ให้ถูกต้องอย่างน้อยหนึ่งรายการให้กับแม่แบบที่เป็นปัญหา ส่วนถ้าเป็นปัญหาที่เกิดจากในตัวแม่แบบ ก็สามารถแก้ไขได้โดยการกำหนดค่าบางอย่างแก่ template ของตาราง options ของฟังก์ชัน _labelledList()