Tropedia

  • Before making a single edit, Tropedia EXPECTS our site policy and manual of style to be followed. Failure to do so may result in deletion of contributions and blocks of users who refuse to learn to do so. Our policies can be reviewed here.
  • All images MUST now have proper attribution, those who neglect to assign at least the "fair use" licensing to an image may have it deleted. All new pages should use the preloadable templates feature on the edit page to add the appropriate basic page markup. Pages that don't do this will be subject to deletion, with or without explanation.
  • All new trope pages will be made with the "Trope Workshop" found on the "Troper Tools" menu and worked on until they have at least three examples. The Trope workshop specific templates can then be removed and it will be regarded as a regular trope page after being moved to the Main namespace. THIS SHOULD BE WORKING NOW, REPORT ANY ISSUES TO Janna2000, SelfCloak or RRabbit42. DON'T MAKE PAGES MANUALLY UNLESS A TEMPLATE IS BROKEN, AND REPORT IT THAT IS THE CASE. PAGES WILL BE DELETED OTHERWISE IF THEY ARE MISSING BASIC MARKUP.

READ MORE

Tropedia
(found on http://meta.wikimedia.org/wiki/Module:Subpages)
 
m (1 revision)
(One intermediate revision by one other user not shown)

Revision as of 04:07, 8 August 2014

Documentation for this module may be created at Module:Subpages/doc

-- subpages = require('Module:Subpages).subpages
-- for page in subpages('Page') do ... end

local _M = {}

function _M.subpages(page)
    page = string.gsub( page, '^%s*%[*%[%[(.-)%]%]%]*%s*$', function(l)
        return string.gsub( l, '^([^|]*)|.*$', '%1', 1 )
    end, 1 )
        :gsub( '[%s_]+', ' ' )
        :gsub( '/+', '/' )
        :gsub( '^%s', '', 1 )
        :gsub( '%s$', '', 1 )
        :gsub( '/$', '', 1 );
 
    if page == '' then
        page = tostring( mw.title.getCurrentTitle() );
    elseif mw.ustring.sub( page, 1, 1) == '/' then
        page = table.concat{ tostring( mw.title.getCurrentTitle() ), page };
    end
    
    local sub, prefix = mw.ustring.sub
    
    prefix, page = pcall(mw.title.new, page, 0)
    if prefix and page then
        prefix = string.len( page.text ) + 2
        page = mw.ustring.gmatch(
            mw.text.unstrip(
                mw:getCurrentFrame():preprocess('{{Special:PrefixIndex/' .. page.prefixedText .. '/}}')
            ),
            '<a href="[^"]*" title="[^"]*">(.-)</a>'
        )
    else
        prefix = nil
        page = function() return nil end
    end
    
    return function()
        local pg = page()
        return pg and sub(pg, prefix) or nil
    end
end

return _M