39 private $loadBalancer;
49 parent::__construct( is_string( $loadBalancer ) ? $loadBalancer :
'Randompage' );
51 $services = MediaWikiServices::getInstance();
54 : $services->getDBLoadBalancer();
55 $nsInfo = $nsInfo ?? $services->getNamespaceInfo();
56 $this->namespaces = $nsInfo->getContentNamespaces();
60 return $this->namespaces;
67 $this->namespaces = [ $ns ];
76 if ( is_string( $par ) ) {
88 $this->getNsList(), count( $this->namespaces ) );
93 $redirectParam = $this->
isRedirect() ? [
'redirect' =>
'no' ] : [];
94 $query = array_merge( $this->
getRequest()->getValues(), $redirectParam );
95 unset( $query[
'title'] );
104 private function getNsList() {
107 foreach ( $this->namespaces as $n ) {
109 $nsNames[] = $this->
msg(
'blanknamespace' )->plain();
111 $nsNames[] = $contLang->getNsText( $n );
115 return $contLang->commaList( $nsNames );
127 $randstr, $this->isRedir, $this->namespaces,
134 $row = $this->selectRandomPageFromDB( $randstr, __METHOD__ );
144 $row = $this->selectRandomPageFromDB(
"0", __METHOD__ );
148 return Title::makeTitleSafe( $row->page_namespace, $row->page_title );
156 $tables = [
'page' ];
157 $conds = array_merge( [
158 'page_namespace' => $this->namespaces,
159 'page_is_redirect' => $redirect,
160 'page_random >= ' . $randstr
165 $this->
getHookRunner()->onRandomPageQuery( $tables, $conds, $joinConds );
169 'fields' => [
'page_title',
'page_namespace' ],
172 'ORDER BY' =>
'page_random',
175 'join_conds' => $joinConds
179 private function selectRandomPageFromDB( $randstr, $fname = __METHOD__ ) {
180 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
192 return $res->fetchObject();
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.
__construct( $loadBalancer=null, NamespaceInfo $nsInfo=null)