function execute($category) { global $wgRequest, $wgOut, $wgUser, $wgTitle; // If a category has been selected (i.e., it's not just // Special:EditSchema), only display this if the user is // allowed to edit the category page. if (!is_null($category) && (!$wgUser->isAllowed('edit') || !$wgTitle->userCan('edit'))) { $wgOut->permissionRequired('edit'); return; } $this->setHeaders(); $text = '<p>' . wfMessage('ps-page-desc-edit-schema')->parse() . '</p>'; PageSchemas::addJavascriptAndCSS(); $save_page = $wgRequest->getCheck('wpSave'); if ($save_page) { $psXML = self::createPageSchemaXMLFromForm(); $categoryTitle = Title::newFromText($category, NS_CATEGORY); $categoryArticle = new Article($categoryTitle); if ($categoryTitle->exists()) { $pageText = $categoryArticle->getContent(); $pageSchemaObj = new PSSchema($category); if ($pageSchemaObj->isPSDefined()) { // Do some preg_replace magic. // This is necessary if the <PageSchema> tag // accepts any attributes - which it currently // does not, but it may well in the future. $tag = "PageSchema"; $pageText = preg_replace('{<' . $tag . '[^>]*>([^@]*?)</' . $tag . '>' . '}', $psXML, $pageText); } else { $pageText = $psXML . $pageText; } } else { $pageText = $psXML; } $editSummary = $wgRequest->getVal('wpSummary'); $categoryArticle->doEdit($pageText, $editSummary); $redirectURL = $categoryTitle->getLocalURL(); $text = <<<END \t\t<script type="text/javascript"> \t\twindow.onload = function() { \t\t\twindow.location="{$redirectURL}"; \t\t} \t\t</script> END; $wgOut->addHTML($text); return true; } if ($category == "") { // No category was specified - show the list of // categories with a page schema defined. $text = self::showLinksToCategories(); $wgOut->addHTML($text); return true; } // We have a category - show a form. // See if a page schema has already been defined for this category. $title = Title::newFromText($category, NS_CATEGORY); $pageId = $title->getArticleID(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page_props', array('pp_page', 'pp_propname', 'pp_value'), array('pp_page' => $pageId)); $row = $dbr->fetchRow($res); if ($row == null && !$title->exists()) { // Category doesn't exist. $wgOut->setPageTitle(wfMessage('createschema')->parse()); $text = '<p>' . wfMessage('ps-page-desc-cat-not-exist')->parse() . '</p>'; $text .= self::printForm(); } elseif ($row[1] != 'PageSchema' || $row[2] == null) { // Category exists, but has no page schema. $text = '<p>' . wfMessage('ps-page-desc-ps-not-exist')->parse() . '</p>'; $wgOut->setPageTitle(wfMessage('createschema')->parse()); $text .= self::printForm(); } else { // It's a category with an existing page schema - // populate the form with its values. $pageSchemaObj = new PSSchema($category); $pageXMLstr = $row[2]; $pageXML = simplexml_load_string($pageXMLstr); $text = self::printForm($pageSchemaObj, $pageXML); } $wgOut->addHTML($text); return true; }