Ejemplo n.º 1
0
    function execute($query)
    {
        global $wgOut, $wgRequest, $wgUser, $sfgScriptPath;
        $this->setHeaders();
        // Cycle through the query values, setting the appropriate
        // local variables.
        $category_name = $wgRequest->getVal('category_name');
        $default_form = $wgRequest->getVal('default_form');
        $parent_category = $wgRequest->getVal('parent_category');
        $category_name_error_str = null;
        $save_page = $wgRequest->getCheck('wpSave');
        $preview_page = $wgRequest->getCheck('wpPreview');
        if ($save_page || $preview_page) {
            // Validate category name
            if ($category_name === '') {
                $category_name_error_str = wfMsg('sf_blank_error');
            } else {
                // Redirect to wiki interface
                $wgOut->setArticleBodyOnly(true);
                $title = Title::makeTitleSafe(NS_CATEGORY, $category_name);
                $full_text = SFCreateCategory::createCategoryText($default_form, $category_name, $parent_category);
                $text = SFUtils::printRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null);
                $wgOut->addHTML($text);
                return;
            }
        }
        $all_forms = SFUtils::getAllForms();
        // Set 'title' as hidden field, in case there's no URL niceness
        global $wgContLang;
        $mw_namespace_labels = $wgContLang->getNamespaces();
        $special_namespace = $mw_namespace_labels[NS_SPECIAL];
        $text = <<<END
\t<form action="" method="get">

END;
        $text .= "\t" . Html::hidden('title', "{$special_namespace}:CreateCategory") . "\n";
        $firstRow = wfMsg('sf_createcategory_name') . ' ' . Html::input('category_name', null, 'text', array('size' => 25)) . "\n";
        if (!is_null($category_name_error_str)) {
            $firstRow .= Html::element('span', array('style' => 'color: red;'), $category_name_error_str) . "\n";
        }
        $firstRow .= "\t" . wfMsg('sf_createcategory_defaultform') . "\n";
        $formSelector = "\t" . Html::element('option', null, null) . "\n";
        foreach ($all_forms as $form) {
            $formSelector .= "\t" . Html::element('option', null, $form) . "\n";
        }
        $firstRow .= Html::rawElement('select', array('id' => 'form_dropdown', 'name' => 'default_form'), $formSelector);
        $text .= Html::rawElement('p', null, $firstRow);
        $subcategory_label = wfMsg('sf_createcategory_makesubcategory');
        $text .= <<<END
\t<p>{$subcategory_label}
\t<select id="category_dropdown" name="parent_category">
\t<option></option>

END;
        $categories = SFUtils::getCategoriesForPage();
        foreach ($categories as $category) {
            $category = str_replace('_', ' ', $category);
            $text .= "\t" . Html::element('option', null, $category) . "\n";
        }
        $text .= "\t</select>\n";
        $editButtonsText = "\t" . Html::input('wpSave', wfMsg('savearticle'), 'submit', array('id' => 'wpSave')) . "\n";
        $editButtonsText .= "\t" . Html::input('wpPreview', wfMsg('preview'), 'submit', array('id' => 'wpPreview')) . "\n";
        $text .= "\t" . Html::rawElement('div', array('class' => 'editButtons'), $editButtonsText) . "\n";
        $text .= <<<END
\t<br /><hr /<br />

END;
        $sk = $wgUser->getSkin();
        $create_form_link = SFUtils::linkForSpecialPage($sk, 'CreateForm');
        $text .= "\t" . Html::rawElement('p', null, $create_form_link . '.') . "\n";
        $text .= "\t</form>\n";
        $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css");
        $wgOut->addHTML($text);
    }
 function execute($query)
 {
     global $wgOut, $wgRequest, $sfgScriptPath;
     $this->setHeaders();
     // Cycle through the query values, setting the appropriate
     // local variables.
     if (!is_null($query)) {
         $presetCategoryName = str_replace('_', ' ', $query);
         $wgOut->setPageTitle(wfMessage('sf-createcategory-with-name', $presetCategoryName)->text());
         $category_name = $presetCategoryName;
     } else {
         $presetCategoryName = null;
         $category_name = $wgRequest->getVal('category_name');
     }
     $default_form = $wgRequest->getVal('default_form');
     $parent_category = $wgRequest->getVal('parent_category');
     $category_name_error_str = null;
     $save_page = $wgRequest->getCheck('wpSave');
     $preview_page = $wgRequest->getCheck('wpPreview');
     if ($save_page || $preview_page) {
         // Guard against cross-site request forgeries (CSRF).
         $validToken = $this->getUser()->matchEditToken($wgRequest->getVal('csrf'), 'CreateCategory');
         if (!$validToken) {
             $text = "This appears to be a cross-site request forgery; canceling save.";
             $wgOut->addHTML($text);
             return;
         }
         // Validate category name
         if ($category_name === '') {
             $category_name_error_str = wfMessage('sf_blank_error')->text();
         } else {
             // Redirect to wiki interface
             $wgOut->setArticleBodyOnly(true);
             $title = Title::makeTitleSafe(NS_CATEGORY, $category_name);
             $full_text = SFCreateCategory::createCategoryText($default_form, $category_name, $parent_category);
             $text = SFUtils::printRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null);
             $wgOut->addHTML($text);
             return;
         }
     }
     $all_forms = SFUtils::getAllForms();
     // Set 'title' as hidden field, in case there's no URL niceness
     global $wgContLang;
     $mw_namespace_labels = $wgContLang->getNamespaces();
     $text = "\t" . '<form action="" method="post">' . "\n";
     $firstRow = '';
     if (is_null($presetCategoryName)) {
         $text .= "\t" . Html::hidden('title', $this->getTitle()->getPrefixedText()) . "\n";
         $firstRow .= wfMessage('sf_createcategory_name')->text() . ' ' . Html::input('category_name', null, 'text', array('size' => 25)) . "\n";
         if (!is_null($category_name_error_str)) {
             $firstRow .= Html::element('span', array('style' => 'color: red;'), $category_name_error_str) . "\n";
         }
     }
     $firstRow .= "\t" . wfMessage('sf_createcategory_defaultform')->text() . "\n";
     $formSelector = "\t" . Html::element('option', null, null) . "\n";
     foreach ($all_forms as $form) {
         $formSelector .= "\t" . Html::element('option', null, $form) . "\n";
     }
     $firstRow .= Html::rawElement('select', array('id' => 'form_dropdown', 'name' => 'default_form'), $formSelector);
     $text .= Html::rawElement('p', null, $firstRow) . "\n";
     $secondRow = wfMessage('sf_createcategory_makesubcategory')->text() . ' ';
     $selectBody = "\t" . Html::element('option', null, null) . "\n";
     $categories = SFUtils::getCategoriesForPage();
     foreach ($categories as $category) {
         $category = str_replace('_', ' ', $category);
         $selectBody .= "\t" . Html::element('option', null, $category) . "\n";
     }
     $secondRow .= Html::rawElement('select', array('id' => 'category_dropdown', 'name' => 'parent_category'), $selectBody);
     $text .= Html::rawElement('p', null, $secondRow) . "\n";
     $text .= "\t" . Html::hidden('csrf', $this->getUser()->getEditToken('CreateCategory')) . "\n";
     $editButtonsText = "\t" . Html::input('wpSave', wfMessage('savearticle')->text(), 'submit', array('id' => 'wpSave')) . "\n";
     $editButtonsText .= "\t" . Html::input('wpPreview', wfMessage('preview')->text(), 'submit', array('id' => 'wpPreview')) . "\n";
     $text .= "\t" . Html::rawElement('div', array('class' => 'editButtons'), $editButtonsText) . "\n";
     $text .= "\t</form>\n";
     $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css");
     $wgOut->addHTML($text);
 }
 static function displayFormChooser($output, $title)
 {
     $output->addModules('ext.semanticforms.main');
     $targetName = $title->getPrefixedText();
     $output->setPageTitle(wfMessage("creating", $targetName)->text());
     $output->addHTML(Html::element('p', null, wfMessage('sf-formedit-selectform')->text()));
     $formNames = SFUtils::getAllForms();
     $fe = SpecialPageFactory::getPage('FormEdit');
     $text = '';
     foreach ($formNames as $i => $formName) {
         if ($i > 0) {
             $text .= " &middot; ";
         }
         // Special handling for forms whose name contains a slash.
         if (strpos($formName, '/') !== false) {
             $url = $fe->getTitle()->getLocalURL(array('form' => $formName, 'target' => $targetName));
         } else {
             $url = $fe->getTitle("{$formName}/{$targetName}")->getLocalURL();
         }
         $text .= Html::element('a', array('href' => $url), $formName);
     }
     $output->addHTML(Html::rawElement('div', array('class' => 'infoMessage'), $text));
     // We need to call linkKnown(), not link(), so that SF's
     // edit=>formedit hook won't be called on this link.
     $noFormLink = Linker::linkKnown($title, wfMessage('sf-formedit-donotuseform')->escaped(), array(), array('action' => 'edit', 'redlink' => true));
     $output->addHTML(Html::rawElement('p', null, $noFormLink));
 }
Ejemplo n.º 4
0
 /**
  * Creates a dropdown of possible form names.
  */
 public static function formDropdownHTML()
 {
     global $wgContLang;
     $namespace_labels = $wgContLang->getNamespaces();
     $form_label = $namespace_labels[SF_NS_FORM];
     $form_names = SFUtils::getAllForms();
     $select_body = "\n";
     foreach ($form_names as $form_name) {
         $select_body .= "\t" . Html::element('option', null, $form_name) . "\n";
     }
     return "\t" . Html::rawElement('label', array('for' => 'formSelector'), $form_label . wfMessage('colon-separator')->escaped()) . "\n" . Html::rawElement('select', array('id' => 'formSelector', 'name' => 'form'), $select_body) . "\n";
 }
Ejemplo n.º 5
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;
 }