Back to index

moin  1.9.0~rc2
fckdialog.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - feed some FCKeditor dialogues
00004 
00005     @copyright: 2005-2006 Bastian Blank, Florian Festi, Thomas Waldmann
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 from MoinMoin import config, wikiutil
00010 from MoinMoin.action.AttachFile import _get_files
00011 from MoinMoin.Page import Page
00012 import re
00013 
00014 ##############################################################################
00015 ### Macro dialog
00016 ##############################################################################
00017 
00018 def macro_dialog(request):
00019     help = get_macro_help(request)
00020     request.write(
00021         '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00022 <html>
00023  <head>
00024   <title>Insert Macro</title>
00025   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
00026   <meta content="noindex,nofollow" name="robots">
00027   <script src="%s/applets/FCKeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
00028   <script language="javascript">
00029 
00030 var oEditor = window.parent.InnerDialogLoaded() ;
00031 var FCKLang = oEditor.FCKLang ;
00032 var FCKMacros = oEditor.FCKMacros ;
00033 
00034 window.onload = function ()
00035 {
00036  // First of all, translate the dialog box texts
00037  oEditor.FCKLanguageManager.TranslatePage( document ) ;
00038 
00039  OnChange( "BR" );
00040 
00041  // Show the "Ok" button.
00042  window.parent.SetOkButton( true ) ;
00043 }
00044 
00045 function Ok()
00046 {
00047  if ( document.getElementById('txtName').value.length == 0 )
00048  {
00049   alert( FCKLang.MacroErrNoName ) ;
00050   return false ;
00051  }
00052 
00053  FCKMacros.Add( txtName.value ) ;
00054  return true ;
00055 }
00056 
00057 function OnChange( sMacro )
00058 {
00059   // sMacro = GetE("txtName").value;
00060   oHelp = GetE("help");
00061   for (var i=0; i<oHelp.childNodes.length; i++)
00062   {
00063     var oDiv = oHelp.childNodes[i];
00064     if (oDiv.nodeType==1)
00065     {
00066       // oDiv.style.display = (GetAttribute(oDiv, "id", "")==sMacro) ? '' : 'none';
00067       if (GetAttribute(oDiv, "id", "") == sMacro)
00068       {
00069           oDiv.style.display = '' ;
00070           // alert("enabled div id " + sMacro) ;
00071       }
00072       else
00073       {
00074           oDiv.style.display = 'none' ;
00075       }
00076     }
00077   }
00078 }
00079 
00080   </script>
00081  </head>
00082  <body scroll="no" style="OVERFLOW: hidden">
00083   <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
00084    <tr>
00085     <td>
00086      <table cellSpacing="0" cellPadding="0" align="center" border="0">
00087       <tr>
00088        <td valign="top">
00089        <span fckLang="MacroDlgName">Macro Name</span><br>
00090        <select id="txtName" size="10" onchange="OnChange(this.value);">
00091 ''' % request.cfg.url_prefix_static)
00092 
00093     macros = []
00094     for macro in macro_list(request):
00095         if macro == "BR":
00096             selected = ' selected="selected"'
00097         else:
00098             selected = ''
00099         if macro in help:
00100             macros.append('<option value="%s"%s>%s</option>' %
00101                           (help[macro].group('prototype'), selected, macro))
00102         else:
00103             macros.append('<option value="%s"%s>%s</option>' %
00104                           (macro, selected, macro))
00105 
00106     request.write('\n'.join(macros))
00107     request.write('''
00108        </select>
00109      </td>
00110      <td id="help">''')
00111 
00112     helptexts = []
00113     for macro in macro_list(request):
00114         if macro in help:
00115             match = help[macro]
00116             prototype = match.group('prototype')
00117             helptext = match.group('help')
00118         else:
00119             prototype = macro
00120             helptext = ""
00121         helptexts.append(
00122             '''<div id="%s" style="DISPLAY: none">
00123                <b>&lt;&lt;%s&gt;&gt;</b>
00124                <br/>
00125                <textarea style="color:#000000" cols="37" rows="10" disabled="disabled">%s</textarea>
00126                </div>'''
00127             % (prototype, prototype, helptext))
00128 
00129     request.write(''.join(helptexts))
00130     request.write('''
00131      </td>
00132     </tr>
00133    </table>
00134   </td>
00135  </tr>
00136 </table>
00137 </body>
00138 </html>
00139 ''')
00140 
00141 def macro_list(request):
00142     from MoinMoin import macro
00143     macros = macro.getNames(request.cfg)
00144     macros.sort()
00145     return macros
00146 
00147 def get_macro_help(request):
00148     """ Read help texts from SystemPage('HelpOnMacros')"""
00149     helppage = wikiutil.getLocalizedPage(request, "HelpOnMacros")
00150     content = helppage.get_raw_body()
00151     macro_re = re.compile(
00152         r"\|\|(<.*?>)?\{\{\{" +
00153         r"<<(?P<prototype>(?P<macro>\w*).*)>>" +
00154         r"\}\}\}\s*\|\|" +
00155         r"[^|]*\|\|[^|]*\|\|<[^>]*>" +
00156         r"\s*(?P<help>.*?)\s*\|\|\s*(?P<example>.*?)\s*(<<[^>]*>>)*\s*\|\|$", re.U|re.M)
00157     help = {}
00158     for match in macro_re.finditer(content):
00159         help[match.group('macro')] = match
00160     return help
00161 
00162 ##############################################################################
00163 ### Link dialog
00164 ##############################################################################
00165 
00166 def page_list(request):
00167     from MoinMoin import search
00168     name = request.values.get("pagename", "")
00169     if name:
00170         searchresult = search.searchPages(request, 't:"%s"' % name)
00171         pages = [p.page_name for p in searchresult.hits]
00172     else:
00173         pages = [name]
00174     request.write(
00175         '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00176 <html>
00177  <head>
00178   <title>Insert Page Link</title>
00179   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
00180   <meta content="noindex,nofollow" name="robots">
00181  </head>
00182  <body scroll="no" style="OVERFLOW: hidden">
00183   <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
00184    <tr>
00185     <td>
00186      <table cellSpacing="0" cellPadding="0" align="center" border="0">
00187       <tr>
00188        <td>
00189        <span fckLang="PageDlgName">Page Name</span><br>
00190        <select id="txtName" size="1">
00191        %s
00192        </select>
00193      </td>
00194     </tr>
00195    </table>
00196   </td>
00197  </tr>
00198 </table>
00199 </body>
00200 </html>
00201 ''' % "".join(["<option>%s</option>\n" % p for p in pages]))
00202 
00203 def link_dialog(request):
00204     # list of wiki pages
00205     name = request.values.get("pagename", "")
00206     if name:
00207         from MoinMoin import search
00208         # XXX error handling!
00209         searchresult = search.searchPages(request, 't:"%s"' % name)
00210 
00211         pages = [p.page_name for p in searchresult.hits]
00212         pages.sort()
00213         pages[0:0] = [name]
00214         page_list = '''
00215          <tr>
00216           <td colspan=2>
00217            <select id="sctPagename" size="1" onchange="OnChangePagename(this.value);">
00218            %s
00219            </select>
00220           <td>
00221          </tr>
00222 ''' % "\n".join(['<option value="%s">%s</option>' % (page, page)
00223                  for page in pages])
00224     else:
00225         page_list = ""
00226 
00227     # list of interwiki names
00228     interwiki_list = wikiutil.load_wikimap(request)
00229     interwiki = interwiki_list.keys()
00230     interwiki.sort()
00231     iwpreferred = request.cfg.interwiki_preferred[:]
00232     if not iwpreferred or iwpreferred and iwpreferred[-1] is not None:
00233         resultlist = iwpreferred
00234         for iw in interwiki:
00235             if not iw in iwpreferred:
00236                 resultlist.append(iw)
00237     else:
00238         resultlist = iwpreferred[:-1]
00239     interwiki = "\n".join(
00240         ['<option value="%s">%s</option>' % (key, key) for key in resultlist])
00241 
00242     # wiki url
00243     url_prefix_static = request.cfg.url_prefix_static
00244     scriptname = request.script_root + '/'
00245     action = scriptname
00246     basepage = request.page.page_name
00247     request.write(u'''
00248 <!--
00249  * FCKeditor - The text editor for internet
00250  * Copyright (C) 2003-2004 Frederico Caldeira Knabben
00251  *
00252  * Licensed under the terms of the GNU Lesser General Public License:
00253  *   http://www.opensource.org/licenses/lgpl-license.php
00254  *
00255  * For further information visit:
00256  *   http://www.fckeditor.net/
00257  *
00258  * File Name: fck_link.html
00259  *  Link dialog window.
00260  *
00261  * Version:  2.0 FC (Preview)
00262  * Modified: 2005-02-18 23:55:22
00263  *
00264  * File Authors:
00265  *   Frederico Caldeira Knabben (fredck@fckeditor.net)
00266 -->
00267 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00268 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
00269 <meta name="robots" content="index,nofollow">
00270 <html>
00271  <head>
00272   <title>Link Properties</title>
00273   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
00274   <meta name="robots" content="noindex,nofollow" />
00275   <script src="%(url_prefix_static)s/applets/FCKeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
00276   <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinlink/fck_link.js" type="text/javascript"></script>
00277   <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinurllib.js" type="text/javascript"></script>
00278  </head>
00279  <body scroll="no" style="OVERFLOW: hidden">
00280   <div id="divInfo" style="DISPLAY: none">
00281    <span fckLang="DlgLnkType">Link Type</span><br />
00282    <select id="cmbLinkType" onchange="SetLinkType(this.value);">
00283     <option value="wiki" selected="selected">WikiPage</option>
00284     <option value="interwiki">Interwiki</option>
00285     <option value="url" fckLang="DlgLnkTypeURL">URL</option>
00286    </select>
00287    <br />
00288    <br />
00289    <div id="divLinkTypeWiki">
00290     <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
00291      <tr>
00292       <td>
00293        <form action=%(action)s method="GET">
00294        <input type="hidden" name="action" value="fckdialog">
00295        <input type="hidden" name="dialog" value="link">
00296        <input type="hidden" id="basepage" name="basepage" value="%(basepage)s">
00297        <table cellSpacing="0" cellPadding="0" align="center" border="0">
00298         <tr>
00299          <td>
00300           <span fckLang="PageDlgName">Page Name</span><br>
00301           <input id="txtPagename" name="pagename" size="30" value="%(name)s">
00302          </td>
00303          <td valign="bottom">
00304            <input id=btnSearchpage type="submit" value="Search">
00305          </td>
00306         </tr>
00307         %(page_list)s
00308        </table>
00309        </form>
00310       </td>
00311      </tr>
00312     </table>
00313    </div>
00314    <div id="divLinkTypeInterwiki">
00315     <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
00316      <tr>
00317       <td>
00318        <table cellSpacing="0" cellPadding="0" align="center" border="0">
00319         <tr>
00320          <td>
00321           <span fckLang="WikiDlgName">Wiki:PageName</span><br>
00322           <select id="sctInterwiki" size="1">
00323           %(interwiki)s
00324           </select>:
00325           <input id="txtInterwikipagename"></input>
00326          </td>
00327         </tr>
00328        </table>
00329       </td>
00330      </tr>
00331     </table>
00332    </div>
00333    <div id="divLinkTypeUrl">
00334     <table cellspacing="0" cellpadding="0" width="100%%" border="0">
00335      <tr>
00336       <td nowrap="nowrap">
00337        <span fckLang="DlgLnkProto">Protocol</span><br />
00338        <select id="cmbLinkProtocol">
00339         <option value="http://" selected="selected">http://</option>
00340         <option value="https://">https://</option>
00341         <option value="ftp://">ftp://</option>
00342         <option value="file://">file://</option>
00343         <option value="news://">news://</option>
00344         <option value="mailto:">mailto:</option>
00345         <option value="" fckLang="DlgLnkProtoOther">&lt;other&gt;</option>
00346        </select>
00347       </td>
00348       <td nowrap="nowrap">&nbsp;</td>
00349       <td nowrap="nowrap" width="100%%">
00350        <span fckLang="DlgLnkURL">URL</span><br />
00351        <input id="txtUrl" style="WIDTH: 100%%" type="text" onkeyup="OnUrlChange();" onchange="OnUrlChange();" />
00352       </td>
00353      </tr>
00354     </table>
00355     <br />
00356    </div>
00357   </div>
00358  </body>
00359 </html>
00360 ''' % locals())
00361 
00362 
00363 def attachment_dialog(request):
00364     """ Attachment dialog for GUI editor. """
00365     """ Features: This dialog can... """
00366     """ - list attachments in a drop down list """
00367     """ - list attachments also for a different page than the current one """
00368     """ - create new attachment """
00369     _ = request.getText
00370     url_prefix_static = request.cfg.url_prefix_static
00371 
00372     # wiki url
00373     action = request.script_root + "/"
00374 
00375     # The following code lines implement the feature "list attachments for a different page".
00376     # Meaning of the variables:
00377     # - requestedPagename : Name of the page where attachments shall be listed from.
00378     # - attachmentsPagename : Name of the page where the attachments where retrieved from.
00379     # - destinationPagename : Name of the page where attachment will be placed on.
00380 
00381     requestedPagename = wikiutil.escape(request.values.get("requestedPagename", ""), quote=True)
00382     destinationPagename = wikiutil.escape(request.values.get("destinationPagename", request.page.page_name), quote=True)
00383 
00384     attachmentsPagename = requestedPagename or request.page.page_name
00385     attachments = _get_files(request, attachmentsPagename)
00386     attachments.sort()
00387     attachmentList = '''
00388         <select id="sctAttachments" size="10" style="width:100%%;visibility:hidden;" onchange="OnAttachmentListChange();">
00389         %s
00390         </select>
00391 ''' % "\n".join(['<option value="%s">%s</option>' % (wikiutil.escape(attachment, quote=True), wikiutil.escape(attachment, quote=True))
00392                  for attachment in attachments])
00393 
00394     # Translation of dialog texts.
00395     langAttachmentLocation = _("Attachment location")
00396     langPagename = _("Page name")
00397     langAttachmentname = _("Attachment name")
00398     langListAttachmentsButton = _("Refresh attachment list")
00399     langAttachmentList = _("List of attachments")
00400 
00401     if len(attachmentsPagename) > 50:
00402         shortenedPagename = "%s ... %s" % (attachmentsPagename[0:25], attachmentsPagename[-25:])
00403     else:
00404         shortenedPagename = attachmentsPagename
00405     langAvailableAttachments = "%s: %s" % (_("Available attachments for page"), shortenedPagename)
00406 
00407     request.write('''
00408 <!--
00409  * FCKeditor - The text editor for internet
00410  * Copyright (C) 2003-2004 Frederico Caldeira Knabben
00411  *
00412  * Licensed under the terms of the GNU Lesser General Public License:
00413  *   http://www.opensource.org/licenses/lgpl-license.php
00414  *
00415  * For further information visit:
00416  *   http://www.fckeditor.net/
00417  *
00418  * File Name: fck_attachment.html
00419  *  Attachment dialog window.
00420  *
00421  * Version:  2.0 FC (Preview)
00422  * Modified: 2005-02-18 23:55:22
00423  *
00424  * File Authors:
00425  *   Frederico Caldeira Knabben (fredck@fckeditor.net)
00426 -->
00427 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00428 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
00429 <meta name="robots" content="index,nofollow">
00430 <html>
00431  <head>
00432   <title>Attachment Properties</title>
00433   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
00434   <meta name="robots" content="noindex,nofollow" />
00435   <script src="%(url_prefix_static)s/applets/FCKeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
00436   <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinattachment/fck_attachment.js" type="text/javascript"></script>
00437   <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinurllib.js" type="text/javascript"></script>
00438  </head>
00439  <body scroll="no" style="OVERFLOW: hidden">
00440     <form id="DlgAttachmentForm" name="DlgAttachmentForm" action=%(action)s method="GET">
00441     <input type="hidden" name="action" value="fckdialog">
00442     <input type="hidden" name="dialog" value="attachment">
00443     <input type="hidden" id="requestedPagename" name="requestedPagename" value="%(requestedPagename)s">
00444     <input type="hidden" id="attachmentsPagename" name="attachmentsPagename" value="%(attachmentsPagename)s">
00445     <input type="hidden" id="destinationPagename" name="destinationPagename" value="%(destinationPagename)s">
00446 
00447     <div id="divInfo" style="valign=top;">
00448     <div id="divLinkTypeAttachment">
00449     <fieldset>
00450     <legend>%(langAttachmentLocation)s</legend>
00451     <table cellSpacing="0" cellPadding="0" width="100%%" border="0">
00452         <tr>
00453             <td valign="bottom" style="width:90%%" style="padding-bottom:10px">
00454                 <span>%(langPagename)s</span><br>
00455             </td>
00456         </tr>
00457         <tr>
00458             <td valign="bottom" style="width:100%%" style="padding-bottom:10px;padding-right:10px;">
00459                 <input id="txtPagename" type="text" onkeyup="OnPagenameChange();" onchange="OnPagenameChange();" style="width:98%%">
00460             </td>
00461         </tr>
00462         <tr>
00463             <td valign="bottom" style="width:90%%" style="padding-bottom:10px;">
00464                 <span>%(langAttachmentname)s</span><br>
00465             </td>
00466         </tr>
00467         <tr valign="bottom">
00468             <td valign="bottom" style="width:100%%" style="padding-bottom:10px;padding-right:10px;">
00469                 <input id="txtAttachmentname" type="text" onkeyup="OnAttachmentnameChange();" onchange="OnPagenameChange();" style="width:98%%"><br>
00470             </td>
00471         </tr>
00472     </table>
00473     </fieldset>
00474     <fieldset>
00475     <legend>%(langAvailableAttachments)s</legend>
00476     <table cellSpacing="0" cellPadding="0" width="100%%" border="0">
00477         <tr>
00478             <td valign="bottom" style="width:100%%" style="padding-bottom:10px">
00479                 <input id="btnListAttachments" type="submit" value="%(langListAttachmentsButton)s">
00480             </td>
00481         </tr>
00482         <tr>
00483             <td valign="top" style="padding-top:10px">
00484                 <label for="sctAttachments">%(langAttachmentList)s</label><br>
00485                 %(attachmentList)s
00486             </td>
00487         </tr>
00488     </table>
00489     </fieldset>
00490    </div>
00491   </div>
00492    </form>
00493  </body>
00494 </html>
00495 ''' % locals())
00496 
00497 
00498 ##############################################################################
00499 ### Image dialog
00500 ##############################################################################
00501 
00502 def image_dialog(request):
00503     url_prefix_static = request.cfg.url_prefix_static
00504     request.write('''
00505 <!--
00506  * FCKeditor - The text editor for internet
00507  * Copyright (C) 2003-2004 Frederico Caldeira Knabben
00508  *
00509  * Licensed under the terms of the GNU Lesser General Public License:
00510  *   http://www.opensource.org/licenses/lgpl-license.php
00511  *
00512  * For further information visit:
00513  *   http://www.fckeditor.net/
00514  *
00515  * File Authors:
00516  *   Frederico Caldeira Knabben (fredck@fckeditor.net)
00517  *   Florian Festi
00518 -->
00519 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00520 <html>
00521  <head>
00522   <title>Link Properties</title>
00523   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
00524   <meta name="robots" content="noindex,nofollow" />
00525   <script src="%(url_prefix_static)s/applets/FCKeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
00526   <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinimage/fck_image.js" type="text/javascript"></script>
00527   <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinurllib.js" type="text/javascript"></script>
00528  </head>
00529  <body scroll="no" style="OVERFLOW: hidden">
00530     <table cellspacing="0" cellpadding="0" width="100%%" border="0">
00531      <tr>
00532       <td nowrap="nowrap">
00533        <span fckLang="DlgLnkProto">Protocol</span><br />
00534        <select id="cmbLinkProtocol" onchange="OnProtocolChange();">
00535         <option value="attachment:" selected="selected">attachment:</option>
00536         <option value="http://">http://</option>
00537         <option value="https://">https://</option>
00538         <!-- crashes often: <option value="drawing:">drawing:</option> -->
00539         <option value="" fckLang="DlgLnkProtoOther">&lt;other&gt;</option>
00540        </select>
00541       </td>
00542       <td nowrap="nowrap">&nbsp;</td>
00543       <td nowrap="nowrap" width="100%%">
00544        <span fckLang="DlgLnkURL">URL or File Name (attachment:)</span><br />
00545        <input id="txtUrl" style="WIDTH: 100%%" type="text" onkeyup="OnUrlChange();" onchange="OnUrlChange();" />
00546       </td>
00547      </tr>
00548      <tr>
00549       <td colspan=2>
00550        <div id="divChkLink">
00551         <input id="chkLink" type="checkbox"> Link to
00552        </div>
00553       </td>
00554     </table>
00555  </body>
00556 </html>
00557 ''' % locals())
00558 
00559 
00560 #############################################################################
00561 ### Main
00562 #############################################################################
00563 
00564 def execute(pagename, request):
00565     dialog = request.values.get("dialog", "")
00566 
00567     if dialog == "macro":
00568         macro_dialog(request)
00569     elif dialog == "macrolist":
00570         macro_list(request)
00571     elif dialog == "pagelist":
00572         page_list(request)
00573     elif dialog == "link":
00574         link_dialog(request)
00575     elif dialog == "attachment":
00576         attachment_dialog(request)
00577     elif dialog == 'image':
00578         image_dialog(request)
00579     else:
00580         from MoinMoin.Page import Page
00581         request.theme.add_msg("Dialog unknown!", "error")
00582         Page(request, pagename).send_page()
00583