r33389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33388‎ | r33389 | r33390 >
Date:20:42, 15 April 2008
Author:ialex
Status:old
Tags:
Comment:
Tweaks for Special:Newpages:
* (bug 13756) Don't show the form and navigation links if the page is included
* Readded options overriding with $par, useful when the page is included
* Override limit and offset in pager so that they are also modified if they are specified in $par (when page is included)
* Force NewPagesPager::getTitle() to return the title object of Special:Newpages even if included, navigation bar was linking to the included page, wich might not a very good idea sometimes
* Fix some whitespaces
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialNewpages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialNewpages.php
@@ -8,10 +8,10 @@
99 /**
1010 * Start point
1111 */
12 -function wfSpecialNewPages( $par ) {
 12+function wfSpecialNewPages( $par, $sp ) {
1313 $page = new NewPagesForm();
1414
15 - $page->showList( $par );
 15+ $page->showList( $par, $sp->including() );
1616 }
1717
1818 /**
@@ -22,16 +22,18 @@
2323 /**
2424 * Show a form for filtering namespace and username
2525 *
 26+ * @param string $par
 27+ * @param bool $including true if the page is being included with {{Special:Newpages}}
2628 * @return string
2729 */
28 - public function showList() {
29 - global $wgScript, $wgContLang, $wgGroupPermissions, $wgRequest, $wgUser, $wgOut;
 30+ public function showList( $par, $including ) {
 31+ global $wgScript, $wgLang, $wgContLang, $wgGroupPermissions, $wgRequest, $wgUser, $wgOut;
3032 $sk = $wgUser->getSkin();
3133 $align = $wgContLang->isRTL() ? 'left' : 'right';
3234 $self = SpecialPage::getTitleFor( 'NewPages' );
3335
3436 // show/hide links
35 - $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ));
 37+ $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
3638
3739 $hidelinks = array();
3840
@@ -55,104 +57,137 @@
5658 $options = $defaults;
5759
5860 // Override all values from requests, if specified
59 - foreach ( $defaults as $v => $t ) {
60 - if ( is_bool($t) ) {
61 - $options[$v] = $wgRequest->getBool( $v, $options[$v] );
62 - } elseif( is_int($t) ) {
63 - $options[$v] = $wgRequest->getInt( $v, $options[$v] );
64 - } elseif( is_string($t) ) {
65 - $options[$v] = $wgRequest->getText( $v, $options[$v] );
66 - }
67 - }
68 -
69 - // hack disable
70 - $options['username'] = '';
 61+ foreach ( $defaults as $v => $t ) {
 62+ if ( is_bool($t) ) {
 63+ $options[$v] = $wgRequest->getBool( $v, $options[$v] );
 64+ } elseif( is_int($t) ) {
 65+ $options[$v] = $wgRequest->getInt( $v, $options[$v] );
 66+ } elseif( is_string($t) ) {
 67+ $options[$v] = $wgRequest->getText( $v, $options[$v] );
 68+ }
 69+ }
7170
72 - $wgOut->setSyndicated( true );
73 - $wgOut->setFeedAppendQuery( "namespace={$options['namespace']}&username={$options['username']}" );
 71+ $shownav = !$including;
 72+ if ( $par ) {
 73+ $bits = preg_split( '/\s*,\s*/', trim( $par ) );
 74+ foreach ( $bits as $bit ) {
 75+ if ( 'shownav' == $bit )
 76+ $shownav = true;
 77+ if ( 'hideliu' === $bit )
 78+ $options['hideliu'] = true;
 79+ if ( 'hidepatrolled' == $bit )
 80+ $options['hidepatrolled'] = true;
 81+ if ( 'hidebots' == $bit )
 82+ $options['hidebots'] = true;
 83+ if ( is_numeric( $bit ) )
 84+ $options['limit'] = intval( $bit );
7485
75 - $feedType = $wgRequest->getVal( 'feed' );
76 - if( $feedType ) {
77 - wfProfileOut( __METHOD__ );
78 - return $this->feed( $feedType, $options );
 86+ $m = array();
 87+ if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
 88+ $options['limit'] = intval($m[1]);
 89+ if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
 90+ $options['offset'] = intval($m[1]);
 91+ if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
 92+ $ns = $wgLang->getNsIndex( $m[1] );
 93+ if( $ns !== false ) {
 94+ $options['namespace'] = $ns;
 95+ }
 96+ }
 97+ }
7998 }
8099
81 - $nondefaults = array();
82 - foreach ( $options as $v => $t ) {
83 - if ( $v === 'offset' ) continue; # Reset offset if parameters change
84 - wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
85 - }
 100+ // hack disable
 101+ $options['username'] = '';
 102+
 103+ if( !$including ){
 104+ $wgOut->setSyndicated( true );
 105+ $wgOut->setFeedAppendQuery( "namespace={$options['namespace']}&username={$options['username']}" );
86106
87 - $links = array();
88 - foreach ( $hidelinks as $key => $msg ) {
89 - $reversed = 1 - $options[$key];
90 - $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
91 - wfArrayToCGI( array( $key => $reversed ), $nondefaults )
92 - );
93 - $links[$key] = wfMsgHtml( $msg, $link );
94 - }
 107+ $feedType = $wgRequest->getVal( 'feed' );
 108+ if( $feedType ) {
 109+ wfProfileOut( __METHOD__ );
 110+ return $this->feed( $feedType, $options );
 111+ }
95112
96 - $hl = implode( ' | ', $links );
 113+ $nondefaults = array();
 114+ foreach ( $options as $v => $t ) {
 115+ if ( $v === 'offset' ) continue; # Reset offset if parameters change
 116+ wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
 117+ }
97118
98 - // Store query values in hidden fields so that form submission doesn't lose them
99 - $hidden = array();
100 - foreach ( $nondefaults as $key => $value ) {
101 - if ( $key === 'namespace' ) continue;
102 - if ( $key === 'username' ) continue;
103 - $hidden[] = Xml::hidden( $key, $value );
104 - }
105 - $hidden = implode( "\n", $hidden );
 119+ $links = array();
 120+ foreach ( $hidelinks as $key => $msg ) {
 121+ $reversed = 1 - $options[$key];
 122+ $link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
 123+ wfArrayToCGI( array( $key => $reversed ), $nondefaults )
 124+ );
 125+ $links[$key] = wfMsgHtml( $msg, $link );
 126+ }
106127
107 - $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
108 - Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
109 - Xml::openElement( 'fieldset' ) .
110 - Xml::element( 'legend', null, wfMsg( 'newpages' ) ) .
111 - Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
112 - "<tr>
113 - <td align=\"$align\">" .
114 - Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
115 - "</td>
116 - <td>" .
117 - Xml::namespaceSelector( $options['namespace'], 'all' ) .
118 - "</td>
119 - </tr>
120 - <!--
121 - <tr>
122 - <td align=\"$align\">" .
123 - Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
124 - "</td>
125 - <td>" .
126 - Xml::input( 'username', 30, $options['username'], array( 'id' => 'mw-np-username' ) ) .
127 - "</td>
128 - </tr>
129 - -->
130 - <tr> <td></td>
131 - <td>" .
132 - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
133 - "</td>
134 - </tr>" .
135 - "<tr>
136 - <td></td>
137 - <td>" .
138 - $hl .
139 - "</td>
140 - </tr>" .
141 - Xml::closeElement( 'table' ) .
142 - Xml::closeElement( 'fieldset' ) .
143 - $hidden .
144 - Xml::closeElement( 'form' );
 128+ $hl = implode( ' | ', $links );
145129
146 - $wgOut->addHTML( $form );
 130+ // Store query values in hidden fields so that form submission doesn't lose them
 131+ $hidden = array();
 132+ foreach ( $nondefaults as $key => $value ) {
 133+ if ( $key === 'namespace' ) continue;
 134+ if ( $key === 'username' ) continue;
 135+ $hidden[] = Xml::hidden( $key, $value );
 136+ }
 137+ $hidden = implode( "\n", $hidden );
147138
 139+ $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
 140+ Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
 141+ Xml::openElement( 'fieldset' ) .
 142+ Xml::element( 'legend', null, wfMsg( 'newpages' ) ) .
 143+ Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
 144+ "<tr>
 145+ <td align=\"$align\">" .
 146+ Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
 147+ "</td>
 148+ <td>" .
 149+ Xml::namespaceSelector( $options['namespace'], 'all' ) .
 150+ "</td>
 151+ </tr>
 152+ <!--
 153+ <tr>
 154+ <td align=\"$align\">" .
 155+ Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
 156+ "</td>
 157+ <td>" .
 158+ Xml::input( 'username', 30, $options['username'], array( 'id' => 'mw-np-username' ) ) .
 159+ "</td>
 160+ </tr>
 161+ -->
 162+ <tr> <td></td>
 163+ <td>" .
 164+ Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
 165+ "</td>
 166+ </tr>" .
 167+ "<tr>
 168+ <td></td>
 169+ <td>" .
 170+ $hl .
 171+ "</td>
 172+ </tr>" .
 173+ Xml::closeElement( 'table' ) .
 174+ Xml::closeElement( 'fieldset' ) .
 175+ $hidden .
 176+ Xml::closeElement( 'form' );
 177+
 178+ $wgOut->addHTML( $form );
 179+ }
 180+
148181 $pager = new NewPagesPager( $this, array(), $options['namespace'], $options['hideliu'],
149182 $options['hidepatrolled'], $options['hidebots'], $options['username'] );
 183+ $pager->mLimit = $options['limit'];
 184+ $pager->mOffset = $options['offset'];
150185
151186 if( $pager->getNumRows() ) {
152 - $wgOut->addHTML( $pager->getNavigationBar() .
 187+ $wgOut->addHTML( ( $shownav ? $pager->getNavigationBar() : '' ) .
153188 $pager->getStartBody() .
154189 $pager->getBody() .
155190 $pager->getEndBody() .
156 - $pager->getNavigationBar() );
 191+ ( $shownav ? $pager->getNavigationBar() : '' ) );
157192 } else {
158193 $wgOut->addHTML( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
159194 }
@@ -289,7 +324,7 @@
290325 * @addtogroup Pager
291326 */
292327 class NewPagesPager extends ReverseChronologicalPager {
293 - private $hideliu, $hidepatrolled, $hidebots, $namespace, $user;
 328+ private $hideliu, $hidepatrolled, $hidebots, $namespace, $user, $spTitle;
294329
295330 function __construct( $form, $conds=array(), $namespace, $hliu=false, $hpatrolled=false, $hbots=1, $user='' ) {
296331 parent::__construct();
@@ -304,6 +339,12 @@
305340 $this->hidebots = (bool)$hbots;
306341 }
307342
 343+ function getTitle(){
 344+ if( !isset( $this->spTitle ) )
 345+ $this->spTitle = SpecialPage::getTitleFor( 'Newpages' );
 346+ return $this->spTitle;
 347+ }
 348+
308349 function getQueryInfo() {
309350 $conds = $this->mConds;
310351 $conds['rc_new'] = 1;
Index: trunk/phase3/RELEASE-NOTES
@@ -185,6 +185,8 @@
186186 * (bug 13727) Don't delete log entries from recentchanges on page deletion
187187 * (bug 13752) Section redirects now works again
188188 * (bug 13725) Upload form watch checkbox state set correctly with wpDestFile
 189+* (bug 13756) Don't show the form and navigation links of Special:Newpages if
 190+ the page is included
189191
190192
191193 === API changes in 1.13 ===

Status & tagging log