MediaWiki  REL1_22
SpecialRandomInCategory Class Reference

Special page to direct the user to a random page. More...

Inheritance diagram for SpecialRandomInCategory:
Collaboration diagram for SpecialRandomInCategory:

List of all members.

Public Member Functions

 __construct ($name= 'RandomInCategory')
 execute ($par)
 Default execute method Checks user permissions, calls the function given in mFunction.
 getRandomTitle ()
 Choose a random title.
 setCategory (Title $cat)
 Set which category to use.

Protected Member Functions

 getGroupName ()
 Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-group-*' for valid names This method defaults to group 'other'.
 getMinAndMaxForCat (Title $category)
 Get the lowest and highest timestamp for a category.
 getQueryInfo ($rand, $offset, $up)
 getTimestampOffset ($rand)

Protected Attributes

 $category = false
 $extra = array()
 $maxOffset = 30

Private Member Functions

 selectRandomPageFromDB ($rand, $offset, $up, $fname=__METHOD__)

Private Attributes

 $maxTimestamp = null
 $minTimestamp = null

Detailed Description

Special page to direct the user to a random page.

Note:
The method used here is rather biased. It is assumed that the use of this page will be people wanting to get a random page out of a maintenance category, to fix it up. The method used by this page should return different pages in an unpredictable fashion which is hoped to be sufficient, even if some pages are selected more often than others.

A more unbiased method could be achieved by adding a cl_random field to the categorylinks table.

The method used here is as follows: * Find the smallest and largest timestamp in the category * Pick a random timestamp in between * Pick an offset between 0 and 30 * Get the offset'ed page that is newer than the timestamp selected The offset is meant to counter the fact the timestamps aren't usually uniformly distributed, so if things are very non-uniform at least we won't have the same page selected 99% of the time.

Definition at line 49 of file SpecialRandomInCategory.php.


Constructor & Destructor Documentation

SpecialRandomInCategory::__construct ( name = 'RandomInCategory')

Definition at line 56 of file SpecialRandomInCategory.php.

References $name.


Member Function Documentation

Default execute method Checks user permissions, calls the function given in mFunction.

This must be overridden by subclasses; it will be made abstract in a future version

Parameters:
$subPagestring|null

Reimplemented from SpecialPage.

Definition at line 70 of file SpecialRandomInCategory.php.

References $form, $query, $title, array(), SpecialPage\getOutput(), getRandomTitle(), SpecialPage\getRequest(), SpecialPage\getTitle(), global, Html\hidden(), Html\input(), Title\makeTitleSafe(), SpecialPage\msg(), Title\newFromText(), Html\rawElement(), setCategory(), SpecialPage\setHeaders(), and wfEscapeWikiText().

Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-group-*' for valid names This method defaults to group 'other'.

Returns:
string
Since:
1.21

Reimplemented from SpecialPage.

Definition at line 288 of file SpecialRandomInCategory.php.

Get the lowest and highest timestamp for a category.

Parameters:
Title$category
Returns:
Array The lowest and highest timestamp
Exceptions:
MWExceptionif category has no entries.

Definition at line 243 of file SpecialRandomInCategory.php.

References $dbr, $res, array(), wfGetDB(), and wfTimestamp().

Referenced by getTimestampOffset().

SpecialRandomInCategory::getQueryInfo ( rand,
offset,
up 
) [protected]
Parameters:
float$randRandom number between 0 and 1
int$offsetExtra offset to fudge randomness
bool$upTrue to get the result above the random number, false for below
Note:
The $up parameter is supposed to counteract what would happen if there was a large gap in the distribution of cl_timestamp values. This way instead of things to the right of the gap being favoured, both sides of the gap are favoured.
Returns:
Array Query information.

Definition at line 183 of file SpecialRandomInCategory.php.

References $dbr, $dir, array(), getTimestampOffset(), and wfGetDB().

Referenced by selectRandomPageFromDB().

Choose a random title.

Returns:
Title object (or null if nothing to choose from)

Definition at line 133 of file SpecialRandomInCategory.php.

References $title, Title\makeTitle(), selectRandomPageFromDB(), and wfRandom().

Referenced by execute().

Parameters:
float$randRandom number between 0 and 1
Returns:
int|bool A random (unix) timestamp from the range of the category or false on failure

Definition at line 219 of file SpecialRandomInCategory.php.

References getMinAndMaxForCat(), and list.

Referenced by getQueryInfo().

SpecialRandomInCategory::selectRandomPageFromDB ( rand,
offset,
up,
fname = __METHOD__ 
) [private]
Parameters:
float$randA random number that is converted to a random timestamp
int$offsetA small offset to make the result seem more "random"
bool$upGet the result above the random value
String$fnameThe name of the calling method
Returns:
Array Info for the title selected.

Definition at line 272 of file SpecialRandomInCategory.php.

References $dbr, $fname, $query, $res, getQueryInfo(), and wfGetDB().

Referenced by getRandomTitle().

Set which category to use.

Parameters:
Title$cat

Definition at line 64 of file SpecialRandomInCategory.php.

Referenced by execute().


Member Data Documentation

SpecialRandomInCategory::$category = false [protected]

Definition at line 51 of file SpecialRandomInCategory.php.

SpecialRandomInCategory::$extra = array() [protected]

Definition at line 50 of file SpecialRandomInCategory.php.

SpecialRandomInCategory::$maxOffset = 30 [protected]

Definition at line 52 of file SpecialRandomInCategory.php.

SpecialRandomInCategory::$maxTimestamp = null [private]

Definition at line 53 of file SpecialRandomInCategory.php.

SpecialRandomInCategory::$minTimestamp = null [private]

Definition at line 54 of file SpecialRandomInCategory.php.


The documentation for this class was generated from the following file: