/** * Run method * @return boolean success */ function run() { global $wgParser, $wgContLang; $linkCache =& LinkCache::singleton(); $linkCache->clear(); smwLog("start", "RF", "category refactoring"); $article = new Article($this->updatetitle); $latestrevision = Revision::newFromTitle($this->updatetitle); smwLog("oldtitle: " . $this->oldtitle, "RF", "category refactoring"); smwLog("newtitle: " . $this->newtitle, "RF", "category refactoring"); if (!$latestrevision) { $this->error = "SMW_UpdateCategoriesAfterMoveJob: Article not found " . $this->updatetitle->getPrefixedDBkey() . " "; wfDebug($this->error); return false; } $oldtext = $latestrevision->getRawText(); //Category X moved to Y // Links changed accordingly: $cat = $wgContLang->getNsText(NS_CATEGORY); $catlcfirst = strtolower(substr($cat, 0, 1)) . substr($cat, 1); $oldtitlelcfirst = strtolower(substr($this->oldtitle, 0, 1)) . substr($this->oldtitle, 1); // [[[C|c]ategory:[S|s]omeCategory]] -> [[[C|c]ategory:[S|s]omeOtherCategory]] $search[0] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])'; $replace[0] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}]]'; $search[1] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])'; $replace[1] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}]]'; $search[2] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\]\\])'; $replace[2] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}]]'; $search[3] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\]\\])'; $replace[3] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}]]'; // [[[C|c]ategory:[S|s]omeCategory | m]] -> [[[C|c]ategory:[S|s]omeOtherCategory | m ]] $search[4] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)\\]\\])'; $replace[4] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $search[5] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)\\]\\])'; $replace[5] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $search[6] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\|([^]]*)\\]\\])'; $replace[6] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $search[7] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\|([^]]*)\\]\\])'; $replace[7] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}|${5}]]'; $newtext = preg_replace($search, $replace, $oldtext); $summary = 'Link(s) to ' . $this->newtitle . ' updated after page move by SMW_UpdateCategoriesAfterMoveJob. ' . $this->oldtitle . ' has been moved to ' . $this->newtitle; $article->doEdit($newtext, $summary, EDIT_FORCE_BOT); smwLog("finished editing article", "RF", "category refactoring"); $options = new ParserOptions(); $wgParser->parse($newtext, $this->updatetitle, $options, true, true, $latestrevision->getId()); smwLog("finished parsing semantic data", "RF", "category refactoring"); return true; }
/** * Run method * @return boolean success */ function run() { global $wgParser; $linkCache =& LinkCache::singleton(); $linkCache->clear(); smwLog("start", "RF", "property refactoring"); $article = new Article($this->updatetitle); $latestrevision = Revision::newFromTitle($this->updatetitle); smwLog("oldtitle: " . $this->oldtitle, "RF", "property refactoring"); smwLog("newtitle: " . $this->newtitle, "RF", "property refactoring"); if (!$latestrevision) { $this->error = "SMW_UpdatePropertiesAfterMoveJob: Article not found " . $this->updatetitle->getPrefixedDBkey() . " "; wfDebug($this->error); return false; } $oldtext = $latestrevision->getRawText(); //Page X moved to Y // Links changed accordingly: // [[X::m]] -> [[Y::m]] $search[0] = '(\\[\\[(\\s*)' . $this->oldtitle . '(\\s*)::([^]]*)\\]\\])'; $replace[0] = '[[${1}' . $this->newtitle . '${2}::${3}]]'; // [[X:=m]] -> [[Y:=m]] $search[1] = '(\\[\\[(\\s*)' . $this->oldtitle . '(\\s*):=([^]]*)\\]\\])'; $replace[1] = '[[${1}' . $this->newtitle . '${2}:=${3}]]'; // TODO check if the wiki is case sensitive on the first letter // This is not the case for the Halo wikis $oldtitlelcfirst = strtolower(substr($this->oldtitle, 0, 1)) . substr($this->oldtitle, 1); // [[x::m]] -> [[Y::m]] $search[2] = '(\\[\\[(\\s*)' . $oldtitlelcfirst . '(\\s*)::([^]]*)\\]\\])'; $replace[2] = '[[${1}' . $this->newtitle . '${2}::${3}]]'; // [[x:=m]] -> [[Y:=m]] $search[3] = '(\\[\\[(\\s*)' . $oldtitlelcfirst . '(\\s*):=([^]]*)\\]\\])'; $replace[3] = '[[${1}' . $this->newtitle . '${2}:=${3}]]'; $newtext = preg_replace($search, $replace, $oldtext); $summary = 'Link(s) to ' . $this->newtitle . ' updated after page move by SMW_UpdatePropertiesAfterMoveJob. ' . $this->oldtitle . ' has been moved to ' . $this->newtitle; $article->doEdit($newtext, $summary, EDIT_FORCE_BOT); smwLog("finished editing article", "RF", "property refactoring"); $options = new ParserOptions(); $wgParser->parse($newtext, $this->updatetitle, $options, true, true, $latestrevision->getId()); smwLog("finished parsing semantic data", "RF", "property refactoring"); return true; }
/** * Run method * @return boolean success */ function run() { global $wgParser; $linkCache =& LinkCache::singleton(); $linkCache->clear(); smwLog("start", "RF", "link refactoring"); $article = new Article($this->updatetitle); $latestrevision = Revision::newFromTitle($this->updatetitle); smwLog("oldtitle: " . $this->oldtitle, "RF", "link refactoring"); smwLog("newtitle: " . $this->newtitle, "RF", "link refactoring"); if (!$latestrevision) { $this->error = "SMW_UpdateLinksAfterMoveJob: Article not found " . $this->updatetitle->getPrefixedDBkey() . " "; wfDebug($this->error); return false; } $oldtext = $latestrevision->getRawText(); //Page X moved to Y // Links changed accordingly: // [[X]] -> [[Y|X]] $search[0] = '(\\[\\[(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])'; $replace[0] = '[[${1}' . $this->newtitle . '${2}|' . $this->oldtitle . ']]'; // [[X|blabla]]] -> [[Y|blabla]] $search[1] = '(\\[\\[(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)?\\]\\])'; $replace[1] = '[[${1}' . $this->newtitle . '${2}|${3}]]'; // pattern to get all anntations (including n-aries!) $semanticLinkPattern = '/\\[\\[' . '([^]:]+):[:=]' . '(' . '(?:[^|\\[\\]] |' . '\\[\\[[^]]*\\]\\] |' . '\\[[^]]*\\]' . ')*)' . '(\\|[^]]*)?' . '\\]\\]' . '/x'; // ignore whitespaces // search object links preg_match_all($semanticLinkPattern, $oldtext, $matches); // identify object links to oldtitle // save the index and the (changed) link $indicesToReplace = array(); for ($i = 0, $n = count($matches[2]); $i < $n; $i++) { $updated = false; $frgs = explode(";", $matches[2][$i]); for ($j = 0, $m = count($frgs); $j < $m; $j++) { if (trim($frgs[$j]) == $this->oldtitle) { $frgs[$j] = $this->newtitle; $updated = true; } } if ($updated) { if ($frgs === false) { $indicesToReplace[$i] = ""; } else { $indicesToReplace[$i] = count($frgs) == 1 ? trim($frgs[0]) : trim(implode("; ", $frgs)); } } } // replace object links $newtext = $oldtext; foreach ($indicesToReplace as $i => $l) { $newtext = preg_replace('(\\[\\[' . $matches[1][$i] . ':[:=]' . $matches[2][$i] . $matches[3][$i] . '\\]\\])', '[[' . $matches[1][$i] . '::' . $l . $matches[3][$i] . ']]', $newtext); } // search and replace normal links $newtext = preg_replace($search, $replace, $newtext); // save and parse article $summary = 'Link(s) to ' . $this->newtitle . ' updated after page move by SMW_UpdateLinksAfterMoveJob. ' . $this->oldtitle . ' has been moved to ' . $this->newtitle; $article->doEdit($newtext, $summary, EDIT_FORCE_BOT); smwLog("finished editing article", "RF", "link refactoring"); $options = new ParserOptions(); $wgParser->parse($newtext, $this->updatetitle, $options, true, true, $latestrevision->getId()); smwLog("finished parsing semantic data", "RF", "link refactoring"); return true; }
public function filterBrowse($p_array) { $browserFilter = new SMWOntologyBrowserFilter(); $type = $p_array[0]; $hint = explode(" ", $p_array[1]); $hint = smwfEliminateStopWords($hint); if ($type == 'category') { /*STARTLOG*/ smwLog($p_array[1], "OB", "searched categories", "Special:OntologyBrowser"); /*ENDLOG*/ return $browserFilter->filterForCategories($hint); } else { if ($type == 'instance') { /*STARTLOG*/ smwLog($p_array[1], "OB", "searched instances", "Special:OntologyBrowser"); /*ENDLOG*/ return $browserFilter->filterForInstances($hint); } else { if ($type == 'propertyTree') { /*STARTLOG*/ smwLog($p_array[1], "OB", "searched property tree", "Special:OntologyBrowser"); /*ENDLOG*/ return $browserFilter->filterForPropertyTree($hint); } else { if ($type == 'property') { /*STARTLOG*/ smwLog($p_array[1], "OB", "searched properties", "Special:OntologyBrowser"); /*ENDLOG*/ return $browserFilter->filterForProperties($hint); } } } } }
public function execute() { global $wgRequest, $wgOut, $wgScriptPath, $wgUser; //$skin = $wgUser->getSkin(); $wgOut->setPageTitle(wfMsg('ontologybrowser')); /*STARTLOG*/ if ($wgRequest->getVal('src') == 'toolbar') { smwLog("", "OB", "opened_from_menu"); } else { if ($wgRequest->getVal('entitytitle') != '') { $ns = $wgRequest->getVal('ns') == '' ? '' : $wgRequest->getVal('ns') . ":"; smwLog($ns . $wgRequest->getVal('entitytitle'), "Factbox", "open_in_OB"); } else { smwLog("", "OB", "opened"); } } /*ENDLOG*/ $showMenuBar = $wgUser->isAllowed("ontologyediting"); // display query browser //$spectitle = Title::makeTitle( NS_SPECIAL, wfMsg('ontologybrowser') ); $refactorstatstitle = Title::makeTitle(NS_SPECIAL, "RefactorStatistics"); // add another container $treeContainer = ""; $menu = ""; $switch = ""; wfRunHooks('smw_ob_add', array(&$treeContainer, &$boxContainer, &$menu, &$switch)); $html = "<span id=\"OBHelp\">" . wfMsg('smw_ob_help') . "</span><br>"; $html .= "<span id=\"OBHint\">" . wfMsg('smw_ac_hint') . "</span>\n"; $html .= "<br><input type=\"text\" size=\"32\" id=\"FilterBrowserInput\" name=\"prefix\" class=\"wickEnabled\" constraints=\"all\"/>"; $html .= "<button type=\"button\" id=\"filterBrowseButton\" name=\"filterBrowsing\" onclick=\"globalActionListener.filterBrowsing(event, true)\">" . wfMsg('smw_ob_filterbrowsing') . "</button>"; $html .= "<button type=\"button\" name=\"refresh\" onclick=\"globalActionListener.reset(event)\">" . wfMsg('smw_ob_reset') . "</button>"; $html .= "<button type=\"button\" id=\"hideInstancesButton\" name=\"hideInstances\" onclick=\"instanceActionListener.toggleInstanceBox(event)\">" . wfMsg('smw_ob_hideinstances') . "</button>"; // <a href=\"".$refactorstatstitle->getFullURL()."\">".wfMsg('smw_ob_link_stats')."</a>"; $html .= "<span id=\"propertyRangeSpan\"><input type=\"checkbox\" id=\"directPropertySwitch\"/>" . wfMsg('smw_ob_onlyDirect') . "</input><input type=\"checkbox\" id=\"showForRange\"/>" . wfMsg('smw_ob_showRange') . "</input></span>"; $html .= "<div id=\"ontologybrowser\">"; //TODO: Add the following code to a hook. However, the problem is, that // advancedOption.js should also be moved to the Linked Data Extension, but it // is used for getting parameters for the ajax calls to smwf_ob_OntologyBrowserAccess(). if (defined('LOD_LINKEDDATA_VERSION')) { // Check if the triples store is propertly connected. $connectionError = ""; $tsa = new LODTripleStoreAccess(); if (!$tsa->isConnected()) { $connectionError = "<div class=\"aoConnectionError\">" . wfMsg("smw_ob_ts_not_connected") . "</div>"; } $ids = LODAdministrationStore::getInstance()->getAllSourceDefinitionIDs(); $sourceOptions = ""; foreach ($ids as $sourceID) { $sourceOptions .= "<option>{$sourceID}</option>"; } $advancedOptions = wfMsg("smw_ob_advanced_options"); $fromWiki = wfMsg("smw_ob_source_wiki"); $selectDatasource = wfMsg("smw_ob_select_datasource"); $selectMultiHint = wfMsg("smw_ob_select_multiple"); $html .= <<<TEXT <div id="advancedOptions" class="advancedOptions"> \t<div id="aoFoldIcon" class="aoFoldClosed"> </div> \t<span id="aoTitle" class="aoTitle"><b>{$advancedOptions}</b> </span> \t<div id="aoContent" class="aoContent"> \t\t{$connectionError} \t\t<div><b>{$selectDatasource}</b></div> \t\t<select id="dataSourceSelector" name="DataSource" size="5" multiple="multiple" class="aoDataSourceSelector"> \t\t\t<option>{$fromWiki}</option> \t\t\t{$sourceOptions} \t\t</select> \t\t<div class="OBStaticHint">{$selectMultiHint}</div> \t</div> </div> TEXT; } $html .= "\t\t\r\n\t\t<!-- Categore Tree hook -->\t" . "<div id=\"treeContainer\"><span class=\"OB-header\">\t\r\n\t\t\t<img src=\"{$wgScriptPath}/extensions/SMWHalo/skins/concept.gif\" style=\"margin-bottom: -1px\"></img><a class=\"selectedSwitch treeSwitch\" id=\"categoryTreeSwitch\" onclick=\"globalActionListener.switchTreeComponent(event,'categoryTree')\">" . wfMsg('smw_ob_categoryTree') . "</a>\r\n\t\t\t<img src=\"{$wgScriptPath}/extensions/SMWHalo/skins/property.gif\" style=\"margin-bottom: -1px\"></img><a class=\"treeSwitch\" id=\"propertyTreeSwitch\" onclick=\"globalActionListener.switchTreeComponent(event,'propertyTree')\">" . wfMsg('smw_ob_attributeTree') . "</a>"; $html .= $switch; $html .= "</span>"; if ($showMenuBar) { $html .= "<span class=\"menuBar menuBarTree menuBarcategoryTree\" id=\"menuBarcategoryTree\"><a onclick=\"categoryActionListener.showSubMenu(" . SMW_OB_COMMAND_ADDSUBCATEGORY . ")\">" . wfMsg('smw_ob_cmd_createsubcategory') . "</a> | <a onclick=\"categoryActionListener.showSubMenu(" . SMW_OB_COMMAND_ADDSUBCATEGORY_SAMELEVEL . ")\">" . wfMsg('smw_ob_cmd_createsubcategorysamelevel') . "</a> | <a onclick=\"categoryActionListener.showSubMenu(" . SMW_OB_COMMAND_CATEGORY_RENAME . ")\">" . wfMsg('smw_ob_cmd_renamecategory') . "</a><div id=\"categoryTreeMenu\"></div></span>\r\n\t\t\t<span style=\"display:none;\" class=\"menuBar menuBarTree menuBarpropertyTree\" id=\"menuBarpropertyTree\"><a onclick=\"propertyActionListener.showSubMenu(" . SMW_OB_COMMAND_ADDSUBPROPERTY . ")\">" . wfMsg('smw_ob_cmd_createsubproperty') . "</a> | <a onclick=\"propertyActionListener.showSubMenu(" . SMW_OB_COMMAND_ADDSUBPROPERTY_SAMELEVEL . ")\">" . wfMsg('smw_ob_cmd_createsubpropertysamelevel') . "</a> | <a onclick=\"propertyActionListener.showSubMenu(" . SMW_OB_COMMAND_PROPERTY_RENAME . ")\">" . wfMsg('smw_ob_cmd_renameproperty') . "</a><div id=\"propertyTreeMenu\"></div></span>"; $html .= $menu; } // add containers $html .= "<div id=\"categoryTree\" class=\"categoryTreeColors treeContainer\">\r\n\t\t </div>\t\t\r\n\t\t <div id=\"propertyTree\" style=\"display:none\" class=\"propertyTreeListColors treeContainer\">\r\n\t\t </div>"; $html .= $treeContainer; $html .= "<span class=\"OB-filters\"><span>" . wfMsg('smw_ob_filter') . "</span><input type=\"text\" id=\"treeFilter\"><button type=\"button\" name=\"filterCategories\" onclick=\"globalActionListener.filterTree(event)\">" . wfMsg('smw_ob_filter') . "</button></span>\r\n\t\t</div>\r\n\t\t\r\n\t\t<!-- Attribute Tree hook -->\r\n\t\t\t\t\r\n\t\t<div id=\"leftArrow\" class=\"pfeil\">\r\n\t\t\t<img src=\"{$wgScriptPath}/extensions/SMWHalo/skins/OntologyBrowser/images/bigarrow.gif\" onclick=\"globalActionListener.toogleCatInstArrow(event)\" />\r\n\t\t</div>"; $html .= $boxContainer; $html .= "<!-- Instance List hook -->\t\r\n\t\t<div id=\"instanceContainer\">\r\n\t\t <span class=\"OB-header\"><img style=\"margin-bottom: -3px\" src=\"{$wgScriptPath}/extensions/SMWHalo/skins/instance.gif\"></img> " . wfMsg('smw_ob_instanceList') . "</span>\r\n\t\t " . ($showMenuBar ? "<span class=\"menuBar menuBarInstance\" id=\"menuBarInstance\"><a onclick=\"instanceActionListener.showSubMenu(" . SMW_OB_COMMAND_INSTANCE_RENAME . ")\">" . wfMsg('smw_ob_cmd_renameinstance') . "</a> | <a onclick=\"instanceActionListener.showSubMenu(" . SMW_OB_COMMAND_INSTANCE_DELETE . ")\">" . wfMsg('smw_ob_cmd_deleteinstance') . "</a><div id=\"instanceListMenu\"></div></span>" : "") . "\t\t\t\r\n\t\t <div id=\"instanceList\" class=\"instanceListColors\">\r\n\t\t </div>\r\n\t\t <span class=\"OB-filters\"><span>" . wfMsg('smw_ob_filter') . "</span><input type=\"text\" id=\"instanceFilter\"><button type=\"button\" name=\"filterInstances\" onclick=\"globalActionListener.filterInstances(event)\">" . wfMsg('smw_ob_filter') . "</button></span>\r\n\t\t</div>\r\n\t\t\t\r\n\t\t<div id=\"rightArrow\" class=\"pfeil\">\r\n\t\t\t<img src=\"{$wgScriptPath}/extensions/SMWHalo/skins/OntologyBrowser/images/bigarrow.gif\" onclick=\"globalActionListener.toogleInstPropArrow(event)\" />\r\n\t\t</div>\r\n\t\t\t\t\r\n\t\t<!-- Relation/Attribute Annotation level hook -->\r\n\t\t<div id=\"relattributesContainer\"><span class=\"OB-header\">\r\n\t\t\t<span><img style=\"margin-bottom: -3px\" src=\"{$wgScriptPath}/extensions/SMWHalo/skins/property.gif\"></img> " . wfMsg('smw_ob_att') . "</span>\r\n\t\t\t<span id=\"relattValues\">" . wfMsg('smw_ob_relattValues') . "</span><span id=\"relattRangeType\" style=\"display:none;\">" . wfMsg('smw_ob_relattRangeType') . "</span></span>\r\n\t\t\t" . ($showMenuBar ? "<span class=\"menuBar menuBarProperties\" id=\"menuBarProperties\"><a onclick=\"schemaActionPropertyListener.showSubMenu(" . SMW_OB_COMMAND_ADD_SCHEMAPROPERTY . ")\">" . wfMsg('smw_ob_cmd_addpropertytodomain') . "<span id=\"currentSelectedCategory\">...</span></a><div id=\"schemaPropertiesMenu\"></div></span>" : "") . "\t\r\n\t\t\t<div id=\"relattributes\" class=\"propertyTreeListColors\"></div>\r\n\t\t\t<span class=\"OB-filters\"><span>" . wfMsg('smw_ob_filter') . "</span><input type=\"text\" size=\"22\" id=\"propertyFilter\"><button type=\"button\" name=\"filterProperties\" onclick=\"globalActionListener.filterProperties(event)\">" . wfMsg('smw_ob_filter') . "</button></span>\t\t\r\n\t\t</div>\t\t\r\n\t\t<div id=\"OB-filters\">\r\n\t\t\t" . "" . "\r\n\t\t</div>" . "<div id=\"OB-footer\">" . wfMsg('smw_ob_footer') . "\r\n\t\t\t\r\n\t\t</div>\r\n\t\t</div>\r\n\t\t"; $wgOut->addHTML($html); }
/** * function smwfAskQuestion * creates a new help page. The contents are made up of the users question * and some automatically generated content. * Every question is encoded with a discourseState. For more information, see * specials/SMWHelpSpecials/SMWHelpSpecial.php * @param $namespace canonical namespace name of current article * @param $action current action of the user * @param $question question entered by the user */ function smwf_tb_AskQuestion($namespace, $action, $question) { if ($question == "") { return "Sorry, you have not entered a question."; } //Replace '?' at the end and leading or ending whitespaces $question = str_replace('?', '', $question); $question = preg_replace('/^\\s*(.*?)\\s*$/', '$1', $question); $wgTitle = Title::newFromText($question . "?", NS_HELP); if (!$wgTitle) { return wfMsg('smw_help_error'); } if ($wgTitle->exists()) { return wfMsg('smw_help_pageexists'); } /*STARTLOG*/ $logmsg = "Added question '{$question}'"; smwLog($logmsg, "CSH", "help_addednew", wfTimestampNow()); /*ENDLOG*/ $discourseState = "{$namespace}:{$action}"; $articleContent = "[[question:={$question}]]?\n\n"; $articleContent .= "[[discourseState:={$discourseState}]]\n\n"; $articleContent .= "[[description:=" . wfMsg('smw_csh_newquestion') . "]]"; //Create a new wikipage in the Help namespace $wgArticle = new Article($wgTitle); $success = $wgArticle->doEdit($articleContent, "New help question added", EDIT_NEW); if ($success) { return wfMsg('smw_help_question_added'); } else { return wfMsg('smw_help_error'); } }
public function logResult(&$result, $articleName) { if ($result == SMW_AC_NORESULT) { smwLog("", "AC", "no result", $articleName); } else { smwLog("", "AC", "opened", $articleName); } }