/** * Reads serialized data in JSON format and saves the requested chages. * * @param JSON $sfdata The posted data including page and SF attributes. * @param string $methodType The action to be performed: c(create) or u(update) or d(delete). * @param string $username The username provided. * @param string $userId The user ID provided. * @param string $loginToken The login token provided. */ public function setSerializedJsonForm($sfdata, $methodType, $username = NULL, $userId = NULL, $loginToken = NULL) { $__jsonData = json_decode(str_replace('#U002B#', '+', $sfdata), true); $__serverUtility = new PCPServer(); $__userCredentials = new PCPUserCredentials($username, NULL, $userId, $loginToken); //print_r($__jsonData);die; $__pageNs = utf8_decode($__jsonData['sfdata']['page']['ns']); $__pageTitle = $__jsonData['sfdata']['page']['title']; $__pageRId = $__jsonData['sfdata']['page']['rid']; $__page = $__serverUtility->readPage($__userCredentials, $__pageTitle, $__pageRId); if (stristr($methodType, "c")) { // the requested method is create if ($__page->pageid == NULL || $__page->pageid == "") { // the page doesn't exist so we have to create it // the XML data is read and a template is created for each SF // since the attributes will be read together with the SF elements unset them unset($__jsonData['sfdata']['page']['title']); unset($__jsonData['sfdata']['page']['ns']); unset($__jsonData['sfdata']['page']['rid']); $__sfNames = array_keys($__jsonData['sfdata']['page']); $__tmplString = ""; // used for the creation of all template strings $__tmplNames = ""; // used for adding addtional info to the summary foreach ($__sfNames as $__sfName) { $__sf = $__jsonData['sfdata']['page'][$__sfName]; if (isset($__sf['mfi'])) { // multiple SF instancies detected - multiple SFs to be saved in one request // TODO: implement } else { // build the template string for each SF element foreach ($__sf as $template) { $__tmplString .= "\n{{" . utf8_decode($template['tmpl_name']) . "\n"; // the tempalte name $__tmplNames .= utf8_decode($template['tmpl_name']) . "\t"; // since @array will be read together with the SF field elements unset it foreach ($template as $__field) { // in the SF element are listed all SF fields // add the field name and value to the template if (array_key_exists('template_field', $__field)) { $__tmplString .= "|" . utf8_decode($__field['template_field']['field_name']) . "=" . utf8_decode($__field['cur_value']) . "\n"; } } $__tmplString .= "}}\n"; // add closing brackets to the template } } } return $__serverUtility->createPage($__userCredentials, $__pageTitle, $__tmplString, "SF data added to the page via the SF API. Templates:\t" . $__tmplNames); } else { // create the POM object for the requested page $__pom = new POMPage($__pageTitle, $__page->text, array('POMExtendedParser')); // since the attributes will be read together with the SF elements unset them unset($__jsonData['sfdata']['page']['title']); unset($__jsonData['sfdata']['page']['ns']); unset($__jsonData['sfdata']['page']['rid']); $__sfNames = array_keys($__jsonData['sfdata']['page']); $__tmplString = $__pom->text; // used for the creation of all template strings - preserve the existing page text if any $__tmplNames = ""; // used for adding addtional info to the summary foreach ($__sfNames as $__sfName) { $__sf = $__jsonData['sfdata']['page'][$__sfName]; foreach ($__sf as $template) { $__iterator = $__pom->getTemplateByTitle($template['tmpl_name'])->listIterator(); if (isset($__sf['mfi'])) { // multiple SF instances detected // TODO: implement } else { // build the template string for each SF element $__tmplString .= "\n{{" . utf8_decode($template['tmpl_name']) . "\n"; // the tempalte name $__tmplNames .= utf8_decode($__sf['tmpl_name']) . "\t"; // since @array will be read together with the SF field elements unset it unset($__sf['tmpl_name']); foreach ($template as $__field) { // in the SF element are listed all SF fields // add the field name and value to the template $__tmplString .= "|" . utf8_decode($__field['template_field']['field_name']) . "=" . utf8_decode($__field['cur_value']) . "\n"; } $__tmplString .= "}}\n"; // add closing brackets to the template } } } return $__serverUtility->updatePage($__userCredentials, $__pageTitle, $__tmplString, "SF data added to the page via the SF API. Templates:\t" . $__tmplNames); } } if (stristr($methodType, "u")) { // the requested method is update if ($__page->pageid != NULL && $__page->pageid != "") { // the page exists // create the POM object for the requested page $__pom = new POMPage($__pageTitle, $__page->text, array('POMExtendedParser')); // since the attributes will be read together with the SF elements unset them unset($__jsonData['sfdata']['page']['title']); unset($__jsonData['sfdata']['page']['ns']); unset($__jsonData['sfdata']['page']['rid']); $__sfNames = array_keys($__jsonData['sfdata']['page']); $__tmplNames = ""; // used for adding addtional info to the summary foreach ($__sfNames as $__sfName) { $__sf = $__jsonData['sfdata']['page'][$__sfName]; foreach ($__sf as $template) { $__iterator = $__pom->getTemplateByTitle(utf8_decode($template['tmpl_name']))->listIterator(); $__tmplNames .= $template . " "; if (isset($__sf['mfi'])) { // multiple SF instances detected // TODO: implement } else { $__template =& $__iterator->getNextNodeValueByReference(); # get reference for direct changes // since the attribute will be read together with the SF field elements unset it unset($template['tmpl_name']); //print_r($__sf); die; foreach ($template as $__field) { // in the SF element are listed all SF fields if ($__template->getParameter($__field['template_field']['field_name']) !== NULL) { $__paramValue =& $__template->getParameterValue(utf8_decode($__field['template_field']['field_name'])); $__paramValue = new POMSimpleText(utf8_decode($__field['cur_value'])); } } } } } $__pom->sync(); //print($__pom->text);die; return $__serverUtility->updatePage($__userCredentials, $__pageTitle, $__pom->text, "SF data updated on the page via the SF API. Templates:\t" . $__tmplNames); } else { // the page does not exist $this->dieUsage("Request cancelled. Page " . $__pageTitle . " does not exist.", 'param_xmldata'); } } if (stristr($methodType, "d")) { // the requested method is delete if ($__page->pageid != NULL && $__page->pageid != "") { // the page exists // create the POM object for the requested page $__pom = new POMPage($__pageTitle, $__page->text, array('POMExtendedParser')); // since the attributes will be read together with the SF elements unset them unset($__jsonData['sfdata']['page']['title']); unset($__jsonData['sfdata']['page']['ns']); unset($__jsonData['sfdata']['page']['rid']); $__sfNames = array_keys($__jsonData['sfdata']['page']); $__tmplNames = ""; // used for adding addtional info to the summary foreach ($__sfNames as $__sfName) { $__sf = $__jsonData['sfdata']['page'][$__sfName]; $__iterator = $__pom->getTemplateByTitle(utf8_decode($__sf['tmpl_name']))->listIterator(); $__tmplNames .= $__sf . " "; if (isset($__sf['@attributes']['mfi'])) { // multiple SF instances detected // TODO: implement } else { $__template =& $__iterator->getNextNodeValueByReference(); # get reference for direct changes $__template = new POMSimpleText(""); } } $__pom->sync(); return $__serverUtility->updatePage($__userCredentials, $__pageTitle, $__pom->text, "SF data deleted on the page via the SF API. Templates:\t" . $__tmplNames); } else { // the page does not exist $this->dieUsage("Request cancelled. Page " . $__pageTitle . " does not exist.", 'param_xmldata'); } } return ""; }
<?php /** * @file * @ingroup DAPCPTest * * @author Dian */ chdir('C:\\xampp\\htdocs\\mw'); require_once 'C:/xampp/htdocs/mw/includes/Webstart.php'; $editTest = new PCPServer(); $uc = $editTest->login(new PCPUserCredentials("WikiSysop", "!>ontoprise?")); #var_dump($editTest->getCookies()); #$editTest->getEditToken("Main Page"); $uc->id = NULL; $uc->un = NULL; $editTest->updatePage($uc, "Testpage", "Works again.", "Page updated."); $editTest->logout(); //}else{ // print ("ERROR: Testing failed!".__FILE__); //}
/** * Update a page. * * @param string $username * @param string $password * @param string $id * @param string $loginToken * @param string $title * @param string $text * @param string $summary * @param string $basetimestamp * @param string $md5_hash * @return status */ protected function updatePage($username = NULL, $password = NULL, $id = NULL, $loginToken = NULL, $title = NULL, $text = NULL, $summary = NULL, $basetimestamp = NULL, $md5_hash = NULL) { $__pcpServer = new PCPServer(); $__userCredentials = new PCPUserCredentials($username, $password, $id, $loginToken); $__result = array(); $__result['updatePage'] = $__pcpServer->updatePage($__userCredentials, $title, $text, $summary, $basetimestamp, $md5_hash); return $__result; }