Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -0,0 +1,230 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Global functions and constants for Semantic MediaWiki. |
| 5 | + */ |
| 6 | + |
| 7 | +/**********************************************/ |
| 8 | +/***** Header modifications *****/ |
| 9 | +/**********************************************/ |
| 10 | + |
| 11 | + /** |
| 12 | + * This method is in charge of inserting additional CSS, JScript, and meta tags |
| 13 | + * into the html header of each page. It is either called after initialising wgout |
| 14 | + * (requiring a patch in MediaWiki), or during parsing. Calling it during parsing, |
| 15 | + * however, is not sufficient to get the header modifiactions into every page that |
| 16 | + * is shipped to a reader, since the parser cache can make parsing obsolete. |
| 17 | + * |
| 18 | + * $out is the modified OutputPage. |
| 19 | + */ |
| 20 | + function smwfAddHTMLHeader(&$out) { |
| 21 | + global $smwgHeadersInPlace; // record whether headers were created already |
| 22 | + global $smwgArticleHeadersInPlace; // record whether article name specific headers are already there |
| 23 | + global $smwgScriptPath; |
| 24 | + |
| 25 | + if (!$smwgHeadersInPlace) { |
| 26 | + $toolTipScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
| 27 | + $out->addScript($toolTipScript); |
| 28 | + $sortTableScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
| 29 | + $out->addScript($sortTableScript); |
| 30 | + |
| 31 | + // Also we add a custom CSS file for our needs |
| 32 | + $customCssUrl = $smwgScriptPath . '/skins/SMW_custom.css'; |
| 33 | + $out->addLink(array( |
| 34 | + 'rel' => 'stylesheet', |
| 35 | + 'type' => 'text/css', |
| 36 | + 'media' => 'screen, projection', |
| 37 | + 'href' => $customCssUrl |
| 38 | + )); |
| 39 | + $smwgHeadersInPlace = true; |
| 40 | + } |
| 41 | + |
| 42 | + if ((!$smwgArticleHeadersInPlace) && ($out->mIsarticle) && ($out->mPagetitle!='')) { |
| 43 | + //print_r('Article ADDHTML... "'. $out->mPagetitle .'"'); |
| 44 | + global $wgContLang, $wgServer, $wgScript; |
| 45 | + |
| 46 | + $out->addLink(array( |
| 47 | + 'rel' => 'alternate', |
| 48 | + 'type' => 'application/rdf+xml', |
| 49 | + 'title' => $out->mPagetitle, |
| 50 | + 'href' => $wgServer . $wgScript . '/' . |
| 51 | + $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . |
| 52 | + str_replace('%2F', "/", urlencode(str_replace(' ', '_', $out->mPagetitle))) . '?xmlmime=rdf' |
| 53 | + )); |
| 54 | + $smwgArticleHeadersInPlace = true; |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | +/**********************************************/ |
| 62 | +/***** namespace settings *****/ |
| 63 | +/**********************************************/ |
| 64 | + |
| 65 | + /** |
| 66 | + * Init the additional namepsaces used by Semantic MediaWiki. The |
| 67 | + * parameter denotes the least unused even namespace ID that is |
| 68 | + * greater or equal to 100. |
| 69 | + */ |
| 70 | + function smwfInitNamespaces($base_idx) { |
| 71 | + global $wgExtraNamespaces, $wgNamespacesWithSubpages, $wgLanguageCode, $smwgContLang; |
| 72 | + |
| 73 | + smwfInitContentLanguage($wgLanguageCode); |
| 74 | + |
| 75 | + $namespaceIndex=$base_idx; |
| 76 | + |
| 77 | + define('SMW_NS_RELATION', $namespaceIndex); |
| 78 | + define('SMW_NS_RELATION_TALK', $namespaceIndex+1); |
| 79 | + define('SMW_NS_ATTRIBUTE', $namespaceIndex+2); |
| 80 | + define('SMW_NS_ATTRIBUTE_TALK', $namespaceIndex+3); |
| 81 | + define('SMW_NS_TYPE', $namespaceIndex+4); |
| 82 | + define('SMW_NS_TYPE_TALK', $namespaceIndex+5); |
| 83 | + |
| 84 | + // Register namespace identifiers |
| 85 | + if (!is_array($wgExtraNamespaces)) { $wgExtraNamespaces=array(); } |
| 86 | + $wgExtraNamespaces = $wgExtraNamespaces + |
| 87 | + $smwgContLang->getNamespaceArray(); |
| 88 | + |
| 89 | + // Support subpages only for talk pages by default |
| 90 | + $wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array( |
| 91 | + SMW_NS_RELATION_TALK => true, |
| 92 | + SMW_NS_ATTRIBUTE_TALK => true, |
| 93 | + SMW_NS_TYPE_TALK => true |
| 94 | + ); |
| 95 | + |
| 96 | + // not modified for Semantic MediaWiki |
| 97 | + /* $wgNamespacesToBeSearchedDefault = array( |
| 98 | + NS_MAIN => true, |
| 99 | + ); |
| 100 | + */ |
| 101 | + } |
| 102 | + |
| 103 | +/**********************************************/ |
| 104 | +/***** language settings *****/ |
| 105 | +/**********************************************/ |
| 106 | + |
| 107 | + /** |
| 108 | + * Initialise a global language object for content language. This |
| 109 | + * must happen early on, even before user language is known, to |
| 110 | + * determine labels for additional namespaces. In contrast, messages |
| 111 | + * can be initialised much later when they are actually needed. |
| 112 | + */ |
| 113 | + function smwfInitContentLanguage($langcode) { |
| 114 | + global $smwgIP, $smwgContLang; |
| 115 | + |
| 116 | + if (!empty($smwgContLang)) { return; } |
| 117 | + |
| 118 | + $smwContLangClass = 'SMW_Language' . str_replace( '-', '_', ucfirst( $langcode ) ); |
| 119 | + |
| 120 | + if (file_exists($smwgIP . '/languages/'. $smwContLangClass . '.php')) { |
| 121 | + include_once( $smwgIP . '/languages/'. $smwContLangClass . '.php' ); |
| 122 | + } |
| 123 | + |
| 124 | + // fallback if language not supported |
| 125 | + if ( !class_exists($smwContLangClass)) { |
| 126 | + include_once($smwgIP . '/languages/SMW_LanguageEn.php'); |
| 127 | + $smwContLangClass = 'SMW_LanguageEn'; |
| 128 | + } |
| 129 | + |
| 130 | + $smwgContLang = new $smwContLangClass(); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Initialise the global language object for user language. This |
| 135 | + * must happen after the content language was initialised, since |
| 136 | + * this language is used as a fallback. |
| 137 | + */ |
| 138 | + function smwfInitUserLanguage($langcode) { |
| 139 | + global $smwgIP, $smwgLang; |
| 140 | + |
| 141 | + if (!empty($smwgLang)) { return; } |
| 142 | + |
| 143 | + $smwLangClass = 'SMW_Language' . str_replace( '-', '_', ucfirst( $langcode ) ); |
| 144 | + |
| 145 | + if (file_exists($smwgIP . '/languages/'. $smwLangClass . '.php')) { |
| 146 | + include_once( $smwgIP . '/languages/'. $smwLangClass . '.php' ); |
| 147 | + } |
| 148 | + |
| 149 | + // fallback if language not supported |
| 150 | + if ( !class_exists($smwLangClass)) { |
| 151 | + global $smwgContLang; |
| 152 | + $smwgLang = $smwgContLang; |
| 153 | + } else { |
| 154 | + $smwgLang = new $smwLangClass(); |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Initialise messages. These settings must be applied later on, since |
| 160 | + * the MessageCache does not exist yet when the settings are loaded in |
| 161 | + * LocalSettings.php. |
| 162 | + */ |
| 163 | + function smwfInitMessages() { |
| 164 | + global $smwgMessagesInPlace; // record whether the function was already called |
| 165 | + |
| 166 | + if ($smwgMessagesInPlace) { return; } |
| 167 | + |
| 168 | + global $wgMessageCache, $smwgContLang, $smwgLang; |
| 169 | + global $wgContLanguageCode, $wgLanguageCode; |
| 170 | + // make sure that language objects exist |
| 171 | + smwfInitContentLanguage($wgContLanguageCode); |
| 172 | + smwfInitUserLanguage($wgLanguageCode); |
| 173 | + |
| 174 | + $wgMessageCache->addMessages($smwgContLang->getContentMsgArray()); |
| 175 | + $wgMessageCache->addMessages($smwgLang->getUserMsgArray()); |
| 176 | + |
| 177 | + $smwgMessagesInPlace = true; |
| 178 | + } |
| 179 | + |
| 180 | +/**********************************************/ |
| 181 | +/***** other global helpers *****/ |
| 182 | +/**********************************************/ |
| 183 | + |
| 184 | + /** |
| 185 | + * Return true if semantic data should be processed and displayed for this page. |
| 186 | + * @return bool |
| 187 | + */ |
| 188 | + function smwfIsSemanticsProcessed($namespace) { |
| 189 | + global $smwgNamespacesWithSemanticLinks; |
| 190 | + return !empty($smwgNamespacesWithSemanticLinks[$namespace]); |
| 191 | + } |
| 192 | + |
| 193 | + |
| 194 | + /** |
| 195 | + * Takes a title text and turns it safely into its DBKey. |
| 196 | + * This function reimplements the title normalization as done |
| 197 | + * in Title.php in order to achieve conversion with less overhead. |
| 198 | + */ |
| 199 | + function smwfNormalTitleDBKey( $text ) { |
| 200 | + return str_replace(' ', '_', ucfirst($text)); |
| 201 | + ///// The long and secure way. Use if problems occur. |
| 202 | + // $t = Title::newFromText( $text ); |
| 203 | + // if ($t != NULL) { |
| 204 | + // return $t->getDBkey(); |
| 205 | + // } |
| 206 | + // return $text; |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * Takes a text and turns it into a normalised version. |
| 211 | + * This function reimplements the title normalization as done |
| 212 | + * in Title.php in order to achieve conversion with less overhead. |
| 213 | + */ |
| 214 | + function smwfNormalTitleText( $text ) { |
| 215 | + return str_replace('_', ' ', ucfirst($text)); |
| 216 | + ///// The long and secure way. Use if problems occur. |
| 217 | + // $t = Title::newFromText( $text ); |
| 218 | + // if ($t != NULL) { |
| 219 | + // return $t->getText(); |
| 220 | + // } |
| 221 | + // return $text; |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * Escapes text in a way that allows it to be used as XML |
| 226 | + * content (e.g. as an string value for some property). |
| 227 | + */ |
| 228 | + function smwfXMLContentEncode($text) { |
| 229 | + return str_replace(array('&','<','>'),array('&','<','>'),$text); |
| 230 | + } |
| 231 | +?> |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Datatype.php |
— | — | @@ -468,7 +468,7 @@ |
469 | 469 | |
470 | 470 | function processValue($value,&$datavalue) { |
471 | 471 | if ($value!='') { //do not accept empty strings |
472 | | - $xsdvalue = str_replace(array('&','<','>'),array('&','<','>'),$value); |
| 472 | + $xsdvalue = smwfXMLContentEncode($value); |
473 | 473 | // 255 below matches smw_attributes.value_xsd definition in smwfMakeSemanticTables() |
474 | 474 | // Note that depending on database encoding and UTF-8 settings, longer or |
475 | 475 | // shorter strings than this with int'l characters may exceed database field. |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_InlineQueries.php |
— | — | @@ -214,7 +214,7 @@ |
215 | 215 | $this->mLimit = min($smwgIQMaxLimit, max(1,$param['limit'] + 0)); //integer between 1 and $smwgMaxLimit |
216 | 216 | } |
217 | 217 | if (array_key_exists('sort', $param)) { |
218 | | - $this->mSort = $this->normalizeTitle($param['sort']); |
| 218 | + $this->mSort = smwfNormalTitleDBKey($param['sort']); |
219 | 219 | } |
220 | 220 | if (array_key_exists('order', $param)) { |
221 | 221 | if (('descending'==$param['order'])||('reverse'==$param['order'])||('desc'==$param['order'])) { |
— | — | @@ -424,14 +424,14 @@ |
425 | 425 | if ('' == $label) $label = $wgContLang->getNSText(NS_CATEGORY); |
426 | 426 | $result->mPrint['C'] = array($label,SMW_IQ_PRINT_CATS); |
427 | 427 | } elseif ( '::' == $op ) { |
428 | | - $result->mPrint['R:' . $qparts[0]] = array($label,SMW_IQ_PRINT_RELS,$this->normalizeTitle($qparts[0])); |
| 428 | + $result->mPrint['R:' . $qparts[0]] = array($label,SMW_IQ_PRINT_RELS,smwfNormalTitleDBKey($qparts[0])); |
429 | 429 | } elseif ( ':=' == $op ) { |
430 | 430 | $av = SMWDataValue::newAttributeValue($qparts[0]); |
431 | 431 | $unit = mb_substr($qparts[2],1); |
432 | 432 | if ($unit != '') { // desired unit selected: |
433 | 433 | $av->setDesiredUnits(array($unit)); |
434 | 434 | } |
435 | | - $result->mPrint['A:' . $qparts[0]] = array($label,SMW_IQ_PRINT_ATTS,$this->normalizeTitle($qparts[0]),$av); |
| 435 | + $result->mPrint['A:' . $qparts[0]] = array($label,SMW_IQ_PRINT_ATTS,smwfNormalTitleDBKey($qparts[0]),$av); |
436 | 436 | } // else: operators like :=> are not supported for printing and are silently ignored |
437 | 437 | $this->mPrintoutCount++; |
438 | 438 | } |
— | — | @@ -466,14 +466,14 @@ |
467 | 467 | $condition = "$pagetable.page_id=$curtable.cl_from"; |
468 | 468 | // TODO: make subcat-inclusion more efficient |
469 | 469 | foreach ($values as $idx => $v) { |
470 | | - $values[$idx] = $this->normalizeTitle($v); |
| 470 | + $values[$idx] = smwfNormalTitleDBKey($v); |
471 | 471 | } |
472 | 472 | $this->includeSubcategories($values,$smwgIQSubcategoryInclusions); |
473 | 473 | foreach ($values as $v) { |
474 | 474 | $or_conditions[] = "$curtable.cl_to=" . $this->dbr->addQuotes($v); |
475 | 475 | } |
476 | 476 | } elseif ('::' == $op ) { // condition on relations |
477 | | - $relation = $this->normalizeTitle($qparts[0]); |
| 477 | + $relation = smwfNormalTitleDBKey($qparts[0]); |
478 | 478 | $result->mTables .= ',' . $this->dbr->tableName('smw_relations') . " AS $curtable"; |
479 | 479 | $condition = "$pagetable.page_id=$curtable.subject_id AND $curtable.relation_title=" . $this->dbr->addQuotes($relation); |
480 | 480 | if ('' != $sq_title) { // objects supplied by subquery |
— | — | @@ -485,7 +485,7 @@ |
486 | 486 | // Also, redirects are not taken into account for sub-queries |
487 | 487 | // anymore now. |
488 | 488 | foreach ($values as $idx => $v) { |
489 | | - $values[$idx] = $this->normalizeTitle($v); |
| 489 | + $values[$idx] = smwfNormalTitleDBKey($v); |
490 | 490 | } |
491 | 491 | $value = $this->normalizeRedirects($values); |
492 | 492 | // search for values |
— | — | @@ -506,7 +506,7 @@ |
507 | 507 | //Note: I do not think we have to include redirects here. Redirects should not |
508 | 508 | // have annotations, so one can just write up the query correctly! -- mak |
509 | 509 | foreach ($values as $v) { |
510 | | - $v = $this->normalizeTitle($v); |
| 510 | + $v = smwfNormalTitleDBKey($v); |
511 | 511 | if (':' == mb_substr($v,0,1)) $v = mb_substr($v,1); // remove initial ':' |
512 | 512 | // TODO: should this be done when normalizing the title??? |
513 | 513 | $ns_idx = $wgContLang->getNsIndex(mb_substr($v,0,-2)); // assume format "Namespace:+" |
— | — | @@ -519,7 +519,7 @@ |
520 | 520 | } |
521 | 521 | } |
522 | 522 | } else { // some attribute operator |
523 | | - $attribute = $this->normalizeTitle($qparts[0]); |
| 523 | + $attribute = smwfNormalTitleDBKey($qparts[0]); |
524 | 524 | $av = SMWDataValue::newAttributeValue($attribute); |
525 | 525 | switch ($op) { |
526 | 526 | case ':=>': $comparator = '>='; break; |
— | — | @@ -682,22 +682,6 @@ |
683 | 683 | return $categories; |
684 | 684 | } |
685 | 685 | |
686 | | - /** |
687 | | - * Takes a text and turns it safely into its DBKey. |
688 | | - * If it fails to do so, the text is returned unchanged. |
689 | | - * |
690 | | - * FIXME: should be (1) a global function that (2) directly |
691 | | - * creates the DB key (currently a simple ucfirst + str_replace) |
692 | | - * for higher efficiency. |
693 | | - */ |
694 | | - function normalizeTitle( $text ) { |
695 | | - $t = Title::newFromText( $text ); |
696 | | - if ($t != NULL) { |
697 | | - return $t->getDBkey(); |
698 | | - } |
699 | | - return $text; |
700 | | - } |
701 | | - |
702 | 686 | /*********************************************************************/ |
703 | 687 | /* Output helper methods */ |
704 | 688 | /*********************************************************************/ |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | static function addAttribute($attribute, $value) { |
78 | 78 | // See if this attribute is a special one like e.g. "Has type" |
79 | 79 | global $smwgContLang; |
80 | | - $attribute = ucfirst($attribute); //slightly normalize label |
| 80 | + $attribute = smwfNormalTitleText($attribute); //slightly normalize label |
81 | 81 | $specprops = $smwgContLang->getSpecialPropertiesArray(); |
82 | 82 | $special = array_search($attribute, $specprops); |
83 | 83 | |
— | — | @@ -100,13 +100,12 @@ |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | | - |
105 | 104 | /** |
106 | 105 | * This method adds a new relation with the given target to the storage. |
107 | 106 | */ |
108 | 107 | static function addRelation($relation, $target) { |
109 | 108 | global $smwgContLang; |
110 | | - $relation = ucfirst($relation); |
| 109 | + $relation = smwfNormalTitleText($relation); |
111 | 110 | $srels = $smwgContLang->getSpecialPropertiesArray(); |
112 | 111 | $special = array_search($relation, $srels); |
113 | 112 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php |
— | — | @@ -43,9 +43,12 @@ |
44 | 44 | |
45 | 45 | |
46 | 46 | // PHP fails to find relative includes at some level of inclusion: |
47 | | -$pathfix = $IP . $smwgScriptPath; |
| 47 | +//$pathfix = $IP . $smwgScriptPath; |
48 | 48 | |
49 | | -// load settings for inline queries first |
| 49 | +// load global functions |
| 50 | +require_once($smwgIP . '/includes/SMW_GlobalFunctions.php'); |
| 51 | + |
| 52 | +// load (default) settings for inline queries first |
50 | 53 | require_once($smwgIP . '/includes/SMW_InlineQueries.php'); |
51 | 54 | |
52 | 55 | // get local configuration ... |
— | — | @@ -92,189 +95,6 @@ |
93 | 96 | /**********************************************/ |
94 | 97 | |
95 | 98 | global $wgExtensionCredits; |
96 | | -$wgExtensionCredits['parserhook'][]= array('name'=>'Semantic MediaWiki', 'version'=>$smwgVersion, 'author'=>'Klaus Lassleben, Markus Krötzsch, Kai Hüner, Denny Vrandecic, S Page', 'url'=>'https://sourceforge.net/projects/semediawiki/', 'description' => 'Making your wiki more accessible – for machines and humans'); |
| 99 | +$wgExtensionCredits['parserhook'][]= array('name'=>'Semantic MediaWiki', 'version'=>$smwgVersion, 'author'=>'Klaus Lassleben, Markus Krötzsch, Kai Hüner, Denny Vrandecic, S Page', 'url'=>'http://sourceforge.net/projects/semediawiki/', 'description' => 'Making your wiki more accessible – for machines and humans'); |
97 | 100 | |
98 | | -/**********************************************/ |
99 | | -/***** Header modifications *****/ |
100 | | -/**********************************************/ |
101 | | - |
102 | | - /** |
103 | | - * This method is in charge of inserting additional CSS, JScript, and meta tags |
104 | | - * into the html header of each page. It is either called after initialising wgout |
105 | | - * (requiring a patch in MediaWiki), or during parsing. Calling it during parsing, |
106 | | - * however, is not sufficient to get the header modifiactions into every page that |
107 | | - * is shipped to a reader, since the parser cache can make parsing obsolete. |
108 | | - * |
109 | | - * $out is the modified OutputPage. |
110 | | - */ |
111 | | - function smwfAddHTMLHeader(&$out) { |
112 | | - global $smwgHeadersInPlace; // record whether headers were created already |
113 | | - global $smwgArticleHeadersInPlace; // record whether article name specific headers are already there |
114 | | - global $smwgScriptPath; |
115 | | - |
116 | | - if (!$smwgHeadersInPlace) { |
117 | | - $toolTipScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
118 | | - $out->addScript($toolTipScript); |
119 | | - $sortTableScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
120 | | - $out->addScript($sortTableScript); |
121 | | - |
122 | | - // Also we add a custom CSS file for our needs |
123 | | - $customCssUrl = $smwgScriptPath . '/skins/SMW_custom.css'; |
124 | | - $out->addLink(array( |
125 | | - 'rel' => 'stylesheet', |
126 | | - 'type' => 'text/css', |
127 | | - 'media' => 'screen, projection', |
128 | | - 'href' => $customCssUrl |
129 | | - )); |
130 | | - $smwgHeadersInPlace = true; |
131 | | - } |
132 | | - |
133 | | - if ((!$smwgArticleHeadersInPlace) && ($out->mIsarticle) && ($out->mPagetitle!='')) { |
134 | | - //print_r('Article ADDHTML... "'. $out->mPagetitle .'"'); |
135 | | - global $wgContLang, $wgServer, $wgScript; |
136 | | - |
137 | | - $out->addLink(array( |
138 | | - 'rel' => 'alternate', |
139 | | - 'type' => 'application/rdf+xml', |
140 | | - 'title' => $out->mPagetitle, |
141 | | - 'href' => $wgServer . $wgScript . '/' . |
142 | | - $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . |
143 | | - str_replace('%2F', "/", urlencode(str_replace(' ', '_', $out->mPagetitle))) . '?xmlmime=rdf' |
144 | | - )); |
145 | | - $smwgArticleHeadersInPlace = true; |
146 | | - } |
147 | | - |
148 | | - |
149 | | - return; |
150 | | - } |
151 | | - |
152 | | -/**********************************************/ |
153 | | -/***** namespace settings *****/ |
154 | | -/**********************************************/ |
155 | | - |
156 | | - /** |
157 | | - * Init the additional namepsaces used by Semantic MediaWiki. The |
158 | | - * parameter denotes the least unused even namespace ID that is |
159 | | - * greater or equal to 100. |
160 | | - */ |
161 | | - function smwfInitNamespaces($base_idx) { |
162 | | - global $wgExtraNamespaces, $wgNamespacesWithSubpages, $wgLanguageCode, $smwgContLang; |
163 | | - |
164 | | - smwfInitContentLanguage($wgLanguageCode); |
165 | | - |
166 | | - $namespaceIndex=$base_idx; |
167 | | - |
168 | | - define('SMW_NS_RELATION', $namespaceIndex); |
169 | | - define('SMW_NS_RELATION_TALK', $namespaceIndex+1); |
170 | | - define('SMW_NS_ATTRIBUTE', $namespaceIndex+2); |
171 | | - define('SMW_NS_ATTRIBUTE_TALK', $namespaceIndex+3); |
172 | | - define('SMW_NS_TYPE', $namespaceIndex+4); |
173 | | - define('SMW_NS_TYPE_TALK', $namespaceIndex+5); |
174 | | - |
175 | | - // Register namespace identifiers |
176 | | - if (!is_array($wgExtraNamespaces)) { $wgExtraNamespaces=array(); } |
177 | | - $wgExtraNamespaces = $wgExtraNamespaces + |
178 | | - $smwgContLang->getNamespaceArray(); |
179 | | - |
180 | | - // Support subpages only for talk pages by default |
181 | | - $wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array( |
182 | | - SMW_NS_RELATION_TALK => true, |
183 | | - SMW_NS_ATTRIBUTE_TALK => true, |
184 | | - SMW_NS_TYPE_TALK => true |
185 | | - ); |
186 | | - |
187 | | - // not modified for Semantic MediaWiki |
188 | | - /* $wgNamespacesToBeSearchedDefault = array( |
189 | | - NS_MAIN => true, |
190 | | - ); |
191 | | - */ |
192 | | - } |
193 | | - |
194 | | -/**********************************************/ |
195 | | -/***** language settings *****/ |
196 | | -/**********************************************/ |
197 | | - |
198 | | - /** |
199 | | - * Initialise a global language object for content language. This |
200 | | - * must happen early on, even before user language is known, to |
201 | | - * determine labels for additional namespaces. In contrast, messages |
202 | | - * can be initialised much later when they are actually needed. |
203 | | - */ |
204 | | - function smwfInitContentLanguage($langcode) { |
205 | | - global $smwgIP, $smwgContLang; |
206 | | - |
207 | | - if (!empty($smwgContLang)) { return; } |
208 | | - |
209 | | - $smwContLangClass = 'SMW_Language' . str_replace( '-', '_', ucfirst( $langcode ) ); |
210 | | - |
211 | | - if (file_exists($smwgIP . '/languages/'. $smwContLangClass . '.php')) { |
212 | | - include_once( $smwgIP . '/languages/'. $smwContLangClass . '.php' ); |
213 | | - } |
214 | | - |
215 | | - // fallback if language not supported |
216 | | - if ( !class_exists($smwContLangClass)) { |
217 | | - include_once($smwgIP . '/languages/SMW_LanguageEn.php'); |
218 | | - $smwContLangClass = 'SMW_LanguageEn'; |
219 | | - } |
220 | | - |
221 | | - $smwgContLang = new $smwContLangClass(); |
222 | | - } |
223 | | - |
224 | | - /** |
225 | | - * Initialise the global language object for user language. This |
226 | | - * must happen after the content language was initialised, since |
227 | | - * this language is used as a fallback. |
228 | | - */ |
229 | | - function smwfInitUserLanguage($langcode) { |
230 | | - global $smwgIP, $smwgLang; |
231 | | - |
232 | | - if (!empty($smwgLang)) { return; } |
233 | | - |
234 | | - $smwLangClass = 'SMW_Language' . str_replace( '-', '_', ucfirst( $langcode ) ); |
235 | | - |
236 | | - if (file_exists($smwgIP . '/languages/'. $smwLangClass . '.php')) { |
237 | | - include_once( $smwgIP . '/languages/'. $smwLangClass . '.php' ); |
238 | | - } |
239 | | - |
240 | | - // fallback if language not supported |
241 | | - if ( !class_exists($smwLangClass)) { |
242 | | - global $smwgContLang; |
243 | | - $smwgLang = $smwgContLang; |
244 | | - } else { |
245 | | - $smwgLang = new $smwLangClass(); |
246 | | - } |
247 | | - } |
248 | | - |
249 | | - /** |
250 | | - * Initialise messages. These settings must be applied later on, since |
251 | | - * the MessageCache does not exist yet when the settings are loaded in |
252 | | - * LocalSettings.php. |
253 | | - */ |
254 | | - function smwfInitMessages() { |
255 | | - global $smwgMessagesInPlace; // record whether the function was already called |
256 | | - |
257 | | - if ($smwgMessagesInPlace) { return; } |
258 | | - |
259 | | - global $wgMessageCache, $smwgContLang, $smwgLang; |
260 | | - global $wgContLanguageCode, $wgLanguageCode; |
261 | | - // make sure that language objects exist |
262 | | - smwfInitContentLanguage($wgContLanguageCode); |
263 | | - smwfInitUserLanguage($wgLanguageCode); |
264 | | - |
265 | | - $wgMessageCache->addMessages($smwgContLang->getContentMsgArray()); |
266 | | - $wgMessageCache->addMessages($smwgLang->getUserMsgArray()); |
267 | | - |
268 | | - $smwgMessagesInPlace = true; |
269 | | - } |
270 | | - |
271 | | - /** |
272 | | - * Return true if semantic data should be processed and displayed for this page. |
273 | | - * @return bool |
274 | | - */ |
275 | | - function smwfIsSemanticsProcessed($namespace) { |
276 | | - global $smwgNamespacesWithSemanticLinks; |
277 | | - return !empty($smwgNamespacesWithSemanticLinks[$namespace]); |
278 | | - } |
279 | | - |
280 | | - |
281 | 101 | ?> |