function createPage($username = NULL, $password = NULL, $id = NULL, $loginToken = NULL, $editToken = NULL, $title = NULL, $text = NULL, $summary = NULL) { $__pcpServer = new PCPServer(); $__userCredentials = new PCPUserCredentials($username, $password, $id, $loginToken, $editToken); print "Testing{$username}, {$password}, {$id}, {$loginToken}, {$editToken}{$title}, {$text}, {$summary}->" . $__pcpServer->createPage($__userCredentials, $title, $text, $summary); print simplexml_load_string(PCPUtil::createXMLResponse($__pcpServer->createPage($__userCredentials, $title, $text, $summary)), 'SimpleXMLElement'); return simplexml_load_string(PCPUtil::createXMLResponse($__pcpServer->createPage($__userCredentials, $title, $text, $summary)), 'SimpleXMLElement'); }
<?php /** * @file * @ingroup DAPCPTest * * @author Dian */ /** * This group contains all parts of the DataAPI that deal with tests for the PCP component * @defgroup DAPCPTest * @ingroup DAPCP */ chdir('F:\\xampp\\htdocs\\mw'); require_once 'F:/xampp/htdocs/mw/includes/Webstart.php'; $editTest = new PCPServer(); $uc = new PCPUserCredentials("WikiSysop", "", 1, "93f49f1cb77a00ae03b3eb90069d76dd"); //$editTest->login($uc); //if ($editTest->login($uc)){ #var_dump($editTest->getCookies()); #$editTest->getEditToken("Main Page"); var_dump($editTest->createPage($uc, "Another test", "Adding some content")); $editTest->logout(); //}else{ // print ("ERROR: Testing failed!".__FILE__); //}
<?php /** * @file * @ingroup DAPCPExample * * @author Dian */ /** * This group contains all parts of the DataAPI that provide examples for the PCP component * @defgroup DAPCPExample * @ingroup DAPCP */ // the path to your wiki installation home chdir('/xampp/htdocs/wiki'); require_once '/xampp/htdocs/wiki/includes/Webstart.php'; $createTest = new PCPServer(); $uc = new PCPUserCredentials("TestUser", "TestPassword"); if ($createTest->login($uc)) { echo $createTest->createPage($uc, "A test page", "Adding some content"); $createTest->logout(); } else { print "ERROR: Testing failed!"; }
/** * 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 ""; }
/** * Create new pages. * * @param string $username * @param string $password * @param string $id * @param string $loginToken * @param string $title The titles must be separated by "|". * @param string $text The texts are read from an associative array with titles as keys. * @param string $summary The summaries are read from an associative array with titles as keys. * @return hashmap Status per title. */ protected function createPages($username = NULL, $password = NULL, $id = NULL, $loginToken = NULL, $title = NULL, $text = NULL, $summary = NULL) { $__pcpServer = new PCPServer(); $__userCredentials = new PCPUserCredentials($username, $password, $id, $loginToken); $__titles = split("|", $title); $__resultSet = array(); $__result = array(); foreach ($__titles as $__title) { $__resultSet[str_replace(" ", "_", $__title)] = $__pcpServer->createPage($__userCredentials, $__title, $text[$__title], $summary[$__title]); } $__result['createPage'] = $__resultSet; return $__result; }