| Index: trunk/extensions/Randomrootpage/Randomrootpage_body.php |
| — | — | @@ -0,0 +1,97 @@ |
| | 2 | +<?php |
| | 3 | +if (!defined('MEDIAWIKI')) die(); |
| | 4 | + |
| | 5 | +class SpecialRandomrootpage extends SpecialPage { |
| | 6 | + |
| | 7 | + public function __construct() { |
| | 8 | + SpecialPage::SpecialPage( 'Randomrootpage' ); |
| | 9 | + } |
| | 10 | + |
| | 11 | + private $namespace = NS_MAIN; // namespace to select pages from |
| | 12 | + |
| | 13 | + public function getNamespace() { |
| | 14 | + return $this->namespace; |
| | 15 | + } |
| | 16 | + |
| | 17 | + public function setNamespace ( $ns ) { |
| | 18 | + if( $ns < NS_MAIN ) $ns = NS_MAIN; |
| | 19 | + $this->namespace = $ns; |
| | 20 | + } |
| | 21 | + |
| | 22 | + // Don't select redirects |
| | 23 | + public function isRedirect(){ |
| | 24 | + return false; |
| | 25 | + } |
| | 26 | + |
| | 27 | + public function execute( $par ) { |
| | 28 | + global $wgOut, $wgContLang; |
| | 29 | + |
| | 30 | + wfLoadExtensionMessages( 'Randomrootpage' ); |
| | 31 | + |
| | 32 | + if ($par) |
| | 33 | + $this->setNamespace( $wgContLang->getNsIndex( $par ) ); |
| | 34 | + |
| | 35 | + $title = $this->getRandomTitle(); |
| | 36 | + |
| | 37 | + if( is_null( $title ) ) { |
| | 38 | + $this->setHeaders(); |
| | 39 | + $wgOut->addWikiMsg( strtolower( $this->mName ) . '-nopages' ); |
| | 40 | + return; |
| | 41 | + } |
| | 42 | + |
| | 43 | + $query = $this->isRedirect() ? 'redirect=no' : ''; |
| | 44 | + $wgOut->redirect( $title->getFullUrl( $query ) ); |
| | 45 | + } |
| | 46 | + |
| | 47 | + |
| | 48 | + /** |
| | 49 | + * Choose a random title. |
| | 50 | + * @return Title object (or null if nothing to choose from) |
| | 51 | + */ |
| | 52 | + public function getRandomTitle() { |
| | 53 | + $randstr = wfRandom(); |
| | 54 | + $row = $this->selectRandomPageFromDB( $randstr ); |
| | 55 | + |
| | 56 | + /* If we picked a value that was higher than any in |
| | 57 | + * the DB, wrap around and select the page with the |
| | 58 | + * lowest value instead! One might think this would |
| | 59 | + * skew the distribution, but in fact it won't cause |
| | 60 | + * any more bias than what the page_random scheme |
| | 61 | + * causes anyway. Trust me, I'm a mathematician. :) |
| | 62 | + */ |
| | 63 | + if( !$row ) |
| | 64 | + $row = $this->selectRandomPageFromDB( "0" ); |
| | 65 | + |
| | 66 | + if( $row ) |
| | 67 | + return Title::makeTitleSafe( $this->namespace, $row->page_title ); |
| | 68 | + else |
| | 69 | + return null; |
| | 70 | + } |
| | 71 | + |
| | 72 | + private function selectRandomPageFromDB( $randstr ) { |
| | 73 | + global $wgExtraRandompageSQL; |
| | 74 | + $fname = 'RandomPage::selectRandomPageFromDB'; |
| | 75 | + |
| | 76 | + $dbr = wfGetDB( DB_SLAVE ); |
| | 77 | + |
| | 78 | + $use_index = $dbr->useIndexClause( 'page_random' ); |
| | 79 | + $page = $dbr->tableName( 'page' ); |
| | 80 | + |
| | 81 | + $ns = (int) $this->namespace; |
| | 82 | + $redirect = $this->isRedirect() ? 1 : 0; |
| | 83 | + |
| | 84 | + $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ""; |
| | 85 | + $sql = "SELECT page_title |
| | 86 | + FROM $page $use_index |
| | 87 | + WHERE page_namespace = $ns |
| | 88 | + AND page_is_redirect = $redirect |
| | 89 | + AND page_random >= $randstr |
| | 90 | + AND page_title NOT LIKE '%/%' |
| | 91 | + $extra |
| | 92 | + ORDER BY page_random"; |
| | 93 | + |
| | 94 | + $sql = $dbr->limitResult( $sql, 1, 0 ); |
| | 95 | + $res = $dbr->query( $sql, $fname ); |
| | 96 | + return $dbr->fetchObject( $res ); |
| | 97 | + } |
| | 98 | +} |
| Property changes on: trunk/extensions/Randomrootpage/Randomrootpage_body.php |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 99 | + native |
| Index: trunk/extensions/Randomrootpage/Randomrootpage.i18n.php |
| — | — | @@ -0,0 +1,89 @@ |
| | 2 | +<?php |
| | 3 | +/** |
| | 4 | + * Internationalisation file for extension RandomRootpage. |
| | 5 | + * |
| | 6 | + * @addtogroup Extensions |
| | 7 | + */ |
| | 8 | + |
| | 9 | +$messages = array(); |
| | 10 | + |
| | 11 | +/** English |
| | 12 | + * @author Hojjat (aka Huji) |
| | 13 | + */ |
| | 14 | +$messages['en'] = array( |
| | 15 | + 'randomrootpage' => 'Random root page', |
| | 16 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Special page]] which fetches a random root page', |
| | 17 | +); |
| | 18 | + |
| | 19 | +/** Arabic (العربية) |
| | 20 | + * @author Meno25 |
| | 21 | + */ |
| | 22 | +$messages['ar'] = array( |
| | 23 | + 'randomrootpage' => 'صفحة جذر عشوائية', |
| | 24 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|صفحة خاصة]] تعرض صفحة جذر عشوائية', |
| | 25 | +); |
| | 26 | + |
| | 27 | +/** Persian (فارسی) |
| | 28 | + * @author Hojjat (aka Huji) |
| | 29 | + */ |
| | 30 | +$messages['fa'] = array( |
| | 31 | + 'randomrootpage' => 'صفحهٔ تصادفی سرشاخه', |
| | 32 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|صفحهٔ ویژهای]] که به طور تصادفی یکی از صفحههای سرشاخه را نشان می دهد', |
| | 33 | +); |
| | 34 | + |
| | 35 | +/** French (Français) |
| | 36 | + * @author Meithal |
| | 37 | + */ |
| | 38 | +$messages['fr'] = array( |
| | 39 | + 'randomrootpage' => 'Page racine aléatoire', |
| | 40 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Page spéciale]] qui va chercher une page racine au hasard', |
| | 41 | +); |
| | 42 | + |
| | 43 | +/** Upper Sorbian (Hornjoserbsce) |
| | 44 | + * @author Michawiki |
| | 45 | + */ |
| | 46 | +$messages['hsb'] = array( |
| | 47 | + 'randomrootpage' => 'Připadna korjenjowa strona', |
| | 48 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Specialna strona]], kotraž připadnu korjenjowu stronu zwobraznja', |
| | 49 | +); |
| | 50 | + |
| | 51 | +/** Hungarian (Magyar) |
| | 52 | + * @author Bdanee |
| | 53 | + */ |
| | 54 | +$messages['hu'] = array( |
| | 55 | + 'randomrootpage' => 'Véletlen lap a gyökérből', |
| | 56 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Speciális lap]], amely egy véletlen lapot jelenít meg a gyökérből', |
| | 57 | +); |
| | 58 | + |
| | 59 | +/** Dutch (Nederlands) |
| | 60 | + * @author Siebrand |
| | 61 | + */ |
| | 62 | +$messages['nl'] = array( |
| | 63 | + 'randomrootpage' => 'Willekeurige hoofdpagina', |
| | 64 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Speciale pagina]] die een willekeurige hoofdpagina toont', |
| | 65 | +); |
| | 66 | + |
| | 67 | +/** Norwegian (Norsk (bokmål)) |
| | 68 | + * @author Jon Harald Søby |
| | 69 | + */ |
| | 70 | +$messages['no'] = array( |
| | 71 | + 'randomrootpage' => 'Tilfeldig rotside', |
| | 72 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Spesialside]] som henter en tilfeldig rotside', |
| | 73 | +); |
| | 74 | + |
| | 75 | +/** Slovak (Slovenčina) |
| | 76 | + * @author Helix84 |
| | 77 | + */ |
| | 78 | +$messages['sk'] = array( |
| | 79 | + 'randomrootpage' => 'Náhodná koreňová stránka', |
| | 80 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Špeciálna stránka]], ktorá zobrazuje náhodnú koreňovú stránku', |
| | 81 | +); |
| | 82 | + |
| | 83 | +/** Vietnamese (Tiếng Việt) |
| | 84 | + * @author Vinhtantran |
| | 85 | + */ |
| | 86 | +$messages['vi'] = array( |
| | 87 | + 'randomrootpage' => 'Trang gốc ngẫu nhiên', |
| | 88 | + 'randomrootpage-desc' => '[[Special:Randomrootpage|Trang đặc biệt]] để truy xuất một trang gốc ngẫu nhiên', |
| | 89 | +); |
| | 90 | + |
| Property changes on: trunk/extensions/Randomrootpage/Randomrootpage.i18n.php |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 91 | + native |
| Index: trunk/extensions/Randomrootpage/Randomrootpage.php |
| — | — | @@ -0,0 +1,25 @@ |
| | 2 | +<?php |
| | 3 | +if (!defined('MEDIAWIKI')) die(); |
| | 4 | +/** |
| | 5 | + * A Special Page Randomly shows one of the root pages (in contrast to subpages) from ns=0 |
| | 6 | + * |
| | 7 | + * @addtogroup Extensions |
| | 8 | + * |
| | 9 | + * @author Hojjat (aka Huji) <huji.huji@gmail.com> |
| | 10 | + * @copyright Copyright 2008, Hojjat (aka Huji) |
| | 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| | 12 | + */ |
| | 13 | + |
| | 14 | +$wgExtensionCredits['specialpage'][] = array( |
| | 15 | + 'name' => 'Random root page', |
| | 16 | + 'version' => '2008-02-18', |
| | 17 | + 'author' => 'Hojjat (aka Huji)', |
| | 18 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:RandomRootPage', |
| | 19 | + 'descriptionmsg' => 'randomrootpage-desc', |
| | 20 | +); |
| | 21 | + |
| | 22 | +$wgSpecialPages['Randomrootpage'] = 'SpecialRandomrootpage'; |
| | 23 | + |
| | 24 | +$dir = dirname(__FILE__) . '/'; |
| | 25 | +$wgExtensionMessagesFiles['Randomrootpage'] = $dir . 'Randomrootpage.i18n.php'; |
| | 26 | +$wgAutoloadClasses['SpecialRandomrootpage'] = $dir . 'Randomrootpage_body.php'; |
| Property changes on: trunk/extensions/Randomrootpage/Randomrootpage.php |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| 1 | 27 | + native |