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
This commit is contained in:
Alexandre Emsenhuber 2008-04-15 20:42:42 +00:00
parent 9b0d75f7b5
commit e4aa97a7a2
2 changed files with 132 additions and 89 deletions

View file

@ -185,6 +185,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
* (bug 13727) Don't delete log entries from recentchanges on page deletion
* (bug 13752) Section redirects now works again
* (bug 13725) Upload form watch checkbox state set correctly with wpDestFile
* (bug 13756) Don't show the form and navigation links of Special:Newpages if
the page is included
=== API changes in 1.13 ===

View file

@ -8,10 +8,10 @@
/**
* Start point
*/
function wfSpecialNewPages( $par ) {
function wfSpecialNewPages( $par, $sp ) {
$page = new NewPagesForm();
$page->showList( $par );
$page->showList( $par, $sp->including() );
}
/**
@ -22,16 +22,18 @@ class NewPagesForm {
/**
* Show a form for filtering namespace and username
*
* @param string $par
* @param bool $including true if the page is being included with {{Special:Newpages}}
* @return string
*/
public function showList() {
global $wgScript, $wgContLang, $wgGroupPermissions, $wgRequest, $wgUser, $wgOut;
public function showList( $par, $including ) {
global $wgScript, $wgLang, $wgContLang, $wgGroupPermissions, $wgRequest, $wgUser, $wgOut;
$sk = $wgUser->getSkin();
$align = $wgContLang->isRTL() ? 'left' : 'right';
$self = SpecialPage::getTitleFor( 'NewPages' );
// show/hide links
$showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ));
$showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
$hidelinks = array();
@ -55,104 +57,137 @@ class NewPagesForm {
$options = $defaults;
// Override all values from requests, if specified
foreach ( $defaults as $v => $t ) {
if ( is_bool($t) ) {
$options[$v] = $wgRequest->getBool( $v, $options[$v] );
} elseif( is_int($t) ) {
$options[$v] = $wgRequest->getInt( $v, $options[$v] );
} elseif( is_string($t) ) {
$options[$v] = $wgRequest->getText( $v, $options[$v] );
}
}
// hack disable
$options['username'] = '';
$wgOut->setSyndicated( true );
$wgOut->setFeedAppendQuery( "namespace={$options['namespace']}&username={$options['username']}" );
$feedType = $wgRequest->getVal( 'feed' );
if( $feedType ) {
wfProfileOut( __METHOD__ );
return $this->feed( $feedType, $options );
foreach ( $defaults as $v => $t ) {
if ( is_bool($t) ) {
$options[$v] = $wgRequest->getBool( $v, $options[$v] );
} elseif( is_int($t) ) {
$options[$v] = $wgRequest->getInt( $v, $options[$v] );
} elseif( is_string($t) ) {
$options[$v] = $wgRequest->getText( $v, $options[$v] );
}
}
$nondefaults = array();
foreach ( $options as $v => $t ) {
if ( $v === 'offset' ) continue; # Reset offset if parameters change
wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
}
$shownav = !$including;
if ( $par ) {
$bits = preg_split( '/\s*,\s*/', trim( $par ) );
foreach ( $bits as $bit ) {
if ( 'shownav' == $bit )
$shownav = true;
if ( 'hideliu' === $bit )
$options['hideliu'] = true;
if ( 'hidepatrolled' == $bit )
$options['hidepatrolled'] = true;
if ( 'hidebots' == $bit )
$options['hidebots'] = true;
if ( is_numeric( $bit ) )
$options['limit'] = intval( $bit );
$links = array();
foreach ( $hidelinks as $key => $msg ) {
$reversed = 1 - $options[$key];
$link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
wfArrayToCGI( array( $key => $reversed ), $nondefaults )
);
$links[$key] = wfMsgHtml( $msg, $link );
$m = array();
if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
$options['limit'] = intval($m[1]);
if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
$options['offset'] = intval($m[1]);
if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
$ns = $wgLang->getNsIndex( $m[1] );
if( $ns !== false ) {
$options['namespace'] = $ns;
}
}
}
}
$hl = implode( ' | ', $links );
// hack disable
$options['username'] = '';
if( !$including ){
$wgOut->setSyndicated( true );
$wgOut->setFeedAppendQuery( "namespace={$options['namespace']}&username={$options['username']}" );
// Store query values in hidden fields so that form submission doesn't lose them
$hidden = array();
foreach ( $nondefaults as $key => $value ) {
if ( $key === 'namespace' ) continue;
if ( $key === 'username' ) continue;
$hidden[] = Xml::hidden( $key, $value );
$feedType = $wgRequest->getVal( 'feed' );
if( $feedType ) {
wfProfileOut( __METHOD__ );
return $this->feed( $feedType, $options );
}
$nondefaults = array();
foreach ( $options as $v => $t ) {
if ( $v === 'offset' ) continue; # Reset offset if parameters change
wfAppendToArrayIfNotDefault( $v, $t, $defaults, $nondefaults );
}
$links = array();
foreach ( $hidelinks as $key => $msg ) {
$reversed = 1 - $options[$key];
$link = $sk->makeKnownLinkObj( $self, $showhide[$reversed],
wfArrayToCGI( array( $key => $reversed ), $nondefaults )
);
$links[$key] = wfMsgHtml( $msg, $link );
}
$hl = implode( ' | ', $links );
// Store query values in hidden fields so that form submission doesn't lose them
$hidden = array();
foreach ( $nondefaults as $key => $value ) {
if ( $key === 'namespace' ) continue;
if ( $key === 'username' ) continue;
$hidden[] = Xml::hidden( $key, $value );
}
$hidden = implode( "\n", $hidden );
$form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', null, wfMsg( 'newpages' ) ) .
Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
"<tr>
<td align=\"$align\">" .
Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
"</td>
<td>" .
Xml::namespaceSelector( $options['namespace'], 'all' ) .
"</td>
</tr>
<!--
<tr>
<td align=\"$align\">" .
Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
"</td>
<td>" .
Xml::input( 'username', 30, $options['username'], array( 'id' => 'mw-np-username' ) ) .
"</td>
</tr>
-->
<tr> <td></td>
<td>" .
Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
"</td>
</tr>" .
"<tr>
<td></td>
<td>" .
$hl .
"</td>
</tr>" .
Xml::closeElement( 'table' ) .
Xml::closeElement( 'fieldset' ) .
$hidden .
Xml::closeElement( 'form' );
$wgOut->addHTML( $form );
}
$hidden = implode( "\n", $hidden );
$form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
Xml::hidden( 'title', $self->getPrefixedDBkey() ) .
Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', null, wfMsg( 'newpages' ) ) .
Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
"<tr>
<td align=\"$align\">" .
Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
"</td>
<td>" .
Xml::namespaceSelector( $options['namespace'], 'all' ) .
"</td>
</tr>
<!--
<tr>
<td align=\"$align\">" .
Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
"</td>
<td>" .
Xml::input( 'username', 30, $options['username'], array( 'id' => 'mw-np-username' ) ) .
"</td>
</tr>
-->
<tr> <td></td>
<td>" .
Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
"</td>
</tr>" .
"<tr>
<td></td>
<td>" .
$hl .
"</td>
</tr>" .
Xml::closeElement( 'table' ) .
Xml::closeElement( 'fieldset' ) .
$hidden .
Xml::closeElement( 'form' );
$wgOut->addHTML( $form );
$pager = new NewPagesPager( $this, array(), $options['namespace'], $options['hideliu'],
$options['hidepatrolled'], $options['hidebots'], $options['username'] );
$pager->mLimit = $options['limit'];
$pager->mOffset = $options['offset'];
if( $pager->getNumRows() ) {
$wgOut->addHTML( $pager->getNavigationBar() .
$wgOut->addHTML( ( $shownav ? $pager->getNavigationBar() : '' ) .
$pager->getStartBody() .
$pager->getBody() .
$pager->getEndBody() .
$pager->getNavigationBar() );
( $shownav ? $pager->getNavigationBar() : '' ) );
} else {
$wgOut->addHTML( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
}
@ -289,7 +324,7 @@ class NewPagesForm {
* @addtogroup Pager
*/
class NewPagesPager extends ReverseChronologicalPager {
private $hideliu, $hidepatrolled, $hidebots, $namespace, $user;
private $hideliu, $hidepatrolled, $hidebots, $namespace, $user, $spTitle;
function __construct( $form, $conds=array(), $namespace, $hliu=false, $hpatrolled=false, $hbots=1, $user='' ) {
parent::__construct();
@ -304,6 +339,12 @@ class NewPagesPager extends ReverseChronologicalPager {
$this->hidebots = (bool)$hbots;
}
function getTitle(){
if( !isset( $this->spTitle ) )
$this->spTitle = SpecialPage::getTitleFor( 'Newpages' );
return $this->spTitle;
}
function getQueryInfo() {
$conds = $this->mConds;
$conds['rc_new'] = 1;