class SpecialNewpages extends IncludableSpecialPage {
// Stored objects
- protected $opts, $skin;
+
+ /**
+ * @var FormOptions
+ */
+ protected $opts;
+ protected $customFilters;
// Some internal settings
protected $showNavigation = false;
}
protected function setup( $par ) {
- global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
+ global $wgEnableNewpagesUserFilter;
// Options
$opts = new FormOptions();
$this->opts = $opts; // bind
$opts->add( 'hideliu', false );
- $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
+ $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'newpageshidepatrolled' ) );
$opts->add( 'hidebots', false );
$opts->add( 'hideredirs', true );
- $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
+ $opts->add( 'limit', (int)$this->getUser()->getOption( 'rclimit' ) );
$opts->add( 'offset', '' );
$opts->add( 'namespace', '0' );
$opts->add( 'username', '' );
$opts->add( 'feed', '' );
$opts->add( 'tagfilter', '' );
+ $this->customFilters = array();
+ wfRunHooks( 'SpecialNewPagesFilters', array( $this, &$this->customFilters ) );
+ foreach( $this->customFilters as $key => $params ) {
+ $opts->add( $key, $params['default'] );
+ }
+
// Set values
- $opts->fetchValuesFromRequest( $wgRequest );
+ $opts->fetchValuesFromRequest( $this->getRequest() );
if ( $par ) $this->parseParams( $par );
// Validate
if( !$wgEnableNewpagesUserFilter ) {
$opts->setValue( 'username', '' );
}
-
- // Store some objects
- $this->skin = $wgUser->getSkin();
}
protected function parseParams( $par ) {
- global $wgLang;
$bits = preg_split( '/\s*,\s*/', trim( $par ) );
foreach ( $bits as $bit ) {
if ( 'shownav' == $bit ) {
$this->opts->setValue( 'username', $m[1] );
}
if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
- $ns = $wgLang->getNsIndex( $m[1] );
+ $ns = $this->getLang()->getNsIndex( $m[1] );
if( $ns !== false ) {
$this->opts->setValue( 'namespace', $ns );
}
* @return String
*/
public function execute( $par ) {
- global $wgOut;
+ $out = $this->getOutput();
$this->setHeaders();
$this->outputHeader();
// Settings
$this->form();
- $this->setSyndicated();
$feedType = $this->opts->getValue( 'feed' );
if( $feedType ) {
return $this->feed( $feedType );
}
+
+ $out->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
}
$pager = new NewPagesPager( $this, $this->opts );
if ( $this->showNavigation ) {
$navigation = $pager->getNavigationBar();
}
- $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
+ $out->addHTML( $navigation . $pager->getBody() . $navigation );
} else {
- $wgOut->addWikiMsg( 'specialpage-empty' );
+ $out->addWikiMsg( 'specialpage-empty' );
}
}
protected function filterLinks() {
- global $wgGroupPermissions, $wgUser, $wgLang;
+ global $wgGroupPermissions;
// show/hide links
$showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
'hidebots' => 'rcshowhidebots',
'hideredirs' => 'whatlinkshere-hideredirs'
);
+ foreach ( $this->customFilters as $key => $params ) {
+ $filters[$key] = $params['msg'];
+ }
// Disable some if needed
- # FIXME: throws E_NOTICEs if not set; and doesn't obey hooks etc.
+ # @todo FIXME: Throws E_NOTICEs if not set; and doesn't obey hooks etc.
if ( $wgGroupPermissions['*']['createpage'] !== true ) {
unset( $filters['hideliu'] );
}
-
- if ( !$wgUser->useNPPatrol() ) {
+ if ( !$this->getUser()->useNPPatrol() ) {
unset( $filters['hidepatrolled'] );
}
$self = $this->getTitle();
foreach ( $filters as $key => $msg ) {
$onoff = 1 - $this->opts->getValue( $key );
- $link = $this->skin->link( $self, $showhide[$onoff], array(),
+ $link = Linker::link( $self, $showhide[$onoff], array(),
array( $key => $onoff ) + $changed
);
$links[$key] = wfMsgHtml( $msg, $link );
}
- return $wgLang->pipeList( $links );
+ return $this->getLang()->pipeList( $links );
}
protected function form() {
- global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
+ global $wgEnableNewpagesUserFilter, $wgScript;
// Consume values
$this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW
Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
Xml::fieldset( wfMsg( 'newpages' ) ) .
Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
- "<tr>
- <td class='mw-label'>" .
+ '<tr>
+ <td class="mw-label">' .
Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
- "</td>
- <td class='mw-input'>" .
+ '</td>
+ <td class="mw-input">' .
Xml::namespaceSelector( $namespace, 'all' ) .
- "</td>
- </tr>" . ( $tagFilter ? (
- "<tr>
- <td class='mw-label'>" .
+ '</td>
+ </tr>' . ( $tagFilter ? (
+ '<tr>
+ <td class="mw-label">' .
$tagFilterLabel .
- "</td>
- <td class='mw-input'>" .
+ '</td>
+ <td class="mw-input">' .
$tagFilterSelector .
- "</td>
- </tr>" ) : '' ) .
+ '</td>
+ </tr>' ) : '' ) .
( $wgEnableNewpagesUserFilter ?
- "<tr>
- <td class='mw-label'>" .
+ '<tr>
+ <td class="mw-label">' .
Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
- "</td>
- <td class='mw-input'>" .
+ '</td>
+ <td class="mw-input">' .
Xml::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
- "</td>
- </tr>" : '' ) .
- "<tr> <td></td>
- <td class='mw-submit'>" .
+ '</td>
+ </tr>' : '' ) .
+ '<tr> <td></td>
+ <td class="mw-submit">' .
Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
- "</td>
- </tr>" .
- "<tr>
+ '</td>
+ </tr>' .
+ '<tr>
<td></td>
- <td class='mw-input'>" .
+ <td class="mw-input">' .
$this->filterLinks() .
- "</td>
- </tr>" .
+ '</td>
+ </tr>' .
Xml::closeElement( 'table' ) .
Xml::closeElement( 'fieldset' ) .
$hidden .
Xml::closeElement( 'form' );
- $wgOut->addHTML( $form );
- }
-
- protected function setSyndicated() {
- global $wgOut;
- $wgOut->setSyndicated( true );
- $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
+ $this->getOutput()->addHTML( $form );
}
/**
* @return String
*/
public function formatRow( $result ) {
- global $wgLang, $wgContLang;
+ # Revision deletion works on revisions, so we should cast one
+ $row = array(
+ 'comment' => $result->rc_comment,
+ 'deleted' => $result->rc_deleted,
+ 'user_text' => $result->rc_user_text,
+ 'user' => $result->rc_user,
+ );
+ $rev = new Revision( $row );
$classes = array();
-
- $dm = $wgContLang->getDirMark();
+
+ $lang = $this->getLang();
+ $dm = $lang->getDirMark();
$title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title );
- $time = Html::element( 'span', array( 'class' => 'mw-newpages-time' ),
- $wgLang->timeAndDate( $result->rc_timestamp, true )
+ $spanTime = Html::element( 'span', array( 'class' => 'mw-newpages-time' ),
+ $lang->timeanddate( $result->rc_timestamp, true )
+ );
+ $time = Linker::linkKnown(
+ $title,
+ $spanTime,
+ array(),
+ array( 'oldid' => $result->rc_this_oldid ),
+ array()
);
$query = array( 'redirect' => 'no' );
$query['rcid'] = $result->rc_id;
}
- $plink = $this->skin->linkKnown(
+ $plink = Linker::linkKnown(
$title,
null,
array( 'class' => 'mw-newpages-pagename' ),
$query,
array( 'known' ) // Set explicitly to avoid the default of 'known','noclasses'. This breaks the colouration for stubs
);
- $histLink = $this->skin->linkKnown(
+ $histLink = Linker::linkKnown(
$title,
wfMsgHtml( 'hist' ),
array(),
);
$hist = Html::rawElement( 'span', array( 'class' => 'mw-newpages-history' ), wfMsg( 'parentheses', $histLink ) );
- $length = Html::rawElement( 'span', array( 'class' => 'mw-newpages-length' ),
- '[' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( $result->length ) ) .
- ']'
+ $length = Html::element( 'span', array( 'class' => 'mw-newpages-length' ),
+ '[' . $this->msg( 'nbytes' )->numParams( $result->length )->text() . ']'
);
- $ulink = $this->skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' .
- $this->skin->userToolLinks( $result->rc_user, $result->rc_user_text );
- $comment = $this->skin->commentBlock( $result->rc_comment );
-
+
+ $ulink = Linker::revUserTools( $rev );
+ $comment = Linker::revComment( $rev );
+
if ( $this->patrollable( $result ) ) {
$classes[] = 'not-patrolled';
}
* @return Boolean
*/
protected function patrollable( $result ) {
- global $wgUser;
- return ( $wgUser->useNPPatrol() && !$result->rc_patrolled );
+ return ( $this->getUser()->useNPPatrol() && !$result->rc_patrolled );
}
/**
* @param $type String
*/
protected function feed( $type ) {
- global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgOut;
+ global $wgFeed, $wgFeedClasses, $wgFeedLimit;
if ( !$wgFeed ) {
- $wgOut->addWikiMsg( 'feed-unavailable' );
+ $this->getOutput()->addWikiMsg( 'feed-unavailable' );
return;
}
if( !isset( $wgFeedClasses[$type] ) ) {
- $wgOut->addWikiMsg( 'feed-invalid' );
+ $this->getOutput()->addWikiMsg( 'feed-invalid' );
return;
}
protected function feedTitle() {
global $wgLanguageCode, $wgSitename;
- $page = SpecialPage::getPage( 'Newpages' );
- $desc = $page->getDescription();
+ $desc = $this->getDescription();
return "$wgSitename - $desc [$wgLanguageCode]";
}
$revision = Revision::newFromId( $row->rev_id );
if( $revision ) {
return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
- htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
+ htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
"</p>\n<hr />\n<div>" .
nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
}
*/
class NewPagesPager extends ReverseChronologicalPager {
// Stored opts
- protected $opts, $mForm;
+ protected $opts;
+
+ /**
+ * @var HtmlForm
+ */
+ protected $mForm;
function __construct( $form, FormOptions $opts ) {
- parent::__construct();
+ parent::__construct( $form->getContext() );
$this->mForm = $form;
$this->opts = $opts;
}
- function getTitle() {
- static $title = null;
- if ( $title === null ) {
- $title = $this->mForm->getTitle();
- }
- return $title;
- }
-
function getQueryInfo() {
- global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
+ global $wgEnableNewpagesUserFilter, $wgGroupPermissions;
$conds = array();
$conds['rc_new'] = 1;
$conds['rc_user'] = 0;
}
# If this user cannot see patrolled edits or they are off, don't do dumb queries!
- if( $this->opts->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
+ if( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
$conds['rc_patrolled'] = 0;
}
if( $this->opts->getValue( 'hidebots' ) ) {
if ( $this->opts->getValue( 'hideredirs' ) ) {
$conds['page_is_redirect'] = 0;
}
-
+
// Allow changes to the New Pages query
- wfRunHooks( 'SpecialNewpagesConditions', array( &$this, $this->opts, &$conds ) );
+ $tables = array( 'recentchanges', 'page' );
+ $fields = array(
+ 'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user', 'rc_user_text',
+ 'rc_comment', 'rc_timestamp', 'rc_patrolled','rc_id', 'rc_deleted',
+ 'page_len AS length', 'page_latest AS rev_id', 'ts_tags', 'rc_this_oldid'
+ );
+ $join_conds = array( 'page' => array( 'INNER JOIN', 'page_id=rc_cur_id' ) );
+
+ wfRunHooks( 'SpecialNewpagesConditions',
+ array( &$this, $this->opts, &$conds, &$tables, &$fields, &$join_conds ) );
$info = array(
- 'tables' => array( 'recentchanges', 'page' ),
- 'fields' => array(
- 'rc_namespace', 'rc_title', 'rc_cur_id', 'rc_user',
- 'rc_user_text', 'rc_comment', 'rc_timestamp', 'rc_patrolled',
- 'rc_id', 'page_len AS length', 'page_latest AS rev_id',
- 'ts_tags'
- ),
- 'conds' => $conds,
- 'options' => array( 'USE INDEX' => array( 'recentchanges' => $rcIndexes ) ),
- 'join_conds' => array(
- 'page' => array( 'INNER JOIN', 'page_id=rc_cur_id' ),
- ),
+ 'tables' => $tables,
+ 'fields' => $fields,
+ 'conds' => $conds,
+ 'options' => array( 'USE INDEX' => array( 'recentchanges' => $rcIndexes ) ),
+ 'join_conds' => $join_conds
);
// Empty array for fields, it'll be set by us anyway.