| Modul Lua ini digunakan pada sekitar 184.000 halaman. Untuk mencegah suntingan mengganggu skala besar dan beban peladen, setiap perubahan harus diuji di subhalaman /bak pasir atau /kasus uji Modul:Italic title, atau bak pasir modul Anda. Perubahan yang telah diuji kemudian dapat ditambahkan ke halaman ini dalam satu suntingan. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya. |
| Modul ini dilindungi. Modul ini sangat mencolok yang digunakan oleh banyak halaman, atau sangat sering disubstitusikan. Karena vandalisme atau kesalahan akan mempengaruhi banyak halaman, dan suntingan kecil dapat memberi beban besar pada server, modul ini dilindungi dari penyuntingan. |
Dokumentasi di atas ditransklusikan dari Modul:Italic title/doc. (sunting | riwayat)
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
-- This module implements {{italic title}}. require('strict') locallibraryUtil=require('libraryUtil') localcheckType=libraryUtil.checkType localcheckTypeForNamedArg=libraryUtil.checkTypeForNamedArg localyesno=require('Modul:Yesno') -------------------------------------------------------------------------------- -- ItalicTitle class -------------------------------------------------------------------------------- localItalicTitle={} do ---------------------------------------------------------------------------- -- Class attributes and functions -- Things that belong to the class are here. Things that belong to each -- object are in the constructor. ---------------------------------------------------------------------------- -- Keys of title parts that can be italicized. localitalicizableKeys={ namespace=true, title=true, dab=true, } ---------------------------------------------------------------------------- -- ItalicTitle constructor -- This contains all the dynamic attributes and methods. ---------------------------------------------------------------------------- functionItalicTitle.new() localobj={} -- Function for checking self variable in methods. localcheckSelf=libraryUtil.makeCheckSelfFunction( 'ItalicTitle', 'obj', obj, 'ItalicTitle object' ) -- Checks a key is present in a lookup table. -- Param: name - the function name. -- Param: argId - integer position of the key in the argument list. -- Param: key - the key. -- Param: lookupTable - the table to look the key up in. localfunctioncheckKey(name,argId,key,lookupTable) ifnotlookupTable[key]then error(string.format( "bad argument #%d to '%s' ('%s' bukan kunci yang valid)", argId, name, key ),3) end end -- Set up object structure. localparsed=false localcategories={} localitalicizedKeys={} localitalicizedSubstrings={} -- Parses a title object into its namespace text, title, and -- disambiguation text. -- Param: options - a table of options with the following keys: -- title - the title object to parse -- ignoreDab - ignore any disambiguation parentheses -- Returns the current object. functionobj:parseTitle(options) checkSelf(self,'parseTitle') checkType('parseTitle',1,options,'table') checkTypeForNamedArg('parseTitle','title',options.title,'table') localtitle=options.title -- Title and dab text localprefix,parentheses ifnotoptions.ignoreDabthen prefix,parentheses=mw.ustring.match( title.text, '^(.+) %(([^%(%)]+)%)$' ) end ifprefixandparenthesesthen self.title=prefix self.dab=parentheses else self.title=title.text end -- Namespace localnamespace=mw.site.namespaces[title.namespace].name ifnamespaceand#namespace>=1then self.namespace=namespace end -- Register the object as having parsed a title. parsed=true returnself end -- Italicizes part of the title. -- Param: key - the key of the title part to be italicized. Possible -- keys are contained in the italicizableKeys table. -- Returns the current object. functionobj:italicize(key) checkSelf(self,'italicize') checkType('italicize',1,key,'string') checkKey('italicize',1,key,italicizableKeys) italicizedKeys[key]=true returnself end -- Un-italicizes part of the title. -- Param: key - the key of the title part to be un-italicized. Possible -- keys are contained in the italicizableKeys table. -- Returns the current object. functionobj:unitalicize(key) checkSelf(self,'unitalicize') checkType('unitalicize',1,key,'string') checkKey('unitalicize',1,key,italicizableKeys) italicizedKeys[key]=nil returnself end -- Italicizes a substring in the title. This only affects the main part -- of the title, not the namespace or the disambiguation text. -- Param: s - the substring to be italicized. -- Returns the current object. functionobj:italicizeSubstring(s) checkSelf(self,'italicizeSubstring') checkType('italicizeSubstring',1,s,'string') italicizedSubstrings[s]=true returnself end -- Un-italicizes a substring in the title. This only affects the main -- part of the title, not the namespace or the disambiguation text. -- Param: s - the substring to be un-italicized. -- Returns the current object. functionobj:unitalicizeSubstring(s) checkSelf(self,'unitalicizeSubstring') checkType('unitalicizeSubstring',1,s,'string') italicizedSubstrings[s]=nil returnself end -- Renders the object into a page name. If no title has yet been parsed, -- the current title is used. -- Returns string functionobj:renderTitle() checkSelf(self,'renderTitle') -- Italicizes a string -- Param: s - the string to italicize -- Returns string. localfunctionitalicize(s) assert(type(s)=='string','bukan sebuah string kosong') assert(s~='','merupakan string yang kosong') returnstring.format('<i>%s</i>',s) end -- Escape characters in a string that are magic in Lua patterns. -- Param: pattern - the pattern to escape -- Returns string. localfunctionescapeMagicCharacters(s) assert(type(s)=='string','bukan sebuah string') returns:gsub('%p','%%%0') end -- If a title hasn't been parsed yet, parse the current title. ifnotparsedthen self:parseTitle{title=mw.title.getCurrentTitle()} end -- Italicize the different parts of the title and store them in a -- titleParts table to be joined together later. localtitleParts={} -- Italicize the italicizable keys. forkeyinpairs(italicizableKeys)do ifself[key]then ifitalicizedKeys[key]then titleParts[key]=italicize(self[key]) else titleParts[key]=self[key] end end end -- Italicize substrings. If there are any substrings to be -- italicized then start from the raw title, as this overrides any -- italicization of the main part of the title. ifnext(italicizedSubstrings)then titleParts.title=self.title forsinpairs(italicizedSubstrings)do localpattern=escapeMagicCharacters(s) localitalicizedTitle,nReplacements=titleParts.title:gsub( pattern, italicize ) titleParts.title=italicizedTitle -- If we didn't make any replacements then it means that we -- have been passed a bad substring or that the page has -- been moved to a bad title, so add a tracking category. ifnReplacements<1then categories['Halaman yang menggunakan judul miring dengan string yang tidak sesuai']=true end end end -- Assemble the title together from the parts. localret='' iftitleParts.namespacethen ret=ret..titleParts.namespace..':' end ret=ret..titleParts.title iftitleParts.dabthen ret=ret..' ('..titleParts.dab..')' end returnret end -- Returns an expanded DISPLAYTITLE parser function called with the -- result of obj:renderTitle, plus any other optional arguments. -- Returns string functionobj:renderDisplayTitle(...) checkSelf(self,'renderDisplayTitle') returnmw.getCurrentFrame():callParserFunction( 'DISPLAYTITLE', self:renderTitle(), ... ) end -- Returns an expanded DISPLAYTITLE parser function called with the -- result of obj:renderTitle, plus any other optional arguments, plus -- any tracking categories. -- Returns string functionobj:render(...) checkSelf(self,'render') localret=self:renderDisplayTitle(...) forcatinpairs(categories)do ret=ret..string.format( '[[Kategori:%s]]', cat ) end returnret end returnobj end end -------------------------------------------------------------------------------- -- Exports -------------------------------------------------------------------------------- localp={} localfunctiongetArgs(frame,wrapper) assert(type(wrapper)=='string','wrapper bukan sebuah string') returnrequire('Modul:Arguments').getArgs(frame,{ wrappers=wrapper }) end -- Main function for {{italic title}} functionp._main(args) checkType('_main',1,args,'table') localitalicTitle=ItalicTitle.new() italicTitle:parseTitle{ title=mw.title.getCurrentTitle(), ignoreDab=yesno(args.all,false) } ifargs.stringthen italicTitle:italicizeSubstring(args.string) else italicTitle:italicize('title') end returnitalicTitle:render(args[1]) end functionp.main(frame) returnp._main(getArgs(frame,'Templat:Italic title')) end functionp._dabonly(args) returnItalicTitle.new() :italicize('dab') :render(args[1]) end functionp.dabonly(frame) returnp._dabonly(getArgs(frame,'Templat:Italic dab')) end returnp