-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSpecialWikilog.php
645 lines (573 loc) · 20.3 KB
/
SpecialWikilog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<?php
/**
* MediaWiki Wikilog extension
* Copyright © 2008-2010 Juliano F. Ravasi
* http://www.mediawiki.org/wiki/Extension:Wikilog
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
/**
* @file
* @ingroup Extensions
* @author Juliano F. Ravasi < dev juliano info >
*/
if ( !defined( 'MEDIAWIKI' ) )
die();
/**
* Special:Wikilog special page.
* The primary function of this special page is to list all wikilog articles
* (from all wikilogs) in reverse chronological order. The special page
* provides many different ways to query articles by wikilog, date, tags, etc.
* The special page also provides syndication feeds and can be included from
* wiki articles.
*/
class SpecialWikilog
extends IncludableSpecialPage
{
/** Alternate views. */
protected static $views = array( 'summary', 'archives' );
/** Statuses. */
protected static $statuses = array( 'all', 'published', 'drafts' );
/**
* Constructor.
*/
function __construct( ) {
parent::__construct( 'Wikilog' );
}
protected function getGroupName() {
return 'changes';
}
/**
* Execute the special page.
* Called from MediaWiki.
*/
public function execute( $parameters ) {
global $wgRequest;
$feedFormat = $wgRequest->getVal( 'feed' );
if ( $feedFormat && !$this->including() ) {
$opts = $this->feedSetup();
return $this->feedOutput( $feedFormat, $opts );
} else {
$opts = $this->webSetup( $parameters );
return $this->webOutput( $opts );
}
}
/**
* Returns default options.
*/
public function getDefaultOptions() {
global $wgWikilogNumArticles;
global $wgWikilogDefaultNotCategory;
$opts = new FormOptions();
$opts->add( 'view', 'summary' );
$opts->add( 'show', 'published' );
$opts->add( 'wikilog', '' );
$opts->add( 'category', '' );
$opts->add( 'notcategory', '' );
$opts->add( 'author', '' );
$opts->add( 'tag', '' );
$opts->add( 'year', '', FormOptions::INTNULL );
$opts->add( 'month', '', FormOptions::INTNULL );
$opts->add( 'day', '', FormOptions::INTNULL );
$opts->add( 'sort', '' );
$opts->add( 'limit', $wgWikilogNumArticles );
$opts->add( 'template', '' );
return $opts;
}
/**
* Prepare special page parameters for a web request.
*/
public function webSetup( $parameters ) {
global $wgRequest, $wgWikilogExpensiveLimit;
global $wgWikilogDefaultNotCategory;
$opts = $this->getDefaultOptions();
$opts->fetchValuesFromRequest( $wgRequest );
# Default "not in category"
if ( is_null( $wgRequest->getVal('notcategory') ) )
$opts['notcategory'] = $wgWikilogDefaultNotCategory;
# Collect inline parameters, they have precedence over query params.
$this->parseInlineParams( $parameters, $opts );
$opts->validateIntBounds( 'limit', 0, $wgWikilogExpensiveLimit );
return $opts;
}
/**
* Prepare special page parameters for a feed request.
* Since feeds must be cached for performance purposes, it is not allowed
* to make arbitrary queries. Only published status and limit parameters
* are recognized. Other parameters are ignored.
*/
public function feedSetup() {
global $wgRequest, $wgFeedLimit;
global $wgWikilogDefaultNotCategory;
$opts = $this->getDefaultOptions();
$opts->fetchValuesFromRequest( $wgRequest );
# Default "not in category"
if ( is_null( $wgRequest->getVal('notcategory') ) )
$opts['notcategory'] = $wgWikilogDefaultNotCategory;
$opts->validateIntBounds( 'limit', 0, $wgFeedLimit );
return $opts;
}
/**
* Format the HTML output of the special page.
* @param $opts Form options, such as wikilog name, category, date, etc.
*/
public function webOutput( FormOptions $opts ) {
global $wgRequest, $wgOut, $wgMimeType, $wgTitle, $wgParser, $wgUser;
# Set page title, html title, nofollow, noindex, etc...
$this->setHeaders();
$this->outputHeader();
# Build query object.
$this->query = $query = self::getQuery( $opts );
# Prepare the parser.
# This must be called here if not including, before the pager
# object is created. WikilogTemplatePager fails otherwise.
if ( !$this->including() ) {
$popts = $wgOut->parserOptions();
$wgParser->startExternalParse( $wgTitle, $popts, Parser::OT_HTML );
}
# Create the pager object that will create the list of articles.
if ( $opts['view'] == 'archives' )
{
if ( !$this->including() && preg_match( '/^\d{14,}$/s', $markallread_time = $wgRequest->getVal( 'markallread' ) ) )
{
$this->markAllRead( $query, $markallread_time );
$vals = $wgRequest->getValues();
unset( $vals['markallread'] );
$wgOut->redirect( $wgTitle->getFullUrl( $vals ) );
return;
}
$pager = new WikilogArchivesPager( $query, $this->including(), $opts['limit'] );
$pager->noActions = true;
}
elseif ( $opts['template'] ) {
$templ = Title::makeTitle( NS_TEMPLATE, $opts['template'] );
$pager = new WikilogTemplatePager( $query, $templ, $opts['limit'], $this->including() );
} else {
$pager = new WikilogSummaryPager( $query, $opts['limit'], $this->including() );
}
$pager->setSort( $opts['sort'] );
global $wlCalPager;
$wlCalPager = $pager;
# Handle special page inclusion.
if ( $this->including() ) {
# Get pager body.
$body = $pager->getBody();
}
else {
# If a wikilog is selected, set the title.
$title = $query->getWikilogTitle();
if ( !is_null( $title ) ) {
# Retrieve wikilog front page
$article = new Article( $title );
$content = $article->getContent();
$wgOut->setPageTitle( $title->getPrefixedText() );
$wgOut->addWikiTextTitle( $content, $title, true );
}
# Display query options.
$body = $this->getHeader( $opts );
if ( $opts['view'] == 'archives' && $wgUser->getId() ) {
# Display "Mark all read" link
$body .= $this->getMarkAllReadLink();
}
# Get pager body.
$body .= $pager->getBody();
# Add navigation bars.
$body .= $pager->getNavigationBar();
# Wikilog Subscribtions
$body .= '<p>' . SpecialWikilogSubscriptions::subcriptionsRuleLink() . '</p>';
# Wrap only when not including
$body = Xml::wrapClass( $body, 'wl-wrapper', 'div' );
}
# Output.
$wgOut->addHTML( $body );
# Get query parameter array, for the following links.
$qarr = $query->getDefaultQuery();
# Add feed links.
$wgOut->setSyndicated();
$altquery = wfArrayToCGI( array_intersect_key( $qarr, WikilogItemFeed::$paramWhitelist ) );
if ( $altquery ) {
$wgOut->setFeedAppendQuery( $altquery );
}
# Add links for alternate views.
foreach ( self::$views as $alt ) {
if ( $alt != $opts['view'] ) {
$altquery = wfArrayToCGI( array( 'view' => $alt ), $qarr );
$wgOut->addLink( array(
'rel' => 'alternate',
'href' => $wgTitle->getLocalURL( $altquery ),
'type' => $wgMimeType,
'title' => wfMessage( "wikilog-view-{$alt}" )->inContentLanguage()->text(),
) );
}
}
}
/**
* Mark all items with last update time before $time='YYYYMMDDHHMMSS' as read.
*/
public function markAllRead( $query, $time )
{
global $wgUser;
$dbw = wfGetDB( DB_MASTER );
$p = $dbw->tablePrefix();
$sql = $query->selectSQLText( $dbw, array(), "wlp_page", array("wlp_pubdate <= $time"), __METHOD__ );
$userid = $wgUser->getId();
$dbw->query("DELETE FROM {$p}page_last_visit WHERE (pv_user, pv_page) IN (SELECT $userid, wlp_page FROM ($sql) t1)", __METHOD__);
$dbw->query("DELETE FROM {$p}page_last_visit WHERE (pv_user, pv_page) IN (SELECT $userid, t2.wlc_comment_page FROM ($sql) t1 JOIN wikilog_comments t2 ON t2.wlc_post=t1.wlp_page AND t2.wlc_updated <= $time)", __METHOD__);
$dbw->query("INSERT INTO {$p}page_last_visit (pv_user, pv_page, pv_date) SELECT $userid, wlp_page, $time FROM ($sql) t1", __METHOD__);
$dbw->query("INSERT INTO {$p}page_last_visit (pv_user, pv_page, pv_date) SELECT $userid, t2.wlc_comment_page, $time FROM ($sql) t1 JOIN wikilog_comments t2 ON t2.wlc_post=t1.wlp_page AND t2.wlc_updated <= $time", __METHOD__);
}
/**
* Output a Mark all read link.
*/
public function getMarkAllReadLink()
{
global $wgRequest, $wgTitle;
$query = $wgRequest->getValues();
$query['markallread'] = wfTimestamp( TS_MW );
return Xml::wrapClass(
Xml::element( 'a', array( 'href' => $wgTitle->getFullUrl( $query ) ), wfMessage( 'wikilog-mark-all-read' )->text() ),
'markallread', 'p'
);
}
/**
* Format the syndication feed output of the special page.
* @param $format Feed format ('atom' or 'rss').
* @param $opts Form options, such as wikilog name, category, date, etc.
*/
public function feedOutput( $format, FormOptions $opts ) {
global $wgTitle;
$feed = new WikilogItemFeed( $wgTitle, $format, self::getQuery( $opts ),
$opts['limit'] );
return $feed->execute();
}
/**
* Returns the name used as page title in the special page itself,
* and also the name that will be listed in Special:Specialpages.
*/
public function getDescription() {
return wfMessage( 'wikilog-specialwikilog-title' )->text();
}
/**
* Parse inline parameters passed after the special page name.
* Example: Special:Wikilog/Category:catname/tag=tagname/5
* @param $parameters Inline parameters after the special page name.
* @param $opts Form options.
*/
public function parseInlineParams( $parameters, FormOptions $opts ) {
global $wgWikilogNamespaces;
if ( empty( $parameters ) ) return;
/* ';' supported for backwards compatibility */
foreach ( preg_split( '|[/;]|', $parameters ) as $par ) {
if ( is_numeric( $par ) ) {
$opts['limit'] = intval( $par );
} elseif ( in_array( $par, self::$statuses ) ) {
$opts['show'] = $par;
} elseif ( in_array( $par, self::$views ) ) {
$opts['view'] = $par;
} elseif ( preg_match( '/^sort=(.+)$/', $par, $m ) ) {
$opts['sort'] = $m[1];
} elseif ( preg_match( '/^t(?:ag)?=(.+)$/', $par, $m ) ) {
$opts['tag'] = $m[1];
} elseif ( preg_match( '/^y(?:ear)?=(.+)$/', $par, $m ) ) {
$opts['year'] = intval( $m[1] );
} elseif ( preg_match( '/^m(?:onth)?=(.+)$/', $par, $m ) ) {
$opts['month'] = intval( $m[1] );
} elseif ( preg_match( '/^d(?:ay)?=(.+)$/', $par, $m ) ) {
$opts['day'] = intval( $m[1] );
} elseif ( preg_match( '/^date=(.+)$/', $par, $m ) ) {
if ( ( $date = self::parseDateParam( $m[1] ) ) ) {
list( $opts['year'], $opts['month'], $opts['day'] ) = $date;
}
} elseif ( preg_match( '/^notcategory=(.*)$/', $par, $m ) ) {
$opts['notcategory'] = $m[1];
} else {
if ( ( $t = Title::newFromText( $par ) ) !== null ) {
$ns = $t->getNamespace();
if ( in_array( $ns, $wgWikilogNamespaces ) ) {
$opts['wikilog'] = $t->getPrefixedDBkey();
} elseif ( $ns == NS_CATEGORY ) {
$opts['category'] = $t->getDBkey();
} elseif ( $ns == NS_USER ) {
$opts['author'] = $t->getDBkey();
} elseif ( $ns == NS_TEMPLATE ) {
$opts['template'] = $t->getDBkey();
}
}
}
}
}
/**
* Formats and returns the page header.
* @param $opts Form options.
* @return HTML of the page header.
*/
protected function getHeader( FormOptions $opts ) {
global $wgScript;
$out = Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
$out .= $this->getQueryForm( $opts );
$unconsumed = $opts->getUnconsumedValues();
foreach ( $unconsumed as $key => $value ) {
$out .= Html::hidden( $key, $value );
}
$out = Xml::tags( 'form', array( 'action' => $wgScript ), $out );
$out = Xml::fieldset( wfMessage( 'wikilog-form-legend' )->text(), $out,
array( 'class' => 'wl-options' )
);
$out .= WikilogMainPage::formNewItem( NULL );
return $out;
}
/**
* Formats and returns a query form.
* @param $opts Form options.
* @return HTML of the query form.
*/
protected function getQueryForm( FormOptions $opts ) {
global $wgContLang;
$align = $wgContLang->isRtl() ? 'left' : 'right';
$fields = $this->getQueryFormFields( $opts );
$columns = array_chunk( $fields, ( count( $fields ) + 1 ) / 2, true );
$out = Xml::openElement( 'table', array( 'width' => '100%' ) ) .
Xml::openElement( 'tr' );
foreach ( $columns as $fields ) {
$out .= Xml::openElement( 'td' );
$out .= Xml::openElement( 'table' );
foreach ( $fields as $row ) {
if ( !$row )
continue;
$out .= Xml::openElement( 'tr' );
if ( is_array( $row ) ) {
$out .= Xml::tags( 'td', array( 'align' => $align ), $row[0] );
$out .= Xml::tags( 'td', null, $row[1] );
} else {
$out .= Xml::tags( 'td', array( 'colspan' => 2 ), $row );
}
$out .= Xml::closeElement( 'tr' );
}
$out .= Xml::closeElement( 'table' );
$out .= Xml::closeElement( 'td' );
}
$out .= Xml::closeElement( 'tr' ) . Xml::closeElement( 'table' );
return $out;
}
/* Get possible options for combo-boxes */
protected function getSelectOptions()
{
$dbr = wfGetDB( DB_SLAVE );
$select_options = array();
/* Wikilogs */
$query = clone $this->query;
$query->setWikilogTitle(NULL);
$res = $query->select( $dbr,
array(), 'p.page_namespace, p.page_title',
array(), __FUNCTION__,
array('GROUP BY' => 'wlp_parent', 'ORDER BY' => 'w.page_title')
);
$values = array();
while( $row = $dbr->fetchRow( $res ) )
{
$parts = explode( '/', $row['page_title'] );
$row = Title::makeTitleSafe( $row['page_namespace'], $parts[0] );
if ($row)
$values[] = array( $row->getText(), $row->getPrefixedText() );
}
$dbr->freeResult( $res );
$select_options['wikilog'] = $values;
/* Authors */
$query = clone $this->query;
$query->setAuthor(NULL);
$res = $query->select( $dbr, array(), 'DISTINCT wlp_authors', array(), __FUNCTION__ );
$rows = array();
while( $row = $dbr->fetchRow( $res ) )
$rows += unserialize( $row['wlp_authors'] );
$dbr->freeResult( $res );
ksort( $rows );
$select_options['author'] = array();
foreach( $rows as $k => $v )
$select_options['author'][] = array($k);
// Categories
// Make two queries instead of one with OR
// Otherwise it leads to fullscan of 'categorylinks'
$query = clone $this->query;
$query->setCategory( NULL );
$res = $query->select(
$dbr, array( 'wlpostcat' => 'categorylinks' ),
'wlpostcat.cl_to', array(), __FUNCTION__, array(),
array( 'wlpostcat' =>
array( 'INNER JOIN', array( 'wlpostcat.cl_from=wlp_page' ) )
)
);
$rows = array();
foreach ( $res as $row )
{
$row = Title::makeTitleSafe( NS_CATEGORY, $row->cl_to )->getText();
$rows[ $row ] = array( $row );
}
$res = $query->select(
$dbr, array( 'wlpostcat' => 'categorylinks' ),
'wlpostcat.cl_to', array(), __FUNCTION__, array(),
array( 'wlpostcat' =>
array( 'INNER JOIN', array( 'wlpostcat.cl_from=wlp_parent' ) )
)
);
foreach ( $res as $row )
{
$row = Title::makeTitleSafe( NS_CATEGORY, $row->cl_to )->getText();
$rows[ $row ] = array( $row );
}
$select_options['category'] = array_values( $rows );
return $select_options;
}
/* Get possible Author options for combo-box */
protected function getAuthorOptions() {
$dbr = wfGetDB( DB_SLAVE );
}
/**
* Returns query form fields.
* @param $opts Form options.
* @return Array of form fields.
*/
protected function getQueryFormFields( FormOptions $opts ) {
global $wgWikilogEnableTags;
global $wgWikilogDefaultNotCategory;
global $wgWikilogSearchDropdowns;
global $wgLang, $wgUser;
$fields = array();
$formvalues = array();
$formfields = array('wikilog' => true, 'category' => true);
if ( $wgUser && $wgUser->getID() )
$formfields['notcategory'] = false;
$formfields['author'] = true;
if ( $wgWikilogEnableTags )
$formfields['tag'] = false;
if ( $wgWikilogSearchDropdowns )
$select_options = $this->getSelectOptions();
foreach ( $formfields as $valueid => $dropdown )
{
$formvalues[$valueid] = str_replace( '_', ' ', $opts->consumeValue( $valueid ) );
if ($wgWikilogSearchDropdowns && $dropdown)
{
/* If drop-down lists are enabled site-wide and permitted for this field */
$values = $select_options[$valueid];
if ( count( $values ) > 0 )
{
$select = new XmlSelect( $valueid, 'wl-'.$valueid, $formvalues[$valueid] );
$select->addOption( wfMessage( 'wikilog-form-all' )->text(), '' );
foreach( $values as $o )
$select->addOption( $o[0], count($o) > 1 ? $o[1] : false );
$fields[$valueid] = array(
Xml::label( wfMessage( 'wikilog-form-'.$valueid )->text(), 'wl-'.$valueid ),
$select->getHTML()
);
}
else
$fields[$valueid] = array();
}
else
{
$fields[$valueid] = Xml::inputLabelSep(
wfMessage( 'wikilog-form-'.$valueid )->text(), $valueid, 'wl-'.$valueid, 40,
$formvalues[$valueid]
);
}
}
$month_select = new XmlSelect( 'month', 'wl-month', $opts->consumeValue( 'month' ) );
$month_select->setAttribute( 'onchange', "{var wly=document.getElementById('wl-year');if(wly&&!wly.value){wly.value='".date('Y')."';}}" );
$month_select->addOption( wfMessage( 'monthsall' )->text(), '' );
for ($i = 1; $i <= 12; $i++)
$month_select->addOption( $wgLang->getMonthName( $i ), $i );
$year_field = Xml::input( 'year', 4, $opts->consumeValue( 'year' ), array( 'maxlength' => 4, 'id' => 'wl-year' ) );
$fields['date'] = array(
Xml::label( wfMessage( 'wikilog-form-date' )->text(), 'wl-month' ),
$month_select->getHTML() . " " . $year_field
);
$opts->consumeValue( 'day' ); // ignore day, not really useful
$viewSelect = new XmlSelect( 'view', 'wl-view', $opts->consumeValue( 'view' ) );
$viewSelect->addOption( wfMessage( 'wikilog-view-summary' )->text(), 'summary' );
$viewSelect->addOption( wfMessage( 'wikilog-view-archives' )->text(), 'archives' );
$fields['view'] = array(
Xml::label( wfMessage( 'wikilog-form-view' )->text(), 'wl-view' ),
$viewSelect->getHTML()
);
if( $wgUser && $wgUser->getID() )
{
$statusSelect = new XmlSelect( 'show', 'wl-status', $opts->consumeValue( 'show' ) );
$statusSelect->addOption( wfMessage( 'wikilog-show-all' )->text(), 'all' );
$statusSelect->addOption( wfMessage( 'wikilog-show-published' )->text(), 'published' );
$statusSelect->addOption( wfMessage( 'wikilog-show-drafts' )->text(), 'drafts' );
$fields['status'] = array(
Xml::label( wfMessage( 'wikilog-form-status' )->text(), 'wl-status' ),
$statusSelect->getHTML()
);
}
$fields['submit'] = Xml::submitbutton( wfMessage( 'allpagessubmit' )->text() );
return $fields;
}
/**
* Returns a Wikilog query object given the form options.
* @param $opts Form options.
* @return Wikilog query object.
*/
public static function getQuery( $opts ) {
global $wgWikilogNamespaces;
$query = new WikilogItemQuery();
$query->setPubStatus( $opts['show'] );
if ( $opts['wikilog'] ) {
$t = Title::newFromText( $opts['wikilog'] );
if ( $t && in_array( $t->getNamespace(), $wgWikilogNamespaces ) ) {
if ( $t->getText() == '*' ) {
$query->setNamespace( $t->getNamespace() );
} else {
$query->setWikilogTitle( $t );
}
} else {
$query->setEmpty();
}
}
if ( ( $t = $opts['category'] ) ) {
$query->setCategory( $t );
}
if ( ( $t = $opts['notcategory'] ) ) {
$query->setNotCategory( $t );
}
if ( ( $t = $opts['author'] ) ) {
$query->setAuthor( $t );
}
if ( ( $t = $opts['tag'] ) ) {
$query->setTag( $t );
}
$query->setDate( $opts['year'], $opts['month'], $opts['day'] );
return $query;
}
/**
* Parse inline date parameter.
* @param $date Text representation of date "YYYY-MM-DD".
* @return Array(3) if date parsed successfully, where each element
* represents a component of the date, being the last two optional.
* False in case of error.
*/
public static function parseDateParam( $date ) {
$m = array();
if ( preg_match( '|^(\d+)(?:[/-](\d+)(?:[/-](\d+))?)?$|', $date, $m ) ) {
return array(
intval( $m[1] ),
( isset( $m[2] ) ? intval( $m[2] ) : null ),
( isset( $m[3] ) ? intval( $m[3] ) : null )
);
} else {
return false;
}
}
}