From: Alex Z Date: Sat, 8 Aug 2009 19:09:16 +0000 (+0000) Subject: Deprecate the $wgExtraRandompageSQL config variable by adding a hook, SpecialRandomBe... X-Git-Tag: 1.31.0-rc.0~40414 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=1166f4b410fec278b0644405fcd7799e12b4b9a8;p=lhc%2Fweb%2Fwiklou.git Deprecate the $wgExtraRandompageSQL config variable by adding a hook, SpecialRandomBeforeSQL This allows extensions more flexibility to modify the query, or replace it entirely by setting their own query and returning false $wgExtraRandompageSQL still retained for back-compat --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 039e98a451..5b9599e3bc 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -79,6 +79,8 @@ this. Was used when mwEmbed was going to be an extension. to control which external domains may access the API via cross-site AJAX. * $wgMaintenanceScripts for extensions to add their scripts to the default list * $wgMemoryLimit has been added, default value '50M' +* $wgExtraRandompageSQL is deprecated, the SpecialRandomBeforeSQL hook should + be used instead === New features in 1.16 === @@ -194,6 +196,9 @@ this. Was used when mwEmbed was going to be an extension. cutting-edge browsers. E.g., some inputs will be autofocused, users will not be allowed to submit forms with certain types of invalid values (like numbers outside the permitted ranges), etc. +* New hook SpecialRandomBeforeSQL allows extensions to modify or replace the SQL + query used in Special:Random and subclasses, deprecating the $wgExtraRandompageSQL + config variable === Bug fixes in 1.16 === diff --git a/docs/hooks.txt b/docs/hooks.txt index 5ec31d9717..fdeaa61ff2 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1368,6 +1368,16 @@ $newTitle: new title (object) hook to remove a core special page $list: list (array) of core special pages +'SpecialRandomBeforeSQL': called before building the SQL statement for +Special:Random and all subclasses +$page: The RandomPage object +&$ns: Comma separated list of namespaces used in the query +&$redirect: 1 or 0, whether to retrieve a redirect or a non-redirect +&$extra: Extra SQL statements in the WHERE clause, after checking +$wgExtraRandompageSQL and after subclasses add extra clauses +&$sql: The query used if the hook returns false, must select +page_namespace and page_title + 'SpecialRecentChangesPanel': called when building form options in SpecialRecentChanges &$extraOpts: array of added items, to which can be added diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 47caf2d1ea..4db9adee0b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2811,7 +2811,10 @@ $wgUseSiteJs = true; /** Use the site's Cascading Style Sheets (CSS)? */ $wgUseSiteCss = true; -/** Filter for Special:Randompage. Part of a WHERE clause */ +/** + * Filter for Special:Randompage. Part of a WHERE clause + * @deprecated as of 1.16, use the SpecialRandomBeforeSQL hook +*/ $wgExtraRandompageSQL = false; /** Allow the "info" action, very inefficient at the moment */ diff --git a/includes/specials/SpecialRandompage.php b/includes/specials/SpecialRandompage.php index af43e9c605..401050578a 100644 --- a/includes/specials/SpecialRandompage.php +++ b/includes/specials/SpecialRandompage.php @@ -89,20 +89,23 @@ class RandomPage extends SpecialPage { $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ""; $extra .= $this->addExtraSQL() ? "AND (".$this->addExtraSQL().")" : ""; - $sql = "SELECT page_title, page_namespace - FROM $page $use_index - WHERE page_namespace IN ( $ns ) - AND page_is_redirect = $redirect - AND page_random >= $randstr - $extra - ORDER BY page_random"; - - $sql = $dbr->limitResult( $sql, 1, 0 ); + $sql = ''; + if ( wfRunHooks( 'SpecialRandomBeforeSQL', array( $this, &$ns, &$redirect, &$extra, &$sql ) ) ) { + $sql = "SELECT page_title, page_namespace + FROM $page $use_index + WHERE page_namespace IN ( $ns ) + AND page_is_redirect = $redirect + AND page_random >= $randstr + $extra + ORDER BY page_random"; + + $sql = $dbr->limitResult( $sql, 1, 0 ); + } $res = $dbr->query( $sql, __METHOD__ ); return $dbr->fetchObject( $res ); } - // an alternative to $wgExtraRandompageSQL so extensions + // an alternative to $wgExtraRandompageSQL so subclasses // can add their own SQL by overriding this function public function addExtraSQL() { return '';