wiki
[ class tree: wiki ] [ index: wiki ] [ all elements ]

Source for file edit.php

Documentation is available at edit.php

  1. <?php
  2. /**
  3.  * Copyright( c ) 2004 bitweaver.org
  4.  * Copyright( c ) 2003 tikwiki.org
  5.  * Copyright( c ) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  6.  * All Rights Reserved. See below for details and a complete list of authors.
  7.  * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  8.  *
  9.  * @package wiki
  10.  * @subpackage functions
  11.  */
  12.  
  13. /**
  14.  * required setup
  15.  */
  16. require_once'../kernel/setup_inc.php' );
  17. include_onceWIKI_PKG_PATH.'BitBook.php' );
  18.  
  19. $gBitSystem->verifyPackage'wiki' );
  20.  
  21. // bypass lookup_content_inc.php as we can't prevent it parsing faulty pages
  22. unset($_REQUEST['content_id']);
  23. // Disable parsing data if not asking to preview page
  24. $_REQUEST["parse"false;
  25. includeWIKI_PKG_PATH.'lookup_page_inc.php' );
  26.  
  27. if$gContent->isValid() ) {
  28.     $gContent->verifyUpdatePermission();
  29. else {
  30.     $gContent->verifyCreatePermission();
  31. }
  32.  
  33. //make comment count for this page available for templates
  34. if$gBitSystem->isFeatureActive'wiki_comments' && !empty$_REQUEST['page_id') ) {
  35.     require_onceLIBERTY_PKG_PATH.'LibertyComment.php' );
  36.     $gComment new LibertyComment();
  37.     $numComments $gComment->getNumComments($gContent->mContentId);
  38.     $gBitSmarty->assign('comments_count'$numComments);
  39. }
  40.  
  41. #edit preview needs this
  42. if!isset$_REQUEST['title'&& isset$gContent->mInfo['title') ) {
  43.     $_REQUEST['title'$gContent->mInfo['title'];
  44. }
  45.  
  46. if$gContent->isLocked() ) {
  47.     $gBitSystem->fatalError'Cannot edit page because it is locked' );
  48. }
  49.  
  50.  
  51. $gContent->invokeServices'content_edit_function' );
  52.  
  53. if!empty$gContent->mInfo ) ) {
  54.     $formInfo $gContent->mInfo;
  55.     $data_to_edit !empty$gContent->mInfo['data'$gContent->mInfo['data''';
  56.     if (!empty($_REQUEST['section'])) {
  57.         $section $_REQUEST['section'];
  58.         $data_to_edit extract_section($data_to_edit,$section);
  59.         $formInfo['data'$data_to_edit;
  60.         $formInfo['edit_section'1;
  61.         $formInfo['section'$_REQUEST['section'];
  62.     }
  63.  
  64.     $formInfo['edit'$data_to_edit;
  65.     $formInfo['edit_comment''';
  66. }
  67.  
  68. $gBitSmarty->assign'footnote''' );
  69. $gBitSmarty->assign'has_footnote''n' );
  70. if$gBitSystem->isFeatureActive'wiki_footnotes' ) ) {
  71.     if$gBitUser->mUserId {
  72.         $footnote $gContent->getFootnote$gBitUser->mUserId );
  73.         $gBitSmarty->assign'footnote'$footnote );
  74.         if$footnote )
  75.             $gBitSmarty->assign'has_footnote''y' );
  76.         $gBitSmarty->assign'parsed_footnote'$gContent->parseData$footnote ) );
  77.         ifisset$_REQUEST['footnote') ) {
  78.  
  79.             $gBitSmarty->assign'parsed_footnote'$gContent->parseData$_REQUEST['footnote') );
  80.             $gBitSmarty->assign'footnote'$_REQUEST['footnote');
  81.             $gBitSmarty->assign'has_footnote''y' );
  82.             ifempty$_REQUEST['footnote') ) {
  83.                 $gContent->expungeFootnote$gBitUser->mUserId );
  84.             else {
  85.                 $gContent->storeFootnote$gBitUser->mUserId$_REQUEST['footnote');
  86.             }
  87.         }
  88.     }
  89. }
  90. ifisset$_REQUEST["edit") ) {
  91.     $formInfo['edit'$_REQUEST["edit"];
  92. }
  93. if(isset($_REQUEST["section"])) {
  94.     $formInfo['section'$_REQUEST["section"];
  95.     $formInfo['edit_section'1;
  96. }
  97. ifisset$_REQUEST['title') ) {
  98.     $formInfo['title'$_REQUEST['title'];
  99. elseifisset$_REQUEST['page') ) {
  100.     $formInfo['title'$_REQUEST['page'];
  101. }
  102. ifisset$_REQUEST["description") ) {
  103.     $formInfo['description'$_REQUEST["description"];
  104. }
  105. ifisset$_REQUEST["edit_comment") ) {
  106.     $formInfo['edit_comment'$_REQUEST["edit_comment"];
  107. else {
  108.     $formInfo['edit_comment''';
  109. }
  110.  
  111. $cat_obj_type BITPAGE_CONTENT_TYPE_GUID;
  112.  
  113. if$gBitSystem->isFeatureActive'wiki_copyrights' ) ) {
  114.     ifisset$_REQUEST['copyrightTitle') ) {
  115.         $gBitSmarty->assign'copyrightTitle'$_REQUEST["copyrightTitle");
  116.     }
  117.     ifisset$_REQUEST['copyrightYear') ) {
  118.         $gBitSmarty->assign'copyrightYear'$_REQUEST["copyrightYear");
  119.     }
  120.     ifisset$_REQUEST['copyrightAuthors') ) {
  121.         $gBitSmarty->assign'copyrightAuthors'$_REQUEST["copyrightAuthors");
  122.     }
  123. }
  124.  
  125. // Pro
  126. // Check if the page has changed
  127. ifisset$_REQUEST["fCancel") ) {
  128.     if@BitBase::verifyId$gContent->mContentId ) ) {
  129.         header"Location: ".$gContent->getDisplayUrl() );
  130.     else {
  131.         header"Location: ".WIKI_PKG_URL );
  132.     }
  133.     die;
  134. elseifisset$_REQUEST["fSavePage") ) {
  135.  
  136.     // Check if all Request values are delivered, and if not, set them
  137.     // to avoid error messages. This can happen if some features are
  138.     // disabled
  139.     // add permisions here otherwise return error!
  140.     if$gBitSystem->isFeatureActive'wiki_copyrights' )
  141.         && isset$_REQUEST['copyrightAuthors')
  142.         && !empty$_REQUEST['copyrightYear')
  143.         && !empty$_REQUEST['copyrightTitle')
  144.     {
  145.         require_onceWIKI_PKG_PATH.'copyrights_lib.php' );
  146.         $copyrightYear $_REQUEST['copyrightYear'];
  147.         $copyrightTitle $_REQUEST['copyrightTitle'];
  148.         $copyrightAuthors $_REQUEST['copyrightAuthors'];
  149.         $copyrightslib->add_copyright$gContent->mPageId$copyrightTitle$copyrightYear$copyrightAuthors$gBitUser->mUserId );
  150.     }
  151.     // Parse $edit and eliminate image references to external URIs( make them internal )
  152.     if$gBitSystem->isPackageActive'imagegals' ) ) {
  153.         include_onceIMAGEGALS_PKG_PATH.'imagegal_lib.php' );
  154.         $edit $imagegallib->capture_images$edit );
  155.     }
  156.  
  157.     if$gContent->mPageId )
  158.     {    ifisset$_REQUEST['isminor'&& $_REQUEST['isminor']=='on' {
  159.             $_REQUEST['minor']=true;
  160.         else {
  161.             $_REQUEST['minor']=false;
  162. //            $links = $gContent->get_links( $edit );
  163. //            $wikilib->cache_links( $links );
  164. //            $gContent->storeLinks( $links );
  165.         }
  166.     else {
  167. //        $links = $gContent->get_links( $_REQUEST["edit"] );
  168. //        $notcachedlinks = $gContent->get_links_nocache( $_REQUEST["edit"] );
  169. //        $cachedlinks = array_diff( $links, $notcachedlinks );
  170. //        $gContent->cache_links( $cachedlinks );
  171. //        $gContent->storeLinks( $cachedlinks );
  172.     }
  173.  
  174.     $data_to_parse $formInfo['edit'];
  175.     if (!empty($formInfo['section']&& !empty($gContent->mInfo['data']) ) {
  176.         $full_page_data $gContent->mInfo['data'];
  177.         $data_to_parse replace_section($full_page_data,$formInfo['section'],$formInfo['edit']);
  178.         $_REQUEST["edit"$data_to_parse;
  179.     }
  180.  
  181.     if$gContent->store$_REQUEST ) ) {
  182.         if$gBitSystem->isFeatureActive'wiki_watch_author' ) ) {
  183.             $gBitUser->storeWatch"wiki_page_changed"$gContent->mPageId$gContent->mContentTypeGuid$_REQUEST['title']$gContent->getDisplayUrl() );
  184.         }
  185.  
  186.         header"Location: ".$gContent->getDisplayUrl$gContent->mPageName ) );
  187.         die;
  188.  
  189.     else {
  190.         $formInfo $_REQUEST;
  191.         $formInfo['data'&$_REQUEST['edit'];
  192.     }
  193. elseif!empty$_REQUEST['edit') ) {
  194.     // perhaps we have a javascript non-saving form submit
  195.     $formInfo $_REQUEST;
  196.     $formInfo['data'&$_REQUEST['edit'];
  197. }
  198.  
  199. ifisset$_REQUEST['format_guid'&& !isset$gContent->mInfo['format_guid') ) {
  200.     $formInfo['format_guid'$gContent->mInfo['format_guid'$_REQUEST['format_guid'];
  201. }
  202.  
  203. ifisset$_REQUEST["preview") ) {
  204.     $gBitSmarty->assign'preview',);
  205.     $gBitSmarty->assign'title',!empty$_REQUEST["title"$_REQUEST["title"]:$gContent->mPageName );
  206.  
  207.     if (!empty($formInfo['section'])) {
  208.         $formInfo['edit_section'1;
  209.     }
  210.  
  211.     $data_to_parse $formInfo['edit'];
  212.     if!empty$formInfo['section'&& !empty$gContent->mInfo['data')) {
  213.         $full_page_data $gContent->mInfo['data'];
  214.     }
  215.  
  216.  
  217.     $formInfo['parsed_data'$gContent->parseData(
  218.         $data_to_parse,
  219.         !empty$_REQUEST['format_guid'$_REQUEST['format_guid'isset$gContent->mInfo['format_guid'$gContent->mInfo['format_guid''tikiwiki' ))
  220.     );
  221.     $gContent->invokeServices'content_preview_function' );
  222. }
  223.  
  224. if$gContent->isInStructure() ) {
  225.     $gBitSmarty->assign'showstructs'$gContent->getStructures() );
  226. }
  227.  
  228. // Flag for 'page bar' that currently 'Edit' mode active
  229. // so no need to show comments & attachments, but need
  230. // to show 'wiki quick help'
  231. $gBitSmarty->assign'edit_page''y' );
  232.  
  233. // formInfo might be set due to a error on submit
  234. ifempty$formInfo ) ) {
  235.     $formInfo &$gContent->mInfo;
  236. }
  237.  
  238. // make original page title available for template
  239. $formInfo['original_title'=!empty$gContent->mInfo['title') ) $gContent->mInfo['title']  "" ;
  240.  
  241. $gBitSmarty->assign_by_ref'pageInfo'$formInfo );
  242. $gBitSmarty->assign_by_ref'errors'$gContent->mErrors );
  243.  
  244. if$gBitSystem->isPackageActive'ckeditor' ) ) {
  245.     loadCkEditor();
  246. }
  247.  
  248. $gBitSystem->display'bitpackage:wiki/edit_page.tpl''Edit: '.$gContent->getTitle(array'display_mode' => 'edit' ));
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. //******************* WIKI Edit Functions
  258.  
  259. function htmldecode$string {
  260.     $string strtr$stringarray_flipget_html_translation_tableHTML_ENTITIES ) ) );
  261.     $string preg_replace"/&#([0-9]+);/me""chr('\\1')"$string );
  262.     return $string;
  263. }
  264. function parse_output&$obj&$parts,$i {
  265.     if!empty$obj->parts ) ) {
  266.         for$i=0$i<count$obj->parts )$i++ {
  267.             parse_output$obj->parts[$i]$parts,$i );
  268.         }
  269.     else {
  270.         $ctype $obj->ctype_primary.'/'.$obj->ctype_secondary;
  271.         switch$ctype {
  272.             case 'application/x-tikiwiki':
  273.                 $aux["body"$obj->body;
  274.                 $ccc=$obj->headers["content-type"];
  275.                 $items split';',$ccc );
  276.                 foreach$items as $item {
  277.                     $portions split'=',$item );
  278.                     ifisset$portions[0&&isset$portions[1) ) {
  279.                         $aux[trim$portions[0)]=trim$portions[1);
  280.                     }
  281.                 }
  282.                 $parts[]=$aux;
  283.         }
  284.     }
  285. }
  286.  
  287. function  extract_section($data,$section{
  288.     global $gContent$gBitSystem;
  289.     if$gContent->mInfo['format_guid'== PLUGIN_GUID_TIKIWIKI {
  290.         $section_data preg_split"/\n(".str_repeat"!"$gBitSystem->getConfig"wiki_section_edit" ) ) )."[^!])/""\n$data"-1PREG_SPLIT_DELIM_CAPTURE );
  291.         $a ($section 12;
  292.         $b $a 1;
  293.         return $section_data[$a$section_data[$b];
  294.     }
  295. }
  296.  
  297. function  replace_section($data,$section,$new_section_data{
  298.     global $gContent$gBitSystem;
  299.     if$gContent->mInfo['format_guid'== PLUGIN_GUID_TIKIWIKI {
  300.         $section_data preg_split("/(\n".str_repeat"!"$gBitSystem->getConfig"wiki_section_edit" ) ) )."[^!])/""\n$data,-1,PREG_SPLIT_DELIM_CAPTURE);
  301.         $a ($section 12;
  302.         $b $a 1;
  303.         $section_data[$a"\n";
  304.         $section_data[$b$new_section_data;
  305.         return substr(implode('',$section_data),1);
  306.     }
  307. }
  308.  
  309. function compare_import_versions$a1$a2 {
  310.     return $a1["version"$a2["version"];
  311. }
  312.  
  313. /**
  314.  * \brief Parsed HTML tree walker( used by HTML sucker )
  315.  *
  316.  * This is initial implementation( stupid... w/o any intellegence( almost : ) )
  317.  * It is rapidly designed version... just for test: 'can this feature be useful'.
  318.  * Later it should be replaced by well designed one :) don't bash me now : )
  319.  *
  320.  * \param &$c array -- parsed HTML
  321.  * \param &$src string -- output string
  322.  * \param &$p array -- ['stack'] = closing strings stack,
  323.                        ['listack'] = stack of list types currently opened
  324.                        ['first_td'] = flag: 'is <tr> was just before this <td>'
  325.  */
  326. function walk_and_parse&$c&$src&$p {
  327.     for$i=0$i <= $c["contentpos"]$i++ {
  328.         // If content type 'text' output it to destination...
  329.         if$c[$i]["type"== "text" {
  330.             $src .= $c[$i]["data"];
  331.         elseif$c[$i]["type"== "tag" {
  332.             if$c[$i]["data"]["type"== "open" {
  333.                 // Open tag type
  334.                 switch$c[$i]["data"]["name"{
  335.                     case "br"$src .= "\n"break;
  336.                     case "title"$src .= "\n!"$p['stack'][array'tag' => 'title''string' => "\n" )break;
  337.                     case "p"$src .= "\n"$p['stack'][array'tag' => 'p''string' => "\n" )break;
  338.                     case "b"$src .= '__'$p['stack'][array'tag' => 'b''string' => '__' )break;
  339.                     case "i"$src .= "''"$p['stack'][array'tag' => 'i''string' => "''" )break;
  340.                     case "u"$src .= "=="$p['stack'][array'tag' => 'u''string' => "==" )break;
  341.                     case "center"$src .= '::'$p['stack'][array'tag' => 'center''string' => '::' )break;
  342.                     case "code"$src .= '-+';  $p['stack'][array'tag' => 'code''string' => '+-' )break;
  343.                     // headers detection looks like real suxx code...
  344.                     // but possible it run faster :) I don't know where is profiler in PHP...
  345.                     case "h1"$src .= "\n!"$p['stack'][array'tag' => 'h1''string' => "\n" )break;
  346.                     case "h2"$src .= "\n!!"$p['stack'][array'tag' => 'h2''string' => "\n" )break;
  347.                     case "h3"$src .= "\n!!!"$p['stack'][array'tag' => 'h3''string' => "\n" )break;
  348.                     case "h4"$src .= "\n!!!!"$p['stack'][array'tag' => 'h4''string' => "\n" )break;
  349.                     case "h5"$src .= "\n!!!!!"$p['stack'][array'tag' => 'h5''string' => "\n" )break;
  350.                     case "h6"$src .= "\n!!!!!!"$p['stack'][array'tag' => 'h6''string' => "\n" )break;
  351.                     case "pre"$src .= '~pp~'$p['stack'][array'tag' => 'pre''string' => '~/pp~' )break;
  352.                     // Table parser
  353.                     case "table"$src .= '||'$p['stack'][array'tag' => 'table''string' => '||' )break;
  354.                     case "tr"$p['first_td'truebreak;
  355.                     case "td"$src .= $p['first_td''' '|'$p['first_td'falsebreak;
  356.                     // Lists parser
  357.                     case "ul"$p['listack']['*'break;
  358.                     case "ol"$p['listack']['#'break;
  359.                     case "li":
  360.                         // Generate wiki list item according to current list depth.
  361.                         //( ensure '*/#' starts from begining of line )
  362.                         for$l ''strlen$l count$p['listack')$l .= end$p['listack') );
  363.                         $src .= "\n$l ";
  364.                         break;
  365.                     case "font":
  366.                         // If color attribute present in <font> tag
  367.                         ifisset$c[$i]["pars"]["color"]["value") ) {
  368.                             $src .= '~~'.$c[$i]["pars"]["color"]["value"].':';
  369.                             $p['stack'][array'tag' => 'font''string' => '~~' );
  370.                         }
  371.                         break;
  372.                     case "img":
  373.                         // If src attribute present in <img> tag
  374.                         ifisset$c[$i]["pars"]["src"]["value") ) {
  375.                             // Note what it produce( img ) not {img}! Will fix this below...
  376.                             $src .= '( img src='.$c[$i]["pars"]["src"]["value"].' )';
  377.                         }
  378.                         break;
  379.                     case "a":
  380.                         // If href attribute present in <a> tag
  381.                         ifisset$c[$i]["pars"]["href"]["value") ) {
  382.                             $src .= '['.$c[$i]["pars"]["href"]["value"].'|';
  383.                             $p['stack'][array'tag' => 'a''string' => ']' );
  384.                         }
  385.                         break;
  386.                 }
  387.             else {
  388.                 // This is close tag type. Is that smth we r waiting for?
  389.                 switch$c[$i]["data"]["name"{
  390.                 case "ul":
  391.                     ifend$p['listack'== '*' array_pop$p['listack');
  392.                     break;
  393.                 case "ol":
  394.                     ifend$p['listack'== '#' array_pop$p['listack');
  395.                     break;
  396.                 default:
  397.                     $e end$p['stack');
  398.                     if$c[$i]["data"]["name"== $e['tag'{
  399.                         $src .= $e['string'];
  400.                         array_pop$p['stack');
  401.                     }
  402.                     break;
  403.                 }
  404.             }
  405.         }
  406.         // Recursive call on tags with content...
  407.         ifisset$c[$i]["content") ) {
  408. //            if( substr( $src, -1 )!= " " )$src .= " ";
  409.             walk_and_parse$c[$i]["content"]$src$p );
  410.         }
  411.     }
  412. }
  413. ifisset$_REQUEST["suck_url") ) {
  414.     if!$gBitSystem->isFeatureActive'wiki_url_import' ) ) {
  415.         $gBitSystem->fatalErrortra"Importing remote URLs is disabled" ));
  416.     }
  417.     // Suck another page and append to the end of current
  418.     require_onceUTIL_PKG_PATH.'htmlparser/html_parser_inc.php' );
  419.     $suck_url = isset$_REQUEST["suck_url"$_REQUEST["suck_url"'';
  420.     $parsehtml = isset$_REQUEST["parsehtml"$_REQUEST["parsehtml"== 'on' 'y' 'n' )'n';
  421.     ifisset$_REQUEST['do_suck'&& strlen$suck_url {
  422.         // \note by zaufi
  423.         //   This is ugly implementation of wiki HTML import.
  424.         //   I think it should be plugable import/export converters with ability
  425.         //   to choose from edit form what converter to use for operation.
  426.         //   In case of import converter, it can try to guess what source
  427.         //   file is( using mime type from remote server response ).
  428.         //   Of couse converters may have itsown configuration panel what should be
  429.         //   pluged into wiki page edit form too...( like HTML importer may have
  430.         //   flags 'strip HTML tags' and 'try to convert HTML to wiki' : )
  431.         //   At least one export filter for wiki already coded : ) -- PDF exporter...
  432.         $parsed_url parse_url($suck_url);
  433.         //Disallow urls without schema (usually relative urls), or http(s)
  434.         if(!isset($parsed_url['scheme']|| ($parsed_url['scheme']!='http' && $parsed_url['scheme']!='https')){
  435.             $gBitSystem->fatalErrortra"Invalid URL; not absolute or not HTTP" ));
  436.         }
  437.         //Make sure the passed host isn't local
  438.         if(!isset($parsed_url['host']|| ($parsed_url['host']=='localhost'|| strncmp($parsed_url['host'],"127.",4)==0){
  439.             $gBitSystem->fatalErrortra"The host specified is either empty or local." ));
  440.         }
  441.         $sdta @file_get_contents$suck_url );
  442.         ifisset$php_errormsg && strlen$php_errormsg ) ) {
  443.             $gBitSystem->fatalErrortra"Can't import remote HTML page" ));
  444.         }
  445.         // Need to parse HTML?
  446.         if$parsehtml == 'y' {
  447.             // Read compiled( serialized ) grammar
  448.             $grammarfile UTIL_PKG_PATH.'htmlparser/htmlgrammar.cmp';
  449.             if!$fp @fopen$grammarfile,'r' ) ) {
  450.                 $gBitSystem->fatalErrortra"Can't parse remote HTML page" ));
  451.             }
  452.             $grammar unserializefread$fpfilesize$grammarfile ) ) );
  453.             fclose$fp );
  454.             // create parser object, insert html code and parse it
  455.             $htmlparser new HtmlParser$sdta$grammar'');
  456.             $htmlparser->Parse();
  457.             // Should I try to convert HTML to wiki?
  458.             $parseddata '';
  459.             $p =  array'stack' => array()'listack' => array()'first_td' => false );
  460.             walk_and_parse$htmlparser->content$parseddata$p );
  461.             // Is some tags still opened?( It can be if HTML not valid, but this is not reason
  462.             // to produce invalid wiki : )
  463.             whilecount$p['stack') ) {
  464.                 $e end$p['stack');
  465.                 $sdta .= $e['string'];
  466.                 array_pop$p['stack');
  467.             }
  468.             // Unclosed lists r ignored... wiki have no special start/end lists syntax....
  469.             // OK. Things remains to do:
  470.             // 1 ) fix linked images
  471.             $parseddata preg_replace',\[(.*)\|\( img src=(.*)\)\],mU','{img src=$2 link=$1}'$parseddata );
  472.             // 2 ) fix remains images( not in links )
  473.             $parseddata preg_replace',\( img src=(.*)\),mU','{img src=$1}'$parseddata );
  474.             // 3 ) remove empty lines
  475.             $parseddata preg_replace",[\n]+,mU","\n"$parseddata );
  476.             // Reassign previous data
  477.             $sdta $parseddata;
  478.         }
  479.         $_REQUEST['edit'.= $sdta;
  480.     }
  481. }
  482.  
  483. //***************************************
  484.  
  485.  
  486.  
  487. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:24 +0000 by phpDocumentor 1.5.0-lsces