static function getXMLForPage($title, $simplified_format, $groupings, $depth = 0) { if ($depth > 5) { return ""; } global $wgContLang, $dtgContLang; // if this page belongs to the exclusion category, exit $parent_categories = $title->getParentCategoryTree(array()); $dt_props = $dtgContLang->getPropertyLabels(); // $exclusion_category = $title->newFromText($dt_props[DT_SP_IS_EXCLUDED_FROM_XML], NS_CATEGORY); $exclusion_category = $wgContLang->getNSText(NS_CATEGORY) . ':' . str_replace(' ', '_', $dt_props[DT_SP_IS_EXCLUDED_FROM_XML]); if (self::treeContainsElement($parent_categories, $exclusion_category)) { return ""; } $pageStructure = DTPageStructure::newFromTitle($title); $text = $pageStructure->toXML($simplified_format); // handle groupings, if any apply here; first check if SMW is installed global $smwgIP; if (isset($smwgIP)) { $store = smwfGetStore(); $page_title = $title->getText(); $page_namespace = $title->getNamespace(); // Escaping is needed for SMWSQLStore3 - this may be a bug in SMW. $escaped_page_title = str_replace(' ', '_', $page_title); foreach ($groupings as $pair) { list($property_page, $grouping_label) = $pair; $options = new SMWRequestOptions(); $options->sort = "subject_title"; // get actual property from the wiki-page of the property if (class_exists('SMWDIProperty')) { $wiki_page = new SMWDIWikiPage($escaped_page_title, $page_namespace, null); $property = SMWDIProperty::newFromUserLabel($property_page->getTitle()->getText()); } else { $wiki_page = SMWDataValueFactory::newTypeIDValue('_wpg', $escaped_page_title); $property = SMWPropertyValue::makeProperty($property_page->getTitle()->getText()); } $res = $store->getPropertySubjects($property, $wiki_page, $options); $num = count($res); if ($num > 0) { $grouping_label = str_replace(' ', '_', $grouping_label); $text .= "<{$grouping_label}>\n"; foreach ($res as $subject) { $subject_title = $subject->getTitle(); $text .= self::getXMLForPage($subject_title, $simplified_format, $groupings, $depth + 1); } $text .= "</{$grouping_label}>\n"; } } } // escape back the curly brackets that were escaped out at the beginning $text = str_replace('&#123;', '{', $text); $text = str_replace('&#125;', '}', $text); return $text; }
/** * Run a dtImport job * @return boolean success */ function run() { wfProfileIn(__METHOD__); if (is_null($this->title)) { $this->error = "dtImport: Invalid title"; wfProfileOut(__METHOD__); return false; } if (method_exists('WikiPage', 'getContent')) { $wikiPage = new WikiPage($this->title); if (!$wikiPage) { $this->error = 'dtImport: Wiki page not found "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut(__METHOD__); return false; } } else { $article = new Article($this->title); if (!$article) { $this->error = 'dtImport: Article not found "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut(__METHOD__); return false; } } $for_pages_that_exist = $this->params['for_pages_that_exist']; if ($for_pages_that_exist == 'skip' && $this->title->exists()) { return true; } // Change global $wgUser variable to the one specified by // the job only for the extent of this import. global $wgUser; $actual_user = $wgUser; $wgUser = User::newFromId($this->params['user_id']); $text = $this->params['text']; if ($this->title->exists()) { if ($for_pages_that_exist == 'append') { if (method_exists('WikiPage', 'getContent')) { // MW >= 1.21 $existingText = $wikiPage->getContent()->getNativeData(); } else { $existingText = $article->getContent(); } $text = $existingText . "\n" . $text; } elseif ($for_pages_that_exist == 'merge') { $existingPageStructure = DTPageStructure::newFromTitle($this->title); $newPageStructure = new DTPageStructure(); $newPageStructure->parsePageContents($text); $existingPageStructure->mergeInPageStructure($newPageStructure); $text = $existingPageStructure->toWikitext(); } // otherwise, $for_pages_that_exist == 'overwrite' } $edit_summary = $this->params['edit_summary']; if (method_exists('WikiPage', 'getContent')) { $new_content = new WikitextContent($text); $wikiPage->doEditContent($new_content, $edit_summary); } else { $article->doEdit($text, $edit_summary); } $wgUser = $actual_user; wfProfileOut(__METHOD__); return true; }
public static function newFromTitle($pageTitle) { $pageStructure = new DTPageStructure(); $pageStructure->mPageTitle = $pageTitle; if (method_exists('WikiPage', 'getContent')) { $wiki_page = new WikiPage($pageTitle); $page_contents = $wiki_page->getContent()->getNativeData(); } else { $article = new Article($pageTitle); $page_contents = $article->getContent(); } $pageStructure->parsePageContents($page_contents); // Now, go through the field values and see if any of them // hold template calls - if any of them do, parse the value // as if it's the full contents of a page, and add the // resulting "components" to that field. foreach ($pageStructure->mComponents as $pageComponent) { if ($pageComponent->mIsTemplate) { foreach ($pageComponent->mFields as $fieldName => $fieldValue) { if (strpos($fieldValue, '{{') !== false) { $dummyPageStructure = new DTPageStructure(); $dummyPageStructure->parsePageContents($fieldValue); $pageComponent->mFields[$fieldName] = $dummyPageStructure->mComponents; } } } } return $pageStructure; }