ページに対する特定操作の制限(いわゆる)の有効期限を取得するためのモジュールです。
使い方
[編集]このモジュールは呼び出される毎に高負荷パーサー関数を1回まで呼び出します。すでにモジュール:Effective protection levelを呼び出している場合は高負荷パーサー関数を呼び出しません。
ほかのモジュールからの利用
[編集]下記のようにモジュールを呼び出してください。
local effectiveProtectionExpiry = require('モジュール:Effective protection expiry')._main
この関数は引数を2つ使用します。第1引数はページに対する操作("edit"、"create"、"move"、"upload"、"autoreview"のどれか)を指定します。第2引数は操作を行うページ名を指定します。第2引数を省略した場合、モジュールが呼び出されたページのページ名が使用されます。
この関数の戻り値は有効期限のタイムスタンプ(書式:YY-MM-DDThh:mm:ss
)の文字列です。ただし、下記の例外があります。
infinity
- 無期限保護の場合か、保護されていないページ(ページが存在する場合)unknown
- 有効期限が不明な場合、保護されていないページ(ページが存在しない場合)
ページが存在し、かつ保護されていない場合はinfinity
を返すので、一般的には保護レベルを調べるモジュール:Effective protection levelと併用します。
ウィキテキストからの利用
[編集]下記のように呼び出します。引数はモジュールから呼び出す場合と同じです。
関連項目
[編集]この解説は、モジュール:Effective protection expiry/docから呼び出されています。 (編集 | 履歴) 編集者は、このモジュールをサンドボックス (作成 | 複製)とテストケース (作成)で試すことができます。(解説) このモジュールのサブページ一覧。 |
local p = {} -- Returns the expiry of a restriction of an action on a given title, or unknown if it cannot be known. -- If no title is specified, the title of the page being displayed is used. function p._main(action, pagename) local title if type(pagename) == 'table' and pagename.prefixedText then title = pagename elseif pagename then title = mw.title.new(pagename) else title = mw.title.getCurrentTitle() end pagename = title.prefixedText if action == 'autoreview' then local stabilitySettings = mw.ext.FlaggedRevs.getStabilitySettings(title) return stabilitySettings and stabilitySettings.expiry or 'unknown' elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' then error( '第1引数にはedit、move、create、upload、autoreviewのどれかを指定してください', 2 ) end local rawExpiry = mw.getCurrentFrame():callParserFunction('PROTECTIONEXPIRY', action, pagename) if rawExpiry == 'infinity' then return 'infinity' elseif rawExpiry == '' then return 'unknown' else local year, month, day, hour, minute, second = rawExpiry:match( '^(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)$' ) if year then return string.format( '%s-%s-%sT%s:%s:%s', year, month, day, hour, minute, second ) else error('[[モジュール:Effective protection expiry]]のエラー; 有効期限のタイムスタンプの書式が不正です') end end end setmetatable(p, { __index = function(t, k) return function(frame) return t._main(k, frame.args[1]) end end }) return p