r41806 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41805‎ | r41806 | r41807 >
Date:14:10, 7 October 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
support allowing only fixed namespaces for input values
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
@@ -16,17 +16,19 @@
1717 */
1818 class SMWWikiPageValue extends SMWDataValue {
1919
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;
3030
 31+ protected $m_fixNamespace = NS_MAIN; // if namespace other than NS_MAIN, restrict inputs to this namespace
 32+
3133 protected function parseUserValue($value) {
3234 $value = ltrim(rtrim($value,' ]'),' ['); // support inputs like " [[Test]] "
3335 if ($value != '') {
@@ -44,11 +46,7 @@
4547 if ($this->m_caption === false) {
4648 $this->m_caption = $value;
4749 }
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()
5351 } else {
5452 wfLoadExtensionMessages('SemanticMediaWiki');
5553 $this->addError(wfMsgForContent('smw_notitle', $value));
@@ -218,15 +216,36 @@
219217
220218 /**
221219 * 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.
222224 */
223225 public function getTitle() {
 226+ global $wgContLang;
224227 $this->unstub();
225228 if ($this->m_title === NULL){
226229 if ($this->m_dbkeyform != '') {
227230 $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+ }
228236 } 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+ }
230247 } else {
 248+ wfLoadExtensionMessages('SemanticMediaWiki');
 249+ $this->addError(wfMsgForContent('smw_notitle', ''));
231250 return NULL; //not possible to create title from empty string
232251 }
233252 }
@@ -303,10 +322,16 @@
304323 /**
305324 * Set all basic values for this datavalue to the extent these are
306325 * 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.
307329 */
308330 public function setValues($dbkey, $namespace, $id = false, $interwiki = '', $sortkey = '') {
309331 $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+ }
311336 $this->m_stubdata = array($dbkey, $namespace, $id, $interwiki, $sortkey);
312337 }
313338
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -57,6 +57,7 @@
5858 'smw_decseparator' => '.',
5959 'smw_kiloseparator' => ',',
6060 '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.',
6162 'smw_unknowntype' => 'Unsupported type "$1" defined for property.',
6263 'smw_manytypes' => 'More than one type defined for property.',
6364 'smw_emptystring' => 'Empty strings are not accepted.',

Status & tagging log