49 parent::__construct(
'Randompage' );
50 $this->dbProvider = $dbProvider;
55 return $this->namespaces;
59 if ( !$this->isValidNS( $ns ) ) {
62 $this->namespaces = [ $ns ];
65 private function isValidNS( $ns ) {
66 return $ns !==
false && $ns >= 0;
75 $this->parsePar( $par );
79 if ( $title ===
null ) {
83 $this->getNsList(), count( $this->namespaces ) );
88 $redirectParam = $this->
isRedirect() ? [
'redirect' =>
'no' ] : [];
89 $query = array_merge( $this->
getRequest()->getValues(), $redirectParam );
90 unset( $query[
'title'] );
91 $this->
getOutput()->redirect( $title->getFullURL( $query ) );
99 private function parsePar( $par ) {
102 if ( is_string( $par ) ) {
104 if ( $ns ===
false && strpos( $par,
',' ) !==
false ) {
107 $parSplit = explode(
',', $par );
108 foreach ( $parSplit as $potentialNs ) {
110 if ( $this->isValidNS( $ns ) ) {
114 $nsList = array_unique( $nsList );
115 $nsList = array_values( $nsList );
116 if ( $nsList !== [] ) {
117 $this->namespaces = $nsList;
136 private function getNsList() {
139 foreach ( $this->namespaces as $n ) {
141 $nsNames[] = $this->
msg(
'blanknamespace' )->plain();
143 $nsNames[] = $contLang->getNsText( $n );
147 return $contLang->commaList( $nsNames );
159 $randstr, $this->isRedir, $this->namespaces,
161 $this->extra, $title )
166 $row = $this->selectRandomPageFromDB( $randstr, __METHOD__ );
176 $row = $this->selectRandomPageFromDB( 0, __METHOD__ );
180 return Title::makeTitleSafe( $row->page_namespace, $row->page_title );
187 $dbr = $this->dbProvider->getReplicaDatabase();
189 $tables = [
'page' ];
190 $conds = array_merge( [
191 'page_namespace' => $this->namespaces,
192 'page_is_redirect' => $redirect,
193 $dbr->expr(
'page_random',
'>=', $randstr ),
198 $this->
getHookRunner()->onRandomPageQuery( $tables, $conds, $joinConds );
202 'fields' => [
'page_title',
'page_namespace' ],
205 'ORDER BY' =>
'page_random',
208 'join_conds' => $joinConds
212 private function selectRandomPageFromDB( $randstr, $fname = __METHOD__ ) {
213 $dbr = $this->dbProvider->getReplicaDatabase();
216 return $dbr->newSelectQueryBuilder()
217 ->queryInfo( $query )
231class_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.
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)