40 private $loadBalancer;
50 parent::__construct( is_string( $loadBalancer ) ? $loadBalancer :
'Randompage' );
52 $services = MediaWikiServices::getInstance();
55 : $services->getDBLoadBalancer();
56 $nsInfo ??= $services->getNamespaceInfo();
57 $this->namespaces = $nsInfo->getContentNamespaces();
61 return $this->namespaces;
68 $this->namespaces = [ $ns ];
77 if ( is_string( $par ) ) {
89 $this->getNsList(), count( $this->namespaces ) );
94 $redirectParam = $this->
isRedirect() ? [
'redirect' =>
'no' ] : [];
95 $query = array_merge( $this->
getRequest()->getValues(), $redirectParam );
96 unset( $query[
'title'] );
105 private function getNsList() {
108 foreach ( $this->namespaces as $n ) {
110 $nsNames[] = $this->
msg(
'blanknamespace' )->plain();
112 $nsNames[] = $contLang->getNsText( $n );
116 return $contLang->commaList( $nsNames );
128 $randstr, $this->isRedir, $this->namespaces,
135 $row = $this->selectRandomPageFromDB( $randstr, __METHOD__ );
145 $row = $this->selectRandomPageFromDB(
"0", __METHOD__ );
149 return Title::makeTitleSafe( $row->page_namespace, $row->page_title );
157 $tables = [
'page' ];
158 $conds = array_merge( [
159 'page_namespace' => $this->namespaces,
160 'page_is_redirect' => $redirect,
161 'page_random >= ' . $randstr
166 $this->
getHookRunner()->onRandomPageQuery( $tables, $conds, $joinConds );
170 'fields' => [
'page_title',
'page_namespace' ],
173 'ORDER BY' =>
'page_random',
176 'join_conds' => $joinConds
180 private function selectRandomPageFromDB( $randstr, $fname = __METHOD__ ) {
193 return $res->fetchObject();
205 class_alias( SpecialRandomPage::class,
'RandomPage' );
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Parent class for all special pages.
getName()
Get the name of this Special Page.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
getContentLanguage()
Shortcut to get content language.
Special page to direct the user to a random page.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Default execute method Checks user permissions.
getRandomTitle()
Choose a random title.
__construct( $loadBalancer=null, NamespaceInfo $nsInfo=null)