70 parent::__construct(
'RandomInCategory' );
79 $this->category = $cat;
80 $this->maxTimestamp =
null;
81 $this->minTimestamp =
null;
92 'label-message' =>
'randomincategory-category',
122 $categoryStr = $data[
'category'];
124 if ( $categoryStr ) {
125 $cat = Title::newFromText( $categoryStr,
NS_CATEGORY );
128 if ( $cat && $cat->getNamespace() !==
NS_CATEGORY ) {
130 $cat = Title::makeTitleSafe(
NS_CATEGORY, $categoryStr );
137 if ( !$this->category && $categoryStr ) {
138 $msg = $this->
msg(
'randomincategory-invalidcategory',
141 return Status::newFatal( $msg );
143 } elseif ( !$this->category ) {
150 $msg = $this->
msg(
'randomincategory-nopages',
151 $this->category->getText() );
153 return Status::newFatal( $msg );
157 unset( $query[
'title'] );
172 $offset = mt_rand( 0, $this->maxOffset );
174 if ( mt_rand( 0, 1 ) ) {
198 return Title::makeTitle( $row->page_namespace, $row->page_title );
216 $op = $up ?
'>=' :
'<=';
217 $dir = $up ?
'ASC' :
'DESC';
218 if ( !$this->category instanceof
Title ) {
222 'tables' => [
'categorylinks',
'page' ],
223 'fields' => [
'page_title',
'page_namespace' ],
224 'conds' => array_merge( [
225 'cl_to' => $this->category->getDBkey(),
228 'ORDER BY' =>
'cl_timestamp ' . $dir,
233 'page' => [
'JOIN',
'cl_from = page_id' ]
237 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
240 $qi[
'conds'][] =
'cl_timestamp ' . $op .
' ' .
241 $dbr->addQuotes(
$dbr->timestamp( $minClTime ) );
253 if ( $rand ===
false ) {
256 if ( !$this->minTimestamp || !$this->maxTimestamp ) {
258 list( $this->minTimestamp, $this->maxTimestamp ) = $this->
getMinAndMaxForCat( $this->category );
259 }
catch ( Exception $e ) {
267 return intval( $ts );
278 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
282 'low' =>
'MIN( cl_timestamp )',
283 'high' =>
'MAX( cl_timestamp )'
286 'cl_to' => $this->category->getDBkey(),
305 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
317 return $res->fetchObject();
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
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.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Special page to direct the user to a random page.
setParameter( $par)
Maybe do something interesting with the subpage parameter.
requiresWrite()
Whether this action requires the wiki not to be locked.
getDisplayFormat()
Get display format for the form.
requiresUnblock()
Whether this action cannot be executed by a blocked user.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getRandomTitle()
Choose a random title.
ILoadBalancer $loadBalancer
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
onSubmit(array $data)
Process the form on POST submission.
getMinAndMaxForCat(Title $category)
Get the lowest and highest timestamp for a category.
setCategory(Title $cat)
Set which category to use.
getQueryInfo( $rand, $offset, $up)
selectRandomPageFromDB( $rand, $offset, $up, $fname=__METHOD__)
getTimestampOffset( $rand)
getFormFields()
Get an HTMLForm descriptor array.
__construct(ILoadBalancer $loadBalancer)
Represents a title within MediaWiki.