Exemplo n.º 1
0
 protected function getTemplateByTitle($username = NULL, $password = NULL, $id = NULL, $loginToken = NULL, $editToken = NULL, $title = NULL, $revisionID = NULL, $templateTitle = NULL)
 {
     $__pcpServer = new PCPServer();
     $__userCredentials = new PCPUserCredentials($username, $password, $id, $loginToken, $editToken);
     $__pcpServer->login($__userCredentials);
     $__pom = new POMPage($title, $__pcpServer->readPage($__userCredentials, $title, $revisionID)->text);
     $__result = array();
     $__elementsIterator = $__pom->getTemplateByTitle($templateTitle)->listIterator();
     while ($__elementsIterator->hasNext()) {
         $__element =& $__elementsIterator->getNextNodeValueByReference();
         $__array = $this->toArray($__element);
         $__result[get_class($__element)][$__element->id] = $__array;
     }
     return $__result;
 }
Exemplo n.º 2
0
 * @file
 * @ingroup DAPOMExample
 * 
 * @author Dian
 */
/**
 * This group contains all parts of the DataAPI that provide examples for the POM component
 * @defgroup DAPOMExample
 * @ingroup DAPOM
 */
chdir('C:\\xampp\\htdocs\\wiki');
require_once 'C:/xampp/htdocs/wiki/includes/Webstart.php';
# Get document from MediaWiki server
$pom = new POMPage('Testeintrag', join(file('http://localhost/wiki/index.php?title=Testeintrag&action=raw')), array('POMExtendedParser'));
# iterate trough the templates
$iterator = $pom->getTemplateByTitle("Post")->listIterator();
while ($iterator->hasNext()) {
    $template =& $iterator->getNextNodeValueByReference();
    # get reference for direct changes
    if ($template->getParameter("PARAMETERNAME") !== NULL) {
        # check if the parameter exists
        if ($template->getParameter("PARAMETERNAME")->getValue()->getElement() !== NULL) {
            # a parameter value exists
            # get the first subelement of the page object representing the parameter value
            var_dump($template->getParameter("PARAMETERNAME"));
            $anElement =& $template->getParameter("PARAMETERNAME")->getValueByReference()->getElement();
            var_dump($anElement);
        } else {
            # add a new text element
            $parameterValue =& $template->getParameter("PARAMETERNAME")->getValueByReference();
            $simpleText = new POMSimpleText("A simple text element!");
Exemplo n.º 3
0
 /**
  * Gets all pages for a specific SF. The pages returned have an instance of the requested SF defined.
  *
  * @param string $sfName The name of the SF.
  * @param string $substring Subtsting to search upon in the names of the SFs.
  * @return array A list of page names.
  */
 public function getPageList($sfName, $substring)
 {
     $__pageList = array();
     $__serverUtility = new PCPServer();
     $__store = smwfGetStore();
     if (strstr($sfName, ':') !== false) {
         list($__sfNamespace, $__sfTitle) = split(':', $sfName);
     } else {
         $__sfTitle = $sfName;
     }
     if ($__sfTitle == '') {
         // search for all SFs
         $__tmpList = SFUtils::getAllForms();
         // categories or properties which use a spcific SF
         // the structure is $__referencingAnnotations['root']['FORMNAME'][NS-NUMBER]['PAGETITLE']
         // 				    $__referencingAnnotations['root']['FORMNAME']['sfobj']
         $__referencingAnnotations = array();
         // first: get all categories / properties that have the SF as default form
         foreach ($__tmpList as $__tmpSF) {
             // workaround: trigger an ASK query
             $__queryobj = SMWQueryProcessor::createQuery("[[Has default form::{$__tmpSF}]]", array());
             $__queryobj->querymode = SMWQuery::MODE_INSTANCES;
             $__res = smwfGetStore()->getQueryResult($__queryobj);
             $__resCount = $__res->getCount();
             for ($__i = 0; $__i < $__resCount; $__i++) {
                 $__resArray = $__res->getNext();
                 // SMWResultArray[]
                 foreach ($__resArray as $__resElement) {
                     // object from class SMWResultArray
                     $__tmpArr = $__resElement->getContent();
                     // SMWWikiPageValue[]
                     $__resPage = $__tmpArr[0];
                     // object from class SMWWikiPageValue - only 1 element is expected
                     $__referencingAnnotations[$__tmpSF][$__resPage->getNamespace()][$__resPage->getText()] = $__resPage->getTitle();
                 }
             }
         }
         // second: get all categories / properties that have the SF as an alternate form
         $__queryobj = array();
         $__res = array();
         foreach ($__tmpList as $__tmpSF) {
             // workaround: trigger an ASK query
             $__queryobj = SMWQueryProcessor::createQuery("[[Has alternate form::{$__tmpSF}]]", array());
             $__queryobj->querymode = SMWQuery::MODE_INSTANCES;
             $__res = smwfGetStore()->getQueryResult($__queryobj);
             $__resCount = $__res->getCount();
             for ($__i = 0; $__i < $__resCount; $__i++) {
                 $__resArray = $__res->getNext();
                 // SMWResultArray[]
                 foreach ($__resArray as $__resElement) {
                     // object from class SMWResultArray
                     $__tmpArr = $__resElement->getContent();
                     // SMWWikiPageValue[]
                     $__resPage = $__tmpArr[0];
                     // object from class SMWWikiPageValue - only 1 element is expected
                     $__referencingAnnotations[$__tmpSF][$__resPage->getNamespace()][$__resPage->getText()] = $__resPage->getTitle();
                 }
             }
             // now add the SF structure
             // we need at first the template title, but in future even comparision based on fields is possible
             if (isset($__referencingAnnotations[$__tmpSF][$__resPage->getNamespace()])) {
                 $__referencingAnnotations[$__tmpSF]['sfobj'] = $this->serializedForm($__tmpSF);
             }
         }
         // now determine the pages using the found categories / properties
         foreach (array_keys($__referencingAnnotations) as $__sformName) {
             $__sfCategories = $__referencingAnnotations[$__sformName][NS_CATEGORY];
             $__sfProperties = $__referencingAnnotations[$__sformName][SMW_NS_PROPERTY];
             // build a complex ASK query for all categories and properties
             $__complexQuery = '';
             if (isset($__sfCategories)) {
                 if ($__sfCategories !== NULL) {
                     foreach (array_keys($__sfCategories) as $__sfCategory) {
                         if ($__complexQuery !== '') {
                             $__complexQuery .= " OR [[Category:{$__sfCategory}]]";
                         } else {
                             $__complexQuery .= "[[Category:{$__sfCategory}]]";
                         }
                     }
                 }
             }
             if (isset($__sfProperties)) {
                 if ($__sfProperties !== NULL) {
                     foreach (array_keys($__sfProperties) as $__sfProperty) {
                         if ($__complexQuery !== '') {
                             $__complexQuery .= " OR [[{$__sfProperty}::+]]";
                         } else {
                             $__complexQuery .= "[[{$__sfProperty}::+]]";
                         }
                     }
                 }
             }
             $__queryobj = SMWQueryProcessor::createQuery($__complexQuery, array());
             $__queryobj->querymode = SMWQuery::MODE_INSTANCES;
             $__res = smwfGetStore()->getQueryResult($__queryobj);
             $__resCount = $__res->getCount();
             for ($__i = 0; $__i < $__resCount; $__i++) {
                 $__resArray = $__res->getNext();
                 // SMWResultArray[]
                 foreach ($__resArray as $__resElement) {
                     // object from class SMWResultArray
                     $__tmpArr = $__resElement->getContent();
                     // SMWWikiPageValue[]
                     $__resPage = $__tmpArr[0];
                     // object from class SMWWikiPageValue - only 1 element is expected
                     // check if the substring matches
                     if ($substring != '') {
                         if (stristr($__resPage->getText(), $substring)) {
                             // now read the POM of each page and search for the template used by the SF
                             $__pcpPage = $__serverUtility->readPage(NULL, $__resPage->getText());
                             $__pom = new POMPage($__resPage->getText(), $__pcpPage->text, array('POMExtendedParser'));
                             // search for the template
                             foreach ($__referencingAnnotations[$__sformName]['sfobj'] as $template) {
                                 $__iterator = $__pom->getTemplateByTitle($template['tmpl_name'])->listIterator();
                                 if ($__iterator->hasNext()) {
                                     $__pageList['root'][str_replace(" ", "_", $__sformName)][str_replace(" ", "_", $__resPage->getText())] = array();
                                     $__pageList['root'][str_replace(" ", "_", $__sformName)][str_replace(" ", "_", $__resPage->getText())]['ns'] = $__pcpPage->ns;
                                     $__pageList['root'][str_replace(" ", "_", $__sformName)][str_replace(" ", "_", $__resPage->getText())]['rid'] = $__pcpPage->lastrevid;
                                 }
                             }
                         }
                     } else {
                         // now read the POM of each page and search for the template used by the SF
                         $__pcpPage = $__serverUtility->readPage(NULL, $__resPage->getText());
                         $__pom = new POMPage($__resPage->getText(), $__pcpPage->text, array('POMExtendedParser'));
                         // search for the template
                         foreach ($__referencingAnnotations[$__sformName]['sfobj'] as $template) {
                             $__iterator = $__pom->getTemplateByTitle($template['tmpl_name'])->listIterator();
                             if ($__iterator->hasNext()) {
                                 $__pageList['root'][str_replace(" ", "_", $__sformName)][str_replace(" ", "_", $__resPage->getText())] = array();
                                 $__pageList['root'][str_replace(" ", "_", $__sformName)][str_replace(" ", "_", $__resPage->getText())]['ns'] = $__pcpPage->ns;
                                 $__pageList['root'][str_replace(" ", "_", $__sformName)][str_replace(" ", "_", $__resPage->getText())]['rid'] = $__pcpPage->lastrevid;
                             }
                         }
                     }
                 }
             }
         }
     } else {
         // search only for a single SF
         // categories or properties which use a spcific SF
         // the structure is $__referencingAnnotations['FORMNAME'][NS-NUMBER]['PAGETITLE']
         // 				    $__referencingAnnotations['FORMNAME']['sfobj']
         $__referencingAnnotations = array();
         // first: get all categories / properties that have the SF as default form
         // workaround: trigger an ASK query
         $__queryobj = SMWQueryProcessor::createQuery("[[Has default form::{$__sfTitle}]]", array());
         $__queryobj->querymode = SMWQuery::MODE_INSTANCES;
         $__res = smwfGetStore()->getQueryResult($__queryobj);
         $__resCount = $__res->getCount();
         for ($__i = 0; $__i < $__resCount; $__i++) {
             $__resArray = $__res->getNext();
             // SMWResultArray[]
             foreach ($__resArray as $__resElement) {
                 // object from class SMWResultArray
                 $__tmpArr = $__resElement->getContent();
                 // SMWWikiPageValue[]
                 $__resPage = $__tmpArr[0];
                 // object from class SMWWikiPageValue - only 1 element is expected
                 $__referencingAnnotations[$__sfTitle][$__resPage->getNamespace()][$__resPage->getText()] = $__resPage->getTitle();
             }
         }
         // second: get all categories / properties that have the SF as an alternate form
         $__queryobj = array();
         $__res = array();
         // workaround: trigger an ASK query
         $__queryobj = SMWQueryProcessor::createQuery("[[Has alternate form::{$__sfTitle}]]", array());
         $__queryobj->querymode = SMWQuery::MODE_INSTANCES;
         $__res = smwfGetStore()->getQueryResult($__queryobj);
         $__resCount = $__res->getCount();
         for ($__i = 0; $__i < $__resCount; $__i++) {
             $__resArray = $__res->getNext();
             // SMWResultArray[]
             foreach ($__resArray as $__resElement) {
                 // object from class SMWResultArray
                 $__tmpArr = $__resElement->getContent();
                 // SMWWikiPageValue[]
                 $__resPage = $__tmpArr[0];
                 // object from class SMWWikiPageValue - only 1 element is expected
                 $__referencingAnnotations[$__sfTitle][$__resPage->getNamespace()][$__resPage->getText()] = $__resPage->getTitle();
             }
         }
         // now add the SF structure
         // we need at first the template title, but in future even comparision based on fields is possible
         if (isset($__referencingAnnotations[$__sfTitle][$__resPage->getNamespace()])) {
             $__referencingAnnotations[$__sfTitle]['sfobj'] = $this->serializedForm($__sfTitle);
         }
         // now determine the pages using the found categories / properties
         $__sfCategories = $__referencingAnnotations[$__sfTitle][NS_CATEGORY];
         $__sfProperties = $__referencingAnnotations[$__sfTitle][SMW_NS_PROPERTY];
         // build a complex ASK query for all categories and properties
         $__complexQuery = '';
         if (isset($__sfCategories)) {
             foreach (array_keys($__sfCategories) as $__sfCategory) {
                 if ($__complexQuery !== '') {
                     $__complexQuery .= " OR [[Category:{$__sfCategory}]]";
                 } else {
                     $__complexQuery .= "[[Category:{$__sfCategory}]]";
                 }
             }
         }
         if (isset($__sfProperties)) {
             foreach (array_keys($__sfProperties) as $__sfProperty) {
                 if ($__complexQuery !== '') {
                     $__complexQuery .= " OR [[{$__sfProperty}::+]]";
                 } else {
                     $__complexQuery .= "[[{$__sfProperty}::+]]";
                 }
             }
         }
         $__queryobj = SMWQueryProcessor::createQuery($__complexQuery, array());
         $__queryobj->querymode = SMWQuery::MODE_INSTANCES;
         $__res = smwfGetStore()->getQueryResult($__queryobj);
         $__resCount = $__res->getCount();
         for ($__i = 0; $__i < $__resCount; $__i++) {
             $__resArray = $__res->getNext();
             // SMWResultArray[]
             foreach ($__resArray as $__resElement) {
                 // object from class SMWResultArray
                 $__tmpArr = $__resElement->getContent();
                 // SMWWikiPageValue[]
                 $__resPage = $__tmpArr[0];
                 // object from class SMWWikiPageValue - only 1 element is expected
                 // check if the substring matches
                 if ($substring != '') {
                     if (stristr($__resPage->getText(), $substring)) {
                         // now read the POM of each page and search for the template used by the SF
                         $__pcpPage = $__serverUtility->readPage(NULL, $__resPage->getText());
                         $__pom = new POMPage($__resPage->getText(), $__pcpPage->text, array('POMExtendedParser'));
                         // search for the template
                         foreach ($__referencingAnnotations[$__sfTitle]['sfobj'] as $template) {
                             $__iterator = $__pom->getTemplateByTitle($template['tmpl_name'])->listIterator();
                             if ($__iterator->hasNext()) {
                                 $__pageList[str_replace(" ", "_", $__sfTitle)][str_replace(" ", "_", $__resPage->getText())] = array();
                                 $__pageList[str_replace(" ", "_", $__sfTitle)][str_replace(" ", "_", $__resPage->getText())]['ns'] = $__pcpPage->ns;
                                 $__pageList[str_replace(" ", "_", $__sfTitle)][str_replace(" ", "_", $__resPage->getText())]['rid'] = $__pcpPage->lastrevid;
                             }
                         }
                     }
                 } else {
                     // now read the POM of each page and search for the template used by the SF
                     $__pcpPage = $__serverUtility->readPage(NULL, $__resPage->getText());
                     $__pom = new POMPage($__resPage->getText(), $__pcpPage->text, array('POMExtendedParser'));
                     // search for the template
                     foreach ($__referencingAnnotations[$__sfTitle]['sfobj'] as $template) {
                         $__iterator = $__pom->getTemplateByTitle($template['tmpl_name'])->listIterator();
                         if ($__iterator->hasNext()) {
                             $__pageList[str_replace(" ", "_", $__sfTitle)][str_replace(" ", "_", $__resPage->getText())] = array();
                             $__pageList[str_replace(" ", "_", $__sfTitle)][str_replace(" ", "_", $__resPage->getText())]['ns'] = $__pcpPage->ns;
                             $__pageList[str_replace(" ", "_", $__sfTitle)][str_replace(" ", "_", $__resPage->getText())]['rid'] = $__pcpPage->lastrevid;
                         }
                     }
                 }
             }
         }
     }
     return $__pageList;
 }