Module:Layout/Deprecated

Uit Wikibooks

Documentatie voor deze module kan aangemaakt worden op de volgende pagina: Module:Layout/Deprecated/doc

-- These functions are deprecated but still needed for some external calls. The aim is to clean this page!
local layout = {};
local private = {};
local CFG = {};
CFG.MEDIA = {};
CFG.MEDIA.PROGRESS_BAR_DEFAULT_IMAGE  = 'Afbeelding:Progress bar 0.svg';
CFG.LOCATION = {};
CFG.LOCATION.BOOK_CONTENT = '/Boekinhoud';

-- MOVED TO LIBRARY
function private.getParameters( frame_args, arg_list )
	local new_args = {};
	local index = 1;
	local value;

	for i,arg in ipairs( arg_list ) do
		value = frame_args[arg]
		if value == nil then
			value = frame_args[index];
			index = index + 1;
		end
		new_args[arg] = value;
	end

	return new_args;
end

function private.get_unnamed_parameters( frame )
	local result = '';
	local i = 1;
 
    for k,v in pairs(frame.args) do
      	if ( tonumber(k) and v ~= nil and v ~= '' ) then
		   result = result .. v;
    	end
    end 	

	return result;
end

function private.separated_argument_list( frame, seperator )
	local result = '';
	if (frame ~= nil) then return '' end;
    for k,v in pairs(frame.args) do
    	if (v ~= nil and v ~= '') then
    	    if (k ~= 1) then result = result .. seperator; end
    	    result = result .. v:match'^%s*(.*)';
    	end
    end 	
    return result;
end

function private.status_progress_bar( frame, title )
	local newtitle = mw.title.new( title );
	if not (newtitle and newtitle.exists) then
	   return '';
	end
	local status_progress = '[[' .. CFG.MEDIA.PROGRESS_BAR_DEFAULT_IMAGE .. '|50px|In ontwikkeling.]]';
	local bookcontent = mw.title.new( title .. CFG.LOCATION.BOOK_CONTENT );
	if bookcontent.exists then
	   local title_status_number_template = frame:expandTemplate{title= ':' .. title .. CFG.LOCATION.BOOK_CONTENT, args={'Statuscijfer'}};
	   status_progress = '[[Afbeelding:Progress bar ' .. title_status_number_template .. '.svg|50px|In ontwikkeling.]]';
    end
    return status_progress;
end

function private.status_square( frame, title )
	local newtitle = mw.title.new( title );
	if not (newtitle and newtitle.exists) then
	   return '';
	end
	local status_square = '';
	local square_sjabloon_null = mw.title.new( 'Sjabloon:0%' );
	if square_sjabloon_null.exists then
	   status_square = frame:expandTemplate{title='Sjabloon:0%', args={ Datum= 'Volgens infobox' }};
	end
	local bookcontent = mw.title.new( title .. CFG.LOCATION.BOOK_CONTENT );
	if bookcontent.exists then
	  local title_status_number_template = "Sjabloon:" .. frame:expandTemplate{title= ':' .. title .. '/Boekinhoud', args={'Statuscijfer'}};
	  local square_sjabloon = mw.title.new( title_status_number_template .. '%' );
	  if square_sjabloon.exists then
	      status_square = frame:expandTemplate{title=title_status_number_template .. '%', args={ Datum= 'Volgens infobox' }};
	  end
    end
    return status_square;
end

function private.readPage(pageName)
  local page = mw.title.new(pageName)
  if not page then
    return nil
  end

  local content = page:getContent()
  if not content then
    return nil
  end

  -- Find the start and end indices of the {{Voorpagina}} template.
  local startIndex, endIndex = string.find(content, "{{Voorpagina", 1, true)
  if not startIndex then
    -- Process the page contents using the expandTemplate function.
    local processedPage = mw.html.create(content):expandTemplate{title = "Voorpagina"}
    return processedPage
  end
  endIndex = startIndex + 1
  local nestingLevel = 1
  while nestingLevel > 0 do
    local start, finish = string.find(content, "{{", endIndex + 1, true)
    if not start then
      -- Process the page contents using the expandTemplate function.
      local processedPage = mw.html.create(content):expandTemplate{title = "Voorpagina"}
      return processedPage
    end
    local _, _, close = string.find(content, "}}", endIndex + 1, true)
    if not close then
      -- Process the page contents using the expandTemplate function.
      local processedPage = mw.html.create(content):expandTemplate{title = "Voorpagina"}
      return processedPage
    end
    if start < close then
      nestingLevel = nestingLevel + 1
      endIndex = finish
    else
      nestingLevel = nestingLevel - 1
      endIndex = close
    end
  end

  -- Remove the {{Voorpagina}} template from the content.
  local newContent = string.sub(content, 1, startIndex - 1) .. string.sub(content, endIndex + 1)

  -- Process the page contents using the expandTemplate function.
  local processedPage = mw.html.create(newContent):expandTemplate{title = "Voorpagina"}

  return processedPage
end

function layout.book_series( frame )
   local new_args = private.getParameters( frame.args, {'type', 'title'} );
   local my_type = new_args['type'] or '';
   local title = new_args['title'] or '';
--   return private.get_unnamed_parameters( frame);
--   return  readPage(title);
local pageName = "Ondernemend leren/Boekinhoud"
local templateName = "Boek/Inhoud"
local parameterName = "Status"
local parameterValue = private.extractTemplateParameter(pageName, templateName, parameterName)
return parameterValue

end

function layout.comma_separated_argument_list( frame )
    return private.separated_argument_list( frame, "," );
end

function layout.find_book_series( frame )
	local new_args = private.getParameters( frame.args, {'boek'} );
	local boek = new_args['boek'] or '';
	local bookseries = frame:expandTemplate{title='Wikibooks:Boekenseries'};
	local splitseries = mw.text.split( bookseries, ',' );
	local found = '';
	for k,v in pairs(splitseries) do
		local sjabloon = mw.title.new( v .. '/Boekenreeks' );
		if sjabloon.exists then
			local books = frame:expandTemplate{title=':' ..v .. '/Boekenreeks', args={'Lijst'}};
	  	    local splitbooks = mw.text.split( books, ',' );
			for ke,va in pairs(splitbooks) do
			    if (boek == va ) then found = v end
			end    
		end
	end
    return tostring(found);
end

function layout.return_separated_argument_list( frame )
    return private.separated_argument_list( frame, "<br>" );
end

function layout.split ( frame )
	local new_args = private.getParameters( frame.args, {'text', 'position', 'separator'} );
	local text = new_args['text'] or '';
	local separator = new_args['separator'] or '%s';
	local splittable = mw.text.split( text, separator ); 
	local positionstring = new_args['position'] or '0';
	local position =  tonumber(positionstring);
	return splittable[position];
end

function layout.percentage_completed( frame )
    local new_args = private.getParameters( frame.args, {'status'} );
    local new_status = new_args['status'] or '';
    local percentage = {
        ["0"] = "00",
        ["0%"] = "00",
        ["00%"] = "00",
        ["25"] = "25",
        ["25%"] = "25",
        ["50"] = "50",
        ["50%"] = "50",
        ["75"] = "75",
        ["75%"] = "75",
        ["100"] = "100",
        ["100%"] = "100"
    }
    return percentage[new_status];
end

function layout.phase_category( frame )
    local new_args = private.getParameters( frame.args, {'status'} );
    local new_status = new_args['status'] or '';
    local phase = {
        ["0"] = "[[Categorie:Fase0]]",
        ["0%"] = "[[Categorie:Fase0]]",
        ["00%"] = "[[Categorie:Fase0]]",
        ["25"] = "[[Categorie:Fase1]]",
        ["25%"] = "[[Categorie:Fase1]]",
        ["50"] = "[[Categorie:Fase2]]",
        ["50%"] = "[[Categorie:Fase2]]",
        ["75"] = "[[Categorie:Fase3]]",
        ["75%"] = "[[Categorie:Fase3]]",
        ["100"] = "[[Categorie:Fase4]]",
        ["100%"] = "[[Categorie:Fase4]]"
    }
    return phase[new_status];
end

function layout.template( frame )
	local new_args = private.getParameters( frame.args, {'sjabloon', 'env'} );
	local sjabloon = new_args['sjabloon'] or '';
	local env = new_args['env'] or '';
	local result = "Dit sjabloon is nog in ontwikkeling en niet geschikt voor gebruik";
	if (env ~= nil and env ~= '') then
	   result = frame:expandTemplate{title=sjabloon};
	end
   return result;
end

function layout.title( frame )
   return mw.title.getCurrentTitle():getContent();	
end

function layout.list_title_with_status_square( frame )
	local title_lists = '';
    for k,v in pairs(frame.args) do
    	if (v ~= nil and v ~= '') then
    		title_lists =  title_lists .. "* [[" .. v .. "]]&nbsp;" .. private.status_square( frame, v ) .. "\n";
    	end
    end
    return title_lists;
end

function layout.list_title_with_progress_bar( frame )
	local title_lists = '';
    for k,v in pairs(frame.args) do
    	if (v ~= nil and v ~= '') then
    		title_lists =  title_lists .. '* [[' .. v .. ']]<div style="display:inline" style="float:right;">' .. private.status_progress_bar( frame, v ) .. '</div>\n';
    	end
    end
    return title_lists;
end

function layout.overview_box( frame )
   local new_args = private.getParameters( frame.args, {'title', 'content'} );
   local title = new_args['title'] or '';
   local content = new_args['content'] or '';
   local result =     '<table width="320px" style="float:left; clear:right; margin: 1em 2em 1em 2em; background-color:#f8f8f8; border: 1px solid rgb(170, 170, 170);">';
   result = result .. '    <tr>';
   result = result .. '        <td>';
   result = result .. '            <p style="text-align: center; padding:5px; margin: 1 px; color:darkblue; font-size: 135%; background-color: #f8f8f8;border: 1px solid rgb(170, 170, 170);">';
   result = result .. '                <b>' .. title .. '</b>';
   result = result .. '            </p>';
   result = result .. '        </td>';
   result = result .. '    </tr>';
   result = result .. '    <tr>';
   result = result .. '        <td>';
   result = result .. '            ' .. content;
   result = result .. '        </td>';
   result = result .. '    </tr>';
   result = result .. '</table>';
   return result;
end

function layout.string_title_with_status_square( frame )
	local title_lists = '';
    for k,v in pairs(frame.args) do
    	if (v ~= nil and v ~= '') then
    	    if (k ~= 1) then title_lists= title_lists .. " - "; end
   	        title_lists =  title_lists .. "[[" .. v .. "]]&nbsp;" .. private.status_square( frame, v );
    	end
    end
    return title_lists;
end

return layout;
Informatie afkomstig van https://nl.wikibooks.org Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.