| 1 |
local site = {} |
| 2 |
|
| 3 |
function site.setupInterface( info ) |
| 4 |
|
| 5 |
site.setupInterface = nil |
| 6 |
local php = mw_interface |
| 7 |
mw_interface = nil |
| 8 |
|
| 9 |
site.siteName = info.siteName |
| 10 |
site.server = info.server |
| 11 |
site.scriptPath = info.scriptPath |
| 12 |
site.stylePath = info.stylePath |
| 13 |
site.currentVersion = info.currentVersion |
| 14 |
site.stats = info.stats |
| 15 |
site.stats.pagesInCategory = php.pagesInCategory |
| 16 |
site.stats.pagesInNamespace = php.pagesInNamespace |
| 17 |
site.stats.usersInGroup = php.usersInGroup |
| 18 |
site.interwikiMap = php.interwikiMap |
| 19 |
|
| 20 |
|
| 21 |
site.namespaces = {} |
| 22 |
local namespacesByName = {} |
| 23 |
site.subjectNamespaces = {} |
| 24 |
site.talkNamespaces = {} |
| 25 |
site.contentNamespaces = {} |
| 26 |
for ns, data in pairs( info.namespaces ) do |
| 27 |
data.subject = info.namespaces[data.subject] |
| 28 |
data.talk = info.namespaces[data.talk] |
| 29 |
data.associated = info.namespaces[data.associated] |
| 30 |
|
| 31 |
site.namespaces[ns] = data |
| 32 |
|
| 33 |
namespacesByName[data.name] = data |
| 34 |
if data.canonicalName then |
| 35 |
namespacesByName[data.canonicalName] = data |
| 36 |
end |
| 37 |
for i = 1, #data.aliases do |
| 38 |
namespacesByName[data.aliases[i]] = data |
| 39 |
end |
| 40 |
|
| 41 |
if data.isSubject then |
| 42 |
site.subjectNamespaces[ns] = data |
| 43 |
end |
| 44 |
if data.isTalk then |
| 45 |
site.talkNamespaces[ns] = data |
| 46 |
end |
| 47 |
if data.isContent then |
| 48 |
site.contentNamespaces[ns] = data |
| 49 |
end |
| 50 |
end |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
local getNsIndex = php.getNsIndex |
| 55 |
setmetatable( namespacesByName, { |
| 56 |
__index = function ( t, k ) |
| 57 |
if type( k ) == 'string' then |
| 58 |
|
| 59 |
k = string.gsub( k, '_', ' ' ) |
| 60 |
if rawget( t, k ) then |
| 61 |
return rawget( t, k ) |
| 62 |
end |
| 63 |
|
| 64 |
|
| 65 |
local ns = getNsIndex( k ) |
| 66 |
if ns then |
| 67 |
rawset( t, k, site.namespaces[ns] ) |
| 68 |
end |
| 69 |
end |
| 70 |
return rawget( t, k ) |
| 71 |
end |
| 72 |
} ) |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
setmetatable( site.namespaces, { __index = namespacesByName } ) |
| 78 |
|
| 79 |
|
| 80 |
mw = mw or {} |
| 81 |
mw.site = site |
| 82 |
|
| 83 |
package.loaded['mw.site'] = site |
| 84 |
end |
| 85 |
|
| 86 |
return site |