Homepage
Games
News
News βΎ
All
Transfers
Drama
Business
Sponsors
Mergers
Investors
Hires
Companies
More
People
Tournaments
Brands
Brands βΎ
Companies
Organizations
Sponsors
Other
Locations
Search
Editing
Module:NewsSearch
From TwogPedia
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local getArgs = require('Module:Arguments').getArgs local News = require('Module:NewsItem') local cargo = mw.ext.cargo local limit = 100000 local NewsSearch = {} function NewsSearch.main(frame) local args = getArgs(frame) local results = NewsSearch.query( args) if #results > 0 then local container = mw.html.create('div'):attr('id', 'news-search-container') local ul = mw.html.create('ul') for r = 1, #results do ul:node(mw.html.create('li'):node(News.main(newsObject(results[r])))) end container:node(ul) return container end end function NewsSearch.query(args) local whereStr = '' if args.categories then local categories = mw.text.split(args.categories, ',') whereStr = whereStr .. '(' for i = 1, #categories do if i ~= 1 then whereStr = whereStr .. ' OR ' end whereStr = whereStr .. ' category HOLDS WITHIN "' .. categories[i] .. '"' end whereStr = whereStr .. ')' end if args.games then if args.categories then whereStr = whereStr .. ' AND (' else whereStr = whereStr .. '(' end local games = mw.text.split(args.games, ',') for i = 1, #games do if i ~= 1 then whereStr = whereStr .. ' OR ' end whereStr = whereStr .. ' game HOLDS WITHIN "' .. games[i] .. '"' end whereStr = whereStr .. ')' end if args.tag then args.tag = string.gsub(args.tag, '_', ' ') if args.categories or args.games then whereStr = whereStr .. ' AND tags HOLDS LIKE "%' .. args.tag .. '%"' else whereStr = whereStr .. ' tags HOLDS LIKE "%' .. args.tag .. '%"' end end if args.title then args.title = string.gsub(args.title, '_', ' ') if whereStr ~= '' then whereStr = whereStr .. ' AND _pageName LIKE "%' .. args.title.. '%"' else whereStr = whereStr .. ' _pageName LIKE "%' .. args.title.. '%"' end end local tables = 'News' local fields = '_pageName, date, category, game, image, content' local cargoArgs = { where = whereStr, orderBy = 'date DESC', limit = limit } local results = cargo.query(tables, fields, cargoArgs) return results end function newsObject(result) local object = { date = result.date, _pageName = result._pageName, category = result.category, game = result.game, content = result.content, author = result.author } return object end return NewsSearch
Summary:
Please note that all contributions to TwogPedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TwogPedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Template used on this page:
Module:NewsSearch/doc
(
edit
)
No categories
Edit