; )HEc@sdZdklZdkZdkZdkZdkZdkZdkZdkl Z l Z l Z l Z l Z lZlZdklZlZdkTdklZlZdklZdklZd klZd klZd klZdk Z d k!l"Z"l#Z#l$Z$l%Z%l&Z&l'Z'l(Z(l)Z)l*Z*l+Z+d k,l-Z-l.Z.l/Z/l0Z0l1Z1l2Z2l3Z3l4Z4l5Z5l6Z6l7Z7l8Z8l9Z9l:Z:l;Z;l<Z<l=Z=l>Z>dk?l@Z@lAZAdkBlCZCdkDlEZEdkFlGZGdkHlIZIlJZJdkKlLZLdkMlNZNdkOlPZPdkQlRZRdkSlTZTdkUlVZVdkWlXZXlYZYdkZl[Z[l\Z\dk]l^Z^dk_l`Z`dkalbZbe[dZcdebdebd ebd!ebd"ebd#ebd$ebd%ebd&ebd'ebd(ebd)ebd*ebd+ebd,ebd-ebd.eTeEeGeJeIeLePeReVe@eCeeNfd/YZdeedd0Zee e d1Zfd2Zgd3Zhd4ZieXd5ejZkeld6ZmdS(7s The main Zwiki module. See README.txt. (c) 1999-2004 Simon Michael for the zwiki community. Wikiwikiweb formatting by Tres Seaver Parenting code and regulations by Ken Manheimer Initial Zope CMF integration by Chris McDonough Full credits are at http://zwiki.org/ZwikiContributors . This product is available under the GNU GPL. All rights reserved, all disclaimers apply, etc. STYLE NOTES imports are usually in three groups: python, then zope, then zwiki imports docstrings "The first line should always be a short, concise summary of the object's purpose. For brevity, it should not explicitly state the object's name or type, since these are available by other means (except if the name happens to be a verb describing a function's operation). This line should begin with a capital letter and end with a period. If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description. The following lines should be one or more paragraphs describing the object's calling conventions, its side effects, etc. Data attributes override method attributes with the same name; to avoid accidental name conflicts, which may cause hard-to-find bugs in large programs, it is wise to use some kind of convention [such as] verbs for methods and nouns for data attributes." method visibility naming with _ for privacy obscures the code, and so do excessive security declarations. Omitting docstrings or documenting with comments are not good either. Where a docstring is needed, I'm considering putting it above the method name to indicate private methods, which avoids these problems and makes it easy to change your mind. No, too weird. (s nested_scopesN(ssplitsjoinsfindslowersrfindsatoisstrip(squotesunquote(s*(sgetSecurityManagersClassSecurityInfo(s rfc1123_date(sDateTime(sInitializeClass(s DTMLDocument(sWriteLockInterface( s AUTO_UPGRADEs IDS_TO_AVOIDs PAGE_METATYPEsLINK_TO_ALL_CATALOGEDsLINK_TO_ALL_OBJECTSsWIKINAME_LINKSs BRACKET_LINKSsDOUBLE_BRACKET_LINKSsDOUBLE_PARENTHESIS_LINKSs ISSUE_LINKS(surls bracketedexprssinglebracketedexprsdoublebracketedexprsdoubleparenthesisexprswikinameswikilinks interwikilinks remotewikiurlsprotected_lineszwikiidcharsexprsanywikilinkexprsmarkedwikilinkexprs localwikilinksspaceandlowerexprsdtmlorsgmlexprs wikinamewordsshashnumberexpr(s PageUtilssBLATHER(s PageViews(sPageOutlineSupport(sPageDiffSupport(sPageSubscriptionSupportsPageMailSupport(sPageCatalogSupport(sPageCMFSupport(sPageCommentsSupport(sPageAdminSupport(sPageEditingSupport(sPageRSSSupport(sDTMLFiles_(s PAGETYPESs PAGE_TYPES(sMIDSECTIONMARKER(s PageTypeStx(sPLUGINSis ZWikiPageiiiiiiiii i i i i iic BsW tZdZeeifZeZeidei e i dei e i dei e i dei e i dei e i ddZei e idd Zd Zhd d <d d<ddei e i-d;d<Z?ei e i-d=d>Z@ei e i-d?d@ZAei e i-dAdBZBei e i-dCdDZCei e i-dEdFZDdGZEdHZFdIZGdJZHdKZIdLZJdMZKdNdOZLdPZMdQZNeNZOei e i-dRdSZPd'e#de#e#dTZQe#e#e#e#dUZRdVZSei e i-dWdXZTei e i-dYdZZUei e i-d[d\ZVei e i-d]d^ZWei e i-d_d`ZXei e i-dad'dbZYei e i-dce#e#d'ddZZdeZ[dfZ\ei e i-dgdhZ]diZ^ei e i-djdkZ_ei e i-dldmZ`ei%dndoZaei e i-dpdqZbei e i-drdsZcei e i-dtduZddvZeei e i-dwdxZfei e i-dydzZgei e i-d{d|Zhei e i-d}d~Ziei e i-ddZjei e i-ddZkei e i-ddZlei e i-ddZmei e i-ddZnei e i-ddZoei e i-ddZpei e i-ddZqei e i-dd'd'dZrei e i-dd'dZsei e i-dd'dZtei e i-dd'd'dNd'dZuei e i-ddZvei e i-de#dZwei e i-dexiyZzZ{ei e i-de|i}Z~exiZexiZexiZeiZeiZeiZePZe.ZRS(s? A ZWikiPage is essentially a DTML Document which knows how to render itself in various wiki styles, and can function inside or outside a CMF site. A lot of extra methods are provided to support wiki-building, email, issue tracking, etc. Mixins are used to organize functionality into modules. sViewsreverts manage_uploadsmanage_FTPstatsmanage_FTPlistsdummycCsdS(N((sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysdummyssdummy2cCsdS(N((sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysdummy2scCsti||SdS(N(sgetSecurityManagerscheckPermissions permissionsobject(sselfs permissionsobject((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyscheckPermissionssidstitlestypesstringsmodeswscreatorsrs creator_ips creation_times last_editorslast_editor_ipslast_edit_timeslast_logsmisc_/ZWiki/ZWikiPage_iconscCs|i||_dS(N(sselfslookupPageTypesids page_type(sselfsid((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys setPageTypesspageTypecCst|itjoC|i|i}td|i|i|f|i|n&t |id o|it n|iSdS(s$Return this page's page type object.s&upgrading %s's page type from %s to %ssrenderN( stypesselfs page_types StringTypesnewPageTypeIdForsnewsBLATHERsids setPageTypeshasattrsDEFAULT_PAGETYPE(sselfsnew((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageTypes cs/tdt}|o|dptSdS(s9Return the page type object with this id (or the default)cs |ijS(N(sxs_idsid(sx(sid(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyssiN(sfilters PAGETYPESsmatchsDEFAULT_PAGETYPE(sselfsidsmatch((sids9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyslookupPageTypess pageTypeIdcCs|iiSdS(s.Return the short id for this page's page type.N(sselfspageTypesid(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys pageTypeIdscCs ||_dS(N(stsselfs _prerendered(sselfst((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyssetPreRenderedscCst|ddpdSdS(Ns _prerendereds(sgetattrsself(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys preRenderedscCsS|io#ti|d|d|d|n ti|d|d|d|dS(s Initialise this instance, including it's CMF data if applicable. Ugly, but putting PageCMFSupport before DTMLDocument in the inheritance order creates problems. s source_stringsmappings__name__N(sselfs supportsCMFsPageCMFSupports__init__s source_stringsmappings__name__s DTMLDocument(sselfs source_stringsmappings__name__((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys__init__s   s__call__cKs8to|i|n|i||||}|SdS(sQ Render this zwiki page, also upgrading it on the fly if needed. N( s AUTO_UPGRADEsselfsupgradesREQUESTsrendersclientsRESPONSEskwsrendered(sselfsclientsREQUESTsRESPONSEskwsrendered((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys__call__s cKs|i o|in|ii||||}|oVt |do|i dt |dq|i d o|i ddqn|SdS(s@ Render this page according to it's page_type. Also tries to ensure the HTTP content-type (and charset) have an appropriate value. These may be set by the page type, or overridden by a zwiki_content_type property (LatexWiki support). NB this can also get set in I18n.py. szwiki_content_types content-types text/htmlN( sselfs preRendereds preRenderspageTypesrendersREQUESTsRESPONSEskwsrshasattrs setHeadersgetattrs getHeader(sselfsclientsREQUESTsRESPONSEskwsr((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysrendersicCs5|o|in|i|ii|dS(s Make sure any applicable pre-rendering for this page has been done. If clear_cache is true, blow away any cached data. XXX I think this happens anyway. N(s clear_cachesselfs clearCachessetPreRenderedspageTypes preRender(sselfs clear_cache((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys preRenderscKs#|i|i|||SdS(sO Render some source text according to the specified page type. N(sselfslookupPageTypestypes renderTextstextskw(sselfstextstypeskw((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys renderTextss clearCachecCs`|idt|dot|dt|dn|o|ii|indS(sI forcibly clear out any cached render data for this page ss _v_cookeds _v_blocksN(sselfssetPreRenderedshasattrsdelattrsREQUESTsRESPONSEsredirectspageUrl(sselfsREQUEST((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys clearCache s  cCs,|io |io|indS(N(sselfs dtmlAllowedshasDynamicContentscook(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyscookDtmlIfNeeded*sscookcCsN|iz2|i|ip |i|_t|_Wd|i XdS(sW Pre-parse this page's text (the pre-rendered, if available) for DTML. N( scooklocksacquiresselfsparses preRenderedsreads _v_blockssNones _v_cookedsrelease(sselfscooklock((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyscook.s % cKsH|i o|iSnti|i|i||||SdS(N( sselfshasDynamicContents preRendereds DTMLDocuments__call__s__of__sfoldersclientsREQUESTsRESPONSEskw(sselfsclientsREQUESTsRESPONSEskw((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysevaluatePreRenderedAsDtml9s cKsti|tdjo:ytit|\}}Wqtj o |SqXnDti|ddjo&tid|\}}d|}n|S||i ||SdS(s Insert some final things between the rendered document and discussion. A page's "midsection" is after the pristine gem-like main document, right before the mudslinging. This is where we want to put the automatic children list (subtopics), next/prev links, etc. XXX This is not good enough. The midsection marker can get mixed up with other rendering in the various page types. isN( sstringsfindstextsMIDSECTIONMARKERsressplitsdocs discussions ValueErrorsselfsrenderMidsectionskw(sselfstextskwsdocs discussion((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysrenderMidsectionInEs  cKs4|i|o |i o|iSndSdS(s Render whatever should be in this page's midsection. This is the subtopics, in the preferred style, if enabled, or nothing. As a convenience, if it seems subtopics are already displayed via custom DTML code, we won't display them again. sN(sselfssubtopicsEnabledskwsdisplaysSubtopicsWithDtmls subtopics(sselfskw((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysrenderMidsectionascCs:|io)|iotid|itj SdS(sQ True if this page appears to display subtopics via custom DTML. s%(?i)(%sN(s markedtextsstateslastpossanywikilinkexprssearchstextsmsgroupslinksspans linkstartslinkendsselfsisValidWikiLinkSyntaxsurlssresmatchsurlswithin_literalswithinSgmlOrDtml( sselfstextsurlssms linkstarts markedtextslinkendsstateslinkslastpos((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys markLinksIns& 3 l cCstit|i|SdS(sL Render the links in text previously marked by markLinksIn. N(sressubsmarkedwikilinkexprsselfs renderLinkstext(sselfstext((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysrenderMarkedLinksInscCs5|i|}titt|i|d|SdS(s Find and render all links in text in one step. An alternative to the more usual markLinksIn + renderMarkedLinksIn. iN( sselfsapplyWikiLinkLineEscapesInstextstsressubsanywikilinkexprsthunk_substituters renderLink(sselfstextst((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys renderLinksIn s  sapplyWikiLinkLineEscapesIncCstitd|SdS(sK Escape all wikilinks in lines in text which begin with !. cCstitd|idS(Ns!\1i(sressubswikilinksmsgroup(sm((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyssN(sressubsprotected_linestext(sselfstext((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysapplyWikiLinkLineEscapesIns c Cs| odSnt|tjo|i}n|tjo|i}|i}nW|}|i}t |i |i d||pt |i|o|Sntitd|}}|ddjo |dSnti t|o|i|Snti t|oWtitd|} tidti| |od|i| | | fSqvnti t|od||fSnti t|om|i|i|} | oFy| i}Wn| i }nX|i!|d |d |d |Sq|Sn|i$| o|Sn|i%| oMt&|}|i'|} | o'y| i}Wq| i }qXqn|i!|d |d |d |Sd S( s9 Render various kinds of hyperlink, based on page and wiki state. Can be called three ways: - directly (link should be a string) - from re.sub (link will be a match object, state will be None) - from re.sub via thunk substituter (state will be a dictionary) (old) sis\1is!s(?s)[%s]s%sslinkorigs link_titles access_keyN((slinkstypes StringTypesselfs preRenderedstextsstatesNonesgroupsmatchswithin_literalsstartsendswithinSgmlOrDtmlsspansressubsmarkedwikilinkexprslinkorigs interwikilinksrenderInterwikiLinkssinglebracketedexprslinknobracketsssearchsescapespageUrlsurlshashnumberexprsissuePageWithNumbersissueNumberFromspsgetIdsidsrenderLinkToPages link_titles access_keysisValidWikiLinkSyntaxs isWikiNamesstripDelimitersFromspageWithFuzzyName( sselfslinksallowedsstatestexts link_titles access_keysmatchslinkorigslinknobracketssp((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys renderLink!sb    <  "    c Csj|i|}|o |i| o'y|i}WqN|i}qNXn|od|pd}|od|pd}|od|pd} |i o/yd|i }Wqd|i }qXnd}t|p|} d|it|||| ||i| fSnFd|i|p||it|it|tdfSd S( s Render a wiki link to page, which may or may not exist. page is renderLink's best guess at the id or name of the page intended. s title="%s"ss name="%s"s accesskey="%s"s style="background-color:%s;"s%ssO%s?screate this pageN(sselfspageWithNameOrIdspagesps pageWithIdsgetIdsids link_titlestitlesnames access_keys accesskeysisIssues issueColoursstylesstripDelimitersFromslinkorigslinkswikiUrlsquotesformatWikinames_( sselfspageslinkorigs link_titles access_keysnamesstylestitlespslinks accesskey((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysrenderLinkToPagezs( 6 cCs|ddjo |dSntit|}|id|idf\}}|i | o|Snti t d|}t |i |oStitt|i |i}|o!d|id|||fSqn|Sd S( sI Render an occurence of interwikilink. link is a string. is!islocalsremotes\1s%s:%ss remoteurlN(slinksresmatchs interwikilinksmsgroupslocalsremotesselfsisValidWikiLinkSyntaxssubs bracketedexprshasattrsfolderssearchs remotewikiurlsgetattrstext(sselfslinksremotesmslocal((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysrenderInterwikiLinks $'%sformatWikinamecCs&|io|i|Sn|SdS(s Convert a wikiname to this wiki's standard display format. Ie, leave it be or add ungodly spaces depending on the 'space_wikinames' property. N(sselfsspacedWikinamesEnabledsspacedNameFromswikiname(sselfswikiname((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysformatWikinames sspacedNameFromcCsgtidt|oHgi}tit|D]}||dq1~}di |Sn|SdS(s Return pagename with spaces inserted if it's a WikiName, or unchanged. Tries to be conformant with the wikiname regexp wrt. i18n, etc. s^%s$is N( sresmatchswikinamespagenamesappends_[1]sfindalls wikinamewordssxswordssjoin(sselfspagenames_[1]swordssx((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysspacedNameFroms 7sspacedWikinamesEnabledcCs!t|iddodSdS(s<Should all wikinames be displayed with spaces in this wiki ?sspace_wikinamesiiN(sgetattrsselfsfolder(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysspacedWikinamesEnabledsslinkscCsPg}x?tit|iD]%}||j o|i|qqW|SdS(s% List the unique links occurring on this page - useful for cataloging. Includes urls & interwiki links but not structured text links. Extracts the marked links from prerendered data. Does not generate this if missing - too expensive when cataloging ? N(slinkssresfindallsmarkedwikilinkexprsselfs preRenderedslsappend(sselfslslinks((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyslinkssscanonicalLinkscCsg}tit}xw|iD]i}|i|oS|ddjo|ddjo|dd!}n|i |}|i |q"q"W|SdS(s List the canonical id form of the local wiki links in this page. Useful for calculating backlinks. Extracts this information from prerendered data, does not generate this if missing. is[is]iN( sclinkssrescompiles localwikilinkslocalwikilinkexprsselfslinksslinksmatchscanonicalIdFromsclinksappend(sselfsclinksslocalwikilinkexprslinksclink((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyscanonicalLinkss "s linkTitlecCs |i|i|id|SdS(s return a suitable value for the title attribute of links to this page with prettyprint=1, format it for use in the standard header. s prettyprintN(sselfs linkTitleFromslast_edit_times last_editors prettyprint(sselfs prettyprint((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys linkTitles s linkTitleFromc CsI|i|}| otdhd|<}nyd|i}|od|d}nd|itd||f}tdhd|<}Wn tdhd|<}nX|ot i d| okt i dd |}| o%|d td hd |<}qA|d td hd d |<}n|SdS(s make a link title string from these last_edit_time and editor strings with prettyprint=1, format it for use in the standard header. slast edited %(interval)s agosintervals (s)s* %ssshow last edits ^[0-9\.\s]*$s"ss s by %(editor)sseditors %sN(sselfs asAgeStringslast_edit_timesintervals prettyprints_ssslastlogspageUrlslinked_intervals last_editorsresmatchssubseditor( sselfslast_edit_times last_editors prettyprintslastlogsintervalssseditorslinked_interval((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys linkTitleFroms$ "%)cCst|dtodSdS(Nslink_to_all_catalogedi(sgetattrsselfsLINK_TO_ALL_CATALOGED(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyslinkToAllCatalogedCs cCst|dtodSdS(Nslink_to_all_objectsi(sgetattrsselfsLINK_TO_ALL_OBJECTS(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyslinkToAllObjectsGs spageNamecCs|iSdS(s Return the name of this wiki page. This is normally in the title attribute, but use title_or_id to handle eg pages created via the ZMI. N(sselfs title_or_id(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageNameOscCs|iSdS(N(sselfsid(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageIdXssspacedPageNamecCs|i|iSdS(s Return this page's name, with spaces inserted if it's a WikiName. We use this for eg the html title tag to improve search engine relevance. N(sselfsspacedNameFromspageName(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysspacedPageName\ssformattedPageNamecCs|i|iSdS(sY Return this page's name in the standard display format (spaced or not). N(sselfsformatWikinamespageName(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysformattedPageNameessTitlecCs|iSdS(s Title N(sselfspageName(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysTitlelsscanonicalIdFromcCs'|tjotSntidd|}tidtitid|}d|}tid|}ti ti |d}d}x@|D]8}t i|o||}q|dt|}qWt|djo|ddjod |}n|tjo|d }n|Sd S( sK Convert a free-form page name to a canonical url- and zope-safe id. Constraints for zwiki page ids: - it must be a legal zope object id - it should be legal in urls - it should be unique for a given name (ignoring whitespace) - we'd like it to be as similar to the name and as simple to read and work with as possible - we'd like to encourage serendipitous linking between free-form and wikiname links & pages - it must avoid certain zope-significant names, to avoid breakage So, we - discard non-word-separating punctuation (') - convert remaining punctuation to spaces - capitalize and join whitespace-separated words into a wikiname - convert any non-zope-and-url-safe characters and _ to _hexvalue - if this results in an id that begins with _ (illegal), prepend X - or if it's one of the delicate IDS_TO_AVOID (eg REQUEST), append X Note these last break the uniqueness property. Better ideas welcome. performance-sensitive s'ss[%s]+s cCsti|idS(Ni(sstringsuppersmsgroup(sm((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysss_%02xis_sXN(snamesNonesressubsescapesstrings punctuationsidsspaceandlowerexprsjoinssplitssafeidscszwikiidcharsexprsmatchsordslens IDS_TO_AVOID(sselfsnamescssafeidsid((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyscanonicalIdFromss& % $ s canonicalIdcCs|i|iSdS(s5 Give the canonical id of this page. N(sselfscanonicalIdFromspageName(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys canonicalIdss pageObjectscCs|iid|iSdS(s: Return a list of all pages in this wiki. sspecN(sselfsfolders objectValuess meta_type(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys pageObjectsscCs!|i|iid SdS(sW This wiki's folder path, for filtering our pages from catalog results s/N(sselfsgetPathsrfind(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyswikiPathsspagesc siddggfoio5tdtdidi|Sqidtdtdtdidid|Sng}x*i D]}|ii|qW|ox|iD]}||d}||djotd |}n|d jotd |}n|d jotd |}n|djotd|}qqWn|SdS(s Look up metadata (brains) for some or all pages in this wiki. optimisation: prior to 0.22 this returned the actual page objects, but to help with caching efficiency it now uses the catalog, if possible. The page metadata objects are catalog brains (search results) containing the catalog's metadata, or workalikes containing a limited number of fields and getObject(). Warning: fields such as the parents list may be copies-by-reference, and should not be mutated. Any keyword arguments will be passed through to the catalog, for refining the search, sorting etc. When there is no catalog, only these arguments are supported: id, Title, text, isIssue, and they do case insensitive partial matching. With no arguments, all pages in the wiki are returned. With a partial catalog, ie a catalog which does not include all the metadata Zwiki expects, we'll get the missing fields from the zodb and add them to the catalog brains. In this case the catalog's caching advantage is lost. ensureCompleteMetadata may return None, indicating a stale catalog entry; we filter those out. Different catalog configurations screw up our title and text searches somewhat. For the standard search form, we want: case insensitive, partial matching in page names and page text. s meta_typespathcCs |tj S(N(sxsNone(sx((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysscs i|S(N(sselfsensureCompleteMetadataInsx(sx(sself(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysscCs||id SdS(Ns/(sssrfind(ss((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys folderpathscs|ijS(N(s folderpathsxsgetPathswikipath(sx(s folderpathswikipath(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysscCs2y|iddSWntj o |SnXdS(Ns*s(sssreplacesAttributeError(ss((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysstripWildCardsFromsstextcs+t|iiiidjS(Ni(sfindsxs getObjectstextslowersvalue(sx(svalue(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysssidcs"t|iiidjS(Ni(sfindsxsidslowersvalue(sx(svalue(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysssTitlecs"t|iiidjS(Ni(sfindsxsTitleslowersvalue(sx(svalue(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysssisIssuecsi|ijS(N(sselfsisIssuesxsTitlesvalue(sx(sselfsvalue(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys sN(sselfshasCatalogIndexesMetadataslinkToAllCatalogedsfiltersmaps searchCatalogs meta_typeskwswikiPathswikipaths folderpathsresultss pageObjectsspsappends metadataForskeyssargsvaluesstripWildCardsFrom( sselfskwswikipathsresultssvaluespsstripWildCardsFromsargs folderpath((sselfswikipaths folderpathsvalues9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspagessH                       s pageCountcCst|iSdS(s: Return the number of pages in this wiki. N(slensselfspages(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys pageCountsspageIdscCs|iid|iSdS(s Return a list of all page ids in this wiki. If there's junk in the catalog, pages could return a page with id None; we guard against that. sspecN(sselfsfolders objectIdss meta_type(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageIdsss pageNamescCstd|iSdS(s? Return a list of all page names in this wiki. cCs|iS(N(sxsTitle(sx((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys*sN(smapsselfspages(sself((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys pageNames&sspageIdsStartingWithcstd|iSdS(s% pageIdsStartingWith cs|t jS(N(sxslenstext(sx(stext(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys1sN(sfiltersselfspageIds(sselfstext((stexts9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageIdsStartingWith-sspageNamesStartingWithcstd|iSdS(s' pageNamesStartingWith cs|t jS(N(sxslenstext(sx(stext(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys8sN(sfiltersselfs pageNames(sselfstext((stexts9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageNamesStartingWith4ssfirstPageIdStartingWithcCs|i|ptgdSdS(s) firstPageIdStartingWith iN(sselfspageIdsStartingWithstextsNone(sselfstext((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysfirstPageIdStartingWith;ssfirstPageNameStartingWithcCs|i|ptgdSdS(s+ firstPageNameStartingWith iN(sselfspageNamesStartingWithstextsNone(sselfstext((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysfirstPageNameStartingWithBsspageIdsMatchingcs)itd|iSdS(s! pageIdsMatching cs|iidjS(Ni(sxslowersfindstext(sx(stext(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysNsN(stextslowersfiltersselfspageIds(sselfstext((stexts9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageIdsMatchingIs spageNamesMatchingcs)itd|iSdS(s# pageNamesMatching cs|iidjS(Ni(sxslowersfindstext(sx(stext(s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysVsN(stextslowersfiltersselfs pageNames(sselfstext((stexts9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageNamesMatchingQs s defaultPagecCst|idg}t|tjo |g}n$t|tjot|}n|idx,|D]$}|i |}|o|SqoqoWt|i t gdSdS(s! Return this wiki's default page object, where eg mail goes by default. That is: - a page named in the default_page string or lines property - or the page named FrontPage - or the first page object in the folder - or None. s default_pages FrontPageiN(sgetattrsselfsfoldersdefault_page_namesstypes StringTypes TupleTypeslistsappendsnames pageWithNamesps pageObjectssNone(sselfsdefault_page_namessnamesp((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys defaultPageYs    s defaultPageIdcCs(|i}|o |iptSdS(sX Return this wiki's default page ID. See defaultPage. N(sselfs defaultPagespsidsNone(sselfsp((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys defaultPageIdrs s pageWithIdcCs#d}|tjotSn|ot|}n|ip|oF|id|p|o|id|}|o|dptSn|i }||i jo|i ||o ||SnU|oIti|}x;|iD]%}|i|jo ||SqqWntSdS(s+ Return the page in this folder (or in the catalog) with this id. Can also do a case-insensitive id search, and optionally unquote id. If no such page exists, return None. XXX if ALLBRAINS is set true below, this and all the methods based on it will return a page brain, not the actual page object. Rats.. enabling this actually slows down zwiki.org FrontPage rendering by 2.5 (due to extra catalog searching work ?) It should still perform better for many pages, small cache, low memory.. in theory. When link_to_all_cataloged is enabled, this will find any matching page in the catalog, regardless of physical location. As above, a brain will be returned, and performance implications are not known. isids id_nocaseN(s ALLBRAINSsidsNones url_quotedsunquotesselfslinkToAllCatalogedspagess ignore_casespagesfoldersfs objectIdss isZwikiPagesstringslowerspageIdssi(sselfsids url_quoteds ignore_cases ALLBRAINSsfspagesi((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys pageWithId|s& , '  s pageWithNamecCs|i|i||SdS(sk Return the page in this folder which has this name, or None. page name may be different from page id, and if so is stored in the title property. Ie page name is currently defined as the value given by title_or_id(). As of 0.17, page ids and names always follow the invariant id == canonicalIdFrom(name). N(sselfs pageWithIdscanonicalIdFromsnames url_quoted(sselfsnames url_quoted((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys pageWithNames spageWithNameOrIdcCs'|i||p|i||SdS(sW Return the page in this folder with this as it's name or id, or None. N(sselfs pageWithIdsnames url_quoteds pageWithName(sselfsnames url_quoted((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageWithNameOrIdsspageWithFuzzyNamec Cs |ot|}n|i|} | o| Sn|i|} ti | }|i }y|i Wntj onXx~|D]v} ti | }||jp@|o|t| |jo"|otid|t| o|i| SqqWtSdS(s Return the page in this folder for which name is a fuzzy link, or None. A fuzzy link ignores whitespace, case and punctuation. If there are multiple fuzzy matches, return the page whose name is alphabetically first. The allow_partial flag allows even fuzzier matching. As of 0.17 ignore_case is not used and kept only for backward compatibility. numeric_match modifies partial matching so that [1] does not match a page "12...". performance-sensitive s[0-9]N(s url_quotedsunquotesnamesselfs pageWithNamespscanonicalIdFromsidsstringslowersidlowerspageIdssidsssortsAttributeErrorsisilowers allow_partialslens numeric_matchsresmatchs pageWithIdsNone( sselfsnames url_quoteds allow_partials ignore_cases numeric_matchsidlowersidssilowerspsisid((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyspageWithFuzzyNames& Ps backlinksForcCs|i|}|o'y|i}WqC|i}qCXn|}|idddggfo|id|Snkg}t i d||f}xD|i D]6}|i |io|i|i|qqW|SdS(s Return metadata objects for all the pages that link to page. Optimisation: like pages(), this method used to return actual page objects but now returns metadata objects (catalog results if possible, or workalikes) to improve caching. page may be a name or id, and need not exist in the wiki The non-catalog search is not too smart. s meta_typespathscanonicalLinkss \b(%s|%s)\bN(sselfspageWithNameOrIdspagespsgetIdsidshasCatalogIndexesMetadataspagessresultssrescompileslinkpats pageObjectsssearchsreadsappends metadataFor(sselfspagesresultssidslinkpatsp((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys backlinksFors"  stranslateHelpercCs;t|}|o y||}Wq3|Sq3Xn|SdS(s When you want to translate a part of a sentence in a tag attribute, which is computed, you can not use i18n:attribute. and it's difficult to call _("") from the python: Expression. dont forget to force i18n extraction with something like N(s_smsgids translate_msgsmap(sselfsmsgidsmaps translate_msg((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pystranslateHelpers   s quickcomments stxToHtml(s__name__s __module__s__doc__sWriteLockInterfacesPageCMFSupports__implements__sClassSecurityInfossecuritysdeclareObjectProtectedsdeclareProtecteds PermissionssEditsFTPs ChangeTypesdummysReparentsdummy2scheckPermissionsPageOutlineSupports _propertiessPageSubscriptionSupportsPageCatalogSupports PAGE_METATYPEs meta_typesiconscreators creator_ips creation_times last_editorslast_editor_ipslast_edit_timeslast_logs PAGE_TYPESsDEFAULT_PAGETYPEs page_typesNones setPageTypes declarePublicspageTypeslookupPageTypes pageTypeIds _prerenderedssetPreRendereds preRendereds__init__sViews__call__srenders preRenders renderTexts clearCachescookDtmlIfNeededsthreads allocate_lockscooksevaluatePreRenderedAsDtmlsrenderMidsectionInsrenderMidsectionsdisplaysSubtopicsWithDtmls supportsStxs supportsRsts supportsWwmlssupportsWikiLinkss supportsHtmls supportsDtmlshasDynamicContents dtmlAlloweds supportsEpozs epozInstalledswikinameLinksAllowedsissueLinksAllowedsbracketLinksAllowedsdoubleBracketLinksAllowedsdoubleParenthesisLinksAlloweds isWikiNamesisValidWikiLinkSyntaxs markLinksInsrenderMarkedLinksIns renderLinksInswikilinksapplyWikiLinkLineEscapesIns renderLinksrenderLinkToPagesrenderInterwikiLinksformatWikinamesspacedNameFromsspacedWikinamesEnabledslinksscanonicalLinkss linkTitles linkTitleFromslinkToAllCatalogedslinkToAllObjectsspageNamespageIdsspacedPageNamesformattedPageNamesTitlescanonicalIdFroms canonicalIds pageObjectsswikiPathspagess pageCountspageIdss pageNamesspageIdsStartingWithspageNamesStartingWithsfirstPageIdStartingWithsfirstPageNameStartingWithspageIdsMatchingspageNamesMatchings defaultPages defaultPageIds pageWithIds pageWithNamespageWithNameOrIdspageWithFuzzyNames backlinksForstranslateHelpersPageEditingSupportscomments quickcomments slowcomments PageTypeStxsformats stxToHtmlstextssrcs timeStamps editTimestampscheckEditConflictscheckEditTimeStamps PageUtilsspage_urls wiki_page_urlswiki_urls wiki_base_urls usernameFromszwiki_username_or_ipsapplyLineEscapesInsview(((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys ZWikiPage]sL '                                     *   Y:       )        5    S           )  &          cCsJhdd<dd<dd<dd<dd<}||||dSdS( sReturn a function which takes one arg and passes it with other args to passed-in func. thunk_substituter passes in the value of it's parameter, 'allowed', and a dictionary {'lastend': int, 'inpre': bool, 'intag': bool}. This is for use in a re.sub situation, to get the 'allowed' parameter and the state dict into the callback. (The technical term really is "thunk". Honest.-)slastendisinpresincodesintagsinanchorcCs|||||S(N(sfuncsargsallowedsstatestext(sargsfuncsallowedstextsstate((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys?sN(sstatesfuncsallowedstext(sfuncstextsallowedsstate((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysthunk_substituter3s 3cCsu|d|d|d|d|df\}}} } } d}} }}||}||d||} | djp|oK| djo| d } n|} d||d | |jo d }qn||d<||d ||} | djp| oK| djo| d } n|} d||d| |jo d } qHn| |d<||d||} | djp| oK| djo| d } n|} d||d| |jo d }qn||d<||d||} | djp| oK| djo| d } n|} d||d| |jo d }qDn||d<||d<|p| p |p|SdS(sF Check text from state['lastend'] to upto for literal context: - within an enclosing '
' preformatted region '
' - within an enclosing '' code fragment '' - within a tag '<' body '>' - within an '' tag's contents '' We also update the state dict accordingly. slastendsinpresincodesintagsinanchorisisssN(sstateslastendsinpresincodesintagsinanchorsnewintags newincodesnewinpres newinanchorslowerstextsrfindsuptosopeningsafter(suptosaftersstatestextsrfindslowerslastends newinanchorsnewintags newincodesinanchorsintagsopeningsincodesinpresnewinpre((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyswithin_literalBsL 8          cCsWt|}x@|D]8}|d|djo|d|djodSqqWdSdS(sI report whether the span lies inside an sgml or dtml tag in text iiN(ssgmlAndDtmlSpansInstextsspanssssspan(sspanstextsssspans((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyswithinSgmlOrDtmls * cCsttit}g}d}xNnoF|i||}| oPq|i }|i ||d}q%W|SdS(sK return a list of spans (tuples) of all sgml and dtml tags in text iiN( srescompilesdtmlorsgmlexprspatsspansslastposssearchstextsmsspansssappend(stextspatsmsssspansslastpos((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pyssgmlAndDtmlSpansIns  cCstidd|SdS(s/Strip a wiki link's enclosing [], [[]] or (()).s#^(\[\[|\[|\(\()(.*?)(\]\]|\]|\)\))$s\2N(sressubslink(slink((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysstripDelimitersFromssskins/zwiki/addwikipageformcCsti|}td|}||_|i||}t ||}|i ||i ||i ||i|i|id||ii|i|oK|idddjo|i}n|dd}|ii|ndS(sA Add a new ZWiki Page to the current folder, in the ZMI. s__name__ssredirectspagesURL1s /manage_mainN(s ZWikiPagescanonicalIdFromsnamesidspstitlesselfs _setObjectsnewidsgetattrs setCreatorsREQUESTs setLastEditors _setOwnerships setPageTypesdefaultPageTypessetTexts wikiOutlinesaddspageNamesgetspageUrlsusRESPONSEsredirect(sselfsnamesREQUESTspsnewidsusid((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pysmanage_addZWikiPages"    (ns__doc__s __future__s nested_scopessosssyssresstringstimesthreadssplitsjoinsfindslowersrfindsatoisstripsurllibsquotesunquotestypess AccessControlsgetSecurityManagersClassSecurityInfos App.Commons rfc1123_datesDateTimesGlobalssInitializeClasssOFS.DTMLDocuments DTMLDocumentswebdav.WriteLockInterfacesWriteLockInterfaces PermissionssDefaultss AUTO_UPGRADEs IDS_TO_AVOIDs PAGE_METATYPEsLINK_TO_ALL_CATALOGEDsLINK_TO_ALL_OBJECTSsWIKINAME_LINKSs BRACKET_LINKSsDOUBLE_BRACKET_LINKSsDOUBLE_PARENTHESIS_LINKSs ISSUE_LINKSsRegexpssurls bracketedexprssinglebracketedexprsdoublebracketedexprsdoubleparenthesisexprswikinameswikilinks interwikilinks remotewikiurlsprotected_lineszwikiidcharsexprsanywikilinkexprsmarkedwikilinkexprs localwikilinksspaceandlowerexprsdtmlorsgmlexprs wikinamewordsshashnumberexprsUtilss PageUtilssBLATHERsViewss PageViewssOutlineSupportsPageOutlineSupportsDiffsPageDiffSupportsMailsPageSubscriptionSupportsPageMailSupportsCatalogsPageCatalogSupportsCMFsPageCMFSupportsCommentssPageCommentsSupportsAdminsPageAdminSupportsEditingsPageEditingSupportsRSSsPageRSSSupportsI18nsDTMLFiles_s pagetypess PAGETYPESs PAGE_TYPESspagetypes.commonsMIDSECTIONMARKERs pagetypes.stxs PageTypeStxspluginssPLUGINSsDEFAULT_PAGETYPEs ZWikiPagesthunk_substituterswithin_literalswithinSgmlOrDtmlssgmlAndDtmlSpansInsstripDelimitersFromsglobalssmanage_addZWikiPageFormsNonesmanage_addZWikiPage(Qsunquotesmarkedwikilinkexprssinglebracketedexprs PAGE_METATYPEs PAGETYPESsPageDiffSupportsdoubleparenthesisexprsLINK_TO_ALL_CATALOGEDs rfc1123_datesPageSubscriptionSupportswikilinksPageAdminSupports ISSUE_LINKSsstripsDOUBLE_BRACKET_LINKSsWriteLockInterfacesfindswikinames AUTO_UPGRADEssgmlAndDtmlSpansInsLINK_TO_ALL_OBJECTSs BRACKET_LINKSsWIKINAME_LINKSsthunk_substituters bracketedexprsDEFAULT_PAGETYPEsPageRSSSupportsprotected_lines IDS_TO_AVOIDsresPageCommentsSupports remotewikiurlssplitsPLUGINSshashnumberexprs PageUtilssPageCMFSupportsPageOutlineSupportsMIDSECTIONMARKERsdtmlorsgmlexprs Permissionsszwikiidcharsexprs PageViewssstrings nested_scopessstripDelimitersFromsmanage_addZWikiPagesquotesClassSecurityInfos DTMLDocumentsInitializeClasssPageEditingSupportsDTMLFilessyssatois ZWikiPageswithin_literalsanywikilinkexprsDateTimesDOUBLE_PARENTHESIS_LINKSs PAGE_TYPESs_sBLATHERslowersjoinsPageMailSupportsthreadsmanage_addZWikiPageFormsurlsgetSecurityManagersdoublebracketedexprsrfinds PageTypeStxsspaceandlowerexprs wikinamewordss localwikilinkstimeswithinSgmlOrDtmlsossPageCatalogSupports interwikilink((s9/mnt/gmirror/ports/www/zope-zwiki/work/ZWiki/ZWikiPage.pys?/sX 61      Cs               ?