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()->getValues(), $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 );
191 $tables = [
'page' ];
192 $conds = array_merge( [
193 'page_namespace' => $this->namespaces,
194 'page_is_redirect' => $redirect,
195 'page_random >= ' . $randstr
200 $this->
getHookRunner()->onRandomPageQuery( $tables, $conds, $joinConds );
204 'fields' => [
'page_title',
'page_namespace' ],
207 'ORDER BY' =>
'page_random',
210 'join_conds' => $joinConds
214 private function selectRandomPageFromDB( $randstr, $fname = __METHOD__ ) {
215 $dbr = $this->dbProvider->getReplicaDatabase();
227 return $res->fetchObject();
239class_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.
Special page to direct the user 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)