r55188 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55187‎ | r55188 | r55189 >
Date:15:23, 17 August 2009
Author:mrzman
Status:ok (Comments)
Tags:
Comment:
Re-implement r54638 in a higher-level way. Allows extensions to modify selection criteria for Special:Random or subsititute their own result.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRandompage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRandomredirect.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1376,6 +1376,15 @@
13771377 hook to remove a core special page
13781378 $list: list (array) of core special pages
13791379
 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+
13801389 'SpecialRecentChangesPanel': called when building form options in
13811390 SpecialRecentChanges
13821391 &$extraOpts: array of added items, to which can be added
Index: trunk/phase3/includes/specials/SpecialRandomredirect.php
@@ -10,10 +10,7 @@
1111 class SpecialRandomredirect extends RandomPage {
1212 function __construct(){
1313 parent::__construct( 'Randomredirect' );
 14+ $this->isRedir = true;
1415 }
1516
16 - // Override parent::isRedirect()
17 - public function isRedirect(){
18 - return true;
19 - }
2017 }
Index: trunk/phase3/includes/specials/SpecialRandompage.php
@@ -9,6 +9,8 @@
1010 */
1111 class RandomPage extends SpecialPage {
1212 private $namespaces; // namespaces to select pages from
 13+ protected $isRedir = false; // should the result be a redirect?
 14+ protected $extra = array(); // Extra SQL statements
1315
1416 public function __construct( $name = 'Randompage' ){
1517 global $wgContentNamespaces;
@@ -26,9 +28,8 @@
2729 }
2830
2931 // select redirects instead of normal pages?
30 - // Overriden by SpecialRandomredirect
3132 public function isRedirect(){
32 - return false;
 33+ return $this->isRedir;
3334 }
3435
3536 public function execute( $par ) {
@@ -75,6 +76,10 @@
7677 */
7778 public function getRandomTitle() {
7879 $randstr = wfRandom();
 80+ $title = null;
 81+ if ( !wfRunHooks( 'SpecialRandomGetRandomTitle', array( &$randstr, &$this->isRedir, &$this->namespaces, &$this->extra, &$title ) ) ) {
 82+ return $title;
 83+ }
7984 $row = $this->selectRandomPageFromDB( $randstr );
8085
8186 /* If we picked a value that was higher than any in
@@ -102,9 +107,17 @@
103108
104109 $ns = implode( ",", $this->namespaces );
105110 $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+ }
109122 $sql = "SELECT page_title, page_namespace
110123 FROM $page $use_index
111124 WHERE page_namespace IN ( $ns )
@@ -118,8 +131,10 @@
119132 return $dbr->fetchObject( $res );
120133 }
121134
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+ */
124139 public function addExtraSQL() {
125140 return '';
126141 }
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2820,7 +2820,11 @@
28212821 /** Use the site's Cascading Style Sheets (CSS)? */
28222822 $wgUseSiteCss = true;
28232823
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+
28252829 $wgExtraRandompageSQL = false;
28262830
28272831 /** Allow the "info" action, very inefficient at the moment */
Index: trunk/phase3/RELEASE-NOTES
@@ -79,6 +79,8 @@
8080 to control which external domains may access the API via cross-site AJAX.
8181 * $wgMaintenanceScripts for extensions to add their scripts to the default list
8282 * $wgMemoryLimit has been added, default value '50M'
 83+* $wgExtraRandompageSQL is deprecated, the SpecialRandomGetRandomTitle hook
 84+ should be used instead
8385
8486 === New features in 1.16 ===
8587
@@ -195,6 +197,9 @@
196198 output by omitting some things like quotation marks where HTML 5 allows.
197199 * Added crop for inline images.
198200 * 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
199204
200205 === Bug fixes in 1.16 ===
201206

Follow-up revisions

RevisionCommit summaryAuthorDate
r55391- update RandomByTest because of r55188...robin19:42, 20 August 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54638Deprecate the $wgExtraRandompageSQL config variable by adding a hook, Special...mrzman19:09, 8 August 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   21:23, 18 August 2009

Looks good :D

Status & tagging log