https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Modul%3AImageCollection%2Fmaintenance Modul:ImageCollection/maintenance - Versionsgeschichte 2025-06-09T16:28:17Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.45.0-wmf.4 https://de.wikipedia.org/w/index.php?title=Modul:ImageCollection/maintenance&diff=249428937&oldid=prev Hgzh: neu 2024-10-14T19:38:35Z <p>neu</p> <p><b>Neue Seite</b></p><div>-- main module<br /> local ImageCollection = {}<br /> <br /> -- export table<br /> local p = {}<br /> <br /> function loadModule()<br /> -- loads the main ImageCollection module<br /> -- returns:<br /> -- (bool) loading successful<br /> <br /> local m -- module handle<br /> local success -- laoding success<br /> <br /> -- load module<br /> success, m = pcall( require, &quot;Module:ImageCollection&quot; )<br /> if type( m ) == &quot;table&quot; then<br /> ImageCollection = m()<br /> end<br /> <br /> -- return success<br /> return success<br /> end<br /> <br /> function colTableRowCount( size )<br /> -- calculates the required row count to fit size in three cols<br /> -- parameters:<br /> -- size: (integer) row count<br /> -- returns:<br /> -- (table) row count by col<br /> <br /> local rc -- row count<br /> local base -- base row count<br /> local add -- additional row count<br /> <br /> -- only use one row if less then 5 items<br /> if size &lt; 5 then<br /> return { size, 0, 0 }<br /> end<br /> <br /> -- calc row count<br /> base = math.floor( size / 3 )<br /> add = size % 3<br /> <br /> -- assign counts<br /> rc = {base, base, base}<br /> if add &gt;= 1 then<br /> rc[1] = rc[1] + 1<br /> end<br /> if add == 2 then<br /> rc[2] = rc[2] + 1<br /> end<br /> <br /> -- return<br /> return rc<br /> end<br /> <br /> function colTable()<br /> -- return all defined images as table in multiple cols<br /> -- returns:<br /> -- (string) overview table wikisyntax<br /> <br /> local imgs -- images assigned to group<br /> local size -- image group size<br /> local colsizes -- size of cols<br /> local i -- increment<br /> local j -- increment<br /> local currgroup -- current group<br /> local currimg -- current image info<br /> local key -- image key<br /> local text -- cell text<br /> local hmain -- html main element<br /> local htable -- html table element<br /> local hhead -- html table header<br /> local hrow -- html table row<br /> <br /> -- assign images to groups<br /> imgs = {}<br /> for key, img in pairs( ImageCollection.data ) do<br /> currgroup = img.group or ImageCollection.config.defaults.group or &quot;-&quot;<br /> <br /> -- add group if necessary<br /> if not imgs[ currgroup ] then<br /> imgs[ currgroup ] = {}<br /> end<br /> <br /> -- add image to group, skip errors<br /> if not img.error then<br /> table.insert( imgs[ currgroup ], key )<br /> end<br /> end<br /> <br /> -- create main output<br /> hmain = mw.html.create( &quot;div&quot; )<br /> <br /> -- create table header with cells<br /> hhead = mw.html.create( &quot;tr&quot; )<br /> for i = 1, 2 do<br /> hhead:node(<br /> mw.html.create( &quot;th&quot; ):wikitext( ImageCollection.config.i18n.colTableHeaderText[ i ] )<br /> )<br /> end<br /> <br /> -- output groups<br /> for _, group in ipairs( ImageCollection.groups.order ) do<br /> currgroup = imgs[ group ]<br /> if currgroup then<br /> table.sort( currgroup )<br /> size = #currgroup<br /> i = 1<br /> if size &gt; 0 then<br /> -- create group title<br /> hmain:node(<br /> mw.html.create( &quot;h3&quot; ):wikitext( ImageCollection.groups.title[ group ] )<br /> )<br /> -- create cols<br /> colsizes = colTableRowCount( size )<br /> for _, rowcount in ipairs( colsizes ) do<br /> if rowcount &gt; 0 then<br /> -- create table<br /> htable = mw.html.create( &quot;table&quot; )<br /> :addClass( &quot;wikitable&quot; )<br /> :cssText( &quot;float:left; margin-right:1em;&quot; )<br /> :node( hhead )<br /> <br /> -- loop through group<br /> j = 1<br /> repeat<br /> -- get current image info<br /> key = imgs[ group ][ i ]<br /> currimg = ImageCollection.data[ key ]<br /> <br /> -- create row<br /> hrow = mw.html.create( &quot;tr&quot; ) <br /> <br /> -- image<br /> if currimg.alias then<br /> text = &quot;&quot;<br /> else<br /> text = ImageCollection.invokeImage( key, currimg, &quot;20px&quot; )<br /> end<br /> hrow:node( mw.html.create( &quot;td&quot; ):wikitext( text ) )<br /> <br /> -- description<br /> if currimg.alias then<br /> text = &quot;&lt;small&gt;&quot; .. key .. &quot;&lt;/small&gt; → &quot; .. currimg.alias<br /> else<br /> text = key<br /> end<br /> hrow:node( mw.html.create( &quot;td&quot; ):wikitext( text ) )<br /> <br /> -- add row to table<br /> htable:node( hrow )<br /> <br /> i = i + 1<br /> j = j + 1<br /> until j &gt; rowcount or i &gt; size<br /> <br /> -- add table to main<br /> hmain:node( htable )<br /> end<br /> end<br /> <br /> -- add clearer to main<br /> hmain:node( mw.html.create( &quot;div&quot; ):cssText( &quot;clear: both;&quot; ) )<br /> end<br /> end<br /> end<br /> <br /> -- return<br /> return tostring( hmain )<br /> end<br /> <br /> p.inventory = function( frame )<br /> -- return set of defined images<br /> -- parameters:<br /> -- frame: (table) wiki environment frame<br /> -- returns:<br /> -- (string) overview wikisyntax<br /> <br /> local success -- loading success<br /> local error -- loading error<br /> local format -- output format<br /> <br /> -- load module and exit if error<br /> success = loadModule()<br /> if not success then<br /> return &quot;&lt;span class=\&quot;error\&quot;&gt;module call failed&lt;/span&gt;&quot;<br /> end<br /> <br /> -- load config and exit if error<br /> success, error = ImageCollection.loadConfigFromTemplate( frame )<br /> if success == false then<br /> return error<br /> end<br /> <br /> -- get output format<br /> format = frame.args.format or &quot;colTable&quot;<br /> <br /> -- switch output format<br /> if format == &quot;colTable&quot; then<br /> return colTable()<br /> end<br /> <br /> end<br /> <br /> return p</div> Hgzh