From: Rob Church Date: Tue, 25 Apr 2006 01:01:10 +0000 (+0000) Subject: (bug 5684) Introduce Special:Randomredirect X-Git-Tag: 1.31.0-rc.0~57378 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=51d2a41d41b1842cd5967c0bbe56f76845d2a79b;p=lhc%2Fweb%2Fwiklou.git (bug 5684) Introduce Special:Randomredirect --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 6963dd9bcb..aecb7687f9 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -117,6 +117,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Treat "allmessagesnotsupporteddb" as wikitext when echoing; change default text * (bug 5497) regeression in HTML normalization in 1.6 (unclosed
  • ,
    ,
    ) * (bug 5709) Allow customisation of separator for categories +* (bug 5684) Introduce Special:Randomredirect == Compatibility == diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 72ce4dcdf8..a0eca5a9bc 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -80,6 +80,7 @@ $wgSpecialPages = array( 'Listredirects' => new SpecialPage( 'Listredirects' ), 'Revisiondelete' => new SpecialPage( 'Revisiondelete', 'deleterevision' ), 'Unusedtemplates' => new SpecialPage( 'Unusedtemplates' ), + 'Randomredirect' => new SpecialPage( 'Randomredirect' ), ); if( !$wgDisableCounters ) { diff --git a/includes/SpecialRandomredirect.php b/includes/SpecialRandomredirect.php new file mode 100644 index 0000000000..512553c02b --- /dev/null +++ b/includes/SpecialRandomredirect.php @@ -0,0 +1,54 @@ + + * @licence GNU General Public Licence 2.0 or later + */ + +/** + * Main execution point + * @param $par Namespace to select the redirect from + */ +function wfSpecialRandomredirect( $par = NULL ) { + global $wgOut, $wgExtraRandompageSQL, $wgContLang; + $fname = 'wfSpecialRandomredirect'; + + # Validate the namespace + $namespace = $wgContLang->getNsIndex( $par ); + if( $namespace === false || $namespace < NS_MAIN ) + $namespace = NS_MAIN; + + # Same logic as RandomPage + $randstr = wfRandom(); + + $dbr =& wfGetDB( DB_SLAVE ); + $use_index = $dbr->useIndexClause( 'page_random' ); + $page = $dbr->tableName( 'page' ); + + $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ''; + $sql = "SELECT page_id,page_title + FROM $page $use_index + WHERE page_namespace = $namespace AND page_is_redirect = 1 $extra + AND page_random > $randstr + ORDER BY page_random"; + + $sql = $dbr->limitResult( $sql, 1, 0 ); + $res = $dbr->query( $sql, $fname ); + + $title = NULL; + if( $row = $dbr->fetchObject( $res ) ) + $title = Title::makeTitleSafe( $namespace, $row->page_title ); + + # Catch dud titles and return to the main page + if( is_null( $title ) ) + $title = Title::newFromText( wfMsg( 'mainpage' ) ); + + $wgOut->reportTime(); + $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) ); +} + +?> diff --git a/languages/Messages.php b/languages/Messages.php index 5526c98c2c..3979f6d1a4 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -926,6 +926,9 @@ this old version, (rev) = revert to this old version. 'unusedtemplatestext' => 'This page lists all pages in the template namespace which are not included in another page. Remember to check for other links to the templates before deleting them.', 'unusedtemplateswlh' => 'other links', +# Random redirect +'randomredirect' => 'Random redirect', + # Statistics # 'statistics' => 'Statistics',