r55874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55873‎ | r55874 | r55875 >
Date:13:07, 6 September 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
remove some long-deprecated functions, move code for SMWPrintRequest class to separate file for clarity
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -7,195 +7,7 @@
88 * @author Markus Krötzsch
99 */
1010
11 -/**
12 - * Container class for request for printout, as used in queries to
13 - * obtain additional information for the retrieved results.
14 - * @ingroup SMWQuery
15 - */
16 -class SMWPrintRequest {
17 - /// Query mode to print all direct categories of the current element.
18 - const PRINT_CATS = 0;
19 - /// Query mode to print all property values of a certain attribute of the current element.
20 - const PRINT_PROP = 1;
21 - /// Query mode to print the current element (page in result set).
22 - const PRINT_THIS = 2;
23 - /// Query mode to print whether current element is in given category (Boolean printout).
24 - const PRINT_CCAT = 3;
2511
26 - protected $m_mode; // type of print request
27 - protected $m_label; // string for labelling results, contains no markup
28 - protected $m_data; // data entries specifyin gwhat was requested (mixed type)
29 - protected $m_typeid = false; // id of the datatype of the printed objects, if applicable
30 - protected $m_outputformat; // output format string for formatting results, if applicable
31 - protected $m_hash = false; // cache your hash (currently useful since SMWQueryResult accesses the hash many times, might be dropped at some point)
32 -
33 - /**
34 - * Create a print request.
35 - * @param $mode a constant defining what to printout
36 - * @param $label the string label to describe this printout
37 - * @param $data optional data for specifying some request, might be a property object, title, or something else; interpretation depends on $mode
38 - * @param $outputformat optional string for specifying an output format, e.g. an output unit
39 - */
40 - public function __construct($mode, $label, $data = NULL, $outputformat = false) {
41 - $this->m_mode = $mode;
42 - $this->m_label = $label;
43 - $this->m_data = $data;
44 - $this->m_outputformat = $outputformat;
45 - if ( ($mode == SMWPrintRequest::PRINT_CCAT) && ($outputformat == false) ) {
46 - $this->m_outputformat = 'x'; // changed default for Boolean case
47 - }
48 - if ($this->m_data instanceof SMWDataValue) {
49 - $this->m_data->setCaption($label);
50 - }
51 - }
52 -
53 - public function getMode() {
54 - return $this->m_mode;
55 - }
56 -
57 - public function getLabel() {
58 - return $this->m_label;
59 - }
60 -
61 - /**
62 - * Obtain an HTML-formatted representation of the label.
63 - * The $linker is a Linker object used for generating hyperlinks.
64 - * If it is NULL, no links will be created.
65 - */
66 - public function getHTMLText($linker = NULL) {
67 - if ( ($linker === NULL) || ($this->m_label == '') ) {
68 - return htmlspecialchars($this->m_label);
69 - }
70 - switch ($this->m_mode) {
71 - case SMWPrintRequest::PRINT_CATS:
72 - return htmlspecialchars($this->m_label); // TODO: link to Special:Categories
73 - case SMWPrintRequest::PRINT_CCAT:
74 - return $linker->makeLinkObj($this->m_data, htmlspecialchars($this->m_label));
75 - case SMWPrintRequest::PRINT_PROP:
76 - return $this->m_data->getShortHTMLText($linker);
77 - case SMWPrintRequest::PRINT_THIS: default: return htmlspecialchars($this->m_label);
78 - }
79 - }
80 -
81 - /**
82 - * Obtain a Wiki-formatted representation of the label.
83 - */
84 - public function getWikiText($linked = false) {
85 - if ( ($linked === NULL) || ($linked === false) || ($this->m_label == '') ) {
86 - return $this->m_label;
87 - } else {
88 - switch ($this->m_mode) {
89 - case SMWPrintRequest::PRINT_CATS:
90 - return $this->m_label; // TODO: link to Special:Categories
91 - case SMWPrintRequest::PRINT_PROP:
92 - return $this->m_data->getShortWikiText($linked);
93 - case SMWPrintRequest::PRINT_CCAT:
94 - return '[[:' . $this->m_data->getPrefixedText() . '|' . $this->m_label . ']]';
95 - case SMWPrintRequest::PRINT_THIS: default: return $this->m_label;
96 - }
97 - }
98 - }
99 -
100 - /**
101 - * Convenience method for accessing the text in either HTML or Wiki format.
102 - */
103 - public function getText($outputmode, $linker = NULL) {
104 - switch ($outputmode) {
105 - case SMW_OUTPUT_WIKI: return $this->getWikiText($linker);
106 - case SMW_OUTPUT_HTML: case SMW_OUTPUT_FILE: default: return $this->getHTMLText($linker);
107 - }
108 - }
109 -
110 - /**
111 - * Return additional data related to the print request. The result might be
112 - * an object of class SMWPropertyValue or Title, or simply NULL if no data
113 - * is required for the given type of printout.
114 - */
115 - public function getData() {
116 - return $this->m_data;
117 - }
118 -
119 - public function getOutputFormat() {
120 - return $this->m_outputformat;
121 - }
122 -
123 - /**
124 - * If this print request refers to some property, return the type id of this property.
125 - * Otherwise return FALSE.
126 - */
127 - public function getTypeID() {
128 - if ($this->m_typeid === false) {
129 - if ($this->m_mode == SMWPrintRequest::PRINT_PROP) {
130 - $this->m_typeid = $this->m_data->getPropertyTypeID();
131 - } else {
132 - $this->m_typeid = '_wpg'; // return objects might be titles, but anyway
133 - }
134 - }
135 - return $this->m_typeid;
136 - }
137 -
138 - /**
139 - * Return a hash string that is used to eliminate duplicate
140 - * print requests. The hash also includes the chosen label,
141 - * so it is possible to print the same date with different
142 - * labels.
143 - */
144 - public function getHash() {
145 - if ($this->m_hash === false) {
146 - $this->m_hash = $this->m_mode . ':' . $this->m_label . ':';
147 - if ($this->m_data instanceof Title) {
148 - $this->m_hash .= $this->m_data->getPrefixedText() . ':';
149 - } elseif ($this->m_data instanceof SMWDataValue) {
150 - $this->m_hash .= $this->m_data->getHash() . ':';
151 - }
152 - $this->m_hash .= $this->m_outputformat . ':';
153 - }
154 - return $this->m_hash;
155 - }
156 -
157 - /**
158 - * Serialise this object like print requests given in \#ask.
159 - */
160 - public function getSerialisation() {
161 - switch ($this->m_mode) {
162 - case SMWPrintRequest::PRINT_CATS:
163 - global $wgContLang;
164 - $catlabel = $wgContLang->getNSText(NS_CATEGORY);
165 - $result = '?' . $catlabel;
166 - if ($this->m_label != $catlabel) {
167 - $result .= '=' . $this->m_label;
168 - }
169 - return $result;
170 - case SMWPrintRequest::PRINT_PROP: case SMWPrintRequest::PRINT_CCAT:
171 - if ($this->m_mode == SMWPrintRequest::PRINT_CCAT) {
172 - $printname = $this->m_data->getPrefixedText();
173 - $result = '?' . $printname;
174 - if ( $this->m_outputformat != 'x' ) {
175 - $result .= '#' . $this->m_outputformat;
176 - }
177 - } else {
178 - $printname = $this->m_data->getWikiValue();
179 - $result = '?' . $printname;
180 - if ( $this->m_outputformat != '' ) {
181 - $result .= '#' . $this->m_outputformat;
182 - }
183 - }
184 - if ( $printname != $this->m_label ) {
185 - $result .= '=' . $this->m_label;
186 - }
187 - return $result;
188 - case SMWPrintRequest::PRINT_THIS: default: return ''; // no current serialisation
189 - }
190 - }
191 -
192 - /**
193 - * @deprecated Use SMWPrintRequest::getData(). This method will vanish in SMW 1.5.
194 - */
195 - public function getTitle() {
196 - return ($this->m_data instanceof Title)?$this->m_data:NULL;
197 - }
198 -}
199 -
20012 /**
20113 * Abstract base class for all descriptions.
20214 * @ingroup SMWQuery
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
@@ -0,0 +1,191 @@
 2+<?php
 3+/**
 4+ * This file contains the class for defining "print requests", i.e. requests for output
 5+ * informatoin to be included in query results.
 6+ * @file
 7+ * @ingroup SMWQuery
 8+ * @author Markus Krötzsch
 9+ */
 10+
 11+/**
 12+ * Container class for request for printout, as used in queries to
 13+ * obtain additional information for the retrieved results.
 14+ * @ingroup SMWQuery
 15+ */
 16+class SMWPrintRequest {
 17+ /// Query mode to print all direct categories of the current element.
 18+ const PRINT_CATS = 0;
 19+ /// Query mode to print all property values of a certain attribute of the current element.
 20+ const PRINT_PROP = 1;
 21+ /// Query mode to print the current element (page in result set).
 22+ const PRINT_THIS = 2;
 23+ /// Query mode to print whether current element is in given category (Boolean printout).
 24+ const PRINT_CCAT = 3;
 25+
 26+ protected $m_mode; // type of print request
 27+ protected $m_label; // string for labelling results, contains no markup
 28+ protected $m_data; // data entries specifyin gwhat was requested (mixed type)
 29+ protected $m_typeid = false; // id of the datatype of the printed objects, if applicable
 30+ protected $m_outputformat; // output format string for formatting results, if applicable
 31+ protected $m_hash = false; // cache your hash (currently useful since SMWQueryResult accesses the hash many times, might be dropped at some point)
 32+
 33+ /**
 34+ * Create a print request.
 35+ * @param $mode a constant defining what to printout
 36+ * @param $label the string label to describe this printout
 37+ * @param $data optional data for specifying some request, might be a property object, title, or something else; interpretation depends on $mode
 38+ * @param $outputformat optional string for specifying an output format, e.g. an output unit
 39+ */
 40+ public function __construct($mode, $label, $data = NULL, $outputformat = false) {
 41+ $this->m_mode = $mode;
 42+ $this->m_label = $label;
 43+ $this->m_data = $data;
 44+ $this->m_outputformat = $outputformat;
 45+ if ( ($mode == SMWPrintRequest::PRINT_CCAT) && ($outputformat == false) ) {
 46+ $this->m_outputformat = 'x'; // changed default for Boolean case
 47+ }
 48+ if ($this->m_data instanceof SMWDataValue) {
 49+ $this->m_data->setCaption($label);
 50+ }
 51+ }
 52+
 53+ public function getMode() {
 54+ return $this->m_mode;
 55+ }
 56+
 57+ public function getLabel() {
 58+ return $this->m_label;
 59+ }
 60+
 61+ /**
 62+ * Obtain an HTML-formatted representation of the label.
 63+ * The $linker is a Linker object used for generating hyperlinks.
 64+ * If it is NULL, no links will be created.
 65+ */
 66+ public function getHTMLText($linker = NULL) {
 67+ if ( ($linker === NULL) || ($this->m_label == '') ) {
 68+ return htmlspecialchars($this->m_label);
 69+ }
 70+ switch ($this->m_mode) {
 71+ case SMWPrintRequest::PRINT_CATS:
 72+ return htmlspecialchars($this->m_label); // TODO: link to Special:Categories
 73+ case SMWPrintRequest::PRINT_CCAT:
 74+ return $linker->makeLinkObj($this->m_data, htmlspecialchars($this->m_label));
 75+ case SMWPrintRequest::PRINT_PROP:
 76+ return $this->m_data->getShortHTMLText($linker);
 77+ case SMWPrintRequest::PRINT_THIS: default: return htmlspecialchars($this->m_label);
 78+ }
 79+ }
 80+
 81+ /**
 82+ * Obtain a Wiki-formatted representation of the label.
 83+ */
 84+ public function getWikiText($linked = false) {
 85+ if ( ($linked === NULL) || ($linked === false) || ($this->m_label == '') ) {
 86+ return $this->m_label;
 87+ } else {
 88+ switch ($this->m_mode) {
 89+ case SMWPrintRequest::PRINT_CATS:
 90+ return $this->m_label; // TODO: link to Special:Categories
 91+ case SMWPrintRequest::PRINT_PROP:
 92+ return $this->m_data->getShortWikiText($linked);
 93+ case SMWPrintRequest::PRINT_CCAT:
 94+ return '[[:' . $this->m_data->getPrefixedText() . '|' . $this->m_label . ']]';
 95+ case SMWPrintRequest::PRINT_THIS: default: return $this->m_label;
 96+ }
 97+ }
 98+ }
 99+
 100+ /**
 101+ * Convenience method for accessing the text in either HTML or Wiki format.
 102+ */
 103+ public function getText($outputmode, $linker = NULL) {
 104+ switch ($outputmode) {
 105+ case SMW_OUTPUT_WIKI: return $this->getWikiText($linker);
 106+ case SMW_OUTPUT_HTML: case SMW_OUTPUT_FILE: default: return $this->getHTMLText($linker);
 107+ }
 108+ }
 109+
 110+ /**
 111+ * Return additional data related to the print request. The result might be
 112+ * an object of class SMWPropertyValue or Title, or simply NULL if no data
 113+ * is required for the given type of printout.
 114+ */
 115+ public function getData() {
 116+ return $this->m_data;
 117+ }
 118+
 119+ public function getOutputFormat() {
 120+ return $this->m_outputformat;
 121+ }
 122+
 123+ /**
 124+ * If this print request refers to some property, return the type id of this property.
 125+ * Otherwise return FALSE.
 126+ */
 127+ public function getTypeID() {
 128+ if ($this->m_typeid === false) {
 129+ if ($this->m_mode == SMWPrintRequest::PRINT_PROP) {
 130+ $this->m_typeid = $this->m_data->getPropertyTypeID();
 131+ } else {
 132+ $this->m_typeid = '_wpg'; // return objects might be titles, but anyway
 133+ }
 134+ }
 135+ return $this->m_typeid;
 136+ }
 137+
 138+ /**
 139+ * Return a hash string that is used to eliminate duplicate
 140+ * print requests. The hash also includes the chosen label,
 141+ * so it is possible to print the same date with different
 142+ * labels.
 143+ */
 144+ public function getHash() {
 145+ if ($this->m_hash === false) {
 146+ $this->m_hash = $this->m_mode . ':' . $this->m_label . ':';
 147+ if ($this->m_data instanceof Title) {
 148+ $this->m_hash .= $this->m_data->getPrefixedText() . ':';
 149+ } elseif ($this->m_data instanceof SMWDataValue) {
 150+ $this->m_hash .= $this->m_data->getHash() . ':';
 151+ }
 152+ $this->m_hash .= $this->m_outputformat . ':';
 153+ }
 154+ return $this->m_hash;
 155+ }
 156+
 157+ /**
 158+ * Serialise this object like print requests given in \#ask.
 159+ */
 160+ public function getSerialisation() {
 161+ switch ($this->m_mode) {
 162+ case SMWPrintRequest::PRINT_CATS:
 163+ global $wgContLang;
 164+ $catlabel = $wgContLang->getNSText(NS_CATEGORY);
 165+ $result = '?' . $catlabel;
 166+ if ($this->m_label != $catlabel) {
 167+ $result .= '=' . $this->m_label;
 168+ }
 169+ return $result;
 170+ case SMWPrintRequest::PRINT_PROP: case SMWPrintRequest::PRINT_CCAT:
 171+ if ($this->m_mode == SMWPrintRequest::PRINT_CCAT) {
 172+ $printname = $this->m_data->getPrefixedText();
 173+ $result = '?' . $printname;
 174+ if ( $this->m_outputformat != 'x' ) {
 175+ $result .= '#' . $this->m_outputformat;
 176+ }
 177+ } else {
 178+ $printname = $this->m_data->getWikiValue();
 179+ $result = '?' . $printname;
 180+ if ( $this->m_outputformat != '' ) {
 181+ $result .= '#' . $this->m_outputformat;
 182+ }
 183+ }
 184+ if ( $printname != $this->m_label ) {
 185+ $result .= '=' . $this->m_label;
 186+ }
 187+ return $result;
 188+ case SMWPrintRequest::PRINT_THIS: default: return ''; // no current serialisation
 189+ }
 190+ }
 191+
 192+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
___________________________________________________________________
Added: svn:eol-style
1193 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -220,17 +220,5 @@
221221 return SMWDataValueFactory::$m_typelabels;
222222 }
223223
224 -
225 - /**
226 - * Create a value from a string supplied by a user for a given property.
227 - * If no value is given, an empty container is created, the value of which
228 - * can be set later on.
229 - * @deprecated This function will vanish in SMW 1.5. Use SMWDataValueFactory::newPropertyObjectValue instead.
230 - */
231 - static public function newPropertyValue($propertyname, $value=false, $caption=false) {
232 - return SMWDataValueFactory::newPropertyObjectValue(SMWPropertyValue::makeUserProperty($propertyname),$value,$caption);
233 - }
234 -
235 -
236224 }
237225
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -14,7 +14,7 @@
1515 * @defgroup SMW Semantic MediaWiki
1616 */
1717
18 -define('SMW_VERSION','1.5f-SVN');
 18+define('SMW_VERSION','1.5g-SVN');
1919
2020 // constants for displaying the factbox
2121 define('SMW_FACTBOX_HIDDEN', 1);
@@ -166,7 +166,7 @@
167167 $wgAutoloadClasses['SMWStore'] = $smwgIP . '/includes/storage/SMW_Store.php';
168168 $wgAutoloadClasses['SMWStringCondition'] = $smwgIP . '/includes/storage/SMW_Store.php';
169169 $wgAutoloadClasses['SMWRequestOptions'] = $smwgIP . '/includes/storage/SMW_Store.php';
170 - $wgAutoloadClasses['SMWPrintRequest'] = $smwgIP . '/includes/storage/SMW_Description.php';
 170+ $wgAutoloadClasses['SMWPrintRequest'] = $smwgIP . '/includes/storage/SMW_PrintRequest.php';
171171 $wgAutoloadClasses['SMWThingDescription'] = $smwgIP . '/includes/storage/SMW_Description.php';
172172 $wgAutoloadClasses['SMWClassDescription'] = $smwgIP . '/includes/storage/SMW_Description.php';
173173 $wgAutoloadClasses['SMWConceptDescription'] = $smwgIP . '/includes/storage/SMW_Description.php';

Status & tagging log