53 parent::__construct( is_string( $dbProvider ) ? $dbProvider :
'Randompage' );
55 wfDeprecated( __METHOD__ .
' without injected services',
'1.41' );
61 : $services->getDBLoadBalancerFactory();
62 $nsInfo ??= $services->getNamespaceInfo();
63 $this->namespaces = $nsInfo->getContentNamespaces();
67 return $this->namespaces;
71 if ( !$this->isValidNS( $ns ) ) {
74 $this->namespaces = [ $ns ];
77 private function isValidNS( $ns ) {
78 return $ns !==
false && $ns >= 0;
87 $this->parsePar( $par );
91 if ( $title ===
null ) {
95 $this->getNsList(), count( $this->namespaces ) );
100 $redirectParam = $this->
isRedirect() ? [
'redirect' =>
'no' ] : [];
101 $query = array_merge( $this->
getRequest()->getValues(), $redirectParam );
102 unset( $query[
'title'] );
103 $this->
getOutput()->redirect( $title->getFullURL( $query ) );
111 private function parsePar( $par ) {
114 if ( is_string( $par ) ) {
116 if ( $ns ===
false && strpos( $par,
',' ) !==
false ) {
119 $parSplit = explode(
',', $par );
120 foreach ( $parSplit as $potentialNs ) {
122 if ( $this->isValidNS( $ns ) ) {
126 $nsList = array_unique( $nsList );
127 $nsList = array_values( $nsList );
128 if ( $nsList !== [] ) {
129 $this->namespaces = $nsList;
148 private function getNsList() {
151 foreach ( $this->namespaces as $n ) {
153 $nsNames[] = $this->
msg(
'blanknamespace' )->plain();
155 $nsNames[] = $contLang->getNsText( $n );
159 return $contLang->commaList( $nsNames );
171 $randstr, $this->isRedir, $this->namespaces,
173 $this->extra, $title )
178 $row = $this->selectRandomPageFromDB( $randstr, __METHOD__ );
188 $row = $this->selectRandomPageFromDB(
"0", __METHOD__ );
192 return Title::makeTitleSafe( $row->page_namespace, $row->page_title );
200 $tables = [
'page' ];
201 $conds = array_merge( [
202 'page_namespace' => $this->namespaces,
203 'page_is_redirect' => $redirect,
204 'page_random >= ' . $randstr
209 $this->
getHookRunner()->onRandomPageQuery( $tables, $conds, $joinConds );
213 'fields' => [
'page_title',
'page_namespace' ],
216 'ORDER BY' =>
'page_random',
219 'join_conds' => $joinConds
223 private function selectRandomPageFromDB( $randstr, $fname = __METHOD__ ) {
224 $dbr = $this->dbProvider->getReplicaDatabase();
236 return $res->fetchObject();
248class_alias( SpecialRandomPage::class,
'RandomPage' );
254class_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 ...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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 name of this Special Page.
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( $dbProvider=null, NamespaceInfo $nsInfo=null)