52 parent::__construct(
'Randompage' );
53 $this->dbProvider = $dbProvider;
58 return $this->namespaces;
62 if ( !$this->isValidNS( $ns ) ) {
65 $this->namespaces = [ $ns ];
68 private function isValidNS( $ns ) {
69 return $ns !==
false && $ns >= 0;
78 $this->parsePar( $par );
82 if ( $title ===
null ) {
86 $this->getNsList(), count( $this->namespaces ) );
91 $redirectParam = $this->
isRedirect() ? [
'redirect' =>
'no' ] : [];
92 $query = array_merge( $this->
getRequest()->getQueryValues(), $redirectParam );
93 unset( $query[
'title'] );
94 $this->
getOutput()->redirect( $title->getFullURL( $query ) );
102 private function parsePar( $par ) {
105 if ( is_string( $par ) ) {
107 if ( $ns ===
false && strpos( $par,
',' ) !==
false ) {
110 $parSplit = explode(
',', $par );
111 foreach ( $parSplit as $potentialNs ) {
113 if ( $this->isValidNS( $ns ) ) {
117 $nsList = array_unique( $nsList );
118 $nsList = array_values( $nsList );
119 if ( $nsList !== [] ) {
120 $this->namespaces = $nsList;
139 private function getNsList() {
142 foreach ( $this->namespaces as $n ) {
144 $nsNames[] = $this->
msg(
'blanknamespace' )->plain();
146 $nsNames[] = $contLang->getNsText( $n );
150 return $contLang->commaList( $nsNames );
162 $randstr, $this->isRedir, $this->namespaces,
164 $this->extra, $title )
169 $row = $this->selectRandomPageFromDB( $randstr, __METHOD__ );
179 $row = $this->selectRandomPageFromDB( 0, __METHOD__ );
183 return Title::makeTitleSafe( $row->page_namespace, $row->page_title );
190 $dbr = $this->dbProvider->getReplicaDatabase();
192 $tables = [
'page' ];
193 $conds = array_merge( [
194 'page_namespace' => $this->namespaces,
195 'page_is_redirect' => $redirect,
196 $dbr->expr(
'page_random',
'>=', $randstr ),
201 $this->
getHookRunner()->onRandomPageQuery( $tables, $conds, $joinConds );
205 'fields' => [
'page_title',
'page_namespace' ],
208 'ORDER BY' =>
'page_random',
211 'join_conds' => $joinConds
215 private function selectRandomPageFromDB( $randstr, $fname ) {
216 $dbr = $this->dbProvider->getReplicaDatabase();
219 return $dbr->newSelectQueryBuilder()
220 ->queryInfo( $query )
234class_alias( SpecialRandomPage::class,
'SpecialRandomPage' );
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getContentLanguage()
Shortcut to get content language.
getName()
Get the canonical, unlocalized name of this special page without namespace.
Redirect to a random page.
array $extra
Extra SQL statements.
execute( $par)
Default execute method Checks user permissions.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getRandomTitle()
Choose a random title.
__construct(IConnectionProvider $dbProvider, NamespaceInfo $nsInfo)
bool $isRedir
should the result be a redirect?