protected $extra = array(); // Extra SQL statements
public function __construct( $name = 'Randompage' ){
- global $wgContentNamespaces;
- $this->namespaces = $wgContentNamespaces;
+ $this->namespaces = MWNamespace::getContentNamespaces();
parent::__construct( $name );
}
}
public function execute( $par ) {
- global $wgOut, $wgContLang, $wgRequest;
+ global $wgContLang;
- if ($par) {
+ if ( $par ) {
$this->setNamespace( $wgContLang->getNsIndex( $par ) );
}
if( is_null( $title ) ) {
$this->setHeaders();
- $wgOut->addWikiMsg( strtolower( $this->mName ) . '-nopages',
+ $this->getOutput()->addWikiMsg( strtolower( $this->getName() ) . '-nopages',
$this->getNsList(), count( $this->namespaces ) );
return;
}
$redirectParam = $this->isRedirect() ? array( 'redirect' => 'no' ) : array();
- $query = array_merge( $wgRequest->getValues(), $redirectParam );
+ $query = array_merge( $this->getRequest()->getValues(), $redirectParam );
unset( $query['title'] );
- $wgOut->redirect( $title->getFullUrl( $query ) );
+ $this->getOutput()->redirect( $title->getFullUrl( $query ) );
}
/**
$nsNames = array();
foreach( $this->namespaces as $n ) {
if( $n === NS_MAIN ) {
- $nsNames[] = wfMsgForContent( 'blanknamespace' );
+ $nsNames[] = $this->msg( 'blanknamespace' )->plain();
} else {
$nsNames[] = $wgContLang->getNsText( $n );
}
return $wgContLang->commaList( $nsNames );
}
-
/**
* Choose a random title.
* @return Title object (or null if nothing to choose from)
}
}
- private function selectRandomPageFromDB( $randstr ) {
- global $wgExtraRandompageSQL;
- $dbr = wfGetDB( DB_SLAVE );
-
+ protected function getQueryInfo( $randstr ) {
$redirect = $this->isRedirect() ? 1 : 0;
-
- if ( $wgExtraRandompageSQL ) {
- $this->extra[] = $wgExtraRandompageSQL;
- }
- if ( $this->addExtraSQL() ) {
- $this->extra[] = $this->addExtraSQL();
- }
- $res = $dbr->doQuery(
- 'page',
- array( 'page_title', 'page_namespace' ),
- array_merge( array(
+ return array(
+ 'tables' => array( 'page' ),
+ 'fields' => array( 'page_title', 'page_namespace' ),
+ 'conds' => array_merge( array(
'page_namespace' => $this->namespaces,
'page_is_redirect' => $redirect,
'page_random >= ' . $randstr
), $this->extra ),
- __METHOD__,
- array(
+ 'options' => array(
'ORDER BY' => 'page_random',
- 'USE INDEX' => 'page_random'
- )
+ 'USE INDEX' => 'page_random',
+ 'LIMIT' => 1,
+ ),
+ 'join_conds' => array()
);
-
- return $dbr->fetchObject( $res );
}
- /* an alternative to $wgExtraRandompageSQL so subclasses
- * can add their own SQL by overriding this function
- * @deprecated, append to $this->extra instead
- */
- public function addExtraSQL() {
- return '';
+ private function selectRandomPageFromDB( $randstr, $fname = __METHOD__ ) {
+ $dbr = wfGetDB( DB_SLAVE );
+
+ $query = $this->getQueryInfo( $randstr );
+ $res = $dbr->select(
+ $query['tables'],
+ $query['fields'],
+ $query['conds'],
+ $fname,
+ $query['options'],
+ $query['join_conds']
+ );
+
+ return $dbr->fetchObject( $res );
}
}