62 parent::__construct( $name );
70 $this->category = $cat;
71 $this->maxTimestamp =
null;
72 $this->minTimestamp =
null;
83 'label-message' =>
'randomincategory-category',
113 $categoryStr = $data[
'category'];
115 if ( $categoryStr ) {
116 $cat = Title::newFromText( $categoryStr,
NS_CATEGORY );
119 if ( $cat && $cat->getNamespace() !==
NS_CATEGORY ) {
121 $cat = Title::makeTitleSafe(
NS_CATEGORY, $categoryStr );
128 if ( !$this->category && $categoryStr ) {
129 $msg = $this->
msg(
'randomincategory-invalidcategory',
132 return Status::newFatal( $msg );
134 } elseif ( !$this->category ) {
141 $msg = $this->
msg(
'randomincategory-nopages',
142 $this->category->getText() );
144 return Status::newFatal( $msg );
148 unset( $query[
'title'] );
163 $offset = mt_rand( 0, $this->maxOffset );
165 if ( mt_rand( 0, 1 ) ) {
189 return Title::makeTitle( $row->page_namespace, $row->page_title );
207 $op = $up ?
'>=' :
'<=';
208 $dir = $up ?
'ASC' :
'DESC';
209 if ( !$this->category instanceof
Title ) {
213 'tables' => [
'categorylinks',
'page' ],
214 'fields' => [
'page_title',
'page_namespace' ],
215 'conds' => array_merge( [
216 'cl_to' => $this->category->getDBkey(),
219 'ORDER BY' =>
'cl_timestamp ' . $dir,
224 'page' => [
'JOIN',
'cl_from = page_id' ]
231 $qi[
'conds'][] =
'cl_timestamp ' . $op .
' ' .
232 $dbr->addQuotes(
$dbr->timestamp( $minClTime ) );
244 if ( $rand ===
false ) {
247 if ( !$this->minTimestamp || !$this->maxTimestamp ) {
249 list( $this->minTimestamp, $this->maxTimestamp ) = $this->
getMinAndMaxForCat( $this->category );
250 }
catch ( Exception $e ) {
258 return intval( $ts );
273 'low' =>
'MIN( cl_timestamp )',
274 'high' =>
'MAX( cl_timestamp )'
277 'cl_to' => $this->category->getDBkey(),
311 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 ...
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.
__construct( $name='RandomInCategory')
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.
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.
Represents a title within MediaWiki.