Index: trunk/extensions/DPLforum/DPLforum.i18n.php |
— | — | @@ -11,9 +11,10 @@ |
12 | 12 | * @author Ross McClure |
13 | 13 | */ |
14 | 14 | $messages['en'] = array( |
15 | | - 'forum_by' => 'by', |
16 | | - 'forum_edited' => ' - Last edited', |
17 | | - 'forum_never' => 'Never', |
18 | | - 'forum_toofew' => 'DPL Forum: Too few categories!', |
19 | | - 'forum_toomany' => 'DPL Forum: Too many categories!' |
20 | | -); |
\ No newline at end of file |
| 15 | + 'dplforum-desc' => 'DPL-based forum extension', |
| 16 | + 'dplforum-by' => 'by', |
| 17 | + 'dplforum-edited' => ' - Last edited', |
| 18 | + 'dplforum-never' => 'Never', |
| 19 | + 'dplforum-toofew' => 'DPL Forum: Too few categories!', |
| 20 | + 'dplforum-toomany' => 'DPL Forum: Too many categories!' |
| 21 | +); |
Index: trunk/extensions/DPLforum/DPLforum.php |
— | — | @@ -33,11 +33,12 @@ |
34 | 34 | $wgExtensionFunctions[] = 'wfDPLforum'; |
35 | 35 | $wgHooks['LanguageGetMagic'][] = 'wfDPLmagic'; |
36 | 36 | $wgExtensionCredits['parserhook'][] = array( |
37 | | - 'name' => 'DPLforum', |
38 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:DPLforum', |
39 | | - 'description' => 'DPL-based forum extension', |
40 | | - 'author' => 'Ross McClure', |
41 | | - 'version' => '3.2' |
| 37 | + 'name' => 'DPLforum', |
| 38 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:DPLforum', |
| 39 | + 'description' => 'DPL-based forum extension', |
| 40 | + 'descriptionmsg' => 'dplforum-desc', |
| 41 | + 'author' => 'Ross McClure', |
| 42 | + 'version' => '3.2' |
42 | 43 | ); |
43 | 44 | |
44 | 45 | $dir = dirname(__FILE__) . '/'; |
— | — | @@ -64,380 +65,380 @@ |
65 | 66 | } |
66 | 67 | |
67 | 68 | class DPLForum { |
68 | | - var $minCategories = 1; // Minimum number of categories to look for |
69 | | - var $maxCategories = 6; // Maximum number of categories to look for |
70 | | - var $maxResultCount = 50; // Maximum number of results to allow |
71 | | - var $unlimitedResults = true; // Allow unlimited results |
72 | | - var $unlimitedCategories = false; // Allow unlimited categories |
73 | | - var $requireCache = false; // Only clear the cache on purge |
| 69 | + var $minCategories = 1; // Minimum number of categories to look for |
| 70 | + var $maxCategories = 6; // Maximum number of categories to look for |
| 71 | + var $maxResultCount = 50; // Maximum number of results to allow |
| 72 | + var $unlimitedResults = true; // Allow unlimited results |
| 73 | + var $unlimitedCategories = false; // Allow unlimited categories |
| 74 | + var $requireCache = false; // Only clear the cache on purge |
74 | 75 | |
75 | | - // Restricted namespaces cannot be searched for page author or creation time. |
76 | | - // Unless this array is empty, namespace-free searches are also restricted. |
77 | | - // Note: Only integers in this array are checked. |
78 | | - var $restrictNamespace = array(); // No restrictions |
| 76 | + // Restricted namespaces cannot be searched for page author or creation time. |
| 77 | + // Unless this array is empty, namespace-free searches are also restricted. |
| 78 | + // Note: Only integers in this array are checked. |
| 79 | + var $restrictNamespace = array(); // No restrictions |
79 | 80 | |
80 | | - var $bTableMode; |
81 | | - var $bTimestamp; |
82 | | - var $bLinkHistory; |
83 | | - var $bEmbedHistory; |
84 | | - var $bShowNamespace; |
85 | | - var $bAddAuthor; |
86 | | - var $bAddCreationDate; |
87 | | - var $bAddLastEdit; |
88 | | - var $bAddLastEditor; |
89 | | - var $bCompactAuthor; |
90 | | - var $bCompactEdit; |
91 | | - var $sInput; |
92 | | - var $sOmit; |
93 | | - var $vMarkNew; |
| 81 | + var $bTableMode; |
| 82 | + var $bTimestamp; |
| 83 | + var $bLinkHistory; |
| 84 | + var $bEmbedHistory; |
| 85 | + var $bShowNamespace; |
| 86 | + var $bAddAuthor; |
| 87 | + var $bAddCreationDate; |
| 88 | + var $bAddLastEdit; |
| 89 | + var $bAddLastEditor; |
| 90 | + var $bCompactAuthor; |
| 91 | + var $bCompactEdit; |
| 92 | + var $sInput; |
| 93 | + var $sOmit; |
| 94 | + var $vMarkNew; |
94 | 95 | |
95 | | - function cat(&$parser, $name) { |
96 | | - $cats = array(); |
97 | | - if(preg_match_all("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
98 | | - foreach($matches[1] as $cat) { |
99 | | - $title = Title::newFromText($parser->replaceVariables(trim($cat))); |
100 | | - if( !is_null( $title ) ) |
101 | | - $cats[] = $title; |
102 | | - } |
103 | | - } |
104 | | - return $cats; |
105 | | - } |
| 96 | + function cat(&$parser, $name) { |
| 97 | + $cats = array(); |
| 98 | + if(preg_match_all("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
| 99 | + foreach($matches[1] as $cat) { |
| 100 | + $title = Title::newFromText($parser->replaceVariables(trim($cat))); |
| 101 | + if( !is_null( $title ) ) |
| 102 | + $cats[] = $title; |
| 103 | + } |
| 104 | + } |
| 105 | + return $cats; |
| 106 | + } |
106 | 107 | |
107 | | - function get($name, $value=NULL, $parser=NULL) { |
108 | | - if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
109 | | - $arg = trim($matches[1]); |
110 | | - if(is_int($value)) return intval($arg); |
111 | | - else if(is_null($parser)) return htmlspecialchars($arg); |
112 | | - else return $parser->replaceVariables($arg); |
113 | | - } |
114 | | - return $value; |
115 | | - } |
| 108 | + function get($name, $value=NULL, $parser=NULL) { |
| 109 | + if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
| 110 | + $arg = trim($matches[1]); |
| 111 | + if(is_int($value)) return intval($arg); |
| 112 | + else if(is_null($parser)) return htmlspecialchars($arg); |
| 113 | + else return $parser->replaceVariables($arg); |
| 114 | + } |
| 115 | + return $value; |
| 116 | + } |
116 | 117 | |
117 | | - function link(&$parser, $count, $page='', $text='') { |
118 | | - $count = intval($count); |
119 | | - if($count<1) return ''; |
| 118 | + function link(&$parser, $count, $page='', $text='') { |
| 119 | + $count = intval($count); |
| 120 | + if($count<1) return ''; |
120 | 121 | |
121 | | - if($this->requireCache) $offset = 0; |
122 | | - else { |
123 | | - global $wgRequest; |
124 | | - $parser->disableCache(); |
125 | | - $offset = intval($wgRequest->getVal('offset','')); |
126 | | - } |
| 122 | + if($this->requireCache) $offset = 0; |
| 123 | + else { |
| 124 | + global $wgRequest; |
| 125 | + $parser->disableCache(); |
| 126 | + $offset = intval($wgRequest->getVal('offset','')); |
| 127 | + } |
127 | 128 | |
128 | | - $i = intval($page); |
129 | | - if(($i!=0) && ctype_digit($page[0])) $i -= 1; |
130 | | - else $i += intval($offset / $count); |
131 | | - if($this->link_test($i,$page)) return ''; |
| 129 | + $i = intval($page); |
| 130 | + if(($i!=0) && ctype_digit($page[0])) $i -= 1; |
| 131 | + else $i += intval($offset / $count); |
| 132 | + if($this->link_test($i,$page)) return ''; |
132 | 133 | |
133 | | - if($text==='') $text = ($i + 1); |
134 | | - $page = ($count * $i); |
135 | | - if($page == $offset) return $text; |
| 134 | + if($text==='') $text = ($i + 1); |
| 135 | + $page = ($count * $i); |
| 136 | + if($page == $offset) return $text; |
136 | 137 | |
137 | | - return '[{{fullurl:{{FULLPAGENAME}}|offset='.$page.'}} '.$text.']'; |
138 | | - } |
| 138 | + return '[{{fullurl:{{FULLPAGENAME}}|offset='.$page.'}} '.$text.']'; |
| 139 | + } |
139 | 140 | |
140 | | - function link_test($page, $cond) { |
141 | | - if(preg_match("/\\d+(\\D+)(\\d+)/",$cond,$m)) { |
142 | | - $m[1] = strtr($m[1], array(('&l'.'t;')=>'<', ('&g'.'t;')=>'>')); |
143 | | - $m[2] = intval($m[2])-1; |
144 | | - switch($m[1]) { |
145 | | - case '<': return ($page >= $m[2]); |
146 | | - case '>': return ($page <= $m[2]); |
147 | | - case '<=': return ($page > $m[2]); |
148 | | - case '>=': return ($page < $m[2]); |
149 | | - } |
150 | | - } |
151 | | - return ($page < 0); |
152 | | - } |
| 141 | + function link_test($page, $cond) { |
| 142 | + if(preg_match("/\\d+(\\D+)(\\d+)/",$cond,$m)) { |
| 143 | + $m[1] = strtr($m[1], array(('&l'.'t;')=>'<', ('&g'.'t;')=>'>')); |
| 144 | + $m[2] = intval($m[2])-1; |
| 145 | + switch($m[1]) { |
| 146 | + case '<': return ($page >= $m[2]); |
| 147 | + case '>': return ($page <= $m[2]); |
| 148 | + case '<=': return ($page > $m[2]); |
| 149 | + case '>=': return ($page < $m[2]); |
| 150 | + } |
| 151 | + } |
| 152 | + return ($page < 0); |
| 153 | + } |
153 | 154 | |
154 | | - function msg($type, $error=NULL) { |
155 | | - if($error && ($this->get('suppresserrors')=='true')) return ''; |
156 | | - return htmlspecialchars(wfMsg($type)); |
157 | | - } |
| 155 | + function msg($type, $error=NULL) { |
| 156 | + if($error && ($this->get('suppresserrors')=='true')) return ''; |
| 157 | + return htmlspecialchars(wfMsg($type)); |
| 158 | + } |
158 | 159 | |
159 | | - function parse(&$input, &$parser) { |
160 | | - global $wgContLang; |
| 160 | + function parse(&$input, &$parser) { |
| 161 | + global $wgContLang; |
161 | 162 | |
162 | | - $this->sInput =& $input; |
163 | | - $sPrefix = $this->get('prefix','',$parser); |
164 | | - $this->sOmit = $this->get('omit',$sPrefix,$parser); |
165 | | - $this->bAddAuthor = ($this->get('addauthor')=='true'); |
166 | | - $this->bTimestamp = ($this->get('timestamp')!='false'); |
167 | | - $this->bAddLastEdit = ($this->get('addlastedit')!='false'); |
168 | | - $this->bAddLastEditor = ($this->get('addlasteditor')=='true'); |
169 | | - $this->bAddCreationDate = ($this->get('addcreationdate')=='true'); |
| 163 | + $this->sInput =& $input; |
| 164 | + $sPrefix = $this->get('prefix','',$parser); |
| 165 | + $this->sOmit = $this->get('omit',$sPrefix,$parser); |
| 166 | + $this->bAddAuthor = ($this->get('addauthor')=='true'); |
| 167 | + $this->bTimestamp = ($this->get('timestamp')!='false'); |
| 168 | + $this->bAddLastEdit = ($this->get('addlastedit')!='false'); |
| 169 | + $this->bAddLastEditor = ($this->get('addlasteditor')=='true'); |
| 170 | + $this->bAddCreationDate = ($this->get('addcreationdate')=='true'); |
170 | 171 | |
171 | | - switch($this->get('historylink')) { |
172 | | - case 'embed': |
173 | | - case 'true': $this->bEmbedHistory = true; |
174 | | - case 'append': |
175 | | - case 'show': $this->bLinkHistory = true; |
176 | | - } |
177 | | - $sOrder = 'rev_timestamp'; |
178 | | - switch($this->get('ordermethod')) { |
179 | | - case 'categoryadd': |
180 | | - case 'created': |
181 | | - $sOrder = 'first_time'; |
182 | | - break; |
183 | | - case 'pageid': |
184 | | - $sOrder = 'page_id'; |
185 | | - } |
| 172 | + switch($this->get('historylink')) { |
| 173 | + case 'embed': |
| 174 | + case 'true': $this->bEmbedHistory = true; |
| 175 | + case 'append': |
| 176 | + case 'show': $this->bLinkHistory = true; |
| 177 | + } |
| 178 | + $sOrder = 'rev_timestamp'; |
| 179 | + switch($this->get('ordermethod')) { |
| 180 | + case 'categoryadd': |
| 181 | + case 'created': |
| 182 | + $sOrder = 'first_time'; |
| 183 | + break; |
| 184 | + case 'pageid': |
| 185 | + $sOrder = 'page_id'; |
| 186 | + } |
186 | 187 | |
187 | | - $arg = $this->get('compact'); |
188 | | - if($arg=='all' || strpos($arg,'edit')===0) |
189 | | - $this->bCompactEdit = $this->bAddLastEdit; |
190 | | - $this->bCompactAuthor = ($arg=='author' || $arg=='all'); |
| 188 | + $arg = $this->get('compact'); |
| 189 | + if($arg=='all' || strpos($arg,'edit')===0) |
| 190 | + $this->bCompactEdit = $this->bAddLastEdit; |
| 191 | + $this->bCompactAuthor = ($arg=='author' || $arg=='all'); |
191 | 192 | |
192 | | - $arg = $this->get('namespace','',$parser); |
193 | | - $iNamespace = $wgContLang->getNsIndex($arg); |
194 | | - if(!$iNamespace) { |
195 | | - if(($arg) || ($arg==='0')) $iNamespace = intval($arg); |
196 | | - else $iNamespace = -1; |
197 | | - } |
198 | | - if($iNamespace<0) |
199 | | - $this->bShowNamespace = ($this->get('shownamespace')!='false'); |
200 | | - else $this->bShowNamespace = ($this->get('shownamespace')=='true'); |
| 193 | + $arg = $this->get('namespace','',$parser); |
| 194 | + $iNamespace = $wgContLang->getNsIndex($arg); |
| 195 | + if(!$iNamespace) { |
| 196 | + if(($arg) || ($arg==='0')) $iNamespace = intval($arg); |
| 197 | + else $iNamespace = -1; |
| 198 | + } |
| 199 | + if($iNamespace<0) |
| 200 | + $this->bShowNamespace = ($this->get('shownamespace')!='false'); |
| 201 | + else $this->bShowNamespace = ($this->get('shownamespace')=='true'); |
201 | 202 | |
202 | | - $this->bTableMode = false; |
203 | | - $sStartItem = $sEndItem = ''; |
204 | | - $bCountMode = false; |
205 | | - $arg = $this->get('mode'); |
206 | | - switch($arg) { |
207 | | - case 'none': |
208 | | - $sEndItem = '<br />'; |
209 | | - break; |
210 | | - case 'count': |
211 | | - $bCountMode = true; |
212 | | - break; |
213 | | - case 'list': |
214 | | - case 'ordered': |
215 | | - case 'unordered': |
216 | | - $sStartItem = '<li>'; |
217 | | - $sEndItem = '</li>'; |
218 | | - break; |
219 | | - case 'table': |
220 | | - default: |
221 | | - $this->bTableMode = true; |
222 | | - $sStartItem = '<tr>'; |
223 | | - $sEndItem = '</tr>'; |
224 | | - } |
225 | | - $aCategories = $this->cat($parser,'category'); |
226 | | - $aExcludeCategories = $this->cat($parser,'notcategory'); |
227 | | - $cats = count($aCategories); |
228 | | - $nocats = count($aExcludeCategories); |
229 | | - $total = $cats + $nocats; |
230 | | - $output = ''; |
| 203 | + $this->bTableMode = false; |
| 204 | + $sStartItem = $sEndItem = ''; |
| 205 | + $bCountMode = false; |
| 206 | + $arg = $this->get('mode'); |
| 207 | + switch($arg) { |
| 208 | + case 'none': |
| 209 | + $sEndItem = '<br />'; |
| 210 | + break; |
| 211 | + case 'count': |
| 212 | + $bCountMode = true; |
| 213 | + break; |
| 214 | + case 'list': |
| 215 | + case 'ordered': |
| 216 | + case 'unordered': |
| 217 | + $sStartItem = '<li>'; |
| 218 | + $sEndItem = '</li>'; |
| 219 | + break; |
| 220 | + case 'table': |
| 221 | + default: |
| 222 | + $this->bTableMode = true; |
| 223 | + $sStartItem = '<tr>'; |
| 224 | + $sEndItem = '</tr>'; |
| 225 | + } |
| 226 | + $aCategories = $this->cat($parser,'category'); |
| 227 | + $aExcludeCategories = $this->cat($parser,'notcategory'); |
| 228 | + $cats = count($aCategories); |
| 229 | + $nocats = count($aExcludeCategories); |
| 230 | + $total = $cats + $nocats; |
| 231 | + $output = ''; |
231 | 232 | |
232 | | - if($sPrefix==='' && (($cats < 1 && $iNamespace < 0) || |
233 | | - ($total < $this->minCategories))) return $this->msg('forum_toofew',1); |
234 | | - if(($total > $this->maxCategories) && (!$this->unlimitedCategories)) |
235 | | - return $this->msg('forum_toomany',1); |
| 233 | + if($sPrefix==='' && (($cats < 1 && $iNamespace < 0) || |
| 234 | + ($total < $this->minCategories))) return $this->msg('dplforum-toofew',1); |
| 235 | + if(($total > $this->maxCategories) && (!$this->unlimitedCategories)) |
| 236 | + return $this->msg('dplforum-toomany',1); |
236 | 237 | |
237 | | - $count = 1; |
238 | | - $start = $this->get('start',0); |
239 | | - $title = Title::newFromText($parser->replaceVariables( |
240 | | - trim($this->get('title')))); |
241 | | - if(!($bCountMode || $this->requireCache || $this->get('cache')=='true')) { |
242 | | - $parser->disableCache(); |
| 238 | + $count = 1; |
| 239 | + $start = $this->get('start',0); |
| 240 | + $title = Title::newFromText($parser->replaceVariables( |
| 241 | + trim($this->get('title')))); |
| 242 | + if(!($bCountMode || $this->requireCache || $this->get('cache')=='true')) { |
| 243 | + $parser->disableCache(); |
243 | 244 | |
244 | | - if(is_null($title)) { |
245 | | - global $wgRequest; |
246 | | - $start += intval($wgRequest->getVal('offset')); |
247 | | - } |
248 | | - } |
249 | | - if($start < 0) $start = 0; |
| 245 | + if(is_null($title)) { |
| 246 | + global $wgRequest; |
| 247 | + $start += intval($wgRequest->getVal('offset')); |
| 248 | + } |
| 249 | + } |
| 250 | + if($start < 0) $start = 0; |
250 | 251 | |
251 | | - if(is_null($title)) { |
252 | | - $count = $this->get('count',0); |
253 | | - if($count > 0) { |
254 | | - if($count > $this->maxResultCount) |
255 | | - $count = $this->maxResultCount; |
256 | | - } |
257 | | - else if($this->unlimitedResults) |
258 | | - $count = 0x7FFFFFFF; // maximum integer value |
259 | | - else |
260 | | - $count = $this->maxResultCount; |
261 | | - } |
| 252 | + if(is_null($title)) { |
| 253 | + $count = $this->get('count',0); |
| 254 | + if($count > 0) { |
| 255 | + if($count > $this->maxResultCount) |
| 256 | + $count = $this->maxResultCount; |
| 257 | + } |
| 258 | + else if($this->unlimitedResults) |
| 259 | + $count = 0x7FFFFFFF; // maximum integer value |
| 260 | + else |
| 261 | + $count = $this->maxResultCount; |
| 262 | + } |
262 | 263 | |
263 | | - //build the SQL query |
264 | | - $dbr =& wfGetDB( DB_SLAVE ); |
265 | | - $sPageTable = $dbr->tableName( 'page' ); |
266 | | - $sRevTable = $dbr->tableName( 'revision' ); |
267 | | - $categorylinks = $dbr->tableName( 'categorylinks' ); |
268 | | - $sSqlSelectFrom = "SELECT page_namespace, page_title," |
269 | | - . " r.rev_user_text, r.rev_timestamp"; |
270 | | - $arg = " FROM $sPageTable INNER JOIN $sRevTable" |
271 | | - . " AS r ON page_latest = r.rev_id"; |
| 264 | + //build the SQL query |
| 265 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 266 | + $sPageTable = $dbr->tableName( 'page' ); |
| 267 | + $sRevTable = $dbr->tableName( 'revision' ); |
| 268 | + $categorylinks = $dbr->tableName( 'categorylinks' ); |
| 269 | + $sSqlSelectFrom = "SELECT page_namespace, page_title," |
| 270 | + . " r.rev_user_text, r.rev_timestamp"; |
| 271 | + $arg = " FROM $sPageTable INNER JOIN $sRevTable" |
| 272 | + . " AS r ON page_latest = r.rev_id"; |
272 | 273 | |
273 | | - if($bCountMode) { |
274 | | - $sSqlSelectFrom = "SELECT COUNT(*) AS num_rows FROM $sPageTable"; |
275 | | - } |
276 | | - else if(($this->bAddAuthor || $this->bAddCreationDate || |
277 | | - ($sOrder=='first_time')) && ((!$this->restrictNamespace) || |
278 | | - ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace)))) { |
279 | | - $sSqlSelectFrom .= ", o.rev_user_text AS first_user, o.rev_timestamp AS" |
280 | | - . " first_time" . $arg . " INNER JOIN $sRevTable AS o" |
281 | | - . " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable" |
282 | | - . " AS q WHERE q.rev_page = page_id )"; |
283 | | - } else { |
284 | | - if($sOrder=='first_time') $sOrder = 'page_id'; |
285 | | - $sSqlSelectFrom .= $arg; |
286 | | - } |
| 274 | + if($bCountMode) { |
| 275 | + $sSqlSelectFrom = "SELECT COUNT(*) AS num_rows FROM $sPageTable"; |
| 276 | + } |
| 277 | + else if(($this->bAddAuthor || $this->bAddCreationDate || |
| 278 | + ($sOrder=='first_time')) && ((!$this->restrictNamespace) || |
| 279 | + ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace)))) { |
| 280 | + $sSqlSelectFrom .= ", o.rev_user_text AS first_user, o.rev_timestamp AS" |
| 281 | + . " first_time" . $arg . " INNER JOIN $sRevTable AS o" |
| 282 | + . " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable" |
| 283 | + . " AS q WHERE q.rev_page = page_id )"; |
| 284 | + } else { |
| 285 | + if($sOrder=='first_time') $sOrder = 'page_id'; |
| 286 | + $sSqlSelectFrom .= $arg; |
| 287 | + } |
287 | 288 | |
288 | | - $sSqlWhere = ' WHERE 1=1'; |
289 | | - if($iNamespace >= 0) |
290 | | - $sSqlWhere = ' WHERE page_namespace='.$iNamespace; |
| 289 | + $sSqlWhere = ' WHERE 1=1'; |
| 290 | + if($iNamespace >= 0) |
| 291 | + $sSqlWhere = ' WHERE page_namespace='.$iNamespace; |
291 | 292 | |
292 | | - if($sPrefix!=='') { |
293 | | - // Escape SQL special characters |
294 | | - $sPrefix = strtr($sPrefix, array('\\'=>'\\\\\\\\', |
295 | | - ' '=>'\\_', '_'=>'\\_', '%'=>'\\%', '\''=>'\\\'')); |
296 | | - $sSqlWhere .= " AND page_title LIKE BINARY '".$sPrefix."%'"; |
297 | | - } |
| 293 | + if($sPrefix!=='') { |
| 294 | + // Escape SQL special characters |
| 295 | + $sPrefix = strtr($sPrefix, array('\\'=>'\\\\\\\\', |
| 296 | + ' '=>'\\_', '_'=>'\\_', '%'=>'\\%', '\''=>'\\\'')); |
| 297 | + $sSqlWhere .= " AND page_title LIKE BINARY '".$sPrefix."%'"; |
| 298 | + } |
298 | 299 | |
299 | | - switch($this->get('redirects')) { |
300 | | - case 'only': |
301 | | - $sSqlWhere .= ' AND page_is_redirect = 1'; |
302 | | - case 'include': |
303 | | - break; |
304 | | - case 'exclude': |
305 | | - default: |
306 | | - $sSqlWhere .= ' AND page_is_redirect = 0'; |
307 | | - break; |
308 | | - } |
| 300 | + switch($this->get('redirects')) { |
| 301 | + case 'only': |
| 302 | + $sSqlWhere .= ' AND page_is_redirect = 1'; |
| 303 | + case 'include': |
| 304 | + break; |
| 305 | + case 'exclude': |
| 306 | + default: |
| 307 | + $sSqlWhere .= ' AND page_is_redirect = 0'; |
| 308 | + break; |
| 309 | + } |
309 | 310 | |
310 | | - $n = 1; |
311 | | - for($i = 0; $i < $cats; $i++) { |
312 | | - $sSqlSelectFrom .= " INNER JOIN $categorylinks AS" . |
313 | | - " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" . |
314 | | - $dbr->addQuotes( $aCategories[$i]->getDbKey() ); |
315 | | - $n++; |
316 | | - } |
317 | | - for($i = 0; $i < $nocats; $i++) { |
318 | | - $sSqlSelectFrom .= " LEFT OUTER JOIN $categorylinks AS" . |
319 | | - " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" . |
320 | | - $dbr->addQuotes( $aExcludeCategories[$i]->getDbKey() ); |
321 | | - $sSqlWhere .= " AND c{$n}.cl_to IS NULL"; |
322 | | - $n++; |
323 | | - } |
| 311 | + $n = 1; |
| 312 | + for($i = 0; $i < $cats; $i++) { |
| 313 | + $sSqlSelectFrom .= " INNER JOIN $categorylinks AS" . |
| 314 | + " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" . |
| 315 | + $dbr->addQuotes( $aCategories[$i]->getDbKey() ); |
| 316 | + $n++; |
| 317 | + } |
| 318 | + for($i = 0; $i < $nocats; $i++) { |
| 319 | + $sSqlSelectFrom .= " LEFT OUTER JOIN $categorylinks AS" . |
| 320 | + " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" . |
| 321 | + $dbr->addQuotes( $aExcludeCategories[$i]->getDbKey() ); |
| 322 | + $sSqlWhere .= " AND c{$n}.cl_to IS NULL"; |
| 323 | + $n++; |
| 324 | + } |
324 | 325 | |
325 | | - if(!$bCountMode) { |
326 | | - $sSqlWhere .= " ORDER BY $sOrder "; |
327 | | - if($this->get('order')=='ascending') $sSqlWhere .= 'ASC'; |
328 | | - else $sSqlWhere .= 'DESC'; |
329 | | - } |
330 | | - $sSqlWhere .= " LIMIT $start, $count"; |
| 326 | + if(!$bCountMode) { |
| 327 | + $sSqlWhere .= " ORDER BY $sOrder "; |
| 328 | + if($this->get('order')=='ascending') $sSqlWhere .= 'ASC'; |
| 329 | + else $sSqlWhere .= 'DESC'; |
| 330 | + } |
| 331 | + $sSqlWhere .= " LIMIT $start, $count"; |
331 | 332 | |
332 | | - //DEBUG: output SQL query |
333 | | - //$output .= 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />"; |
| 333 | + //DEBUG: output SQL query |
| 334 | + //$output .= 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />"; |
334 | 335 | |
335 | | - // process the query |
336 | | - $res = $dbr->query($sSqlSelectFrom . $sSqlWhere); |
| 336 | + // process the query |
| 337 | + $res = $dbr->query($sSqlSelectFrom . $sSqlWhere); |
337 | 338 | |
338 | | - $this->vMarkNew = $dbr->timestamp(time() - |
339 | | - intval($this->get('newdays',7) * 86400)); |
| 339 | + $this->vMarkNew = $dbr->timestamp(time() - |
| 340 | + intval($this->get('newdays',7) * 86400)); |
340 | 341 | |
341 | | - if($bCountMode) { |
342 | | - if($row = $dbr->fetchObject( $res )) $output .= $row->num_rows; |
343 | | - else $output .= '0'; |
344 | | - } |
345 | | - else if(is_null($title)) { |
346 | | - while($row = $dbr->fetchObject( $res )) { |
347 | | - $title = Title::makeTitle($row->page_namespace, $row->page_title); |
348 | | - $output .= $sStartItem; |
349 | | - $output .= $this->buildOutput($title, $title, $row->rev_timestamp, |
350 | | - $row->rev_user_text, $row->first_user, $row->first_time); |
351 | | - $output .= $sEndItem . "\n"; |
352 | | - } |
353 | | - } else { |
354 | | - $output .= $sStartItem; |
355 | | - if($row = $dbr->fetchObject( $res )) { |
356 | | - $output .= $this->buildOutput(Title::makeTitle($row->page_namespace, |
357 | | - $row->page_title), $title, $row->rev_timestamp, $row->rev_user_text); |
358 | | - } else { |
359 | | - $output .= $this->buildOutput(NULL, $title, $this->msg('forum_never')); |
360 | | - } |
361 | | - $output .= $sEndItem . "\n"; |
362 | | - } |
363 | | - return $output; |
364 | | - } |
| 342 | + if($bCountMode) { |
| 343 | + if($row = $dbr->fetchObject( $res )) $output .= $row->num_rows; |
| 344 | + else $output .= '0'; |
| 345 | + } |
| 346 | + else if(is_null($title)) { |
| 347 | + while($row = $dbr->fetchObject( $res )) { |
| 348 | + $title = Title::makeTitle($row->page_namespace, $row->page_title); |
| 349 | + $output .= $sStartItem; |
| 350 | + $output .= $this->buildOutput($title, $title, $row->rev_timestamp, |
| 351 | + $row->rev_user_text, $row->first_user, $row->first_time); |
| 352 | + $output .= $sEndItem . "\n"; |
| 353 | + } |
| 354 | + } else { |
| 355 | + $output .= $sStartItem; |
| 356 | + if($row = $dbr->fetchObject( $res )) { |
| 357 | + $output .= $this->buildOutput(Title::makeTitle($row->page_namespace, |
| 358 | + $row->page_title), $title, $row->rev_timestamp, $row->rev_user_text); |
| 359 | + } else { |
| 360 | + $output .= $this->buildOutput(NULL, $title, $this->msg('dplforum-never')); |
| 361 | + } |
| 362 | + $output .= $sEndItem . "\n"; |
| 363 | + } |
| 364 | + return $output; |
| 365 | + } |
365 | 366 | |
366 | | - // Generates a single line of output. |
367 | | - function buildOutput($page, $title, $time, $user='', $author='', $made='') { |
368 | | - global $wgLang, $wgUser; |
369 | | - $sk =& $wgUser->getSkin(); |
370 | | - $tm =& $this->bTableMode; |
371 | | - $by = $this->msg('forum_by'); |
372 | | - $output = ''; |
| 367 | + // Generates a single line of output. |
| 368 | + function buildOutput($page, $title, $time, $user='', $author='', $made='') { |
| 369 | + global $wgLang, $wgUser; |
| 370 | + $sk =& $wgUser->getSkin(); |
| 371 | + $tm =& $this->bTableMode; |
| 372 | + $by = $this->msg('dplforum-by'); |
| 373 | + $output = ''; |
373 | 374 | |
374 | | - if($this->bAddCreationDate) { |
375 | | - if(is_numeric($made)) $made = $wgLang->date($made, true); |
376 | | - if($page && $this->bLinkHistory && !$this->bAddLastEdit) { |
377 | | - if($this->bEmbedHistory) |
378 | | - $made = $sk->makeKnownLinkObj($page, $made, 'action=history'); |
379 | | - else |
380 | | - $made .= ' (' . $sk->makeKnownLinkObj($page, |
381 | | - wfMsg('hist'), 'action=history') . ')'; |
382 | | - } |
383 | | - if($tm) $output .= "<td class='forum_created'>$made</td>"; |
384 | | - else if($made) $output = "{$made}: "; |
385 | | - } |
386 | | - if($tm) $output .= "<td class='forum_title'>"; |
| 375 | + if($this->bAddCreationDate) { |
| 376 | + if(is_numeric($made)) $made = $wgLang->date($made, true); |
| 377 | + if($page && $this->bLinkHistory && !$this->bAddLastEdit) { |
| 378 | + if($this->bEmbedHistory) |
| 379 | + $made = $sk->makeKnownLinkObj($page, $made, 'action=history'); |
| 380 | + else |
| 381 | + $made .= ' (' . $sk->makeKnownLinkObj($page, |
| 382 | + wfMsg('hist'), 'action=history') . ')'; |
| 383 | + } |
| 384 | + if($tm) $output .= "<td class='forum_created'>$made</td>"; |
| 385 | + else if($made) $output = "{$made}: "; |
| 386 | + } |
| 387 | + if($tm) $output .= "<td class='forum_title'>"; |
387 | 388 | |
388 | | - $text = $query = $props = ''; |
389 | | - if($this->bShowNamespace == true) $text = $title->getEscapedText(); |
390 | | - else $text = htmlspecialchars($title->getText()); |
391 | | - if(($this->sOmit) && strpos($text, $this->sOmit)===0) |
392 | | - $text = substr($text, strlen($this->sOmit)); |
393 | | - if(is_numeric($time)) { |
394 | | - if($this->bTimestamp) $query = 't=' . $time; |
395 | | - if($time > $this->vMarkNew) $props = " class='forum_new'"; |
396 | | - } |
397 | | - $output .= $sk->makeKnownLinkObj($title, $text, $query, '', '', $props); |
398 | | - $text = ''; |
| 389 | + $text = $query = $props = ''; |
| 390 | + if($this->bShowNamespace == true) $text = $title->getEscapedText(); |
| 391 | + else $text = htmlspecialchars($title->getText()); |
| 392 | + if(($this->sOmit) && strpos($text, $this->sOmit)===0) |
| 393 | + $text = substr($text, strlen($this->sOmit)); |
| 394 | + if(is_numeric($time)) { |
| 395 | + if($this->bTimestamp) $query = 't=' . $time; |
| 396 | + if($time > $this->vMarkNew) $props = " class='forum_new'"; |
| 397 | + } |
| 398 | + $output .= $sk->makeKnownLinkObj($title, $text, $query, '', '', $props); |
| 399 | + $text = ''; |
399 | 400 | |
400 | | - if($this->bAddAuthor) { |
401 | | - $author = Title::newFromText( $author, NS_USER ); |
402 | | - if($author) $author = $sk->makeKnownLinkObj($author,$author->getText()); |
403 | | - if($tm) { |
404 | | - if($this->bCompactAuthor) { |
405 | | - if($author) |
406 | | - $output .= " <span class='forum_author'>$by {$author}</span>"; |
407 | | - else $output .= " <span class='forum_author'>&nb"."sp;</span>"; |
408 | | - } |
409 | | - else $output .= "</td><td class='forum_author'>$author"; |
410 | | - } |
411 | | - else if($author) $output .= " $by $author"; |
412 | | - } |
| 401 | + if($this->bAddAuthor) { |
| 402 | + $author = Title::newFromText( $author, NS_USER ); |
| 403 | + if($author) $author = $sk->makeKnownLinkObj($author,$author->getText()); |
| 404 | + if($tm) { |
| 405 | + if($this->bCompactAuthor) { |
| 406 | + if($author) |
| 407 | + $output .= " <span class='forum_author'>$by {$author}</span>"; |
| 408 | + else $output .= " <span class='forum_author'>&nb"."sp;</span>"; |
| 409 | + } |
| 410 | + else $output .= "</td><td class='forum_author'>$author"; |
| 411 | + } |
| 412 | + else if($author) $output .= " $by $author"; |
| 413 | + } |
413 | 414 | |
414 | | - if($this->bAddLastEdit) { |
415 | | - if(is_numeric($time)) $time = $wgLang->timeanddate($time, true); |
416 | | - if($page && $this->bLinkHistory) { |
417 | | - if($this->bEmbedHistory) |
418 | | - $time = $sk->makeKnownLinkObj($page, $time, 'action=history'); |
419 | | - else |
420 | | - $time .= ' (' . $sk->makeKnownLinkObj($page, |
421 | | - wfMsg('hist'), 'action=history') . ')'; |
422 | | - } |
423 | | - if($tm) $output .= "</td><td class='forum_edited'>$time"; |
424 | | - else $text .= "$time "; |
425 | | - } |
| 415 | + if($this->bAddLastEdit) { |
| 416 | + if(is_numeric($time)) $time = $wgLang->timeanddate($time, true); |
| 417 | + if($page && $this->bLinkHistory) { |
| 418 | + if($this->bEmbedHistory) |
| 419 | + $time = $sk->makeKnownLinkObj($page, $time, 'action=history'); |
| 420 | + else |
| 421 | + $time .= ' (' . $sk->makeKnownLinkObj($page, |
| 422 | + wfMsg('hist'), 'action=history') . ')'; |
| 423 | + } |
| 424 | + if($tm) $output .= "</td><td class='forum_edited'>$time"; |
| 425 | + else $text .= "$time "; |
| 426 | + } |
426 | 427 | |
427 | | - if($this->bAddLastEditor) { |
428 | | - $user = Title::newFromText( $user, NS_USER ); |
429 | | - if($user) $user = $sk->makeKnownLinkObj($user, $user->getText()); |
430 | | - if($tm) { |
431 | | - if($this->bCompactEdit) { |
432 | | - if($user) |
433 | | - $output .= " <span class='forum_editor'>$by {$user}</span>"; |
434 | | - else $output .= " <span class='forum_editor'>&nb"."sp;</span>"; |
435 | | - } |
436 | | - else $output .= "</td><td class='forum_editor'>$user"; |
437 | | - } |
438 | | - else if($user) $text .= "$by $user"; |
439 | | - } |
440 | | - if($tm) $output .= "</td>"; |
441 | | - else if($text) $output .= $this->msg('forum_edited') . " $text"; |
442 | | - return $output; |
443 | | - } |
444 | | -} |
\ No newline at end of file |
| 428 | + if($this->bAddLastEditor) { |
| 429 | + $user = Title::newFromText( $user, NS_USER ); |
| 430 | + if($user) $user = $sk->makeKnownLinkObj($user, $user->getText()); |
| 431 | + if($tm) { |
| 432 | + if($this->bCompactEdit) { |
| 433 | + if($user) |
| 434 | + $output .= " <span class='forum_editor'>$by {$user}</span>"; |
| 435 | + else $output .= " <span class='forum_editor'>&nb"."sp;</span>"; |
| 436 | + } |
| 437 | + else $output .= "</td><td class='forum_editor'>$user"; |
| 438 | + } |
| 439 | + else if($user) $text .= "$by $user"; |
| 440 | + } |
| 441 | + if($tm) $output .= "</td>"; |
| 442 | + else if($text) $output .= $this->msg('dplforum-edited') . " $text"; |
| 443 | + return $output; |
| 444 | + } |
| 445 | +} |