Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -1376,6 +1376,15 @@ |
1377 | 1377 | hook to remove a core special page |
1378 | 1378 | $list: list (array) of core special pages |
1379 | 1379 | |
| 1380 | +'SpecialRandomGetRandomTitle': called during the execution of Special:Random, |
| 1381 | +use this to change some selection criteria or substitute a different title |
| 1382 | +&$randstr: The random number from wfRandom() |
| 1383 | +&$isRedir: Boolean, whether to select a redirect or non-redirect |
| 1384 | +&$namespaces: An array of namespace indexes to get the title from |
| 1385 | +&$extra: An array of extra SQL statements |
| 1386 | +&$title: If the hook returns false, a Title object to use instead of the |
| 1387 | +result from the normal query |
| 1388 | + |
1380 | 1389 | 'SpecialRecentChangesPanel': called when building form options in |
1381 | 1390 | SpecialRecentChanges |
1382 | 1391 | &$extraOpts: array of added items, to which can be added |
Index: trunk/phase3/includes/specials/SpecialRandomredirect.php |
— | — | @@ -10,10 +10,7 @@ |
11 | 11 | class SpecialRandomredirect extends RandomPage { |
12 | 12 | function __construct(){ |
13 | 13 | parent::__construct( 'Randomredirect' ); |
| 14 | + $this->isRedir = true; |
14 | 15 | } |
15 | 16 | |
16 | | - // Override parent::isRedirect() |
17 | | - public function isRedirect(){ |
18 | | - return true; |
19 | | - } |
20 | 17 | } |
Index: trunk/phase3/includes/specials/SpecialRandompage.php |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | */ |
11 | 11 | class RandomPage extends SpecialPage { |
12 | 12 | private $namespaces; // namespaces to select pages from |
| 13 | + protected $isRedir = false; // should the result be a redirect? |
| 14 | + protected $extra = array(); // Extra SQL statements |
13 | 15 | |
14 | 16 | public function __construct( $name = 'Randompage' ){ |
15 | 17 | global $wgContentNamespaces; |
— | — | @@ -26,9 +28,8 @@ |
27 | 29 | } |
28 | 30 | |
29 | 31 | // select redirects instead of normal pages? |
30 | | - // Overriden by SpecialRandomredirect |
31 | 32 | public function isRedirect(){ |
32 | | - return false; |
| 33 | + return $this->isRedir; |
33 | 34 | } |
34 | 35 | |
35 | 36 | public function execute( $par ) { |
— | — | @@ -75,6 +76,10 @@ |
76 | 77 | */ |
77 | 78 | public function getRandomTitle() { |
78 | 79 | $randstr = wfRandom(); |
| 80 | + $title = null; |
| 81 | + if ( !wfRunHooks( 'SpecialRandomGetRandomTitle', array( &$randstr, &$this->isRedir, &$this->namespaces, &$this->extra, &$title ) ) ) { |
| 82 | + return $title; |
| 83 | + } |
79 | 84 | $row = $this->selectRandomPageFromDB( $randstr ); |
80 | 85 | |
81 | 86 | /* If we picked a value that was higher than any in |
— | — | @@ -102,9 +107,17 @@ |
103 | 108 | |
104 | 109 | $ns = implode( ",", $this->namespaces ); |
105 | 110 | $redirect = $this->isRedirect() ? 1 : 0; |
106 | | - |
107 | | - $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ""; |
108 | | - $extra .= $this->addExtraSQL() ? "AND (".$this->addExtraSQL().")" : ""; |
| 111 | + |
| 112 | + if ( $wgExtraRandompageSQL ) { |
| 113 | + $this->extra[] = $wgExtraRandompageSQL; |
| 114 | + } |
| 115 | + if ( $this->addExtraSQL() ) { |
| 116 | + $this->extra[] = $this->addExtraSQL(); |
| 117 | + } |
| 118 | + $extra = ''; |
| 119 | + if ( $this->extra ) { |
| 120 | + $extra = 'AND (' . implode( ') AND (', $this->extra ) . ')'; |
| 121 | + } |
109 | 122 | $sql = "SELECT page_title, page_namespace |
110 | 123 | FROM $page $use_index |
111 | 124 | WHERE page_namespace IN ( $ns ) |
— | — | @@ -118,8 +131,10 @@ |
119 | 132 | return $dbr->fetchObject( $res ); |
120 | 133 | } |
121 | 134 | |
122 | | - // an alternative to $wgExtraRandompageSQL so extensions |
123 | | - // can add their own SQL by overriding this function |
| 135 | + /* an alternative to $wgExtraRandompageSQL so subclasses |
| 136 | + * can add their own SQL by overriding this function |
| 137 | + * @deprecated, append to $this->extra instead |
| 138 | + */ |
124 | 139 | public function addExtraSQL() { |
125 | 140 | return ''; |
126 | 141 | } |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2820,7 +2820,11 @@ |
2821 | 2821 | /** Use the site's Cascading Style Sheets (CSS)? */ |
2822 | 2822 | $wgUseSiteCss = true; |
2823 | 2823 | |
2824 | | -/** Filter for Special:Randompage. Part of a WHERE clause */ |
| 2824 | +/** |
| 2825 | + * Filter for Special:Randompage. Part of a WHERE clause |
| 2826 | + * @deprecated as of 1.16, use the SpecialRandomGetRandomTitle hook |
| 2827 | +*/ |
| 2828 | + |
2825 | 2829 | $wgExtraRandompageSQL = false; |
2826 | 2830 | |
2827 | 2831 | /** Allow the "info" action, very inefficient at the moment */ |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -79,6 +79,8 @@ |
80 | 80 | to control which external domains may access the API via cross-site AJAX. |
81 | 81 | * $wgMaintenanceScripts for extensions to add their scripts to the default list |
82 | 82 | * $wgMemoryLimit has been added, default value '50M' |
| 83 | +* $wgExtraRandompageSQL is deprecated, the SpecialRandomGetRandomTitle hook |
| 84 | + should be used instead |
83 | 85 | |
84 | 86 | === New features in 1.16 === |
85 | 87 | |
— | — | @@ -195,6 +197,9 @@ |
196 | 198 | output by omitting some things like quotation marks where HTML 5 allows. |
197 | 199 | * Added crop for inline images. |
198 | 200 | * The description message in $wgExtensionCredits can be an array with parameters |
| 201 | +* New hook SpecialRandomGetRandomTitle allows extensions to modify the selection |
| 202 | + criteria used by Special:Random and subclasses, or substitute a custom result, |
| 203 | + deprecating the $wgExtraRandompageSQL config variable |
199 | 204 | |
200 | 205 | === Bug fixes in 1.16 === |
201 | 206 | |