62 parent::__construct( $name );
70 $this->category = $cat;
71 $this->maxTimestamp =
null;
72 $this->minTimestamp =
null;
83 'label-message' =>
'randomincategory-category',
102 $form->setSubmitTextMsg(
'randomincategory-submit' );
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 ) {
140 if ( is_null( $title ) ) {
141 $msg = $this->
msg(
'randomincategory-nopages',
142 $this->category->getText() );
144 return Status::newFatal( $msg );
147 $this->
getOutput()->redirect( $title->getFullURL() );
161 $offset = mt_rand( 0, $this->maxOffset );
163 if ( mt_rand( 0, 1 ) ) {
187 return Title::makeTitle( $row->page_namespace, $row->page_title );
205 $op = $up ?
'>=' :
'<=';
206 $dir = $up ?
'ASC' :
'DESC';
207 if ( !$this->category instanceof
Title ) {
211 'tables' => [
'categorylinks',
'page' ],
212 'fields' => [
'page_title',
'page_namespace' ],
213 'conds' => array_merge( [
214 'cl_to' => $this->category->getDBkey(),
217 'ORDER BY' =>
'cl_timestamp ' . $dir,
222 'page' => [
'INNER JOIN',
'cl_from = page_id' ]
229 $qi[
'conds'][] =
'cl_timestamp ' . $op .
' ' .
230 $dbr->addQuotes(
$dbr->timestamp( $minClTime ) );
242 if ( $rand ===
false ) {
245 if ( !$this->minTimestamp || !$this->maxTimestamp ) {
248 }
catch ( Exception
$e ) {
256 return intval( $ts );
271 'low' =>
'MIN( cl_timestamp )',
272 'high' =>
'MAX( cl_timestamp )'
275 'cl_to' => $this->category->getDBkey(),
309 return $res->fetchObject();
wfRandom()
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
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,...
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Special page which uses an HTMLForm to handle processing.
string $par
The sub-page of the special page.
getOutput()
Get the OutputPage being used for this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
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.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
returning false will NOT prevent logging $e
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))