Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php |
— | — | @@ -0,0 +1,207 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This datavalue implements special processing suitable for defining |
| 5 | + * wikipages as values of properties. This value container currently |
| 6 | + * behaves somewhat special in that its xsdvalue is not containint all |
| 7 | + * relevant information (it just gives the DB-Key, not the namespace). |
| 8 | + * TODO: This should change, but is not really critical now. |
| 9 | + * |
| 10 | + * @author Nikolas Iwan |
| 11 | + * @author Markus Krötzsch |
| 12 | + */ |
| 13 | +class SMWWikiPageValue extends SMWDataValue { |
| 14 | + |
| 15 | + private $m_value = ''; |
| 16 | + private $m_textform = ''; |
| 17 | + private $m_dbkeyform = ''; |
| 18 | + private $m_prefixedtext = ''; |
| 19 | + private $m_namespace = NS_MAIN; |
| 20 | + private $m_id; // false if unset |
| 21 | + private $m_title = NULL; |
| 22 | + |
| 23 | + public function parseUserValue($value) { |
| 24 | + if ($value != '') { |
| 25 | + $this->m_value = $value; |
| 26 | + if ($this->getTitle() != NULL) { |
| 27 | + $this->m_textform = $this->m_title->getText(); |
| 28 | + $this->m_dbkeyform = $this->m_title->getDBkey(); |
| 29 | + $this->m_prefixedtext = $this->m_title->getPrefixedText(); |
| 30 | + $this->m_namespace = $this->m_title->getNamespace(); |
| 31 | + $this->m_id = false; // unset id |
| 32 | + if ($this->m_caption === false) { |
| 33 | + $this->m_caption = $this->m_textform; |
| 34 | + } |
| 35 | + } else { |
| 36 | + $this->addError('Invalid title string'); // TODO: internationalise |
| 37 | + } |
| 38 | + } else { |
| 39 | + $this->addError(wfMsgForContent('smw_emptystring')); |
| 40 | + } |
| 41 | + if ($this->m_caption === false) { |
| 42 | + $this->m_caption = ''; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public function parseXSDValue($value, $unit) { // (ignore "unit") |
| 47 | + global $wgContLang; |
| 48 | + $this->m_dbkeyform = $value; |
| 49 | + $this->m_textform = str_replace('_', ' ', $value); |
| 50 | + $this->m_caption = $this->m_textform; |
| 51 | + $nstext = $wgContLang->getNSText($this->m_namespace); |
| 52 | + if ($nstext !== '') { |
| 53 | + $nstext .= ':'; |
| 54 | + } |
| 55 | + $this->m_prefixedtext = $nstext . $this->m_textform; |
| 56 | + $this->m_value = $this->m_prefixedtext; |
| 57 | + $this->m_id = false; // unset id |
| 58 | + $this->m_title = NULL; // unset title |
| 59 | + } |
| 60 | + |
| 61 | + public function setOutputFormat($formatstring) { |
| 62 | + //no formatting |
| 63 | + } |
| 64 | + |
| 65 | + public function getShortWikiText($linked = NULL) { |
| 66 | + if ( ($linked === NULL) || ($linked === false) || (!$this->isValid()) ) { |
| 67 | + return $this->m_caption; |
| 68 | + } else { |
| 69 | + return '[[' . $this->m_prefixedtext . '|' . $this->m_caption . ']]'; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + public function getShortHTMLText($linker = NULL) { |
| 74 | + if (($linker === NULL) || (!$this->isValid())) { |
| 75 | + return htmlspecialchars($this->m_caption); |
| 76 | + } else { |
| 77 | + return $linker->makeLinkObj($this->getTitle(), $this->m_caption); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + public function getLongWikiText($linked = NULL) { |
| 82 | + if (!$this->isValid()) { |
| 83 | + return $this->getErrorText(); |
| 84 | + } |
| 85 | + if ( ($linked === NULL) || ($linked === false) ) { |
| 86 | + return $this->m_prefixedtext; |
| 87 | + } else { |
| 88 | + return '[[' . $this->m_prefixedtext . '|' . $this->m_textform . ']]'; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + public function getLongHTMLText($linker = NULL) { |
| 93 | + if (!$this->isValid()) { |
| 94 | + return $this->getErrorText(); |
| 95 | + } |
| 96 | + if ($linker === NULL) { |
| 97 | + return htmlspecialchars($this->m_prefixedtext); |
| 98 | + } else { |
| 99 | + return $linker->makeLinkObj($this->getTitle()); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + public function getXSDValue() { |
| 104 | + return $this->m_dbkeyform; |
| 105 | + } |
| 106 | + |
| 107 | + public function getWikiValue() { |
| 108 | + if ($this->m_namespace == NS_CATEGORY) { |
| 109 | + // escape to enable use in links; todo: not generally required/suitable :-/ |
| 110 | + return ':' . $this->m_prefixedtext; |
| 111 | + } else { |
| 112 | + return $this->m_prefixedtext; |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + public function getNumericValue() { |
| 117 | + return false; |
| 118 | + } |
| 119 | + |
| 120 | + public function getUnit() { |
| 121 | + return ''; |
| 122 | + } |
| 123 | + |
| 124 | + public function getHash() { |
| 125 | + return $this->m_prefixedtext; |
| 126 | + } |
| 127 | + |
| 128 | + public function isNumeric() { |
| 129 | + return false; |
| 130 | + } |
| 131 | + |
| 132 | +///// special interface for wiki page values |
| 133 | + |
| 134 | + /** |
| 135 | + * Return according Title object or NULL if no valid value was set. |
| 136 | + */ |
| 137 | + public function getTitle() { |
| 138 | + if ($this->m_title === NULL){ |
| 139 | + if ($this->m_value != ''){ |
| 140 | + $this->m_title = Title::newFromText($this->m_value); |
| 141 | + } else { |
| 142 | + return NULL; //not possible to create title from empty string |
| 143 | + } |
| 144 | + } |
| 145 | + return $this->m_title; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Get MediaWiki's ID for this value, if any. |
| 150 | + */ |
| 151 | + public function getID() { |
| 152 | + if ($this->m_id === false) { |
| 153 | + if ($this->getTitle() !== NULL) { |
| 154 | + $this->m_id = $this->m_title->getID(); |
| 155 | + } else { |
| 156 | + $this->m_id = -1; |
| 157 | + } |
| 158 | + } |
| 159 | + return $this->m_id; |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * Get namespace constant for this value, if any. Otherwise |
| 164 | + * return FALSE. |
| 165 | + */ |
| 166 | + public function getNamespace() { |
| 167 | + if (!$this->isValid()) { |
| 168 | + return false; |
| 169 | + } |
| 170 | + return $this->m_namespace; |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Get DBKey for this value. |
| 175 | + */ |
| 176 | + public function getDBKey() { |
| 177 | + return $this->m_dbkeyform; |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Set all basic values for this datavalue to the extent these are |
| 182 | + * available. Simplifies and speeds up creation from stored data. |
| 183 | + */ |
| 184 | + public function setValues($dbkey, $namespace, $id = false) { |
| 185 | + $this->m_namespace = $namespace; |
| 186 | + $this->setXSDValue($dbkey); |
| 187 | + $this->m_id = $id; |
| 188 | + } |
| 189 | + |
| 190 | +///// Legacy methods for compatibility |
| 191 | + |
| 192 | + /** |
| 193 | + * @DEPRECATED |
| 194 | + */ |
| 195 | + public function getPrefixedText(){ |
| 196 | + //trigger_error("The function SMWWikiPageValue::getPrefixedText) is deprecated.", E_USER_NOTICE); |
| 197 | + return $this->getLongWikiText(false); |
| 198 | + } |
| 199 | + /** |
| 200 | + * @DEPRECATED |
| 201 | + */ |
| 202 | + public function getText(){ |
| 203 | + //trigger_error("The function SMWWikiPageValue::getText() is deprecated.", E_USER_NOTICE); |
| 204 | + return $this->getLongWikiText(false); |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 209 | + native |