Module documentation
This module implements all Appropedia-specific Lua features. It should be the only Lua module in Appropedia not copied from Wikipedia.
See also
- All modules - All pages in the Module namespace
-- Module:Appropedia implements all Appropedia-specific Lua features -- This module uses Appropedia's custom Lua library, see https://github.com/Appropedia/extension -- This module is used throughout the entire site, so any changes will trigger thousands of updates -- Author: Felipe Schenone (User:Sophivorus) -- License: GNU General Public License 3 or later (http://www.gnu.org/licenses/gpl-3.0.html) local Appropedia = {} -- Check whether the given page exists -- including Commons and without recording a link -- Used by [[Template:EXISTS]] function Appropedia.exists( frame ) local page = frame.args[1] if not page or mw.text.trim( page ) == '' then page = mw.title.getCurrentTitle().prefixedText end if mw.ext.appropedia.pageExists( page ) then return 1 end end -- Return the video service out of a video URL, id or file name -- Note! This method assumes that the video exists and will return 'commons' if it doesn't -- Used by [[Template:Video]] function Appropedia.videoService( frame ) local video = frame.args[1] if string.match( video, 'vimeo' ) then return 'vimeo' end if string.match( video, 'youtu' ) then return 'youtube' end if string.match( video, '^%d+$' ) then return 'vimeo' end if string.match( video, '^[%d%a_-]+$' ) then return 'youtube' end local title = mw.title.new( video, 6 ) -- Use PROTECTIONEXPIRY to prevent https://phabricator.wikimedia.org/T14019 if frame:callParserFunction( 'PROTECTIONEXPIRY', 'edit', title.fullText ) == '' then return 'commons' end return 'appropedia' end -- Return the video ID out of a video URL -- Used by [[Template:Video]] function Appropedia.videoID( frame ) local url = frame.args[1] local parts = mw.text.split( url, '&', true ) local id = parts[1] id = string.gsub( id, 'https://www%.youtube%.com/watch%?v=', '' ) id = string.gsub( id, 'https://youtu%.be/', '' ) id = string.gsub( id, 'https://vimeo%.com/', '' ) return id end -- Return the affiliation of the given user name out of the email domain -- Used by [[Template:User data]] function Appropedia.affiliation( frame ) local map = { [ 'alum.mit.edu' ] = 'Massachusetts Institute of Technology', [ 'auburn.edu' ] = 'Auburn University', [ 'berkeley.edu' ] = 'Berkeley University of California', [ 'bsu.edu' ] = 'Ball State University', [ 'carinya.nsw.edu.au' ] = 'Carinya Christian School', [ 'clarion.edu' ] = 'Pennsylvania Western University Clarion', [ 'clarkson.edu' ] = 'Clarkson University', [ 'cornell.edu' ] = 'Cornell University', [ 'csuci.edu' ] = 'California State University Channel Islands', [ 'deakin.edu.au' ] = 'Deakin University', [ 'diu.edu.bd' ] = 'Daffodil International University', [ 'edinboro.edu' ] = 'Edinboro University', [ 'eiu.edu' ] = 'Eastern Illinois University', [ 'fordham.edu' ] = 'Fordham University', [ 'gmu.edu' ] = 'George Mason University', [ 'griffith.edu.au' ] = 'Griffith University', [ 'humboldt.edu' ] = 'Cal Poly Humboldt', [ 'hust.edu.cn' ] = 'Huazhong University', [ 'indiana.edu' ] = 'Indiana University', [ 'iut-dhaka.edu' ] = 'Islamic University of Technology', [ 'jcu.edu.au' ] = 'James Cook University', [ 'mail.usf.edu' ] = 'University of South Florida', [ 'maxwell.syr.edu' ] = 'Maxwell School of Citizenship and Public Affairs', [ 'mit.edu' ] = 'Massachusetts Institute of Technology', [ 'msu.edu' ] = 'Michigan State University', [ 'mtu.edu' ] = 'Michigan Technological University', [ 'murdoch.edu.au' ] = 'Murdoch University', [ 'ncsu.edu' ] = 'North Carolina State University', [ 'ou.edu' ] = 'University of Oklahoma', [ 'pgrad.unimelb.edu.au' ] = 'University of Melbourne', [ 'principia.edu' ] = 'The Principia', [ 'psu.edu' ] = 'Pennsylvania State University', [ 'rams.colostate.edu' ] = 'Colorado State University', [ 'rci.rutgers.edu' ] = 'Rutgers University', [ 'scots.edinboro.edu' ] = 'Edinboro University', [ 'sfsu.edu' ] = 'San Francisco State University', [ 'snceagles.sierranevada.edu' ] = 'Sierra Nevada University', [ 'southalabama.edu' ] = 'University of South Alabama', [ 'sru.edu' ] = 'Slippery Rock University', [ 'students.olin.edu' ] = 'Olin College of Engineering', [ 'tuskegee.edu' ] = 'Tuskegee University', [ 'u.boisestate.edu' ] = 'Boise State University', [ 'udayton.edu' ] = 'University of Dayton', [ 'umich.edu' ] = 'University of Michigan', [ 'unab.edu.co' ] = 'Universidad Autónoma de Bucaramanga', [ 'unlv.nevada.edu' ] = 'University of Nevada', [ 'uoregon.edu' ] = 'University of Oregon', [ 'virginia.edu' ] = 'University of Virginia', [ 'vols.utk.edu' ] = 'University of Tennessee', [ 'usf.edu' ] = 'University of South Florida', } local user = frame.args[1] or mw.title.getCurrentTitle().text if not user or mw.text.trim( user ) == '' then error( 'missing user name' ) end local domain = mw.ext.appropedia.emailDomain( user ) domain = string.lower( mw.text.trim( domain ) ) return map[ domain ] end -- Return the categories of the given or current page as a comma-separated list -- Used by [[Template:Automatic translation notice]] function Appropedia.categories( frame ) local page = frame.args[1] or mw.title.getCurrentTitle().prefixedText if not page or mw.text.trim( page ) == '' then error( 'missing page name' ) end local categories = mw.ext.appropedia.pageCategories( page ) return table.concat( categories, ', ' ) end return Appropedia