<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://safernicotine.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ACheck_bibcode</id>
	<title>Module:Check bibcode - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://safernicotine.wiki/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ACheck_bibcode"/>
	<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Check_bibcode&amp;action=history"/>
	<updated>2026-04-07T16:35:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://safernicotine.wiki/mediawiki/index.php?title=Module:Check_bibcode&amp;diff=42367&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://safernicotine.wiki/mediawiki/index.php?title=Module:Check_bibcode&amp;diff=42367&amp;oldid=prev"/>
		<updated>2022-10-21T21:03:05Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/mediawiki/index.php/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&amp;quot; )&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; B I B C O D E &amp;gt;--------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Validates (sort of) a bibcode id.&lt;br /&gt;
&lt;br /&gt;
Format for bibcodes is specified here: http://adsabs.harvard.edu/abs_doc/help_pages/data.html#bibcodes&lt;br /&gt;
&lt;br /&gt;
But, this: 2015arXiv151206696F is apparently valid so apparently, the only things that really matter are length, 19 characters&lt;br /&gt;
and first four digits must be a year.  This function makes these tests:&lt;br /&gt;
	length must be 19 characters&lt;br /&gt;
	characters in position&lt;br /&gt;
		1–4 must be digits and must represent a year in the range of 1000 – next year&lt;br /&gt;
		5 must be a letter&lt;br /&gt;
		6–8 must be letter, digit, ampersand, or dot (ampersand cannot directly precede a dot; &amp;amp;. )&lt;br /&gt;
		9–18 must be letter, digit, or dot&lt;br /&gt;
		19 must be a letter or dot&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function bibcode (id)&lt;br /&gt;
	local err_type;&lt;br /&gt;
	local year;&lt;br /&gt;
&lt;br /&gt;
	if 19 ~= id:len() then&lt;br /&gt;
		err_type = &amp;#039;length&amp;#039;;&lt;br /&gt;
	else&lt;br /&gt;
		year = id:match (&amp;quot;^(%d%d%d%d)[%a][%w&amp;amp;%.][%w&amp;amp;%.][%w&amp;amp;%.][%w.]+[%a%.]$&amp;quot;)	-- &lt;br /&gt;
		if not year then														-- if nil then no pattern match&lt;br /&gt;
			err_type = &amp;#039;value&amp;#039;;													-- so value error&lt;br /&gt;
		else&lt;br /&gt;
			local next_year = tonumber(os.date (&amp;#039;%Y&amp;#039;))+1;						-- get the current year as a number and add one for next year&lt;br /&gt;
			year = tonumber (year);												-- convert year portion of bibcode to a number&lt;br /&gt;
			if (1000 &amp;gt; year) or (year &amp;gt; next_year) then&lt;br /&gt;
				err_type = &amp;#039;year&amp;#039;;												-- year out of bounds&lt;br /&gt;
			end&lt;br /&gt;
			if id:find(&amp;#039;&amp;amp;%.&amp;#039;) then&lt;br /&gt;
				err_type = &amp;#039;journal&amp;#039;;											-- journal abbreviation must not have &amp;#039;&amp;amp;.&amp;#039; (if it does its missing a letter)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return err_type;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[=[-------------------------&amp;lt; E N T R Y   P O I N T S &amp;gt;------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
This module is mostly a copy of the bibcode validation used in [[Module:Citation/CS1]]&lt;br /&gt;
&lt;br /&gt;
call this module with:&lt;br /&gt;
	{{#invoke:check bibcode|check_bibcode|{{{1|}}}}}&lt;br /&gt;
where {{{1|}}} is the bibcode&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function check_bibcode (frame)&lt;br /&gt;
	local err_type = bibcode (mw.text.trim (frame.args[1]));					-- trim leading and trailing white space before evaluation&lt;br /&gt;
	if err_type then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%&amp;quot; class=&amp;quot;error citation-comment&amp;quot;&amp;gt;Check bibcode: &amp;#039; .. err_type .. &amp;#039; ([[Template:Bibcode#Error_messages|help]])&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
	return &amp;#039;&amp;#039;;																	-- return empty string when bibcode appears to be valid&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T E D   F U N C T I O N S &amp;gt;------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	check_bibcode = check_bibcode,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>