Index: trunk/extensions/DPLforum/DPLforum_body.php |
— | — | @@ -0,0 +1,413 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + |
| 5 | + DPLforum v3.2 -- DynamicPageList-based forum extension |
| 6 | + |
| 7 | + Author: Ross McClure |
| 8 | + http://www.mediawiki.org/wiki/User:Algorithm |
| 9 | + |
| 10 | + DynamicPageList written by: n:en:User:IlyaHaykinson n:en:User:Amgine |
| 11 | + http://en.wikinews.org/wiki/User:Amgine |
| 12 | + http://en.wikinews.org/wiki/User:IlyaHaykinson |
| 13 | + |
| 14 | + This program is free software; you can redistribute it and/or modify |
| 15 | + it under the terms of the GNU General Public License as published by |
| 16 | + the Free Software Foundation; either version 2 of the License, or |
| 17 | + (at your option) any later version. |
| 18 | + |
| 19 | + This program is distributed in the hope that it will be useful, |
| 20 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | + GNU General Public License for more details. |
| 23 | + |
| 24 | + You should have received a copy of the GNU General Public License along |
| 25 | + with this program; if not, write to the Free Software Foundation, Inc., |
| 26 | + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 | + http://www.gnu.org/copyleft/gpl.html |
| 28 | + |
| 29 | + * @addtogroup Extensions |
| 30 | + */ |
| 31 | + |
| 32 | +if(!defined('MEDIAWIKI')) { |
| 33 | + echo("This file is an extension to the MediaWiki software and is not a valid access point"); |
| 34 | + die(1); |
| 35 | +} |
| 36 | + |
| 37 | +class DPLForum { |
| 38 | + var $minCategories = 1; // Minimum number of categories to look for |
| 39 | + var $maxCategories = 6; // Maximum number of categories to look for |
| 40 | + var $maxResultCount = 50; // Maximum number of results to allow |
| 41 | + var $unlimitedResults = true; // Allow unlimited results |
| 42 | + var $unlimitedCategories = false; // Allow unlimited categories |
| 43 | + var $requireCache = false; // Only clear the cache on purge |
| 44 | + |
| 45 | + // Restricted namespaces cannot be searched for page author or creation time. |
| 46 | + // Unless this array is empty, namespace-free searches are also restricted. |
| 47 | + // Note: Only integers in this array are checked. |
| 48 | + var $restrictNamespace = array(); // No restrictions |
| 49 | + |
| 50 | + var $bTableMode; |
| 51 | + var $bTimestamp; |
| 52 | + var $bLinkHistory; |
| 53 | + var $bEmbedHistory; |
| 54 | + var $bShowNamespace; |
| 55 | + var $bAddAuthor; |
| 56 | + var $bAddCreationDate; |
| 57 | + var $bAddLastEdit; |
| 58 | + var $bAddLastEditor; |
| 59 | + var $bCompactAuthor; |
| 60 | + var $bCompactEdit; |
| 61 | + var $sInput; |
| 62 | + var $sOmit; |
| 63 | + var $vMarkNew; |
| 64 | + |
| 65 | + function cat(&$parser, $name) { |
| 66 | + $cats = array(); |
| 67 | + if(preg_match_all("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
| 68 | + foreach($matches[1] as $cat) { |
| 69 | + $title = Title::newFromText($parser->replaceVariables(trim($cat))); |
| 70 | + if( !is_null( $title ) ) |
| 71 | + $cats[] = $title; |
| 72 | + } |
| 73 | + } |
| 74 | + return $cats; |
| 75 | + } |
| 76 | + |
| 77 | + function get($name, $value=NULL, $parser=NULL) { |
| 78 | + if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$this->sInput,$matches)) { |
| 79 | + $arg = trim($matches[1]); |
| 80 | + if(is_int($value)) return intval($arg); |
| 81 | + else if(is_null($parser)) return htmlspecialchars($arg); |
| 82 | + else return $parser->replaceVariables($arg); |
| 83 | + } |
| 84 | + return $value; |
| 85 | + } |
| 86 | + |
| 87 | + function link(&$parser, $count, $page='', $text='') { |
| 88 | + $count = intval($count); |
| 89 | + if($count<1) return ''; |
| 90 | + |
| 91 | + if($this->requireCache) $offset = 0; |
| 92 | + else { |
| 93 | + global $wgRequest; |
| 94 | + $parser->disableCache(); |
| 95 | + $offset = intval($wgRequest->getVal('offset','')); |
| 96 | + } |
| 97 | + |
| 98 | + $i = intval($page); |
| 99 | + if(($i!=0) && ctype_digit($page[0])) $i -= 1; |
| 100 | + else $i += intval($offset / $count); |
| 101 | + if($this->link_test($i,$page)) return ''; |
| 102 | + |
| 103 | + if($text==='') $text = ($i + 1); |
| 104 | + $page = ($count * $i); |
| 105 | + if($page == $offset) return $text; |
| 106 | + |
| 107 | + return '[{{fullurl:{{FULLPAGENAME}}|offset='.$page.'}} '.$text.']'; |
| 108 | + } |
| 109 | + |
| 110 | + function link_test($page, $cond) { |
| 111 | + if(preg_match("/\\d+(\\D+)(\\d+)/",$cond,$m)) { |
| 112 | + $m[1] = strtr($m[1], array(('&l'.'t;')=>'<', ('&g'.'t;')=>'>')); |
| 113 | + $m[2] = intval($m[2])-1; |
| 114 | + switch($m[1]) { |
| 115 | + case '<': return ($page >= $m[2]); |
| 116 | + case '>': return ($page <= $m[2]); |
| 117 | + case '<=': return ($page > $m[2]); |
| 118 | + case '>=': return ($page < $m[2]); |
| 119 | + } |
| 120 | + } |
| 121 | + return ($page < 0); |
| 122 | + } |
| 123 | + |
| 124 | + function msg($type, $error=NULL) { |
| 125 | + if($error && ($this->get('suppresserrors')=='true')) return ''; |
| 126 | + return htmlspecialchars(wfMsg($type)); |
| 127 | + } |
| 128 | + |
| 129 | + function parse(&$input, &$parser) { |
| 130 | + global $wgContLang; |
| 131 | + |
| 132 | + $this->sInput =& $input; |
| 133 | + $sPrefix = $this->get('prefix','',$parser); |
| 134 | + $this->sOmit = $this->get('omit',$sPrefix,$parser); |
| 135 | + $this->bAddAuthor = ($this->get('addauthor')=='true'); |
| 136 | + $this->bTimestamp = ($this->get('timestamp')!='false'); |
| 137 | + $this->bAddLastEdit = ($this->get('addlastedit')!='false'); |
| 138 | + $this->bAddLastEditor = ($this->get('addlasteditor')=='true'); |
| 139 | + $this->bAddCreationDate = ($this->get('addcreationdate')=='true'); |
| 140 | + |
| 141 | + switch($this->get('historylink')) { |
| 142 | + case 'embed': |
| 143 | + case 'true': $this->bEmbedHistory = true; |
| 144 | + case 'append': |
| 145 | + case 'show': $this->bLinkHistory = true; |
| 146 | + } |
| 147 | + $sOrder = 'rev_timestamp'; |
| 148 | + switch($this->get('ordermethod')) { |
| 149 | + case 'categoryadd': |
| 150 | + case 'created': |
| 151 | + $sOrder = 'first_time'; |
| 152 | + break; |
| 153 | + case 'pageid': |
| 154 | + $sOrder = 'page_id'; |
| 155 | + } |
| 156 | + |
| 157 | + $arg = $this->get('compact'); |
| 158 | + if($arg=='all' || strpos($arg,'edit')===0) |
| 159 | + $this->bCompactEdit = $this->bAddLastEdit; |
| 160 | + $this->bCompactAuthor = ($arg=='author' || $arg=='all'); |
| 161 | + |
| 162 | + $arg = $this->get('namespace','',$parser); |
| 163 | + $iNamespace = $wgContLang->getNsIndex($arg); |
| 164 | + if(!$iNamespace) { |
| 165 | + if(($arg) || ($arg==='0')) $iNamespace = intval($arg); |
| 166 | + else $iNamespace = -1; |
| 167 | + } |
| 168 | + if($iNamespace<0) |
| 169 | + $this->bShowNamespace = ($this->get('shownamespace')!='false'); |
| 170 | + else $this->bShowNamespace = ($this->get('shownamespace')=='true'); |
| 171 | + |
| 172 | + $this->bTableMode = false; |
| 173 | + $sStartItem = $sEndItem = ''; |
| 174 | + $bCountMode = false; |
| 175 | + $arg = $this->get('mode'); |
| 176 | + switch($arg) { |
| 177 | + case 'none': |
| 178 | + $sEndItem = '<br />'; |
| 179 | + break; |
| 180 | + case 'count': |
| 181 | + $bCountMode = true; |
| 182 | + break; |
| 183 | + case 'list': |
| 184 | + case 'ordered': |
| 185 | + case 'unordered': |
| 186 | + $sStartItem = '<li>'; |
| 187 | + $sEndItem = '</li>'; |
| 188 | + break; |
| 189 | + case 'table': |
| 190 | + default: |
| 191 | + $this->bTableMode = true; |
| 192 | + $sStartItem = '<tr>'; |
| 193 | + $sEndItem = '</tr>'; |
| 194 | + } |
| 195 | + $aCategories = $this->cat($parser,'category'); |
| 196 | + $aExcludeCategories = $this->cat($parser,'notcategory'); |
| 197 | + $cats = count($aCategories); |
| 198 | + $nocats = count($aExcludeCategories); |
| 199 | + $total = $cats + $nocats; |
| 200 | + $output = ''; |
| 201 | + |
| 202 | + if($sPrefix==='' && (($cats < 1 && $iNamespace < 0) || |
| 203 | + ($total < $this->minCategories))) return $this->msg('dplforum-toofew',1); |
| 204 | + if(($total > $this->maxCategories) && (!$this->unlimitedCategories)) |
| 205 | + return $this->msg('dplforum-toomany',1); |
| 206 | + |
| 207 | + $count = 1; |
| 208 | + $start = $this->get('start',0); |
| 209 | + $title = Title::newFromText($parser->replaceVariables( |
| 210 | + trim($this->get('title')))); |
| 211 | + if(!($bCountMode || $this->requireCache || $this->get('cache')=='true')) { |
| 212 | + $parser->disableCache(); |
| 213 | + |
| 214 | + if(is_null($title)) { |
| 215 | + global $wgRequest; |
| 216 | + $start += intval($wgRequest->getVal('offset')); |
| 217 | + } |
| 218 | + } |
| 219 | + if($start < 0) $start = 0; |
| 220 | + |
| 221 | + if(is_null($title)) { |
| 222 | + $count = $this->get('count',0); |
| 223 | + if($count > 0) { |
| 224 | + if($count > $this->maxResultCount) |
| 225 | + $count = $this->maxResultCount; |
| 226 | + } |
| 227 | + else if($this->unlimitedResults) |
| 228 | + $count = 0x7FFFFFFF; // maximum integer value |
| 229 | + else |
| 230 | + $count = $this->maxResultCount; |
| 231 | + } |
| 232 | + |
| 233 | + //build the SQL query |
| 234 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 235 | + $sPageTable = $dbr->tableName( 'page' ); |
| 236 | + $sRevTable = $dbr->tableName( 'revision' ); |
| 237 | + $categorylinks = $dbr->tableName( 'categorylinks' ); |
| 238 | + $sSqlSelectFrom = "SELECT page_namespace, page_title," |
| 239 | + . " r.rev_user_text, r.rev_timestamp"; |
| 240 | + $arg = " FROM $sPageTable INNER JOIN $sRevTable" |
| 241 | + . " AS r ON page_latest = r.rev_id"; |
| 242 | + |
| 243 | + if($bCountMode) { |
| 244 | + $sSqlSelectFrom = "SELECT COUNT(*) AS num_rows FROM $sPageTable"; |
| 245 | + } |
| 246 | + else if(($this->bAddAuthor || $this->bAddCreationDate || |
| 247 | + ($sOrder=='first_time')) && ((!$this->restrictNamespace) || |
| 248 | + ($iNamespace>=0 && !in_array($iNamespace,$this->restrictNamespace)))) { |
| 249 | + $sSqlSelectFrom .= ", o.rev_user_text AS first_user, o.rev_timestamp AS" |
| 250 | + . " first_time" . $arg . " INNER JOIN $sRevTable AS o" |
| 251 | + . " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable" |
| 252 | + . " AS q WHERE q.rev_page = page_id )"; |
| 253 | + } else { |
| 254 | + if($sOrder=='first_time') $sOrder = 'page_id'; |
| 255 | + $sSqlSelectFrom .= $arg; |
| 256 | + } |
| 257 | + |
| 258 | + $sSqlWhere = ' WHERE 1=1'; |
| 259 | + if($iNamespace >= 0) |
| 260 | + $sSqlWhere = ' WHERE page_namespace='.$iNamespace; |
| 261 | + |
| 262 | + if($sPrefix!=='') { |
| 263 | + // Escape SQL special characters |
| 264 | + $sPrefix = strtr($sPrefix, array('\\'=>'\\\\\\\\', |
| 265 | + ' '=>'\\_', '_'=>'\\_', '%'=>'\\%', '\''=>'\\\'')); |
| 266 | + $sSqlWhere .= " AND page_title LIKE BINARY '".$sPrefix."%'"; |
| 267 | + } |
| 268 | + |
| 269 | + switch($this->get('redirects')) { |
| 270 | + case 'only': |
| 271 | + $sSqlWhere .= ' AND page_is_redirect = 1'; |
| 272 | + case 'include': |
| 273 | + break; |
| 274 | + case 'exclude': |
| 275 | + default: |
| 276 | + $sSqlWhere .= ' AND page_is_redirect = 0'; |
| 277 | + break; |
| 278 | + } |
| 279 | + |
| 280 | + $n = 1; |
| 281 | + for($i = 0; $i < $cats; $i++) { |
| 282 | + $sSqlSelectFrom .= " INNER JOIN $categorylinks AS" . |
| 283 | + " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" . |
| 284 | + $dbr->addQuotes( $aCategories[$i]->getDbKey() ); |
| 285 | + $n++; |
| 286 | + } |
| 287 | + for($i = 0; $i < $nocats; $i++) { |
| 288 | + $sSqlSelectFrom .= " LEFT OUTER JOIN $categorylinks AS" . |
| 289 | + " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" . |
| 290 | + $dbr->addQuotes( $aExcludeCategories[$i]->getDbKey() ); |
| 291 | + $sSqlWhere .= " AND c{$n}.cl_to IS NULL"; |
| 292 | + $n++; |
| 293 | + } |
| 294 | + |
| 295 | + if(!$bCountMode) { |
| 296 | + $sSqlWhere .= " ORDER BY $sOrder "; |
| 297 | + if($this->get('order')=='ascending') $sSqlWhere .= 'ASC'; |
| 298 | + else $sSqlWhere .= 'DESC'; |
| 299 | + } |
| 300 | + $sSqlWhere .= " LIMIT $start, $count"; |
| 301 | + |
| 302 | + //DEBUG: output SQL query |
| 303 | + //$output .= 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />"; |
| 304 | + |
| 305 | + // process the query |
| 306 | + $res = $dbr->query($sSqlSelectFrom . $sSqlWhere); |
| 307 | + |
| 308 | + $this->vMarkNew = $dbr->timestamp(time() - |
| 309 | + intval($this->get('newdays',7) * 86400)); |
| 310 | + |
| 311 | + if($bCountMode) { |
| 312 | + if($row = $dbr->fetchObject( $res )) $output .= $row->num_rows; |
| 313 | + else $output .= '0'; |
| 314 | + } |
| 315 | + else if(is_null($title)) { |
| 316 | + while($row = $dbr->fetchObject( $res )) { |
| 317 | + $title = Title::makeTitle($row->page_namespace, $row->page_title); |
| 318 | + $output .= $sStartItem; |
| 319 | + $output .= $this->buildOutput($title, $title, $row->rev_timestamp, |
| 320 | + $row->rev_user_text, $row->first_user, $row->first_time); |
| 321 | + $output .= $sEndItem . "\n"; |
| 322 | + } |
| 323 | + } else { |
| 324 | + $output .= $sStartItem; |
| 325 | + if($row = $dbr->fetchObject( $res )) { |
| 326 | + $output .= $this->buildOutput(Title::makeTitle($row->page_namespace, |
| 327 | + $row->page_title), $title, $row->rev_timestamp, $row->rev_user_text); |
| 328 | + } else { |
| 329 | + $output .= $this->buildOutput(NULL, $title, $this->msg('dplforum-never')); |
| 330 | + } |
| 331 | + $output .= $sEndItem . "\n"; |
| 332 | + } |
| 333 | + return $output; |
| 334 | + } |
| 335 | + |
| 336 | + // Generates a single line of output. |
| 337 | + function buildOutput($page, $title, $time, $user='', $author='', $made='') { |
| 338 | + global $wgLang, $wgUser; |
| 339 | + $sk =& $wgUser->getSkin(); |
| 340 | + $tm =& $this->bTableMode; |
| 341 | + $by = $this->msg('dplforum-by'); |
| 342 | + $output = ''; |
| 343 | + |
| 344 | + if($this->bAddCreationDate) { |
| 345 | + if(is_numeric($made)) $made = $wgLang->date($made, true); |
| 346 | + if($page && $this->bLinkHistory && !$this->bAddLastEdit) { |
| 347 | + if($this->bEmbedHistory) |
| 348 | + $made = $sk->makeKnownLinkObj($page, $made, 'action=history'); |
| 349 | + else |
| 350 | + $made .= ' (' . $sk->makeKnownLinkObj($page, |
| 351 | + wfMsg('hist'), 'action=history') . ')'; |
| 352 | + } |
| 353 | + if($tm) $output .= "<td class='forum_created'>$made</td>"; |
| 354 | + else if($made) $output = "{$made}: "; |
| 355 | + } |
| 356 | + if($tm) $output .= "<td class='forum_title'>"; |
| 357 | + |
| 358 | + $text = $query = $props = ''; |
| 359 | + if($this->bShowNamespace == true) $text = $title->getEscapedText(); |
| 360 | + else $text = htmlspecialchars($title->getText()); |
| 361 | + if(($this->sOmit) && strpos($text, $this->sOmit)===0) |
| 362 | + $text = substr($text, strlen($this->sOmit)); |
| 363 | + if(is_numeric($time)) { |
| 364 | + if($this->bTimestamp) $query = 't=' . $time; |
| 365 | + if($time > $this->vMarkNew) $props = " class='forum_new'"; |
| 366 | + } |
| 367 | + $output .= $sk->makeKnownLinkObj($title, $text, $query, '', '', $props); |
| 368 | + $text = ''; |
| 369 | + |
| 370 | + if($this->bAddAuthor) { |
| 371 | + $author = Title::newFromText( $author, NS_USER ); |
| 372 | + if($author) $author = $sk->makeKnownLinkObj($author,$author->getText()); |
| 373 | + if($tm) { |
| 374 | + if($this->bCompactAuthor) { |
| 375 | + if($author) |
| 376 | + $output .= " <span class='forum_author'>$by {$author}</span>"; |
| 377 | + else $output .= " <span class='forum_author'>&nb"."sp;</span>"; |
| 378 | + } |
| 379 | + else $output .= "</td><td class='forum_author'>$author"; |
| 380 | + } |
| 381 | + else if($author) $output .= " $by $author"; |
| 382 | + } |
| 383 | + |
| 384 | + if($this->bAddLastEdit) { |
| 385 | + if(is_numeric($time)) $time = $wgLang->timeanddate($time, true); |
| 386 | + if($page && $this->bLinkHistory) { |
| 387 | + if($this->bEmbedHistory) |
| 388 | + $time = $sk->makeKnownLinkObj($page, $time, 'action=history'); |
| 389 | + else |
| 390 | + $time .= ' (' . $sk->makeKnownLinkObj($page, |
| 391 | + wfMsg('hist'), 'action=history') . ')'; |
| 392 | + } |
| 393 | + if($tm) $output .= "</td><td class='forum_edited'>$time"; |
| 394 | + else $text .= "$time "; |
| 395 | + } |
| 396 | + |
| 397 | + if($this->bAddLastEditor) { |
| 398 | + $user = Title::newFromText( $user, NS_USER ); |
| 399 | + if($user) $user = $sk->makeKnownLinkObj($user, $user->getText()); |
| 400 | + if($tm) { |
| 401 | + if($this->bCompactEdit) { |
| 402 | + if($user) |
| 403 | + $output .= " <span class='forum_editor'>$by {$user}</span>"; |
| 404 | + else $output .= " <span class='forum_editor'>&nb"."sp;</span>"; |
| 405 | + } |
| 406 | + else $output .= "</td><td class='forum_editor'>$user"; |
| 407 | + } |
| 408 | + else if($user) $text .= "$by $user"; |
| 409 | + } |
| 410 | + if($tm) $output .= "</td>"; |
| 411 | + else if($text) $output .= $this->msg('dplforum-edited') . " $text"; |
| 412 | + return $output; |
| 413 | + } |
| 414 | +} |
Property changes on: trunk/extensions/DPLforum/DPLforum_body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 415 | + native |
Index: trunk/extensions/DPLforum/DPLforum.php |
— | — | @@ -30,6 +30,11 @@ |
31 | 31 | |
32 | 32 | */ |
33 | 33 | |
| 34 | +if(!defined('MEDIAWIKI')) { |
| 35 | + echo("This file is an extension to the MediaWiki software and is not a valid access point"); |
| 36 | + die(1); |
| 37 | +} |
| 38 | + |
34 | 39 | $wgExtensionFunctions[] = 'wfDPLforum'; |
35 | 40 | $wgHooks['LanguageGetMagic'][] = 'wfDPLmagic'; |
36 | 41 | $wgExtensionCredits['parserhook'][] = array( |
— | — | @@ -43,6 +48,7 @@ |
44 | 49 | |
45 | 50 | $dir = dirname(__FILE__) . '/'; |
46 | 51 | $wgExtensionMessagesFiles['DPLforum'] = $dir . 'DPLforum.i18n.php'; |
| 52 | +$wgAutoloadClasses['DPLForum'] = $dir . 'DPLforum_body.php'; |
47 | 53 | |
48 | 54 | function wfDPLforum() { |
49 | 55 | global $wgParser; |
— | — | @@ -63,382 +69,3 @@ |
64 | 70 | $f = new DPLForum(); |
65 | 71 | return $f->parse($input, $parser); |
66 | 72 | } |
67 | | - |
68 | | -class DPLForum { |
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 |
75 | | - |
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 |
80 | | - |
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; |
95 | | - |
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 | | - } |
107 | | - |
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 | | - } |
117 | | - |
118 | | - function link(&$parser, $count, $page='', $text='') { |
119 | | - $count = intval($count); |
120 | | - if($count<1) return ''; |
121 | | - |
122 | | - if($this->requireCache) $offset = 0; |
123 | | - else { |
124 | | - global $wgRequest; |
125 | | - $parser->disableCache(); |
126 | | - $offset = intval($wgRequest->getVal('offset','')); |
127 | | - } |
128 | | - |
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 ''; |
133 | | - |
134 | | - if($text==='') $text = ($i + 1); |
135 | | - $page = ($count * $i); |
136 | | - if($page == $offset) return $text; |
137 | | - |
138 | | - return '[{{fullurl:{{FULLPAGENAME}}|offset='.$page.'}} '.$text.']'; |
139 | | - } |
140 | | - |
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 | | - } |
154 | | - |
155 | | - function msg($type, $error=NULL) { |
156 | | - if($error && ($this->get('suppresserrors')=='true')) return ''; |
157 | | - return htmlspecialchars(wfMsg($type)); |
158 | | - } |
159 | | - |
160 | | - function parse(&$input, &$parser) { |
161 | | - global $wgContLang; |
162 | | - |
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'); |
171 | | - |
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 | | - } |
187 | | - |
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'); |
192 | | - |
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'); |
202 | | - |
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 = ''; |
232 | | - |
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); |
237 | | - |
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(); |
244 | | - |
245 | | - if(is_null($title)) { |
246 | | - global $wgRequest; |
247 | | - $start += intval($wgRequest->getVal('offset')); |
248 | | - } |
249 | | - } |
250 | | - if($start < 0) $start = 0; |
251 | | - |
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 | | - } |
263 | | - |
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"; |
273 | | - |
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 | | - } |
288 | | - |
289 | | - $sSqlWhere = ' WHERE 1=1'; |
290 | | - if($iNamespace >= 0) |
291 | | - $sSqlWhere = ' WHERE page_namespace='.$iNamespace; |
292 | | - |
293 | | - if($sPrefix!=='') { |
294 | | - // Escape SQL special characters |
295 | | - $sPrefix = strtr($sPrefix, array('\\'=>'\\\\\\\\', |
296 | | - ' '=>'\\_', '_'=>'\\_', '%'=>'\\%', '\''=>'\\\'')); |
297 | | - $sSqlWhere .= " AND page_title LIKE BINARY '".$sPrefix."%'"; |
298 | | - } |
299 | | - |
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 | | - } |
310 | | - |
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 | | - } |
325 | | - |
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"; |
332 | | - |
333 | | - //DEBUG: output SQL query |
334 | | - //$output .= 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />"; |
335 | | - |
336 | | - // process the query |
337 | | - $res = $dbr->query($sSqlSelectFrom . $sSqlWhere); |
338 | | - |
339 | | - $this->vMarkNew = $dbr->timestamp(time() - |
340 | | - intval($this->get('newdays',7) * 86400)); |
341 | | - |
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 | | - } |
366 | | - |
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 = ''; |
374 | | - |
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'>"; |
388 | | - |
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 = ''; |
400 | | - |
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 | | - } |
414 | | - |
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 | | - } |
427 | | - |
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 | | -} |