VOOZH about

URL: https://minecraft.wiki/w/Module:News

⇱ Module:News – Minecraft Wiki


Module:News

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

This module implements {{News}}, and {{News entry}}, see their respective documentation pages for usages.

[view] [edit] [history] [purge]The above documentation is transcluded from Module:News/doc.
localp={}
locali18n={
['date-format']='F j, Y',
['icon-template']='CommentSprite',
['approved-icon']='3',
['unapproved-icon']='2',
}
localdefaultSprites={
['Book']='ItemSprite book',
['Update']='ItemSprite firework-rocket',
['LEGO']='LegoSprite brick',
['Dungeons']='DungeonsMiscellaneousSprite Mission',
['Hotfix']='EntitySprite silverfish',
}
localfunctionrenderCategoryButton(category,count)
return'<div class="mcw-news-category" data-category="'..category..'">'
..category..(count~=niland(' ('..count..')')or'')
..'</div>'
end
localfunctionrenderNewsEntry(f,entry,args)
localformattedDate=mw.getContentLanguage():formatDate(i18n['date-format'],entry['date'])
localicon=''
ifargs.showStatusthen
localapprovalIcon=i18n[entry.approvedand'approved-icon'or'unapproved-icon']
icon=f:expandTemplate{title=i18n['icon-template'],args={approvalIcon}}..' '
ifnotentry.approvedandentry.page_name~=nilthen
locallink=entry.page_name
ifentry.anchor~=nilthen
link=link..'#'..entry.anchor
end
formattedDate='[['
..link
..'|'
..'<span class="explain" style="cursor: pointer;" title="This news is currently unapproved">'
..formattedDate
..'</span>'
..']]'
end
end
localcategories=''
localcategoryData=''
ifargs.showCategoriesthen
categoryData=' data-categories="'..table.concat(entry.category,',')..'"'
table.sort(entry.category)
categories='<div class="mcw-news-category-list">'
for_,categoryinipairs(entry.category)do
categories=categories..renderCategoryButton(category,nil)
end
categories=categories..'</div>'
end
localentryId=''
ifentry.anchor~=nilthen
entryId=' id="'..entry.anchor..'"'
end
localsprite=''
ifentry.sprite==nilthen
for_,categoryinipairs(entry.category)do
ifdefaultSprites[category]~=nilthen
entry.sprite=defaultSprites[category]
break
end
end
end
ifentry.sprite~=nilthen
sprite='[[File:'..entry.sprite..'.png|16x16px|link=]] '
end
localref=''
ifargs.showRefsandentry.ref~=nilthen
ref=f:preprocess('<ref>'..entry.ref..'</ref>')
end
localapproveTools=''
ifmw.title.getCurrentTitle().fullText=='News/Suggestions'then
approveTools=[['']]
..'To approve, move the code for this suggestion to [[News/Archive]].'
..[['']]
end
return'<div class="mcw-news-entry"'..entryId..categoryData..'>'
..'<div class="mcw-news-entry-date">'..icon..'<span style="opacity: 0.5">'.."''"..formattedDate.."''"..'</span></div>'
..'<div class="mcw-news-entry-text">'..sprite..entry['text']..ref..'</div>'
..categories
..approveTools
..'</div>'
end
functionp.list(f)
localargs=f.argsorf
iff==mw.getCurrentFrame()andargs[1]==nilthen
args=f:getParent().args
end
localresult=''
localshowCategoryList=args.showCategoryList~=nilandtonumber(args.showCategoryList)>0
ifshowCategoryListthen
localcategoryQuery=bucket('news').select('category').run()
localcategories={}
for_,rowinipairs(categoryQuery)do
for_,catinipairs(row.category)do
categories[cat]=(categories[cat]or0)+1
end
end
localsortedCategories={}
forcategory,countinpairs(categories)do
table.insert(sortedCategories,{name=category,count=count})
end
functioncompareCategories(a,b)
ifa.count>b.countthenreturntrue
elseifa.name<b.namethenreturntrue
elsereturnfalseend
end
table.sort(sortedCategories,compareCategories)
result=result..'<div class="mcw-news-category-list mcw-news-category-selector">'
fori,categoryinipairs(sortedCategories)do
result=result..renderCategoryButton(category.name,category.count)
end
result=result..'</div>'
end
localqueryConditions={{'date','!=',''}}
ifargs.approvedthen
table.insert(queryConditions,{'approved',tonumber(args.approved)>0})
end
localfilteredCategories={}
localcategoryArgs=mw.text.split(args.categoriesor'',',')
for_,categoryinipairs(categoryArgs)do
category=mw.text.trim(category)
ifcategory~=''then
ifcategory:sub(0,1)=='!'then
category=category:sub(2)
-- see Bucket issue #42
table.insert(filteredCategories,category)
-- table.insert(queryConditions, bucket.All{'category', '!=', category})
else
table.insert(queryConditions,{'category',category})
end
end
end
localshowFuture=args.showFuture~=nilandtonumber(args.showFuture)>0
ifnotshowFuturethen
table.insert(queryConditions,{'date','<=',os.date('%F')})
end
mw.logObject(queryConditions)
locallimit=args.limitandtonumber(args.limit)ornil
localnews=bucket('news')
.select('page_name','date','text','ref','sprite','approved','category','anchor')
.where(unpack(queryConditions))
.orderBy('date','desc')
.limit(5000)-- see Bucket issue #42
-- .limit(limit)
.run()
-- START Bucket issue #42 workaround
localfilteredNews={}
for_,entryinipairs(news)do
localentryOk=true
for_,categoryinipairs(entry.category)do
for_,filteredCategoryinipairs(filteredCategories)do
ifcategory==filteredCategorythen
entryOk=false
end
end
end
ifentryOkthen
table.insert(filteredNews,entry)
end
end
locallimitedNews={}
fori,entryinipairs(filteredNews)do
ifi>limitthenbreakend
table.insert(limitedNews,entry)
end
news=limitedNews
-- END Bucket issue #42 workaround
localshowCategories=false
ifargs.showCategories~=nilthenshowCategories=tonumber(args.showCategories)>0end
localshowStatus=args.approved==nilortonumber(args.approved)==0
ifargs.showStatus~=nilthenshowStatus=tonumber(args.showStatus)>0end
localshowRefs=false
ifargs.showRefs~=nilthenshowRefs=tonumber(args.showRefs)>0end
result=result..'<div class="mcw-news-list">'
fori,entryinipairs(news)do
result=result..renderNewsEntry(f,entry,{
showCategories=showCategories,
showStatus=showStatus,
showRefs=showRefs,
})
end
result=result..'</div>'
returnresult
end
functionp.entry(f)
localargs=f.argsorf
iff==mw.getCurrentFrame()andargs[1]==nilthen
args=f:getParent().args
end
ifargs[1]==nilthen
mw.error('Missing first argument of news entry (date)')
elseifargs[2]==nilthen
mw.error('Missing second argument of news entry (text)')
end
localisApprovedPage=tostring(mw.title.getCurrentTitle())=='News/Archive'
localentryDate=mw.text.trim(args[1])
localentryText=mw.text.trim(args[2])
localentryRef=args.refandmw.text.trim(args.ref)ornil
localentrySprite=args.spriteandmw.text.trim(args.sprite)ornil
localentryCategories=mw.text.split(args.categoriesor'',',')
fori,catinipairs(entryCategories)do
entryCategories[i]=mw.text.trim(cat)
end
ifstring.find(entryDate,'^%d%d%d%d%-%d%d%-%d%d$')==nilthen
error('Invalid date format: expected date to be given in format YYYY-MM-DD')
end
localanchor=nil
ifnotisApprovedPagethen
anchor='mcw-news-entry-'..entryDate..'-'..mw.hash.hashValue('md5',entryText)
end
localentry={
['date']=entryDate,
['text']=entryText,
['ref']=entryRef,
['sprite']=entrySprite,
['approved']=isApprovedPage,
['category']=entryCategories,
['anchor']=anchor,
}
ifargs.hide==nilthen
bucket('news').put(entry)
end
returnrenderNewsEntry(f,entry,{
showCategories=true,
showStatus=false,
showRefs=true,
})
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:News?oldid=3508462"

Navigation menu