Odo.lv » Recipes » Xwiki satura pārvaldības sistēma » Xwiki anonīmie komentāri

Xwiki anonīmie komentāri

en

Xwiki iespējams uzlikt, ka lapas var komentēt anonīmi, tomēr esošais risinājums nav drošs pret mēslotājiem. Ir paredzēts, ka Xwiki ieviesīs t.s. CAPTCHA, bet tas ir apjomīgs darbs un, un captcha cilvēkiem nepatīk.

Te ir aprakstīts, kā atvairīt mēslotājus, pieņemot, ka vairums no tiem neizpilda JavaScript.

  1. Nomaina faila ..../webapps/xwiki/templates/commentsinline.vm saturu:
    …
    #macro(displayCommentForm)
      #if($xwiki.hasAccessLevel('comment'))
        ##!! <form action="$doc.getURL('commentadd', "xpage=view&viewer=comments#commentform")" method="post" id="AddComment">
          <form name="frm" action="/Submit" method="post" id="AddComment">
          <fieldset class="expanded" id="commentform">
            <noscript>
    	#set($warn=$msg.get("custom.javascriptneeded.${context.language}"))
            #warning($warn)
            </noscript>
            <legend>$msg.get('core.viewers.comments.add.title')</legend>
            ##!!<div class="commentavatar">#mediumUserAvatar($context.user)</div>
            #if($xcontext.user != 'XWiki.XWikiGuest')
              <label>$msg.get('core.viewers.comments.add.guestName.prompt') $xwiki.getUserName($xcontext.user)</label>
              <input type="hidden" name="${xCommentClass}_author" value="$xcontext.user"/>
            #else
              <label for="${xCommentClass}_author">$msg.get('core.viewers.comments.add.guestName.prompt') <input type="text" id="${xCommentClass}_author" name="${xCommentClass}_author" value="$author"/></label>
              <strong><a href='$xwiki.getURL('XWiki.XWikiLogin', 'login', "xredirect=$escapetool.url($xwiki.getRequestURL())")'>$msg.get('login')</a></strong>
            #end
            ## CSRF prevention
            <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
            <input type="hidden" name="${xCommentClass}_date" value=""/>
            <input type="hidden" name="${xCommentClass}_replyto" value="$!replyTo"/>
    	<input type="hidden" name="spacedoc" value="$doc.space/$doc.name"/>
            <div class="commentcontainer">
               <label for="${xCommentClass}_comment">$msg.get('core.viewers.comments.add.comment.label')</label>
               <textarea id='${xCommentClass}_comment' rows='5' cols="80" name='${xCommentClass}_comment'>$!comment</textarea>
            </div>
            #if($xcontext.user == 'XWiki.XWikiGuest' && $offerGuestsCaptcha)
              #displayCaptcha()
            #end
            <div>
              ##!!<span class="buttonwrapper"><input type="submit" value="$msg.get('core.viewers.comments.add.submit')" class="button"/></span>
    	  <span class="buttonwrapper"><input name="sub" type="button" value="$msg.get('core.viewers.comments.add.submit')" class="button" onClick="submitComment()"/></span>
              <span class="buttonwrapper"><a class="cancel secondary button" href="$doc.getURL()">$msg.get('core.viewers.comments.add.cancel')</a></span>
            </div>
          </fieldset>
        </form>
      #end
    #end
    ...
  2. Papildina failu ../webapps/xwiki/resources/js/xwiki/xwiki.js:
    …
    //////////////////////////
    //   Custom functions   //
    //////////////////////////
    // Adding comments using JavaScript
    // Adjust action value to RewriteRule in /etc/apache2/sites-available/default file
    function submitComment() {
      var spacedoc = document.frm.spacedoc.value;
      spacedoc = '/xwiki/bin/commentaddXXX/'+spacedoc+'?xpage=view&viewer=comments#commentform';
      document.frm.action = spacedoc;
      document.frm.submit();
    }
Warning: Apache pārsūtīšanas likumus vajag tikai tāpēc, ka šajā vietnē oriģinālie URLi ir zināmi mēslotājiem.
Tīrai Xwiki instance tie nav nepieciešami, ja vien mēslotāji neprot dalīties zināšanās ;-/.

  1. Papildina failus /etc/apache2/sites-available/default un /etc/apache2/sites-available/ssl:
    …
    ## Xwiki comments
    # Redirect new location set in ../webapps/xwiki/recources/js/xwiki/xwiki.js to the original place
    RewriteRule ^/xwiki/bin/commentaddXXX/(.*)$ http://localhost:8180/xwiki/bin/commentadd/$1 [P,L]    
    # Redirect original location to the honeypot
    RewriteRule ^/xwiki/bin/commentadd/(.*)$ /Submit [L]
    ...
  2. Pārlādē Apache iestatījumus:
    /etc/init.d/apache2 reload
  3. Nomaina Xwiki iestatījums. Izvēlas Adminstration- Rights- Users, iezīmē Comment priekš Unregistered Users.


Skatīt arī
Saites

Created by Valdis Vītoliņš on 2009/03/27 11:35
Last modified by Valdis Vītoliņš on 2011/12/07 22:21

XWiki Enterprise 2.7.33656 - Documentation
Creative Commons Attribution 3.0 Unported License