Modul : Data?ni kategorie

Z Wikizprav

Dokumentaci tohoto modulu lze vytvo?it na strance Napov?da:Modul:Data?ni kategorie

-- @brief

--  Backend for {{Data?ni kategorie}}.

-- 

-- @author

--  [[meta:User:Danny B.]]

local
 _module
 =
 {}

----------------------------------------



local
 DateTime
 =
 require
(
 "Module:DateTime"
 )

local
 CategoryTypes
 =
 {}



function
 CategoryTypes
.
DM
(
 dmy
 )

	
	local
 output
 =
 {}

	local
 day
 =
 dmy
[
1
]

	local
 month
 =
 dmy
[
2
]

	local
 year
 =
 2008

	
	local
 monthName
 =
 DateTime
.
months
[
month
].
name

	local
 monthNameEn
 =
 os.date
(
 "%B"
,
 os.time
(
 {
 year
 =
 year
,
 month
 =
 month
,
 day
 =
 day
 }
 )
 )

	
	local
 dayPrev
 =
 os.date
(
 "*t"
,
 os.time
(
 {
 day
 =
 day
 -
 1
,
 month
 =
 month
,
 year
 =
 year
 }
 )
 )

	local
 dayNext
 =
 os.date
(
 "*t"
,
 os.time
(
 {
 day
 =
 day
 +
 1
,
 month
 =
 month
,
 year
 =
 year
 }
 )
 )

	local
 verbalDatePrev
 =
 string.format
(
 "%d. %s"
,
 dayPrev
.
day
,
 DateTime
.
months
[
dayPrev
.
month
].
name
 )

	local
 verbalDateNext
 =
 string.format
(
 "%d. %s"
,
 dayNext
.
day
,
 DateTime
.
months
[
dayNext
.
month
].
name
 )

	
	
	output
.
navigation
 =
 {

		[
"prev"
]
 =
 string.format
(
 "[[:Kategorie:%s|? %s]]"
,
 verbalDatePrev
,
 verbalDatePrev
 ),

		[
"next"
]
 =
 string.format
(
 "[[:Kategorie:%s|%s ?]]"
,
 verbalDateNext
,
 verbalDateNext
 )

	}

	
	output
.
sisterprojects
 =
 {

		{

			[
"project"
]
 =
 "Wikipedie"
,

			[
"type"
]
 =
 "?lanek"
,

			[
"title"
]
 =
 string.format
(
 "%d. %s"
,
 day
,
 monthName
 )

		},
 {

			[
"project"
]
 =
 "Wikipedie"
,

			[
"type"
]
 =
 "kategorie"
,

			[
"title"
]
 =
 string.format
(
 "%d. %s"
,
 day
,
 monthName
 )

		},
 {

			[
"project"
]
 =
 "Commons"
,

			[
"type"
]
 =
 "kategorie"
,

			[
"title"
]
 =
 string.format
(
 "%d %s"
,
 day
,
 monthNameEn
 )

		}

	}

	
	output
.
categories
 =
 {

		{

			[
"title"
]
 =
 monthName
,

			[
"sortkey"
]
 =
 string.format
(
 "*%d"
,
 year
 )

		},
 {

			[
"title"
]
 =
 year
,

			[
"sortkey"
]
 =
 string.format
(
 " %02d"
,
 month
 )

		}

	}

	
	return
 output

	
end



function
 CategoryTypes
.
DMY
(
 dmy
 )

	
	local
 output
 =
 {}

	local
 day
 =
 dmy
[
1
]

	local
 month
 =
 dmy
[
2
]

	local
 year
 =
 dmy
[
3
]

	
	local
 monthName
 =
 DateTime
.
months
[
month
].
name

	local
 verbalDate
 =
 string.format
(
 "%d. %s %d"
,
 day
,
 monthName
,
 year
 )

	
	local
 dayPrev
 =
 os.date
(
 "*t"
,
 os.time
(
 {
 day
 =
 day
 -
 1
,
 month
 =
 month
,
 year
 =
 year
 }
 )
 )

	local
 dayNext
 =
 os.date
(
 "*t"
,
 os.time
(
 {
 day
 =
 day
 +
 1
,
 month
 =
 month
,
 year
 =
 year
 }
 )
 )

	local
 verbalDatePrev
 =
 string.format
(
 "%d. %s %d"
,
 dayPrev
.
day
,
 DateTime
.
months
[
dayPrev
.
month
].
name
,
 dayPrev
.
year
 )

	local
 verbalDateNext
 =
 string.format
(
 "%d. %s %d"
,
 dayNext
.
day
,
 DateTime
.
months
[
dayNext
.
month
].
name
,
 dayNext
.
year
 )

	
	local
 dayOverview

	local
 categoryPrev
 =
 ""

	local
 categoryNext
 =
 ""

	local
 pagesInCategory

	
	local
 titleObject

	
	
	if
 tonumber
(
 year
 )
 >=
 2008
 then

		titleObject
 =
 mw
.
title
.
new
(
 verbalDate
 )

		-- expensive++

		if
 titleObject
.
exists
 then

			dayOverview
 =
 string.format
(
 "[[%s|Denni p?ehled]]"
,
 verbalDate
 )

		else

			pagesInCategory
 =
 mw
.
site
.
stats
.
pagesInCategory
(
 verbalDate
,
 "pages"
 )

			-- expensive++

			dayOverview
 =
 string.format
(
 "<span title=
\"
Zalo?it denni p?ehled pro %s
\"
>[%s Zalo?it denni p?ehled]</span>"
,

				verbalDate
,

				titleObject
:
fullUrl
({

					action
 =
 "edit"
,

					editintro
 =
 "Wikizpravy:Kostry stranek/Denni p?ehled/navod"
,

					preload
 =
 "Wikizpravy:Kostry stranek/Denni p?ehled"
,

					summary
 =
 verbalDate

				})

			)

		end

	end

	
	titleObject
 =
 mw
.
title
.
new
(
 "Kategorie:"
 ..
 verbalDatePrev
 )

	-- expensive++

	if
 not
 titleObject
.
exists
 then

		categoryPrev
 =
 string.format
(
 " <span title=
\"
Zalo?it data?ni kategorii pro %s
\"
>[%s ?]</span>"
,

			verbalDatePrev
,

			titleObject
:
fullUrl
({

				action
 =
 "edit"
,

				preload
 =
 "Wikizpravy:Kostry stranek/Data?ni kategorie"
,

				summary
 =
 "Dokumentace"

			})

		)

	end

	
	titleObject
 =
 mw
.
title
.
new
(
 "Kategorie:"
 ..
 verbalDateNext
 )

	-- expensive++

	if
 not
 titleObject
.
exists
 then

		categoryNext
 =
 string.format
(
 "<span title=
\"
Zalo?it data?ni kategorii pro %s
\"
>[%s ?]</span> "
,

			verbalDateNext
,

			titleObject
:
fullUrl
({

				action
 =
 "edit"
,

				preload
 =
 "Wikizpravy:Kostry stranek/Data?ni kategorie"
,

				summary
 =
 "Dokumentace"

			})

		)

	end

	
	output
.
navigation
 =
 {

		[
"prev"
]
 =
 string.format
(
 "[[:Kategorie:%s|? %s]]%s"
,
 verbalDatePrev
,
 verbalDatePrev
,
 categoryPrev
 ),

		[
"curr"
]
 =
 dayOverview
,

		[
"next"
]
 =
 string.format
(
 "%s[[:Kategorie:%s|%s ?]]"
,
 categoryNext
,
 verbalDateNext
,
 verbalDateNext
 )

	}

	
	output
.
categories
 =
 {

		{

			[
"title"
]
 =
 string.format
(
 "%d. %s"
,
 day
,
 monthName
 ),

			[
"sortkey"
]
 =
 string.format
(
 " %04d"
,
 year
 )

		},
 {

			[
"title"
]
 =
 string.format
(
 "%s %d"
,
 monthName
,
 year
 ),

			[
"sortkey"
]
 =
 string.format
(
 " %02d"
,
 day
 )

		}

	}

	if
 pagesInCategory
 then

		table.insert
(
 output
.
categories
,
 
			{

				[
"title"
]
 =
 string.format
(
 "Monitoring:Data?ni kategorie dne bez denniho p?ehledu/%d"
,
 pagesInCategory
 ),

				[
"sortkey"
]
 =
 string.format
(
 " %04d%02d%02d"
,
 year
,
 month
,
 day
 )

			}

		)

	end

	
	return
 output

	
end



function
 CategoryTypes
.
M
(
 dmy
 )

	
	local
 output
 =
 {}

	local
 month
 =
 dmy
[
2
]

	
	local
 monthPrev
 =
 DateTime
.
months
[
month
 ==
 1
 and
 12
 or
 month
 -
 1
].
name

	local
 monthNext
 =
 DateTime
.
months
[
month
 ==
 12
 and
 1
 or
 month
 +
 1
].
name

	
	
	output
.
navigation
 =
 {

		[
"prev"
]
 =
 string.format
(
 "[[:Kategorie:%s|? %s]]"
,
 monthPrev
,
 monthPrev
 ),

		[
"next"
]
 =
 string.format
(
 "[[:Kategorie:%s|%s ?]]"
,
 monthNext
,
 monthNext
 )

	}

	
	output
.
sisterprojects
 =
 {

		{

			[
"project"
]
 =
 "Wikipedie"
,

			[
"type"
]
 =
 "?lanek"
,

			[
"title"
]
 =
 mw
.
language
.
getContentLanguage
():
ucfirst
(
 DateTime
.
months
[
month
].
name
 )

		}

	}

	
	output
.
categories
 =
 {

		{

			[
"title"
]
 =
 "Podle m?sice"
,

			[
"sortkey"
]
 =
 string.format
(
 " %02d"
,
 month
 )

		}

	}

	
	return
 output

	
end



function
 CategoryTypes
.
MY
(
 dmy
 )

	
	local
 output
 =
 {}

	local
 day
 =
 1

	local
 month
 =
 dmy
[
2
]

	local
 year
 =
 dmy
[
3
]

	
	local
 monthName
 =
 DateTime
.
months
[
month
].
name

	local
 monthNameGen
 =
 DateTime
.
months
[
month
].
genitive

	local
 monthNameEn
 =
 os.date
(
 "%B"
,
 os.time
(
 {
 year
 =
 year
,
 month
 =
 month
,
 day
 =
 day
 }
 )
 )

	
	local
 monthPrev
 =
 os.date
(
 "*t"
,
 os.time
(
 {
 year
 =
 year
,
 month
 =
 month
 -
 1
,
 day
 =
 day
 }
 )
 )

	local
 monthNext
 =
 os.date
(
 "*t"
,
 os.time
(
 {
 year
 =
 year
,
 month
 =
 month
 +
 1
,
 day
 =
 day
 }
 )
 )

	local
 monthYearPrev
 =
 string.format
(
 "%s %s"
,
 DateTime
.
months
[
monthPrev
.
month
].
name
,
 monthPrev
.
year
)

	local
 monthYearNext
 =
 string.format
(
 "%s %s"
,
 DateTime
.
months
[
monthNext
.
month
].
name
,
 monthNext
.
year
)

	
	
	output
.
navigation
 =
 {

		[
"prev"
]
 =
 string.format
(
 "[[:Kategorie:%s|? %s]]"
,
 monthYearPrev
,
 monthYearPrev
 ),

		[
"next"
]
 =
 string.format
(
 "[[:Kategorie:%s|%s ?]]"
,
 monthYearNext
,
 monthYearNext
 )

	}

	
	output
.
description
 =
 "Tato kategorie obsahuje kategorie dn? z&#160;"
 ..
 monthNameGen
 ..
 " "
 ..
 year
 ..
 ". Nem?la by obsahovat ?adne p?imo vlo?ene zpravy."

	
	output
.
sisterprojects
 =
 {

		{

			[
"project"
]
 =
 "Wikipedie"
,

			[
"type"
]
 =
 "?lanek"
,

			[
"title"
]
 =
 string.format
(
 "%s %s"
,
 mw
.
language
.
getContentLanguage
():
ucfirst
(
 monthName
 ),
 year
 )

		},
 {

			[
"project"
]
 =
 "Commons"
,

			[
"type"
]
 =
 "kategorie"
,

			[
"title"
]
 =
 string.format
(
 "%s %s"
,
 monthNameEn
,
 year
 )

		}

	}

	
	output
.
categories
 =
 {

		{

			[
"title"
]
 =
 monthName
,

			[
"sortkey"
]
 =
 string.format
(
 "*%d"
,
 year
 )

		},
 {

			[
"title"
]
 =
 year
,

			[
"sortkey"
]
 =
 string.format
(
 " %02d"
,
 month
 )

		}

	}

	
	return
 output

	
end



function
 CategoryTypes
.
Y
(
 dmy
 )

	
	local
 output
 =
 {}

	local
 year
 =
 dmy
[
3
]

	
	
	output
.
navigation
 =
 {

		[
"prev"
]
 =
 string.format
(
 "[[:Kategorie:%s|? %s]]"
,
 year
 -
 1
,
 year
 -
 1
 ),

		[
"next"
]
 =
 string.format
(
 "[[:Kategorie:%s|%s ?]]"
,
 year
 +
 1
,
 year
 +
 1
 )

	}

	
	output
.
sisterprojects
 =
 {

		{

			[
"project"
]
 =
 "Wikipedie"
,

			[
"type"
]
 =
 "?lanek"
,

			[
"title"
]
 =
 year

		},
 {

			[
"project"
]
 =
 "Wikipedie"
,

			[
"type"
]
 =
 "kategorie"
,

			[
"title"
]
 =
 year

		},
 {

			[
"project"
]
 =
 "Commons"
,

			[
"type"
]
 =
 "kategorie"
,

			[
"title"
]
 =
 year

		}

	}

	
	output
.
categories
 =
 {

		{

			[
"title"
]
 =
 "Podle roku"
,

			[
"sortkey"
]
 =
 string.format
(
 " %04d"
,
 year
 )

		}

	}

	
	return
 output

	
end



-- @brief

--  Generates the text for date categories.

-- 

-- @param

--  frame The current frame object

-- 

-- @return

--  Preprocessed wikitext

function
 _module
.
print
(
 frame
 )

	
	local
 output
 =
 ""

	local
 titleObject
 =
 mw
.
title
.
getCurrentTitle
()

	
	if
 titleObject
.
namespace
 ~=
 14
 then

		return

	end

	
	local
 day

	local
 month

	local
 year

	local
 categoryType

	local
 data

	
	day
,
 month
,
 year
,
 categoryType
 =
 DateTime
.
parseVerbalDate
(
 titleObject
.
text
 )

	data
 =
 CategoryTypes
[
categoryType
](
 {
 day
,
 month
,
 year
 }
 )

	
	if
 data
.
navigation
 then

		local
 navigation
 =
 {}

		table.insert
(
 navigation
,
 data
.
navigation
.
prev
 )

		table.insert
(
 navigation
,
 data
.
navigation
.
curr
 )

		table.insert
(
 navigation
,
 data
.
navigation
.
next
 )

		output
 =
 output
 ..
 "<div class=
\"
sequenceBoxSimple plainlinks
\"
>
\n
"

		output
 =
 output
 ..
 table.concat
(
 navigation
,
 " ? "
 )

		output
 =
 output
 ..
 "
\n
</div>
\n\n
"

	end

	
	if
 data
.
description
 then

		output
 =
 output
 ..
 data
.
description
 ..
 "
\n\n
"

	end

	
	if
 data
.
sisterprojects
 then

		output
 =
 output
 ..
 "== Externi odkazy ==
\n
"

		for
 _
,
 link
 in
 ipairs
(
 data
.
sisterprojects
 )
 do

			output
 =
 output
 ..
 string.format
(
 "* {{%s|%s=%s}}
\n
"
,
 link
.
project
,
 link
.
type
,
 link
.
title
 )

		end

		output
 =
 output
 ..
 "
\n
"

	end

	
	if
 data
.
categories
 then

		for
 _
,
 category
 in
 ipairs
(
 data
.
categories
 )
 do

			output
 =
 output
 ..
 string.format
(
 "[[Kategorie:%s|%s]]
\n
"
,
 category
.
title
,
 category
.
sortkey
 )

		end

	end

	
	output
 =
 frame
:
preprocess
(
 output
 )

	
	return
 output

	
end



----------------------------------------

return
 _module