fbpx
วิกิพีเดีย

มอดูล:AutomaticTOC

คู่มือการใช้งานมอดูล[ดู] [แก้] [ประวัติ] [ล้างแคช]

การใช้งาน

พารามิเตอร์

  1. name: เป็นชื่อของตาราง ถ้าไม่ระบุจะไม่แสดงผล อาจระบุเป็น {{MediaWiki:Toc}}: ก็ได้
  2. short: หากระบุ จะทำให้ name อยู่บรรทัดเดียวกับข้อมูล แต่ถ้าไม่ระบุจะทำให้ name อยู่บนสุด และลอยอยู่ตรงกลาง
  3. delim: ไว้ใช้เป็นตัวแบ่งสำหรับพารามิเตอร์ include, exclude, pre, post ค่ามาตรฐานคือ ","
  4. sep: ไว้ใช้เป็นตัวแบ่งเวลาแสดงผล TOC ค่ามาตรฐานคือ " " (ช่องว่าง) สามารถกำหนดเป็นอย่างอื่น เช่น " · " ได้
  5. pre: เป็นรายการอะไรก็ได้ที่ต้องการให้แสดงผลก่อนลิงก์ที่สร้างขึ้นโดยอัตโนมัติ เช่น [[#top|บนสุด]]
  6. post: เป็นรายการอะไรก็ได้ที่ต้องการให้แสดงผลหลังลิงก์ที่สร้างขึ้นโดยอัตโนมัติ เช่น [[#อ้างอิง|อ้างอิง]]
  7. prebreak: เป็นตัวคั่นระหว่าง pre กับชุดข้อมูล โดยปกติจะมีค่าเป็น sep อาจระบุเป็น <br> หากต้องการให้ pre กับชุดข้อมูลอยู่คนละบรรทัดกัน
  8. postbreak: เป็นตัวคั่นระหว่าง post กับชุดข้อมูล โดยปกติจะมีค่าเป็น sep อาจระบุเป็น <br> หากต้องการให้ post กับชุดข้อมูลอยู่คนละบรรทัดกัน
  9. include: เป็นรายการหัวเรื่องที่ต้องการให้รวมเป็นกรณีพิเศษ เช่น "0-9"
  10. exclude: เป็นรายการหัวเรื่องที่ต้องการให้นำออกเป็นกรณีพิเศษ
  11. top: หากกำหนด จะมีลิงก์โยงไปยังบนสุดของหน้า โดยมีชื่อแสดงผลลิงก์ตามที่กำหนดไว้ ค่ามาตรฐานคือค่าว่าง (นั่นคือไม่แสดงผล)
  12. anchor: จับกับ anchor ที่สร้างผ่านแม่แบบ anchor ด้วย
  13. title: หากกำหนดจะดึงข้อมูลจากหน้านั้น ๆ ค่ามาตรฐานคือหน้าปัจจุบันที่กำลังเปิดอยู่
  14. prefix: หากกำหนด จะใส่ข้อความแสดงผลลิงก์จะมีข้อความนี้เติมเข้าไปข้างหน้า
  15. suffix: หากกำหนด จะใส่ข้อความแสดงผลลิงก์จะมีข้อความนี้เติมเข้าไปด้านหลัง
  16. level: รวบรวมลิงก์ที่มีความยาวน้อยกว่าหรือเท่ากับ level มาสร้างตาราง ค่ามาตรฐานคือ 1

ข้อจำกัด

  1. เมื่อมีการเปลี่ยนแปลงหัวข้อย่อย อาจจะต้องทำการล้างแคชเซิร์ฟเวอร์เสียก่อน จึงจะแสดงผลถูกต้อง

ดูเพิ่ม

z = {};  -- main function function z.main(frame)  local args = frame.args  local title = handle_param(args.title, nil)  title = title and mw.title.new(args.title) or mw.title.getCurrentTitle()  local delim = handle_param(args.delim, ",")  local sep = handle_param(args.sep, " ")  local short = handle_param(args.short, nil)  local name = handle_param(args.name, '')  name = (name == '') and '' or "'''" .. name .. "'''"  name = "|" .. (short and name or "<center>" .. name .. "</center>\n|-") .. "\n|"   local include = args.include and Set(Split(args.include, "%" .. delim)) or {}  local exclude = args.exclude and Set(Split(args.exclude, "%" .. delim)) or {}   local pre = args.pre and Split(args.pre, "%" .. delim) or {}  local prebreak = handle_param(args.prebreak, sep)   local post = args.post and Split(args.post, "%" .. delim) or {}  local postbreak = handle_param(args.postbreak, sep)   local prefix = handle_param(args.prefix, "")  local suffix = handle_param(args.suffix, "")   local anchor = handle_param(args.anchor, nil)  local wiki_text = title:getContent()  local all = {}   local level = handle_param(tonumber(args.level), 1)   eval = function(v)  v = v:match "^%s*(.-)%s*$"  if v ~= "" then  if (mw.ustring.len(v) <= level or include[v]) then table.insert(all, v) end  end  end   for line in wiki_text:gmatch("[^\n]+") do  ---  eval(string.gsub(line:match("^=+%s*(.-)%s*=+%s-$") or "", "%b{}", ""))  if anchor then  for _, v in pairs(Split(line:match("%{%{[Aa]nchor%|(.-)%}%}") or "", "%|")) do eval(v) end  end  ---  end   table.sort(all, function(a, b) return mw.ustring.codepoint(a) < mw.ustring.codepoint(b) end)   complete_list = {}  for k, v in pairs(all) do  if not exclude[v] and (k == 0 or (k > 0 and all[k - 1] ~= v)) then  table.insert(complete_list, table.concat{"[[#", v, "|", prefix, v, suffix, "]]"})  end  end   local cat_error = "[[Category:หน้าที่แม่แบบดรรชนีอัตโนมัติทำงานผิดพลาด]]"  if #complete_list == 0 then return errorPrinter({{"", "no section link found" .. cat_error}}) end  if #pre == 0 then prebreak = "" end  if #post == 0 then postbreak = "" end   out = '{| class="toccolours" style="margin: 0px auto;"\n' .. name ..  table.concat(pre, sep) .. prebreak .. table.concat(complete_list, sep) .. postbreak ..  table.concat(post, sep) .. ' __NOTOC__\n|}'   if args.db then out = '<pre>' .. out .. '</pre>' end  return frame:preprocess(out) end  -- handle parameter function handle_param(value, default)  if (value == nil or value == "¬") then  return default  else  return value  end end  -- from Module:Coordinates function errorPrinter(errors)  local result = ""  for i,v in ipairs(errors) do  local errorHTML = '<strong class="error">AutomaticTOC: ' .. v[2] .. '</strong>'  result = result .. errorHTML .. "<br />"  end  return result end  -- http://stackoverflow.com/questions/656199/search-for-an-item-in-a-lua-list function Set (list)  local set = {}  for _, l in pairs(list) do set[l] = true end  return set end  -- http://lua-users.org/wiki/SplitJoin function Split(str, delim, maxNb)  -- Eliminate bad cases...  if string.find(str, delim) == nil then  if str == "" then return {} else return {str} end  end  if maxNb == nil or maxNb < 1 then  maxNb = 0 -- No limit  end  local result = {}  local pat = "(.-)" .. delim .. "()"  local nb = 0  local lastPos  for part, pos in string.gfind(str, pat) do  nb = nb + 1  result[nb] = part  lastPos = pos  if nb == maxNb then break end  end  -- Handle the last field  if nb ~= maxNb then  nb = nb + 1  result[nb] = string.sub(str, lastPos)  end  if result[nb] == "" then table.remove(result, nb) end  return result end  return z  -- 2 May 2013:‎ Thanks to [[:en:User:Darklama]] for helping improving the code :) 

มอด, automatictoc, เป, นมอด, ลท, กป, องก, นถาวรเน, องจากม, ความเส, ยงส, งกร, ณาอภ, ปรายการเปล, ยนแปลงใด, ทางหน, าค, ณอาจส, งคำขอแก, ไข, ไปย, งผ, แลระบบเพ, อให, แก, ไขได, หากเป, นการแก, ไขท, ไม, การค, ดค, านหร, อม, ความเห, นพ, องสน, บสน, ณย, งสามารถขอให, เล, กป. niepnmxdulthithukpxngknthawrenuxngcakmikhwamesiyngsungkrunaxphipraykarepliynaeplngid thanghnakhuy khunxacsngkhakhxaekikh ipyngphuduaelrabbephuxihaekikhidhakepnkaraekikhthiimmikarkhdkhanhruxmikhwamehnphxngsnbsnun khunyngsamarthkhxihelikpxngknhnaidkhumuxkarichnganmxdul du aek prawti langaekhch enuxha 1 karichngan 2 pharamietxr 3 khxcakd 4 duephim karichngan swnnirxephimetimkhxmul khunsamarthchwyephimkhxmulswnniidpharamietxr name epnchuxkhxngtarang thaimrabucaimaesdngphl xacrabuepn MediaWiki Toc kid short hakrabu cathaih name xyubrrthdediywkbkhxmul aetthaimrabucathaih name xyubnsud aelalxyxyutrngklang delim iwichepntwaebngsahrbpharamietxr include exclude pre post khamatrthankhux sep iwichepntwaebngewlaaesdngphl TOC khamatrthankhux chxngwang samarthkahndepnxyangxun echn id pre epnraykarxairkidthitxngkarihaesdngphlkxnlingkthisrangkhunodyxtonmti echn top bnsud post epnraykarxairkidthitxngkarihaesdngphlhlnglingkthisrangkhunodyxtonmti echn xangxing xangxing prebreak epntwkhnrahwang pre kbchudkhxmul odypkticamikhaepn sep xacrabuepn lt br gt haktxngkarih pre kbchudkhxmulxyukhnlabrrthdkn postbreak epntwkhnrahwang post kbchudkhxmul odypkticamikhaepn sep xacrabuepn lt br gt haktxngkarih post kbchudkhxmulxyukhnlabrrthdkn include epnraykarhweruxngthitxngkarihrwmepnkrniphiess echn 0 9 exclude epnraykarhweruxngthitxngkarihnaxxkepnkrniphiess top hakkahnd camilingkoyngipyngbnsudkhxnghna odymichuxaesdngphllingktamthikahndiw khamatrthankhuxkhawang nnkhuximaesdngphl anchor cbkb anchor thisrangphanaemaebb anchor dwy title hakkahndcadungkhxmulcakhnann khamatrthankhuxhnapccubnthikalngepidxyu prefix hakkahnd caiskhxkhwamaesdngphllingkcamikhxkhwamnietimekhaipkhanghna suffix hakkahnd caiskhxkhwamaesdngphllingkcamikhxkhwamnietimekhaipdanhlng level rwbrwmlingkthimikhwamyawnxykwahruxethakb level masrangtarang khamatrthankhux 1khxcakd emuxmikarepliynaeplnghwkhxyxy xaccatxngthakarlangaekhchesirfewxresiykxn cungcaaesdngphlthuktxngduephim drrchnixtonmti khumuxkarichnganthipraktdanbnnidungmacak mxdul AutomaticTOC doc aek prawti phuekhiynsamarththakarthdlxngidthikrabathray aek dukhwamaetktang aelachudthdsxb srang khxngmxdulni hnayxykhxngmxdulniz main function function z main frame local args frame args local title handle param args title nil title title and mw title new args title or mw title getCurrentTitle local delim handle param args delim local sep handle param args sep local short handle param args short nil local name handle param args name name name and or name name short and name or lt center gt name lt center gt n n local include args include and Set Split args include delim or local exclude args exclude and Set Split args exclude delim or local pre args pre and Split args pre delim or local prebreak handle param args prebreak sep local post args post and Split args post delim or local postbreak handle param args postbreak sep local prefix handle param args prefix local suffix handle param args suffix local anchor handle param args anchor nil local wiki text title getContent local all local level handle param tonumber args level 1 eval function v v v match s s if v then if mw ustring len v lt level or include v then table insert all v end end end for line in wiki text gmatch n do eval string gsub line match s s s or b if anchor then for v in pairs Split line match Aa nchor or do eval v end end end table sort all function a b return mw ustring codepoint a lt mw ustring codepoint b end complete list for k v in pairs all do if not exclude v and k 0 or k gt 0 and all k 1 v then table insert complete list table concat v prefix v suffix end end local cat error Category hnathiaemaebbdrrchnixtonmtithanganphidphlad if complete list 0 then return errorPrinter no section link found cat error end if pre 0 then prebreak end if post 0 then postbreak end out class toccolours style margin 0px auto n name table concat pre sep prebreak table concat complete list sep postbreak table concat post sep NOTOC n if args db then out lt pre gt out lt pre gt end return frame preprocess out end handle parameter function handle param value default if value nil or value then return default else return value end end from Module Coordinates function errorPrinter errors local result for i v in ipairs errors do local errorHTML lt strong class error gt AutomaticTOC v 2 lt strong gt result result errorHTML lt br gt end return result end http stackoverflow com questions 656199 search for an item in a lua list function Set list local set for l in pairs list do set l true end return set end http lua users org wiki SplitJoin function Split str delim maxNb Eliminate bad cases if string find str delim nil then if str then return else return str end end if maxNb nil or maxNb lt 1 then maxNb 0 No limit end local result local pat delim local nb 0 local lastPos for part pos in string gfind str pat do nb nb 1 result nb part lastPos pos if nb maxNb then break end end Handle the last field if nb maxNb then nb nb 1 result nb string sub str lastPos end if result nb then table remove result nb end return result end return z 2 May 2013 Thanks to en User Darklama for helping improving the code ekhathungcak https th wikipedia org w index php title mxdul AutomaticTOC amp oldid 5403812, wikipedia, วิกิ หนังสือ, หนังสือ, ห้องสมุด,

บทความ

, อ่าน, ดาวน์โหลด, ฟรี, ดาวน์โหลดฟรี, mp3, วิดีโอ, mp4, 3gp, jpg, jpeg, gif, png, รูปภาพ, เพลง, เพลง, หนัง, หนังสือ, เกม, เกม