<!DOCTYPE html>
<html lang='en'>
<head>
<title>ikiwiki-upstream - Unnamed repository; edit this file to name it for gitweb.</title>
<meta name='generator' content='cgit v1.2.3'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/cgit-css/cgit.css'/>
<link rel='stylesheet' type='text/css' href='/cgit-local/local.css'/>
<script type='text/javascript' src='/cgit.js'></script>
<link rel='shortcut icon' href='/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='https://source.jones.dk/ikiwiki-upstream/atom/doc/examples/softwaresite/news?h=master' type='application/atom+xml'/>
<link rel='vcs-git' href='https://source.jones.dk/ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
<link rel='vcs-git' href='user@source.jones.dk:ikiwiki-upstream' title='ikiwiki-upstream Git repository'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/'><img src='/cgit-css/cgit.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/'>index</a> : <a href='/ikiwiki-upstream/'>ikiwiki-upstream</a></td><td class='form'><form method='get'>
<input type='hidden' name='id' value='dccd76487151acc6adc93ec79f1808096bc41324'/><select name='h' onchange='this.form.submit();'>
<option value='layoutgala'>layoutgala</option>
<option value='master' selected='selected'>master</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Unnamed repository; edit this file to name it for gitweb.</td><td class='sub right'>Jonas Smedegaard</td></tr></table>
<table class='tabs'><tr><td>
<a href='/ikiwiki-upstream/'>summary</a><a href='/ikiwiki-upstream/refs/?id=dccd76487151acc6adc93ec79f1808096bc41324'>refs</a><a href='/ikiwiki-upstream/log/doc/examples/softwaresite/news'>log</a><a href='/ikiwiki-upstream/tree/doc/examples/softwaresite/news?id=dccd76487151acc6adc93ec79f1808096bc41324'>tree</a><a href='/ikiwiki-upstream/commit/doc/examples/softwaresite/news?id=dccd76487151acc6adc93ec79f1808096bc41324'>commit</a><a class='active' href='/ikiwiki-upstream/diff/doc/examples/softwaresite/news?id=dccd76487151acc6adc93ec79f1808096bc41324'>diff</a></td><td class='form'><form class='right' method='get' action='/ikiwiki-upstream/log/doc/examples/softwaresite/news'>
<input type='hidden' name='id' value='dccd76487151acc6adc93ec79f1808096bc41324'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/ikiwiki-upstream/diff/?id=dccd76487151acc6adc93ec79f1808096bc41324'>root</a>/<a href='/ikiwiki-upstream/diff/doc?id=dccd76487151acc6adc93ec79f1808096bc41324'>doc</a>/<a href='/ikiwiki-upstream/diff/doc/examples?id=dccd76487151acc6adc93ec79f1808096bc41324'>examples</a>/<a href='/ikiwiki-upstream/diff/doc/examples/softwaresite?id=dccd76487151acc6adc93ec79f1808096bc41324'>softwaresite</a>/<a href='/ikiwiki-upstream/diff/doc/examples/softwaresite/news?id=dccd76487151acc6adc93ec79f1808096bc41324'>news</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='dccd76487151acc6adc93ec79f1808096bc41324'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option>ss="hl opt">::</span>attachment<span class="hl opt">;</span></li>
<li id="n_3" class="hl"></li>
<li id="n_4" class="hl"><span class="hl kwa">use </span>warnings<span class="hl opt">;</span></li>
<li id="n_5" class="hl"><span class="hl kwa">use </span>strict<span class="hl opt">;</span></li>
<li id="n_6" class="hl"><span class="hl kwa">use </span>IkiWiki <span class="hl num">3.00</span><span class="hl opt">;</span></li>
<li id="n_7" class="hl"></li>
<li id="n_8" class="hl"><span class="hl kwa">sub </span>import <span class="hl opt">{</span></li>
<li id="n_9" class="hl">    add_underlay<span class="hl opt">(</span><span class="hl sng">&quot;javascript&quot;</span><span class="hl opt">);</span></li>
<li id="n_10" class="hl">    hook<span class="hl opt">(</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;getsetup&quot;</span><span class="hl opt">, </span>id <span class="hl opt">=&gt; </span><span class="hl sng">&quot;attachment&quot;</span><span class="hl opt">, </span>call <span class="hl opt">=&gt; </span>\<span class="hl opt">&amp;</span>getsetup<span class="hl opt">);</span></li>
<li id="n_11" class="hl">    hook<span class="hl opt">(</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;checkconfig&quot;</span><span class="hl opt">, </span>id <span class="hl opt">=&gt; </span><span class="hl sng">&quot;attachment&quot;</span><span class="hl opt">, </span>call <span class="hl opt">=&gt; </span>\<span class="hl opt">&amp;</span>checkconfig<span class="hl opt">);</span></li>
<li id="n_12" class="hl">    hook<span class="hl opt">(</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;formbuilder_setup&quot;</span><span class="hl opt">, </span>id <span class="hl opt">=&gt; </span><span class="hl sng">&quot;attachment&quot;</span><span class="hl opt">, </span>call <span class="hl opt">=&gt; </span>\<span class="hl opt">&amp;</span>formbuilder_setup<span class="hl opt">);</span></li>
<li id="n_13" class="hl">    hook<span class="hl opt">(</span>type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;formbuilder&quot;</span><span class="hl opt">, </span>id <span class="hl opt">=&gt; </span><span class="hl sng">&quot;attachment&quot;</span><span class="hl opt">, </span>call <span class="hl opt">=&gt; </span>\<span class="hl opt">&amp;</span>formbuilder<span class="hl opt">);</span></li>
<li id="n_14" class="hl">    IkiWiki<span class="hl opt">::</span>loadplugin<span class="hl opt">(</span><span class="hl sng">&quot;filecheck&quot;</span><span class="hl opt">);</span></li>
<li id="n_15" class="hl"><span class="hl opt">}</span></li>
<li id="n_16" class="hl"></li>
<li id="n_17" class="hl"><span class="hl kwa">sub </span>getsetup <span class="hl opt">() {</span></li>
<li id="n_18" class="hl">    <span class="hl kwa">return</span></li>
<li id="n_19" class="hl">        plugin <span class="hl opt">=&gt; {</span></li>
<li id="n_20" class="hl">            safe <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_21" class="hl">            rebuild <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_22" class="hl">        <span class="hl opt">},</span></li>
<li id="n_23" class="hl">        allowed_attachments <span class="hl opt">=&gt; {</span></li>
<li id="n_24" class="hl">            type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;pagespec&quot;</span><span class="hl opt">,</span></li>
<li id="n_25" class="hl">            example <span class="hl opt">=&gt; </span><span class="hl sng">&quot;virusfree() and mimetype(image/*) and maxsize(50kb)&quot;</span><span class="hl opt">,</span></li>
<li id="n_26" class="hl">            description <span class="hl opt">=&gt; </span><span class="hl sng">&quot;enhanced PageSpec specifying what attachments are allowed&quot;</span><span class="hl opt">,</span></li>
<li id="n_27" class="hl">            <span class="hl kwc">link </span><span class="hl opt">=&gt; </span><span class="hl sng">&quot;ikiwiki/PageSpec/attachment&quot;</span><span class="hl opt">,</span></li>
<li id="n_28" class="hl">            safe <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">,</span></li>
<li id="n_29" class="hl">            rebuild <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_30" class="hl">        <span class="hl opt">},</span></li>
<li id="n_31" class="hl">        virus_checker <span class="hl opt">=&gt; {</span></li>
<li id="n_32" class="hl">            type <span class="hl opt">=&gt; </span><span class="hl sng">&quot;string&quot;</span><span class="hl opt">,</span></li>
<li id="n_33" class="hl">            example <span class="hl opt">=&gt; </span><span class="hl sng">&quot;clamdscan -&quot;</span><span class="hl opt">,</span></li>
<li id="n_34" class="hl">            description <span class="hl opt">=&gt; </span><span class="hl sng">&quot;virus checker program (reads STDIN, returns nonzero if virus found)&quot;</span><span class="hl opt">,</span></li>
<li id="n_35" class="hl">            safe <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">, </span><span class="hl slc"># executed</span></li>
<li id="n_36" class="hl">            rebuild <span class="hl opt">=&gt; </span><span class="hl num">0</span><span class="hl opt">,</span></li>
<li id="n_37" class="hl">        <span class="hl opt">},</span></li>
<li id="n_38" class="hl"><span class="hl opt">}</span></li>
<li id="n_39" class="hl"></li>
<li id="n_40" class="hl"><span class="hl kwa">sub </span>check_canattach <span class="hl opt">(</span><span class="hl kwb">$$</span><span class="hl opt">;$) {</span></li>
<li id="n_41" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_42" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$dest</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">; </span><span class="hl slc"># where it&#39;s going to be put, under the srcdir</span></li>
<li id="n_43" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$file</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">; </span><span class="hl slc"># the path to the attachment currently</span></li>
<li id="n_44" class="hl"></li>
<li id="n_45" class="hl">    <span class="hl slc"># Don&#39;t allow an attachment to be uploaded with the same name as an</span></li>
<li id="n_46" class="hl">    <span class="hl slc"># existing page.</span></li>
<li id="n_47" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">exists </span><span class="hl kwb">$IkiWiki</span><span class="hl opt">::</span>pagesources<span class="hl opt">{</span><span class="hl kwb">$dest</span><span class="hl opt">} &amp;&amp;</span></li>
<li id="n_48" class="hl">        <span class="hl kwb">$IkiWiki</span><span class="hl opt">::</span>pagesources<span class="hl opt">{</span><span class="hl kwb">$dest</span><span class="hl opt">} </span><span class="hl kwc">ne </span><span class="hl kwb">$dest</span><span class="hl opt">) {</span></li>
<li id="n_49" class="hl">        error<span class="hl opt">(</span><span class="hl kwc">sprintf</span><span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;there is already a page named </span><span class="hl ipl">%s</span><span class="hl sng">&quot;</span><span class="hl opt">), </span><span class="hl kwb">$dest</span><span class="hl opt">));</span></li>
<li id="n_50" class="hl">    <span class="hl opt">}</span></li>
<li id="n_51" class="hl"></li>
<li id="n_52" class="hl">    <span class="hl slc"># Use a special pagespec to test that the attachment is valid.</span></li>
<li id="n_53" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$allowed</span><span class="hl opt">=</span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_54" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$config</span><span class="hl opt">{</span>allowed_attachments<span class="hl opt">} &amp;&amp;</span></li>
<li id="n_55" class="hl">        <span class="hl kwc">length </span><span class="hl kwb">$config</span><span class="hl opt">{</span>allowed_attachments<span class="hl opt">}) {</span></li>
<li id="n_56" class="hl">        <span class="hl kwb">$allowed</span><span class="hl opt">=</span>pagespec_match<span class="hl opt">(</span><span class="hl kwb">$dest</span><span class="hl opt">,</span></li>
<li id="n_57" class="hl">            <span class="hl kwb">$config</span><span class="hl opt">{</span>allowed_attachments<span class="hl opt">},</span></li>
<li id="n_58" class="hl">            file <span class="hl opt">=&gt; </span><span class="hl kwb">$file</span><span class="hl opt">,</span></li>
<li id="n_59" class="hl">            user <span class="hl opt">=&gt; </span><span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">),</span></li>
<li id="n_60" class="hl">            ip <span class="hl opt">=&gt; </span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>REMOTE_ADDR<span class="hl opt">},</span></li>
<li id="n_61" class="hl">        <span class="hl opt">);</span></li>
<li id="n_62" class="hl">    <span class="hl opt">}</span></li>
<li id="n_63" class="hl"></li>
<li id="n_64" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwb">$allowed</span><span class="hl opt">) {</span></li>
<li id="n_65" class="hl">        error<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;prohibited by allowed_attachments&quot;</span><span class="hl opt">).</span><span class="hl sng">&quot; (</span><span class="hl ipl">$allowed</span><span class="hl sng">)&quot;</span><span class="hl opt">);</span></li>
<li id="n_66" class="hl">    <span class="hl opt">}</span></li>
<li id="n_67" class="hl">    <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_68" class="hl">        <span class="hl kwa">return </span><span class="hl num">1</span><span class="hl opt">;</span></li>
<li id="n_69" class="hl">    <span class="hl opt">}</span></li>
<li id="n_70" class="hl"><span class="hl opt">}</span></li>
<li id="n_71" class="hl"></li>
<li id="n_72" class="hl"><span class="hl kwa">sub </span>checkconfig <span class="hl opt">() {</span></li>
<li id="n_73" class="hl">    <span class="hl kwb">$config</span><span class="hl opt">{</span>cgi_disable_uploads<span class="hl opt">}=</span><span class="hl num">0</span><span class="hl opt">;</span></li>
<li id="n_74" class="hl"><span class="hl opt">}</span></li>
<li id="n_75" class="hl"></li>
<li id="n_76" class="hl"><span class="hl kwa">sub </span>formbuilder_setup <span class="hl opt">(&#64;) {</span></li>
<li id="n_77" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%params</span><span class="hl opt">=</span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_78" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$form</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>form<span class="hl opt">};</span></li>
<li id="n_79" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>cgi<span class="hl opt">};</span></li>
<li id="n_80" class="hl"></li>
<li id="n_81" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) &amp;&amp; (</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) </span><span class="hl kwc">eq </span><span class="hl sng">&quot;edit&quot;</span> <span class="hl opt">||</span></li>
<li id="n_82" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) </span><span class="hl kwc">eq </span><span class="hl sng">&quot;create&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_83" class="hl">        <span class="hl slc"># Add attachment field, set type to multipart.</span></li>
<li id="n_84" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">enctype</span><span class="hl opt">(&amp;</span>CGI<span class="hl opt">::</span>MULTIPART<span class="hl opt">);</span></li>
<li id="n_85" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&#39;attachment&#39;</span><span class="hl opt">, </span>type <span class="hl opt">=&gt; </span><span class="hl sng">&#39;file&#39;</span><span class="hl opt">);</span></li>
<li id="n_86" class="hl">        <span class="hl slc"># These buttons are not put in the usual place, so</span></li>
<li id="n_87" class="hl">        <span class="hl slc"># are not added to the normal formbuilder button list.</span></li>
<li id="n_88" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpl_param</span><span class="hl opt">(</span><span class="hl sng">&quot;field-upload&quot;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&lt;input name=&quot;_submit&quot; type=&quot;submit&quot; value=&quot;Upload Attachment&quot; /&gt;&#39;</span><span class="hl opt">);</span></li>
<li id="n_89" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpl_param</span><span class="hl opt">(</span><span class="hl sng">&quot;field-link&quot;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&lt;input name=&quot;_submit&quot; type=&quot;submit&quot; value=&quot;Insert Links&quot; /&gt;&#39;</span><span class="hl opt">);</span></li>
<li id="n_90" class="hl"></li>
<li id="n_91" class="hl">        <span class="hl slc"># Add the toggle javascript; the attachments interface uses</span></li>
<li id="n_92" class="hl">        <span class="hl slc"># it to toggle visibility.</span></li>
<li id="n_93" class="hl">        <span class="hl kwa">require </span>IkiWiki<span class="hl opt">::</span>Plugin<span class="hl opt">::</span>toggle<span class="hl opt">;</span></li>
<li id="n_94" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpl_param</span><span class="hl opt">(</span><span class="hl sng">&quot;javascript&quot;</span> <span class="hl opt">=&gt; </span>IkiWiki<span class="hl opt">::</span>Plugin<span class="hl opt">::</span>toggle<span class="hl opt">::</span>include_javascript<span class="hl opt">(</span><span class="hl kwb">$params</span><span class="hl opt">{</span>page<span class="hl opt">}, </span><span class="hl num">1</span><span class="hl opt">));</span></li>
<li id="n_95" class="hl">        <span class="hl slc"># Start with the attachments interface toggled invisible,</span></li>
<li id="n_96" class="hl">        <span class="hl slc"># but if it was used, keep it open.</span></li>
<li id="n_97" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">ne </span><span class="hl sng">&quot;Upload Attachment&quot;</span> <span class="hl opt">&amp;&amp;</span></li>
<li id="n_98" class="hl">            <span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;attachment_select&quot;</span><span class="hl opt">) ||</span></li>
<li id="n_99" class="hl">            <span class="hl opt">! </span><span class="hl kwc">length </span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;attachment_select&quot;</span><span class="hl opt">))) {</span></li>
<li id="n_100" class="hl">            <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpl_param</span><span class="hl opt">(</span><span class="hl sng">&quot;attachments-class&quot;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&quot;toggleable&quot;</span><span class="hl opt">);</span></li>
<li id="n_101" class="hl">        <span class="hl opt">}</span></li>
<li id="n_102" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_103" class="hl">            <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpl_param</span><span class="hl opt">(</span><span class="hl sng">&quot;attachments-class&quot;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&quot;toggleable-open&quot;</span><span class="hl opt">);</span></li>
<li id="n_104" class="hl">        <span class="hl opt">}</span></li>
<li id="n_105" class="hl">    <span class="hl opt">}</span></li>
<li id="n_106" class="hl"><span class="hl opt">}</span></li>
<li id="n_107" class="hl"></li>
<li id="n_108" class="hl"><span class="hl kwa">sub </span>formbuilder <span class="hl opt">(&#64;) {</span></li>
<li id="n_109" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">%params</span><span class="hl opt">=</span><span class="hl kwb">&#64;_</span><span class="hl opt">;</span></li>
<li id="n_110" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$form</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>form<span class="hl opt">};</span></li>
<li id="n_111" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$q</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>cgi<span class="hl opt">};</span></li>
<li id="n_112" class="hl"></li>
<li id="n_113" class="hl">    <span class="hl kwa">return if </span><span class="hl opt">! </span><span class="hl kwc">defined </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) || (</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) </span><span class="hl kwc">ne </span><span class="hl sng">&quot;edit&quot;</span> <span class="hl opt">&amp;&amp; </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&quot;do&quot;</span><span class="hl opt">) </span><span class="hl kwc">ne </span><span class="hl sng">&quot;create&quot;</span><span class="hl opt">) ;</span></li>
<li id="n_114" class="hl"></li>
<li id="n_115" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$filename</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&#39;attachment&#39;</span><span class="hl opt">);</span></li>
<li id="n_116" class="hl">    <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">defined </span><span class="hl kwb">$filename </span><span class="hl opt">&amp;&amp; </span><span class="hl kwc">length </span><span class="hl kwb">$filename </span><span class="hl opt">&amp;&amp;</span></li>
<li id="n_117" class="hl">            <span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">eq </span><span class="hl sng">&quot;Upload Attachment&quot;</span> <span class="hl opt">|| </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">eq </span><span class="hl sng">&quot;Save Page&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_118" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$session</span><span class="hl opt">=</span><span class="hl kwb">$params</span><span class="hl opt">{</span>session<span class="hl opt">};</span></li>
<li id="n_119" class="hl">        </li>
<li id="n_120" class="hl">        <span class="hl slc"># This is an (apparently undocumented) way to get the name</span></li>
<li id="n_121" class="hl">        <span class="hl slc"># of the temp file that CGI writes the upload to.</span></li>
<li id="n_122" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$tempfile</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpFileName</span><span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">);</span></li>
<li id="n_123" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$tempfile </span><span class="hl opt">|| ! </span><span class="hl kwc">length </span><span class="hl kwb">$tempfile</span><span class="hl opt">) {</span></li>
<li id="n_124" class="hl">            <span class="hl slc"># perl 5.8 needs an alternative, awful method</span></li>
<li id="n_125" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$q </span><span class="hl opt">=~ </span><span class="hl kwd">/HASH/ </span><span class="hl opt">&amp;&amp; </span><span class="hl kwc">exists </span><span class="hl kwb">$q</span><span class="hl opt">-&gt;{</span><span class="hl sng">&#39;.tmpfiles&#39;</span><span class="hl opt">}) {</span></li>
<li id="n_126" class="hl">                <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$key </span><span class="hl opt">(</span><span class="hl kwc">keys</span><span class="hl opt">(%{</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;{</span><span class="hl sng">&#39;.tmpfiles&#39;</span><span class="hl opt">}})) {</span></li>
<li id="n_127" class="hl">                    <span class="hl kwb">$tempfile</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpFileName</span><span class="hl opt">(</span>\<span class="hl kwb">$key</span><span class="hl opt">);</span></li>
<li id="n_128" class="hl">                    <span class="hl kwa">last if </span><span class="hl kwc">defined </span><span class="hl kwb">$tempfile </span><span class="hl opt">&amp;&amp; </span><span class="hl kwc">length </span><span class="hl kwb">$tempfile</span><span class="hl opt">;</span></li>
<li id="n_129" class="hl">                <span class="hl opt">}</span></li>
<li id="n_130" class="hl">            <span class="hl opt">}</span></li>
<li id="n_131" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$tempfile </span><span class="hl opt">|| ! </span><span class="hl kwc">length </span><span class="hl kwb">$tempfile</span><span class="hl opt">) {</span></li>
<li id="n_132" class="hl">                error<span class="hl opt">(</span><span class="hl sng">&quot;CGI::tmpFileName failed to return the uploaded file name&quot;</span><span class="hl opt">);</span></li>
<li id="n_133" class="hl">            <span class="hl opt">}</span></li>
<li id="n_134" class="hl">        <span class="hl opt">}</span></li>
<li id="n_135" class="hl"></li>
<li id="n_136" class="hl">        <span class="hl kwb">$filename</span><span class="hl opt">=</span>linkpage<span class="hl opt">(</span>IkiWiki<span class="hl opt">::</span>possibly_foolish_untaint<span class="hl opt">(</span></li>
<li id="n_137" class="hl">                attachment_location<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&#39;page&#39;</span><span class="hl opt">)).</span></li>
<li id="n_138" class="hl">                IkiWiki<span class="hl opt">::</span>basename<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">)));</span></li>
<li id="n_139" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span>IkiWiki<span class="hl opt">::</span>file_pruned<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>srcdir<span class="hl opt">})) {</span></li>
<li id="n_140" class="hl">            error<span class="hl opt">(</span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;bad attachment filename&quot;</span><span class="hl opt">));</span></li>
<li id="n_141" class="hl">        <span class="hl opt">}</span></li>
<li id="n_142" class="hl">        </li>
<li id="n_143" class="hl">        <span class="hl slc"># Check that the user is allowed to edit a page with the</span></li>
<li id="n_144" class="hl">        <span class="hl slc"># name of the attachment.</span></li>
<li id="n_145" class="hl">        IkiWiki<span class="hl opt">::</span>check_canedit<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">, </span><span class="hl kwb">$q</span><span class="hl opt">, </span><span class="hl kwb">$session</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">);</span></li>
<li id="n_146" class="hl">        <span class="hl slc"># And that the attachment itself is acceptable.</span></li>
<li id="n_147" class="hl">        check_canattach<span class="hl opt">(</span><span class="hl kwb">$session</span><span class="hl opt">, </span><span class="hl kwb">$filename</span><span class="hl opt">, </span><span class="hl kwb">$tempfile</span><span class="hl opt">);</span></li>
<li id="n_148" class="hl"></li>
<li id="n_149" class="hl">        <span class="hl slc"># Needed for fast_file_copy and for rendering below.</span></li>
<li id="n_150" class="hl">        <span class="hl kwa">require </span>IkiWiki<span class="hl opt">::</span>Render<span class="hl opt">;</span></li>
<li id="n_151" class="hl"></li>
<li id="n_152" class="hl">        <span class="hl slc"># Move the attachment into place.</span></li>
<li id="n_153" class="hl">        <span class="hl slc"># Try to use a fast rename; fall back to copying.</span></li>
<li id="n_154" class="hl">        IkiWiki<span class="hl opt">::</span>prep_writefile<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>srcdir<span class="hl opt">});</span></li>
<li id="n_155" class="hl">        <span class="hl kwc">unlink</span><span class="hl opt">(</span><span class="hl kwb">$config</span><span class="hl opt">{</span>srcdir<span class="hl opt">}.</span><span class="hl sng">&quot;/&quot;</span><span class="hl opt">.</span><span class="hl kwb">$filename</span><span class="hl opt">);</span></li>
<li id="n_156" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwc">rename</span><span class="hl opt">(</span><span class="hl kwb">$tempfile</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>srcdir<span class="hl opt">}.</span><span class="hl sng">&quot;/&quot;</span><span class="hl opt">.</span><span class="hl kwb">$filename</span><span class="hl opt">)) {</span></li>
<li id="n_157" class="hl">            <span class="hl slc"># The temp file has tight permissions; loosen up.</span></li>
<li id="n_158" class="hl">            <span class="hl kwc">chmod</span><span class="hl opt">(</span><span class="hl num">0666 </span><span class="hl opt">&amp; ~</span><span class="hl kwc">umask</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>srcdir<span class="hl opt">}.</span><span class="hl sng">&quot;/&quot;</span><span class="hl opt">.</span><span class="hl kwb">$filename</span><span class="hl opt">);</span></li>
<li id="n_159" class="hl">        <span class="hl opt">}</span></li>
<li id="n_160" class="hl">        <span class="hl kwa">else </span><span class="hl opt">{</span></li>
<li id="n_161" class="hl">            <span class="hl kwc">my </span><span class="hl kwb">$fh</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">upload</span><span class="hl opt">(</span><span class="hl sng">&#39;attachment&#39;</span><span class="hl opt">);</span></li>
<li id="n_162" class="hl">            <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$fh </span><span class="hl opt">|| ! </span><span class="hl kwc">ref </span><span class="hl kwb">$fh</span><span class="hl opt">) {</span></li>
<li id="n_163" class="hl">                <span class="hl slc"># needed by old CGI versions</span></li>
<li id="n_164" class="hl">                <span class="hl kwb">$fh</span><span class="hl opt">=</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&#39;attachment&#39;</span><span class="hl opt">);</span></li>
<li id="n_165" class="hl">                <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span><span class="hl kwb">$fh </span><span class="hl opt">|| ! </span><span class="hl kwc">ref </span><span class="hl kwb">$fh</span><span class="hl opt">) {</span></li>
<li id="n_166" class="hl">                    <span class="hl slc"># even that doesn&#39;t always work,</span></li>
<li id="n_167" class="hl">                    <span class="hl slc"># fall back to opening the tempfile</span></li>
<li id="n_168" class="hl">                    <span class="hl kwb">$fh</span><span class="hl opt">=</span><span class="hl kwc">undef</span><span class="hl opt">;</span></li>
<li id="n_169" class="hl">                    <span class="hl kwc">open</span><span class="hl opt">(</span><span class="hl kwb">$fh</span><span class="hl opt">, </span><span class="hl sng">&quot;&lt;&quot;</span><span class="hl opt">, </span><span class="hl kwb">$tempfile</span><span class="hl opt">) || </span>error<span class="hl opt">(</span><span class="hl sng">&quot;failed to open </span><span class="hl esc">\&quot;</span><span class="hl sng"></span><span class="hl ipl">$tempfile</span><span class="hl sng"></span><span class="hl esc">\&quot;</span><span class="hl sng">: </span><span class="hl ipl">$!</span><span class="hl sng">&quot;</span><span class="hl opt">);</span></li>
<li id="n_170" class="hl">                <span class="hl opt">}</span></li>
<li id="n_171" class="hl">            <span class="hl opt">}</span></li>
<li id="n_172" class="hl">            <span class="hl kwc">binmode</span><span class="hl opt">(</span><span class="hl kwb">$fh</span><span class="hl opt">);</span></li>
<li id="n_173" class="hl">            writefile<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">, </span><span class="hl kwb">$config</span><span class="hl opt">{</span>srcdir<span class="hl opt">}, </span><span class="hl kwc">undef</span><span class="hl opt">, </span><span class="hl num">1</span><span class="hl opt">, </span><span class="hl kwa">sub </span><span class="hl opt">{</span></li>
<li id="n_174" class="hl">                IkiWiki<span class="hl opt">::</span>fast_file_copy<span class="hl opt">(</span><span class="hl kwb">$tempfile</span><span class="hl opt">, </span><span class="hl kwb">$filename</span><span class="hl opt">, </span><span class="hl kwb">$fh</span><span class="hl opt">, </span><span class="hl kwb">&#64;_</span><span class="hl opt">);</span></li>
<li id="n_175" class="hl">            <span class="hl opt">});</span></li>
<li id="n_176" class="hl">        <span class="hl opt">}</span></li>
<li id="n_177" class="hl"></li>
<li id="n_178" class="hl">        <span class="hl slc"># Check the attachment in and trigger a wiki refresh.</span></li>
<li id="n_179" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(</span><span class="hl kwb">$config</span><span class="hl opt">{</span>rcs<span class="hl opt">}) {</span></li>
<li id="n_180" class="hl">            IkiWiki<span class="hl opt">::</span>rcs_add<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">);</span></li>
<li id="n_181" class="hl">            IkiWiki<span class="hl opt">::</span>disable_commit_hook<span class="hl opt">();</span></li>
<li id="n_182" class="hl">            IkiWiki<span class="hl opt">::</span>rcs_commit<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">, </span>gettext<span class="hl opt">(</span><span class="hl sng">&quot;attachment upload&quot;</span><span class="hl opt">),</span></li>
<li id="n_183" class="hl">                IkiWiki<span class="hl opt">::</span>rcs_prepedit<span class="hl opt">(</span><span class="hl kwb">$filename</span><span class="hl opt">),</span></li>
<li id="n_184" class="hl">                <span class="hl kwb">$session</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;name&quot;</span><span class="hl opt">), </span><span class="hl kwb">$ENV</span><span class="hl opt">{</span>REMOTE_ADDR<span class="hl opt">});</span></li>
<li id="n_185" class="hl">            IkiWiki<span class="hl opt">::</span>enable_commit_hook<span class="hl opt">();</span></li>
<li id="n_186" class="hl">            IkiWiki<span class="hl opt">::</span>rcs_update<span class="hl opt">();</span></li>
<li id="n_187" class="hl">        <span class="hl opt">}</span></li>
<li id="n_188" class="hl">        IkiWiki<span class="hl opt">::</span>refresh<span class="hl opt">();</span></li>
<li id="n_189" class="hl">        IkiWiki<span class="hl opt">::</span>saveindex<span class="hl opt">();</span></li>
<li id="n_190" class="hl">    <span class="hl opt">}</span></li>
<li id="n_191" class="hl">    <span class="hl kwa">elsif </span><span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">submitted </span><span class="hl kwc">eq </span><span class="hl sng">&quot;Insert Links&quot;</span><span class="hl opt">) {</span></li>
<li id="n_192" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$page</span><span class="hl opt">=</span><span class="hl kwc">quotemeta</span><span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;page&quot;</span><span class="hl opt">));</span></li>
<li id="n_193" class="hl">        <span class="hl kwc">my </span><span class="hl kwb">$add</span><span class="hl opt">=</span><span class="hl sng">&quot;&quot;</span><span class="hl opt">;</span></li>
<li id="n_194" class="hl">        <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$f </span><span class="hl opt">(</span><span class="hl kwb">$q</span><span class="hl opt">-&gt;</span><span class="hl kwd">param</span><span class="hl opt">(</span><span class="hl sng">&quot;attachment_select&quot;</span><span class="hl opt">)) {</span></li>
<li id="n_195" class="hl">            <span class="hl kwb">$f</span><span class="hl opt">=~</span><span class="hl kwd">s/^$page\//</span><span class="hl opt">/;</span></li>
<li id="n_196" class="hl">            <span class="hl kwb">$add</span><span class="hl opt">.=</span><span class="hl sng">&quot;[[</span><span class="hl ipl">$f</span><span class="hl sng">]]</span><span class="hl esc">\n</span><span class="hl sng">&quot;</span><span class="hl opt">;</span></li>
<li id="n_197" class="hl">        <span class="hl opt">}</span></li>
<li id="n_198" class="hl">        <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span>name <span class="hl opt">=&gt; </span><span class="hl sng">&#39;editcontent&#39;</span><span class="hl opt">,</span></li>
<li id="n_199" class="hl">            value <span class="hl opt">=&gt; </span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&#39;editcontent&#39;</span><span class="hl opt">).</span><span class="hl sng">&quot;</span><span class="hl esc">\n\n</span><span class="hl sng">&quot;</span><span class="hl opt">.</span><span class="hl kwb">$add</span><span class="hl opt">,</span></li>
<li id="n_200" class="hl">            force <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">) </span><span class="hl kwa">if </span><span class="hl kwc">length </span><span class="hl kwb">$add</span><span class="hl opt">;</span></li>
<li id="n_201" class="hl">    <span class="hl opt">}</span></li>
<li id="n_202" class="hl">    </li>
<li id="n_203" class="hl">    <span class="hl slc"># Generate the attachment list only after having added any new</span></li>
<li id="n_204" class="hl">    <span class="hl slc"># attachments.</span></li>
<li id="n_205" class="hl">    <span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">tmpl_param</span><span class="hl opt">(</span><span class="hl sng">&quot;attachment_list&quot;</span> <span class="hl opt">=&gt; [</span>attachment_list<span class="hl opt">(</span><span class="hl kwb">$form</span><span class="hl opt">-&gt;</span><span class="hl kwd">field</span><span class="hl opt">(</span><span class="hl sng">&#39;page&#39;</span><span class="hl opt">))]);</span></li>
<li id="n_206" class="hl"><span class="hl opt">}</span></li>
<li id="n_207" class="hl"></li>
<li id="n_208" class="hl"><span class="hl kwa">sub </span>attachment_location <span class="hl opt">($) {</span></li>
<li id="n_209" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$page</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_210" class="hl">    </li>
<li id="n_211" class="hl">    <span class="hl slc"># Put the attachment in a subdir of the page it&#39;s attached</span></li>
<li id="n_212" class="hl">    <span class="hl slc"># to, unless that page is an &quot;index&quot; page.</span></li>
<li id="n_213" class="hl">    <span class="hl kwb">$page</span><span class="hl opt">=~</span><span class="hl kwd">s/(^|\/)index/</span><span class="hl opt">/;</span></li>
<li id="n_214" class="hl">    <span class="hl kwb">$page</span><span class="hl opt">.=</span><span class="hl sng">&quot;/&quot;</span> <span class="hl kwa">if </span><span class="hl kwc">length </span><span class="hl kwb">$page</span><span class="hl opt">;</span></li>
<li id="n_215" class="hl">    </li>
<li id="n_216" class="hl">    <span class="hl kwa">return </span><span class="hl kwb">$page</span><span class="hl opt">;</span></li>
<li id="n_217" class="hl"><span class="hl opt">}</span></li>
<li id="n_218" class="hl"></li>
<li id="n_219" class="hl"><span class="hl kwa">sub </span>attachment_list <span class="hl opt">($) {</span></li>
<li id="n_220" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$page</span><span class="hl opt">=</span><span class="hl kwc">shift</span><span class="hl opt">;</span></li>
<li id="n_221" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">$loc</span><span class="hl opt">=</span>attachment_location<span class="hl opt">(</span><span class="hl kwb">$page</span><span class="hl opt">);</span></li>
<li id="n_222" class="hl"></li>
<li id="n_223" class="hl">    <span class="hl kwc">my </span><span class="hl kwb">&#64;ret</span><span class="hl opt">;</span></li>
<li id="n_224" class="hl">    <span class="hl kwa">foreach </span><span class="hl kwc">my </span><span class="hl kwb">$f </span><span class="hl opt">(</span><span class="hl kwc">values </span><span class="hl kwb">%pagesources</span><span class="hl opt">) {</span></li>
<li id="n_225" class="hl">        <span class="hl kwa">if </span><span class="hl opt">(! </span><span class="hl kwc">defined </span>pagetype<span class="hl opt">(</span><span class="hl kwb">$f</span><span class="hl opt">) &amp;&amp;</span></li>
<li id="n_226" class="hl">            <span class="hl kwb">$f</span><span class="hl opt">=~</span><span class="hl kwd">m/^\Q$loc\E[^\/</span><span class="hl opt">]+</span><span class="hl kwb">$/ </span><span class="hl opt">&amp;&amp;</span></li>
<li id="n_227" class="hl">            <span class="hl opt">-</span>e <span class="hl sng">&quot;</span><span class="hl ipl">$config</span><span class="hl sng">{srcdir}/</span><span class="hl ipl">$f</span><span class="hl sng">&quot;</span><span class="hl opt">) {</span></li>
<li id="n_228" class="hl">            <span class="hl kwc">push </span><span class="hl kwb">&#64;ret</span><span class="hl opt">, {</span></li>
<li id="n_229" class="hl">                <span class="hl sng">&quot;field-select&quot;</span> <span class="hl opt">=&gt; </span><span class="hl sng">&#39;&lt;input type=&quot;checkbox&quot; name=&quot;attachment_select&quot; value=&quot;&#39;</span><span class="hl opt">.</span><span class="hl kwb">$f</span><span class="hl opt">.</span><span class="hl sng">&#39;&quot; /&gt;&#39;</span><span class="hl opt">,</span></li>
<li id="n_230" class="hl">                <span class="hl kwc">link </span><span class="hl opt">=&gt; </span>htmllink<span class="hl opt">(</span><span class="hl kwb">$page</span><span class="hl opt">, </span><span class="hl kwb">$page</span><span class="hl opt">, </span><span class="hl kwb">$f</span><span class="hl opt">, </span>noimageinline <span class="hl opt">=&gt; </span><span class="hl num">1</span><span class="hl opt">),</span></li>
<li id="n_231" class="hl">                size <span class="hl opt">=&gt; </span>IkiWiki<span class="hl opt">::</span>Plugin<span class="hl opt">::</span>filecheck<span class="hl opt">::</span>humansize<span class="hl opt">((</span><span class="hl kwc">stat</span><span class="hl opt">(</span>_<span class="hl opt">))[</span><span class="hl num">7</span><span class="hl opt">]),</span></li>
<li id="n_232" class="hl">                mtime <span class="hl opt">=&gt; </span>displaytime<span class="hl opt">(</span><span class="hl kwb">$IkiWiki</span><span class="hl opt">::</span>pagemtime<span class="hl opt">{</span><span class="hl kwb">$f</span><span class="hl opt">}),</span></li>
<li id="n_233" class="hl">            <span class="hl opt">};</span></li>
<li id="n_234" class="hl">        <span class="hl opt">}</span></li>
<li id="n_235" class="hl">    <span class="hl opt">}</span></li>
<li id="n_236" class="hl"></li>
<li id="n_237" class="hl">    <span class="hl slc"># Sort newer attachments to the top of the list, so a newly-added</span></li>
<li id="n_238" class="hl">    <span class="hl slc"># attachment appears just before the form used to add it.</span></li>
<li id="n_239" class="hl">    <span class="hl kwa">return </span><span class="hl kwc">sort </span><span class="hl opt">{ </span><span class="hl kwb">$b</span><span class="hl opt">-&gt;{</span>mtime_raw<span class="hl opt">} &lt;=&gt; </span><span class="hl kwb">$a</span><span class="hl opt">-&gt;{</span>mtime_raw<span class="hl opt">} || </span><span class="hl kwb">$a</span><span class="hl opt">-&gt;{</span><span class="hl kwc">link</span><span class="hl opt">} </span><span class="hl kwc">cmp </span><span class="hl kwb">$b</span><span class="hl opt">-&gt;{</span><span class="hl kwc">link</span><span class="hl opt">} } </span><span class="hl kwb">&#64;ret</span><span class="hl opt">;</span></li>
<li id="n_240" class="hl"><span class="hl opt">}</span></li>
<li id="n_241" class="hl"></li>
<li id="n_242" class="hl"><span class="hl num">1</span></li>
</ol></code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.46.0</a>) at 2025-06-14 15:57:45 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
