Update docs/hooks.txt for ShowSearchHitTitle
[mediawiki.git] / includes / specials / pagers / NewPagesPager.php
blobe298f103a23d321a27ade7a44c465d757c01a56f
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Pager
22 /**
23 * @ingroup Pager
25 class NewPagesPager extends ReverseChronologicalPager {
27 // Stored opts
28 protected $opts;
30 /**
31 * @var HtmlForm
33 protected $mForm;
35 function __construct( $form, FormOptions $opts ) {
36 parent::__construct( $form->getContext() );
37 $this->mForm = $form;
38 $this->opts = $opts;
41 function getQueryInfo() {
42 $conds = [];
43 $conds['rc_new'] = 1;
45 $namespace = $this->opts->getValue( 'namespace' );
46 $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
48 $username = $this->opts->getValue( 'username' );
49 $user = Title::makeTitleSafe( NS_USER, $username );
51 $size = abs( intval( $this->opts->getValue( 'size' ) ) );
52 if ( $size > 0 ) {
53 if ( $this->opts->getValue( 'size-mode' ) === 'max' ) {
54 $conds[] = 'page_len <= ' . $size;
55 } else {
56 $conds[] = 'page_len >= ' . $size;
60 $rcIndexes = [];
62 if ( $namespace !== false ) {
63 if ( $this->opts->getValue( 'invert' ) ) {
64 $conds[] = 'rc_namespace != ' . $this->mDb->addQuotes( $namespace );
65 } else {
66 $conds['rc_namespace'] = $namespace;
70 if ( $user ) {
71 $conds['rc_user_text'] = $user->getText();
72 $rcIndexes = 'rc_user_text';
73 } elseif ( User::groupHasPermission( '*', 'createpage' ) &&
74 $this->opts->getValue( 'hideliu' )
75 ) {
76 # If anons cannot make new pages, don't "exclude logged in users"!
77 $conds['rc_user'] = 0;
80 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
81 if ( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
82 $conds['rc_patrolled'] = 0;
85 if ( $this->opts->getValue( 'hidebots' ) ) {
86 $conds['rc_bot'] = 0;
89 if ( $this->opts->getValue( 'hideredirs' ) ) {
90 $conds['page_is_redirect'] = 0;
93 // Allow changes to the New Pages query
94 $tables = [ 'recentchanges', 'page' ];
95 $fields = [
96 'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user', 'rc_user_text',
97 'rc_comment', 'rc_timestamp', 'rc_patrolled', 'rc_id', 'rc_deleted',
98 'length' => 'page_len', 'rev_id' => 'page_latest', 'rc_this_oldid',
99 'page_namespace', 'page_title'
101 $join_conds = [ 'page' => [ 'INNER JOIN', 'page_id=rc_cur_id' ] ];
103 Hooks::run( 'SpecialNewpagesConditions',
104 [ &$this, $this->opts, &$conds, &$tables, &$fields, &$join_conds ] );
106 $options = [];
108 if ( $rcIndexes ) {
109 $options = [ 'USE INDEX' => [ 'recentchanges' => $rcIndexes ] ];
112 $info = [
113 'tables' => $tables,
114 'fields' => $fields,
115 'conds' => $conds,
116 'options' => $options,
117 'join_conds' => $join_conds
120 // Modify query for tags
121 ChangeTags::modifyDisplayQuery(
122 $info['tables'],
123 $info['fields'],
124 $info['conds'],
125 $info['join_conds'],
126 $info['options'],
127 $this->opts['tagfilter']
130 return $info;
133 function getIndexField() {
134 return 'rc_timestamp';
137 function formatRow( $row ) {
138 return $this->mForm->formatRow( $row );
141 function getStartBody() {
142 # Do a batch existence check on pages
143 $linkBatch = new LinkBatch();
144 foreach ( $this->mResult as $row ) {
145 $linkBatch->add( NS_USER, $row->rc_user_text );
146 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
147 $linkBatch->add( $row->page_namespace, $row->page_title );
149 $linkBatch->execute();
151 return '<ul>';
154 function getEndBody() {
155 return '</ul>';