Index: trunk/phase3/includes/SpecialNewpages.php |
— | — | @@ -4,28 +4,109 @@ |
5 | 5 | * @addtogroup SpecialPage |
6 | 6 | */ |
7 | 7 | |
| 8 | + |
8 | 9 | /** |
| 10 | + * Start point |
| 11 | + */ |
| 12 | +function wfSpecialNewPages( $par, $specialPage ) { |
| 13 | + $page = new NewPagesPage( $specialPage ); |
| 14 | + $page->execute( $par ); |
| 15 | +} |
| 16 | + |
| 17 | +/** |
9 | 18 | * implements Special:Newpages |
10 | 19 | * @addtogroup SpecialPage |
11 | 20 | */ |
12 | 21 | class NewPagesPage extends QueryPage { |
13 | 22 | |
14 | | - var $namespace; |
15 | | - var $username; |
16 | | - var $hideliu; |
17 | | - var $hidepatrolled; |
18 | | - var $hidebots; |
19 | | - var $defaults; |
20 | | - |
21 | | - function NewPagesPage( $namespace=NS_MAIN, $username='', $hideliu=false, $hidepatrolled=false, $hidebots=false, $defaults=array()) { |
22 | | - $this->namespace = $namespace; |
23 | | - $this->username = $username; |
24 | | - $this->hideliu = $hideliu; |
25 | | - $this->hidepatrolled = $hidepatrolled; |
26 | | - $this->hidebots = $hidebots; |
27 | | - $this->defaults = $defaults; |
| 23 | + protected $options = array(); |
| 24 | + protected $nondefaults = array(); |
| 25 | + protected $specialPage; |
| 26 | + |
| 27 | + public function __construct( $specialPage ) { |
| 28 | + $this->specialPage = $specialPage; |
28 | 29 | } |
29 | 30 | |
| 31 | + public function execute( $par ) { |
| 32 | + global $wgRequest, $wgLang; |
| 33 | + |
| 34 | + $shownavigation = !$this->specialPage->including(); |
| 35 | + |
| 36 | + $defaults = array( |
| 37 | + /* bool */ 'hideliu' => false, |
| 38 | + /* bool */ 'hidepatrolled' => false, |
| 39 | + /* bool */ 'hidebots' => false, |
| 40 | + /* text */ 'namespace' => "0", |
| 41 | + /* text */ 'username' => '', |
| 42 | + /* int */ 'offset' => 0, |
| 43 | + /* int */ 'limit' => 50, |
| 44 | + ); |
| 45 | + |
| 46 | + $options = $defaults; |
| 47 | + |
| 48 | + if ( $par ) { |
| 49 | + $bits = preg_split( '/\s*,\s*/', trim( $par ) ); |
| 50 | + foreach ( $bits as $bit ) { |
| 51 | + if ( 'shownav' == $bit ) |
| 52 | + $shownavigation = true; |
| 53 | + if ( 'hideliu' === $bit ) |
| 54 | + $options['hideliu'] = true; |
| 55 | + if ( 'hidepatrolled' == $bit ) |
| 56 | + $options['hidepatrolled'] = true; |
| 57 | + if ( 'hidebots' == $bit ) |
| 58 | + $options['hidebots'] = true; |
| 59 | + if ( is_numeric( $bit ) ) |
| 60 | + $options['limit'] = intval( $bit ); |
| 61 | + |
| 62 | + $m = array(); |
| 63 | + if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) |
| 64 | + $options['limit'] = intval($m[1]); |
| 65 | + if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) ) |
| 66 | + $options['offset'] = intval($m[1]); |
| 67 | + if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) { |
| 68 | + $ns = $wgLang->getNsIndex( $m[1] ); |
| 69 | + if( $ns !== false ) { |
| 70 | + $options['namespace'] = $ns; |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + // Override all values from requests, if specified |
| 77 | + foreach ( $defaults as $v => $t ) { |
| 78 | + if ( is_bool($t) ) { |
| 79 | + $options[$v] = $wgRequest->getBool( $v, $options[$v] ); |
| 80 | + } elseif( is_int($t) ) { |
| 81 | + $options[$v] = $wgRequest->getInt( $v, $options[$v] ); |
| 82 | + } elseif( is_string($t) ) { |
| 83 | + $options[$v] = $wgRequest->getText( $v, $options[$v] ); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + $nondefaults = array(); |
| 88 | + foreach ( $options as $v => $t ) { |
| 89 | + if ( $v === 'offset' ) continue; # Reset offset if parameters change |
| 90 | + wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults ); |
| 91 | + } |
| 92 | + |
| 93 | + # bind to class |
| 94 | + $this->options = $options; |
| 95 | + $this->nondefaults = $nondefaults; |
| 96 | + |
| 97 | + if ( !$this->doFeed( $wgRequest->getVal( 'feed' ), $options['limit'] ) ) { |
| 98 | + $this->doQuery( $options['offset'], $options['limit'], $shownavigation ); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + function linkParameters() { |
| 103 | + $nondefaults = $this->nondefaults; |
| 104 | + // QueryPage seems to handle limit and offset itself |
| 105 | + if ( isset( $nondefaults['limit'] ) ) { |
| 106 | + unset($nondefaults['limit']); |
| 107 | + } |
| 108 | + return $nondefaults; |
| 109 | + } |
| 110 | + |
30 | 111 | function getName() { |
31 | 112 | return 'Newpages'; |
32 | 113 | } |
— | — | @@ -35,29 +116,26 @@ |
36 | 117 | return false; |
37 | 118 | } |
38 | 119 | |
39 | | - function makeUserWhere( &$dbo ) { |
| 120 | + function makeUserWhere( $db ) { |
40 | 121 | global $wgGroupPermissions; |
41 | | - $where = ''; |
42 | | - if ($this->hidepatrolled) |
43 | | - $where .= ' AND rc_patrolled = 0'; |
44 | | - if ($this->hidebots) |
45 | | - $where .= ' AND rc_bot = 0'; |
46 | | - if ($wgGroupPermissions['*']['createpage'] == true && $this->hideliu) { |
47 | | - $where .= ' AND rc_user = 0'; |
| 122 | + $conds = array(); |
| 123 | + if ($this->options['hidepatrolled']) { |
| 124 | + $conds['rc_patrolled'] = 0; |
| 125 | + } |
| 126 | + if ($this->options['hidebots']) { |
| 127 | + $conds['rc_bot'] = 0; |
| 128 | + } |
| 129 | + if ($wgGroupPermissions['*']['createpage'] == true && $this->options['hideliu']) { |
| 130 | + $conds['rc_user'] = 0; |
48 | 131 | } else { |
49 | | - $title = Title::makeTitleSafe( NS_USER, $this->username ); |
| 132 | + $title = Title::makeTitleSafe( NS_USER, $this->options['username'] ); |
50 | 133 | if( $title ) { |
51 | | - $where .= ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() ); |
| 134 | + $conds['rc_user_text'] = $title->getText(); |
52 | 135 | } |
53 | 136 | } |
54 | | - return $where; |
| 137 | + return $conds; |
55 | 138 | } |
56 | 139 | |
57 | | - private function makeNamespaceWhere() { |
58 | | - return $this->namespace !== 'all' |
59 | | - ? ' AND rc_namespace = ' . intval( $this->namespace ) |
60 | | - : ''; |
61 | | - } |
62 | 140 | |
63 | 141 | function getSQL() { |
64 | 142 | global $wgUser, $wgUseNPPatrol, $wgUseRCPatrol; |
— | — | @@ -65,8 +143,14 @@ |
66 | 144 | $dbr = wfGetDB( DB_SLAVE ); |
67 | 145 | list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' ); |
68 | 146 | |
69 | | - $nsfilter = $this->makeNamespaceWhere(); |
70 | | - $uwhere = $this->makeUserWhere( $dbr ); |
| 147 | + $conds = array(); |
| 148 | + $conds['rc_new'] = 1; |
| 149 | + if ( $this->options['namespace'] !== 'all' ) { |
| 150 | + $conds['rc_namespace'] = intval( $this->options['namespace'] ); |
| 151 | + } |
| 152 | + $conds['page_is_redirect'] = 0; |
| 153 | + $conds += $this->makeUserWhere( $dbr ); |
| 154 | + $condstext = $dbr->makeList( $conds, LIST_AND ); |
71 | 155 | |
72 | 156 | # FIXME: text will break with compression |
73 | 157 | return |
— | — | @@ -85,23 +169,20 @@ |
86 | 170 | page_len as length, |
87 | 171 | page_latest as rev_id |
88 | 172 | FROM $recentchanges,$page |
89 | | - WHERE rc_cur_id=page_id AND rc_new=1 |
90 | | - {$nsfilter} |
91 | | - AND page_is_redirect = 0 |
92 | | - {$uwhere}"; |
| 173 | + WHERE rc_cur_id=page_id AND $condstext"; |
93 | 174 | } |
94 | 175 | |
95 | | - function preprocessResults( &$dbo, &$res ) { |
| 176 | + function preprocessResults( $db, $res ) { |
96 | 177 | # Do a batch existence check on the user and talk pages |
97 | 178 | $linkBatch = new LinkBatch(); |
98 | | - while( $row = $dbo->fetchObject( $res ) ) { |
99 | | - $linkBatch->addObj( Title::makeTitleSafe( NS_USER, $row->user_text ) ); |
100 | | - $linkBatch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_text ) ); |
| 179 | + while( $row = $db->fetchObject( $res ) ) { |
| 180 | + $linkBatch->add( NS_USER, $row->user_text ); |
| 181 | + $linkBatch->add( NS_USER_TALK, $row->user_text ); |
101 | 182 | } |
102 | 183 | $linkBatch->execute(); |
103 | 184 | # Seek to start |
104 | | - if( $dbo->numRows( $res ) > 0 ) |
105 | | - $dbo->dataSeek( $res, 0 ); |
| 185 | + if( $db->numRows( $res ) > 0 ) |
| 186 | + $db->dataSeek( $res, 0 ); |
106 | 187 | } |
107 | 188 | |
108 | 189 | /** |
— | — | @@ -158,35 +239,43 @@ |
159 | 240 | */ |
160 | 241 | function getPageHeader() { |
161 | 242 | global $wgScript, $wgContLang, $wgGroupPermissions, $wgUser, $wgUseRCPatrol, $wgUseNPPatrol; |
| 243 | + $sk = $wgUser->getSkin(); |
162 | 244 | $align = $wgContLang->isRTL() ? 'left' : 'right'; |
163 | 245 | $self = SpecialPage::getTitleFor( $this->getName() ); |
164 | 246 | |
165 | 247 | // show/hide links |
166 | | - $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' )); |
| 248 | + $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' )); |
167 | 249 | |
168 | | - $nondefaults = array(); |
169 | | - wfAppendToArrayIfNotDefault( 'hidepatrolled', $this->hidepatrolled, $this->defaults, $nondefaults); |
170 | | - wfAppendToArrayIfNotDefault( 'hideliu', $this->hideliu, $this->defaults, $nondefaults); |
171 | | - wfAppendToArrayIfNotDefault( 'hidebots', $this->hidebots, $this->defaults, $nondefaults); |
172 | | - wfAppendToArrayIfNotDefault( 'namespace', $this->namespace, $this->defaults, $nondefaults); |
173 | | - wfAppendToArrayIfNotDefault( 'limit', $this->limit , $this->defaults, $nondefaults); |
174 | | - wfAppendToArrayIfNotDefault( 'offset', $this->offset , $this->defaults, $nondefaults); |
175 | | - wfAppendToArrayIfNotDefault( 'username', $this->username , $this->defaults, $nondefaults); |
176 | | - |
177 | | - $liuLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ), |
178 | | - htmlspecialchars( $showhide[1-$this->hideliu] ), wfArrayToCGI( array( 'hideliu' => 1-$this->hideliu ), $nondefaults ) ); |
179 | | - $patrLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ), |
180 | | - htmlspecialchars( $showhide[1-$this->hidepatrolled] ), wfArrayToCGI( array( 'hidepatrolled' => 1-$this->hidepatrolled ), $nondefaults ) ); |
181 | | - $botsLink = $wgUser->getSkin()->makeKnownLink( $wgContLang->specialPage( 'Newpages' ), |
182 | | - htmlspecialchars( $showhide[1-$this->hidebots] ), wfArrayToCGI( array( 'hidebots' => 1-$this->hidebots ), $nondefaults ) ); |
| 250 | + $hidelinks = array(); |
| 251 | + |
| 252 | + if ( $wgGroupPermissions['*']['createpage'] === true ) { |
| 253 | + $hidelinks['hideliu'] = 'rcshowhideliu'; |
| 254 | + } |
| 255 | + if ( $wgUseNPPatrol || $wgUseRCPatrol ) { |
| 256 | + $hidelinks['hidepatrolled'] = 'rcshowhidepatr'; |
| 257 | + } |
| 258 | + $hidelinks['hidebots'] = 'rcshowhidebots'; |
| 259 | + |
183 | 260 | $links = array(); |
184 | | - if( $wgGroupPermissions['*']['createpage'] == true ) |
185 | | - $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink ); |
186 | | - if( $wgUseNPPatrol || $wgUseRCPatrol ) |
187 | | - $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink ); |
188 | | - $links[] = wfMsgHtml( 'rcshowhidebots', $botsLink ); |
| 261 | + foreach ( $hidelinks as $key => $msg ) { |
| 262 | + $reversed = 1-$this->options[$key]; |
| 263 | + $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed], |
| 264 | + wfArrayToCGI( array( $key => $reversed ), $this->nondefaults ) |
| 265 | + ); |
| 266 | + $links[$key] = wfMsgHtml( $msg, $link ); |
| 267 | + } |
| 268 | + |
189 | 269 | $hl = implode( ' | ', $links ); |
190 | 270 | |
| 271 | + // Store query values in hidden fields so that form submission doesn't lose them |
| 272 | + $hidden = array(); |
| 273 | + foreach ( $this->nondefaults as $key => $value ) { |
| 274 | + if ( $key === 'namespace' ) continue; |
| 275 | + if ( $key === 'username' ) continue; |
| 276 | + $hidden[] = Xml::hidden( $key, $value ); |
| 277 | + } |
| 278 | + $hidden = implode( "\n", $hidden ); |
| 279 | + |
191 | 280 | $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . |
192 | 281 | Xml::hidden( 'title', $self->getPrefixedDBkey() ) . |
193 | 282 | Xml::openElement( 'table' ) . |
— | — | @@ -195,105 +284,27 @@ |
196 | 285 | Xml::label( wfMsg( 'namespace' ), 'namespace' ) . |
197 | 286 | "</td> |
198 | 287 | <td>" . |
199 | | - Xml::namespaceSelector( intval( $this->namespace ), 'all' ) . |
| 288 | + Xml::namespaceSelector( $this->options['namespace'], 'all' ) . |
200 | 289 | "</td> |
201 | 290 | </tr> |
202 | | -<tr> |
| 291 | + <tr> |
203 | 292 | <td align=\"$align\">" . |
204 | 293 | Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) . |
205 | 294 | "</td> |
206 | 295 | <td>" . |
207 | | - Xml::input( 'username', 30, $this->username, array( 'id' => 'mw-np-username' ) ) . |
| 296 | + Xml::input( 'username', 30, $this->options['username'], array( 'id' => 'mw-np-username' ) ) . |
208 | 297 | "</td> |
209 | | - </tr><tr><td></td><td>" . $hl . "</td></tr> |
| 298 | + </tr> |
210 | 299 | <tr> <td></td> |
211 | 300 | <td>" . |
212 | 301 | Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . |
213 | 302 | "</td> |
214 | 303 | </tr>" . |
| 304 | + "<tr><td></td><td>" . $hl . "</td></tr>" . |
215 | 305 | Xml::closeElement( 'table' ) . |
216 | | - Xml::hidden( 'offset', $this->offset ) . |
217 | | - Xml::hidden( 'limit', $this->limit ) . |
| 306 | + $hidden . |
218 | 307 | Xml::closeElement( 'form' ); |
219 | 308 | return $form; |
220 | 309 | } |
221 | 310 | |
222 | | - /** |
223 | | - * Link parameters |
224 | | - * |
225 | | - * @return array |
226 | | - */ |
227 | | - function linkParameters() { |
228 | | - return( array( 'namespace' => $this->namespace, 'username' => $this->username, 'hideliu' => $this->hideliu, 'hidepatrolled' => $this->hidepatrolled ) ); |
229 | | - } |
230 | | - |
231 | | -} |
232 | | - |
233 | | -/** |
234 | | - * constructor |
235 | | - */ |
236 | | -function wfSpecialNewpages($par, $specialPage) { |
237 | | - global $wgRequest, $wgContLang; |
238 | | - |
239 | | - |
240 | | - list( $limit, $offset ) = wfCheckLimits(); |
241 | | - |
242 | | - $defaults = array( |
243 | | - /* bool */ 'hideliu' => false, |
244 | | - /* bool */ 'hidepatrolled' => false, |
245 | | - /* bool */ 'hidebots' => false, |
246 | | - /* text */ 'namespace' => NS_MAIN, |
247 | | - /* text */ 'username' => '', |
248 | | - /* int */ 'offset' => $offset, |
249 | | - /* int */ 'limit' => $limit, |
250 | | -); |
251 | | - |
252 | | - extract($defaults); |
253 | | - |
254 | | - if ( $par ) { |
255 | | - $bits = preg_split( '/\s*,\s*/', trim( $par ) ); |
256 | | - foreach ( $bits as $bit ) { |
257 | | - if ( 'shownav' == $bit ) |
258 | | - $shownavigation = true; |
259 | | - if ( 'hideliu' == $bit ) |
260 | | - $hideliu = true; |
261 | | - if ( 'hidepatrolled' == $bit ) |
262 | | - $hidepatrolled = true; |
263 | | - if ( 'hidebots' == $bit ) |
264 | | - $hidebots = true; |
265 | | - if ( is_numeric( $bit ) ) |
266 | | - $limit = $bit; |
267 | | - |
268 | | - $m = array(); |
269 | | - if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) |
270 | | - $limit = intval($m[1]); |
271 | | - if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) ) |
272 | | - $offset = intval($m[1]); |
273 | | - if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) { |
274 | | - $ns = $wgContLang->getNsIndex( $m[1] ); |
275 | | - if( $ns !== false ) { |
276 | | - $namespace = $ns; |
277 | | - } |
278 | | - } |
279 | | - } |
280 | | - } else { |
281 | | - if( $ns = $wgRequest->getInt( 'namespace', NS_MAIN ) ) |
282 | | - $namespace = $ns; |
283 | | - if( $un = $wgRequest->getText( 'username' ) ) |
284 | | - $username = $un; |
285 | | - if( $hliu = $wgRequest->getBool( 'hideliu' ) ) |
286 | | - $hideliu = $hliu; |
287 | | - if( $hpatrolled = $wgRequest->getBool( 'hidepatrolled' ) ) |
288 | | - $hidepatrolled = $hpatrolled; |
289 | | - if( $hbots = $wgRequest->getBool( 'hidebots' ) ) |
290 | | - $hidebots = $hbots; |
291 | | - } |
292 | | - |
293 | | - if ( ! isset( $shownavigation ) ) |
294 | | - $shownavigation = ! $specialPage->including(); |
295 | | - |
296 | | - $npp = new NewPagesPage( $namespace, $username, $hideliu, $hidepatrolled, $hidebots, $defaults ); |
297 | | - |
298 | | - if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) ) |
299 | | - $npp->doQuery( $offset, $limit, $shownavigation ); |
300 | | -} |
| 311 | +} |
\ No newline at end of file |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -241,6 +241,8 @@ |
242 | 242 | language |
243 | 243 | * (bug 10184) Extensions' stylesheets and scripts should be loaded before |
244 | 244 | user-customized ones (like Common.css, Common.js) |
| 245 | +* (bug 12283) Special:Newpages forgets parameters |
| 246 | +* (bug 12031) All namespaces doesn't work in Special:Newpages |
245 | 247 | |
246 | 248 | == Parser changes in 1.12 == |
247 | 249 | |