~ubuntu-branches/ubuntu/maverick/mediawiki/maverick

« back to all changes in this revision

Viewing changes to includes/specials/SpecialContributions.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-06-19 01:38:50 UTC
  • mfrom: (16.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090619013850-dsn4lrxvs90ab4rx
Tags: 1:1.15.0-1
* New upstream release. 
* Upstream added support for OASIS documents.
Closes: #530328
* Refreshed quilt patches
* Bumped standards versions to 3.8.2
* Bumped compat to 7
* Pointed to GPL-2 in debian/copyright
* Added php5-sqlite to possible DB backend dependencies.
Closes: #501569
* Proofread README.Debian, upgrade is documented there.
Closes: #520121

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                }
36
36
 
37
37
                if( !strlen( $target ) ) {
38
 
                        $wgOut->addHTML( $this->getForm( '' ) );
 
38
                        $wgOut->addHTML( $this->getForm() );
39
39
                        return;
40
40
                }
41
41
 
44
44
 
45
45
                $nt = Title::makeTitleSafe( NS_USER, $target );
46
46
                if( !$nt ) {
47
 
                        $wgOut->addHTML( $this->getForm( '' ) );
 
47
                        $wgOut->addHTML( $this->getForm() );
48
48
                        return;
49
49
                }
50
50
                $id = User::idFromName( $nt->getText() );
52
52
                if( $target != 'newbies' ) {
53
53
                        $target = $nt->getText();
54
54
                        $wgOut->setSubtitle( $this->contributionsSub( $nt, $id ) );
55
 
                        $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'contributions-title', $target ) ) );
 
55
                        $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ),$target ) ) );
56
56
                } else {
57
57
                        $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
58
58
                        $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) );
63
63
                } else {
64
64
                        $this->opts['namespace'] = '';
65
65
                }
 
66
 
 
67
                $this->opts['tagfilter'] = (string) $wgRequest->getVal( 'tagfilter' );
66
68
        
67
69
                // Allows reverts to have the bot flag in recent changes. It is just here to
68
70
                // be passed in the form at the top of the page 
72
74
 
73
75
                $skip = $wgRequest->getText( 'offset' ) || $wgRequest->getText( 'dir' ) == 'prev';
74
76
                # Offset overrides year/month selection
75
 
                if( ( $month = $wgRequest->getIntOrNull( 'month' ) ) !== null && $month !== -1 ) {
76
 
                        $this->opts['month'] = intval( $month );
77
 
                } else {
78
 
                        $this->opts['month'] = '';
79
 
                }
80
 
                if( ( $year = $wgRequest->getIntOrNull( 'year' ) ) !== null ) {
81
 
                        $this->opts['year'] = intval( $year );
82
 
                } else if( $this->opts['month'] ) {
83
 
                        $thisMonth = intval( gmdate( 'n' ) );
84
 
                        $thisYear = intval( gmdate( 'Y' ) );
85
 
                        if( intval( $this->opts['month'] ) > $thisMonth ) {
86
 
                                $thisYear--;
87
 
                        }
88
 
                        $this->opts['year'] = $thisYear;
89
 
                } else {
90
 
                        $this->opts['year'] = '';
91
 
                }
92
 
 
93
77
                if( $skip ) {
94
78
                        $this->opts['year'] = '';
95
79
                        $this->opts['month'] = '';
 
80
                } else {
 
81
                        $this->opts['year'] = $wgRequest->getIntOrNull( 'year' );
 
82
                        $this->opts['month'] = $wgRequest->getIntOrNull( 'month' );
96
83
                }
97
84
                
98
85
                // Add RSS/atom links
104
91
 
105
92
                wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
106
93
 
107
 
                $wgOut->addHTML( $this->getForm( $this->opts ) );
 
94
                $wgOut->addHTML( $this->getForm() );
108
95
 
109
96
                $pager = new ContribsPager( $target, $this->opts['namespace'], $this->opts['year'], $this->opts['month'] );
110
97
                if( !$pager->getNumRows() ) {
111
 
                        $wgOut->addWikiMsg( 'nocontribs' );
 
98
                        $wgOut->addWikiMsg( 'nocontribs', $target );
112
99
                        return;
113
100
                }
114
101
 
177
164
                                        wfMsgHtml( 'sp-contributions-blocklog' ), 'type=block&page=' . $nt->getPrefixedUrl() );
178
165
                        }
179
166
                        # Other logs link
180
 
                        $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), wfMsgHtml( 'log' ), 
181
 
                                'user=' . $nt->getPartialUrl()  );
 
167
                        $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log' ), wfMsg( 'sp-contributions-logs' ), 
 
168
                                'user=' . $nt->getPartialUrl() );
182
169
 
183
170
                        # Add link to deleted user contributions for priviledged users
184
171
                        if( $wgUser->isAllowed( 'deletedhistory' ) ) {
185
 
                                        $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'DeletedContributions', 
 
172
                                $tools[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'DeletedContributions', 
186
173
                                        $nt->getDBkey() ), wfMsgHtml( 'deletedcontributions' ) );
187
174
                        }
188
 
        
 
175
 
 
176
                        # Add a link to change user rights for privileged users
 
177
                        $userrightsPage = new UserrightsPage();
 
178
                        if( 0 !== $id && $userrightsPage->userCanChangeRights( User::newFromId( $id ) ) ) {
 
179
                                $tools[] = $sk->makeKnownLinkObj(
 
180
                                        SpecialPage::getTitleFor( 'Userrights', $nt->getDBkey() ),
 
181
                                        wfMsgHtml( 'userrights' )
 
182
                                );
 
183
                        }
 
184
 
189
185
                        wfRunHooks( 'ContributionsToolLinks', array( $id, $nt, &$tools ) );
190
186
        
191
 
                        $links = implode( ' | ', $tools );
 
187
                        $links = $wgLang->pipeList( $tools );
192
188
                }
193
189
        
194
190
                // Old message 'contribsub' had one parameter, but that doesn't work for
235
231
                if( $this->opts['contribs'] == 'newbie' ) {
236
232
                        $this->opts['target'] = '';
237
233
                }
 
234
 
 
235
                if( !isset( $this->opts['tagfilter'] ) ) {
 
236
                        $this->opts['tagfilter'] = '';
 
237
                }
238
238
        
239
239
                $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
240
 
        
 
240
                # Add hidden params for tracking
241
241
                foreach ( $this->opts as $name => $value ) {
242
242
                        if( in_array( $name, array( 'namespace', 'target', 'contribs', 'year', 'month' ) ) ) {
243
243
                                continue;
244
244
                        }
245
245
                        $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
246
246
                }
 
247
 
 
248
                $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] );
247
249
        
248
250
                $f .= '<fieldset>' .
249
251
                        Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) .
256
258
                        Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
257
259
                        Xml::namespaceSelector( $this->opts['namespace'], '' ) .
258
260
                        '</span>' .
 
261
                        ( $tagFilter ? Xml::tags( 'p', null, implode( '&nbsp;', $tagFilter ) ) : '' ) .
259
262
                        Xml::openElement( 'p' ) .
260
263
                        '<span style="white-space: nowrap">' .
261
 
                        Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
262
 
                        Xml::input( 'year', 4, $this->opts['year'], array('id' => 'year', 'maxlength' => 4) ) .
263
 
                        '</span>' .
264
 
                        ' '.
265
 
                        '<span style="white-space: nowrap">' .
266
 
                        Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
267
 
                        Xml::monthSelector( $this->opts['month'], -1 ) . ' '.
268
 
                        '</span>' .
 
264
                        Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) .
 
265
                        '</span>' . ' ' .
269
266
                        Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
270
267
                        Xml::closeElement( 'p' );
271
268
        
278
275
                return $f;
279
276
        }
280
277
        
281
 
                /**
 
278
        /**
282
279
         * Output a subscription feed listing recent edits to this page.
283
280
         * @param string $type
284
281
         */
300
297
                $feed = new $wgFeedClasses[$type](
301
298
                        $this->feedTitle(),
302
299
                        wfMsgExt( 'tagline', 'parsemag' ),
303
 
                        $this->getTitle()->getFullUrl() );
 
300
                        $this->getTitle()->getFullUrl() . "/" . urlencode($this->opts['target'])
 
301
                );
304
302
                        
305
303
                // Already valid title
306
304
                $nt = Title::makeTitleSafe( NS_USER, $this->opts['target'] );
307
305
                $target = $this->opts['target'] == 'newbies' ? 'newbies' : $nt->getText();
308
306
                        
309
307
                $pager = new ContribsPager( $target, $this->opts['namespace'], 
310
 
                        $this->opts['year'], $this->opts['month'] );
 
308
                        $this->opts['year'], $this->opts['month'], $this->opts['tagfilter'] );
311
309
 
312
310
                $pager->mLimit = min( $this->opts['limit'], $wgFeedLimit );
313
311
 
353
351
 
354
352
        protected function feedItemDesc( $revision ) {
355
353
                if( $revision ) {
356
 
                        return '<p>' . htmlspecialchars( $revision->getUserText() ) . ': ' .
 
354
                        return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
357
355
                                htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) . 
358
356
                                "</p>\n<hr />\n<div>" .
359
357
                                nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
371
369
        var $messages, $target;
372
370
        var $namespace = '', $mDb;
373
371
 
374
 
        function __construct( $target, $namespace = false, $year = false, $month = false ) {
 
372
        function __construct( $target, $namespace = false, $year = false, $month = false, $tagFilter = false ) {
375
373
                parent::__construct();
376
374
                foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist newpageletter minoreditletter' ) as $msg ) {
377
375
                        $this->messages[$msg] = wfMsgExt( $msg, array( 'escape') );
378
376
                }
379
377
                $this->target = $target;
380
378
                $this->namespace = $namespace;
 
379
                $this->tagFilter = $tagFilter;
381
380
 
382
381
                $this->getDateCond( $year, $month );
383
382
 
391
390
        }
392
391
 
393
392
        function getQueryInfo() {
 
393
                global $wgUser;
394
394
                list( $tables, $index, $userCond, $join_cond ) = $this->getUserCond();
395
 
                $conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond() );
 
395
                
 
396
                $conds = array_merge( $userCond, $this->getNamespaceCond() );
 
397
                // Paranoia: avoid brute force searches (bug 17342)
 
398
                if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
 
399
                        $conds[] = 'rev_deleted & ' . Revision::DELETED_USER . ' = 0';
 
400
                }
 
401
                $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
 
402
                
396
403
                $queryInfo = array(
397
404
                        'tables' => $tables,
398
405
                        'fields' => array(
399
 
                                'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'rev_id', 'rev_page',
400
 
                                'rev_text_id', 'rev_timestamp', 'rev_comment', 'rev_minor_edit', 'rev_user',
401
 
                                'rev_user_text', 'rev_parent_id', 'rev_deleted'
 
406
                                'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'page_is_redirect',
 
407
                                'page_len','rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment', 
 
408
                                'rev_minor_edit', 'rev_user', 'rev_user_text', 'rev_parent_id', 'rev_deleted'
402
409
                        ),
403
410
                        'conds' => $conds,
404
411
                        'options' => array( 'USE INDEX' => array('revision' => $index) ),
405
412
                        'join_conds' => $join_cond
406
413
                );
 
414
                
 
415
                ChangeTags::modifyDisplayQuery( $queryInfo['tables'],
 
416
                                                                                $queryInfo['fields'],
 
417
                                                                                $queryInfo['conds'],
 
418
                                                                                $queryInfo['join_conds'],
 
419
                                                                                $queryInfo['options'],
 
420
                                                                                $this->tagFilter );
 
421
                
407
422
                wfRunHooks( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) );
408
423
                return $queryInfo;
409
424
        }
458
473
         * @todo This would probably look a lot nicer in a table.
459
474
         */
460
475
        function formatRow( $row ) {
 
476
                global $wgLang, $wgUser, $wgContLang;
461
477
                wfProfileIn( __METHOD__ );
462
478
 
463
 
                global $wgLang, $wgUser, $wgContLang;
464
 
 
465
479
                $sk = $this->getSkin();
466
480
                $rev = new Revision( $row );
 
481
                $classes = array();
467
482
 
468
 
                $page = Title::makeTitle( $row->page_namespace, $row->page_title );
469
 
                $link = $sk->makeKnownLinkObj( $page );
 
483
                $page = Title::newFromRow( $row );
 
484
                $page->resetArticleId( $row->rev_page ); // use process cache
 
485
                $link = $sk->makeLinkObj( $page, $page->getPrefixedText(), $page->isRedirect() ? 'redirect=no' : '' );
 
486
                # Mark current revisions
470
487
                $difftext = $topmarktext = '';
471
488
                if( $row->rev_id == $row->page_latest ) {
472
489
                        $topmarktext .= '<strong>' . $this->messages['uctop'] . '</strong>';
473
490
                        if( !$row->page_is_new ) {
474
491
                                $difftext .= '(' . $sk->makeKnownLinkObj( $page, $this->messages['diff'], 'diff=0' ) . ')';
 
492
                                # Add rollback link
 
493
                                if( $page->quickUserCan( 'rollback') && $page->quickUserCan( 'edit' ) ) {
 
494
                                        $topmarktext .= ' '.$sk->generateRollback( $rev );
 
495
                                }
475
496
                        } else {
476
497
                                $difftext .= $this->messages['newarticle'];
477
498
                        }
478
 
 
479
 
                        if( $page->userCan( 'rollback') && $page->userCan( 'edit' ) ) {
480
 
                                $topmarktext .= ' '.$sk->generateRollback( $rev );
481
 
                        }
482
 
 
483
499
                }
484
500
                # Is there a visible previous revision?
485
501
                if( $rev->userCan(Revision::DELETED_TEXT) ) {
486
 
                        $difftext = '(' . $sk->makeKnownLinkObj( $page, $this->messages['diff'], 'diff=prev&oldid='.$row->rev_id ) . ')';
 
502
                        $difftext = '(' . $sk->makeKnownLinkObj( $page, $this->messages['diff'],
 
503
                                'diff=prev&oldid='.$row->rev_id ) . ')';
487
504
                } else {
488
505
                        $difftext = '(' . $this->messages['diff'] . ')';
489
506
                }
490
 
                $histlink='('.$sk->makeKnownLinkObj( $page, $this->messages['hist'], 'action=history' ) . ')';
 
507
                $histlink = '('.$sk->makeKnownLinkObj( $page, $this->messages['hist'], 'action=history' ) . ')';
491
508
 
492
509
                $comment = $wgContLang->getDirMark() . $sk->revComment( $rev, false, true );
493
510
                $date = $wgLang->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
510
527
                        $nflag = '';
511
528
                }
512
529
 
513
 
                if( $row->rev_minor_edit ) {
 
530
                if( $rev->isMinor() ) {
514
531
                        $mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
515
532
                } else {
516
533
                        $mflag = '';
520
537
                if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
521
538
                        $ret .= ' ' . wfMsgHtml( 'deletedrev' );
522
539
                }
 
540
 
 
541
                # Tags, if any.
 
542
                list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'contributions' );
 
543
                $classes = array_merge( $classes, $newClasses );
 
544
                $ret .= " $tagSummary";
 
545
 
523
546
                // Let extensions add data
524
547
                wfRunHooks( 'ContributionsLineEnding', array( &$this, &$ret, $row ) );
525
 
                
526
 
                $ret = "<li>$ret</li>\n";
 
548
 
 
549
                $classes = implode( ' ', $classes );
 
550
                $ret = "<li class=\"$classes\">$ret</li>\n";
527
551
                wfProfileOut( __METHOD__ );
528
552
                return $ret;
529
553
        }