Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php |
— | — | @@ -16,17 +16,19 @@ |
17 | 17 | */ |
18 | 18 | class SMWWikiPageValue extends SMWDataValue { |
19 | 19 | |
20 | | - private $m_value = ''; // the raw string passed to that datavalue, rough version of prefixedtext |
21 | | - private $m_textform = ''; // the isolated title as text |
22 | | - private $m_dbkeyform = ''; // the isolated title in DB form |
23 | | - private $m_interwiki = ''; // interwiki prefix or '', actually stored in SMWSQLStore2 |
24 | | - private $m_sortkey = ''; // key for alphabetical sorting |
25 | | - private $m_fragment = ''; // not stored, but kept for printout on page |
26 | | - private $m_prefixedtext = ''; // full titletext with prefixes, including interwiki prefix |
27 | | - private $m_namespace = NS_MAIN; |
28 | | - private $m_id; // false if unset |
29 | | - private $m_title = NULL; |
| 20 | + protected $m_value = ''; // the raw string passed to that datavalue, rough version of prefixedtext |
| 21 | + protected $m_textform = ''; // the isolated title as text |
| 22 | + protected $m_dbkeyform = ''; // the isolated title in DB form |
| 23 | + protected $m_interwiki = ''; // interwiki prefix or '', actually stored in SMWSQLStore2 |
| 24 | + protected $m_sortkey = ''; // key for alphabetical sorting |
| 25 | + protected $m_fragment = ''; // not stored, but kept for printout on page |
| 26 | + protected $m_prefixedtext = ''; // full titletext with prefixes, including interwiki prefix |
| 27 | + protected $m_namespace = NS_MAIN; |
| 28 | + protected $m_id; // false if unset |
| 29 | + protected $m_title = NULL; |
30 | 30 | |
| 31 | + protected $m_fixNamespace = NS_MAIN; // if namespace other than NS_MAIN, restrict inputs to this namespace |
| 32 | + |
31 | 33 | protected function parseUserValue($value) { |
32 | 34 | $value = ltrim(rtrim($value,' ]'),' ['); // support inputs like " [[Test]] " |
33 | 35 | if ($value != '') { |
— | — | @@ -44,11 +46,7 @@ |
45 | 47 | if ($this->m_caption === false) { |
46 | 48 | $this->m_caption = $value; |
47 | 49 | } |
48 | | - } else { |
49 | | - wfLoadExtensionMessages('SemanticMediaWiki'); |
50 | | - $this->addError(wfMsgForContent('smw_notitle', $value)); |
51 | | - # TODO: Escape the text so users can see any punctuation problems (bug 11666). |
52 | | - } |
| 50 | + } // else: no action, errors are reported by getTitle() |
53 | 51 | } else { |
54 | 52 | wfLoadExtensionMessages('SemanticMediaWiki'); |
55 | 53 | $this->addError(wfMsgForContent('smw_notitle', $value)); |
— | — | @@ -218,15 +216,36 @@ |
219 | 217 | |
220 | 218 | /** |
221 | 219 | * Return according Title object or NULL if no valid value was set. |
| 220 | + * If using a base value, this method also checks whether the given namespace |
| 221 | + * is appropriate. Whenever this method sets the title page, it also implements |
| 222 | + * error reporting, i.e. the object might become invalid when calling this |
| 223 | + * function. |
222 | 224 | */ |
223 | 225 | public function getTitle() { |
| 226 | + global $wgContLang; |
224 | 227 | $this->unstub(); |
225 | 228 | if ($this->m_title === NULL){ |
226 | 229 | if ($this->m_dbkeyform != '') { |
227 | 230 | $this->m_title = Title::makeTitle($this->m_namespace, $this->m_dbkeyform); |
| 231 | + if ($this->m_title === NULL) { // should not normally happen, but anyway ... |
| 232 | + wfLoadExtensionMessages('SemanticMediaWiki'); |
| 233 | + $this->addError(wfMsgForContent('smw_notitle', $wgContLang->getNsText($this->m_namespace) . ':' . $this->m_dbkeyform)); |
| 234 | + $this->m_dbkeyform = ''; |
| 235 | + } |
228 | 236 | } elseif ($this->m_value != ''){ |
229 | | - $this->m_title = Title::newFromText($this->m_value); |
| 237 | + $this->m_title = Title::newFromText($this->m_value, $this->m_fixNamespace); |
| 238 | + ///TODO: Escape the text so users can see any punctuation problems (bug 11666). |
| 239 | + if ($this->m_title === NULL) { |
| 240 | + wfLoadExtensionMessages('SemanticMediaWiki'); |
| 241 | + $this->addError(wfMsgForContent('smw_notitle', $this->m_value)); |
| 242 | + } elseif ( ($this->m_fixNamespace != NS_MAIN) && |
| 243 | + ($this->m_fixNamespace != $this->m_title->getNamespace()) ) { |
| 244 | + wfLoadExtensionMessages('SemanticMediaWiki'); |
| 245 | + $this->addError(wfMsgForContent('smw_wrong_namespace', $wgContLang->getNsText($this->m_fixNamespace))); |
| 246 | + } |
230 | 247 | } else { |
| 248 | + wfLoadExtensionMessages('SemanticMediaWiki'); |
| 249 | + $this->addError(wfMsgForContent('smw_notitle', '')); |
231 | 250 | return NULL; //not possible to create title from empty string |
232 | 251 | } |
233 | 252 | } |
— | — | @@ -303,10 +322,16 @@ |
304 | 323 | /** |
305 | 324 | * Set all basic values for this datavalue to the extent these are |
306 | 325 | * available. Simplifies and speeds up creation from stored data. |
| 326 | + * |
| 327 | + * @todo Rethink our standard set interfaces for datavalues to make wikipage |
| 328 | + * fit better with the rest. |
307 | 329 | */ |
308 | 330 | public function setValues($dbkey, $namespace, $id = false, $interwiki = '', $sortkey = '') { |
309 | 331 | $this->setXSDValue($dbkey,''); // just used to trigger standard parent class methods! |
310 | | - /// TODO: rethink our standard set interfaces for datavalues to make wikipage fit better with the rest |
| 332 | + if ( ($this->m_fixNamespace != NS_MAIN) && ( $this->m_fixNamespace != $namespace) ) { |
| 333 | + wfLoadExtensionMessages('SemanticMediaWiki'); |
| 334 | + $this->addError(wfMsgForContent('smw_notitle', $value)); |
| 335 | + } |
311 | 336 | $this->m_stubdata = array($dbkey, $namespace, $id, $interwiki, $sortkey); |
312 | 337 | } |
313 | 338 | |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | 'smw_decseparator' => '.', |
59 | 59 | 'smw_kiloseparator' => ',', |
60 | 60 | 'smw_notitle' => '"$1" cannot be used as a page name in this wiki.', |
| 61 | + 'smw_wrong_namespace' => 'Only pages in namespace "$1" are allowed here.', |
61 | 62 | 'smw_unknowntype' => 'Unsupported type "$1" defined for property.', |
62 | 63 | 'smw_manytypes' => 'More than one type defined for property.', |
63 | 64 | 'smw_emptystring' => 'Empty strings are not accepted.', |