Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -213,6 +213,7 @@ |
214 | 214 | 'PreferencesForm' => 'includes/SpecialPreferences.php', |
215 | 215 | 'SpecialPrefixindex' => 'includes/SpecialPrefixindex.php', |
216 | 216 | 'RandomPage' => 'includes/SpecialRandompage.php', |
| 217 | + 'SpecialRandomredirect' => 'includes/SpecialRandomredirect.php', |
217 | 218 | 'PasswordResetForm' => 'includes/SpecialResetpass.php', |
218 | 219 | 'RevisionDeleteForm' => 'includes/SpecialRevisiondelete.php', |
219 | 220 | 'RevisionDeleter' => 'includes/SpecialRevisiondelete.php', |
Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -141,7 +141,7 @@ |
142 | 142 | 'Listredirects' => array( 'SpecialPage', 'Listredirects' ), |
143 | 143 | 'Revisiondelete' => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ), |
144 | 144 | 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ), |
145 | | - 'Randomredirect' => array( 'SpecialPage', 'Randomredirect' ), |
| 145 | + 'Randomredirect' => 'SpecialRandomredirect', |
146 | 146 | 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ), |
147 | 147 | |
148 | 148 | 'Mypage' => array( 'SpecialMypage' ), |
Index: trunk/phase3/includes/SpecialRandomredirect.php |
— | — | @@ -7,27 +7,14 @@ |
8 | 8 | * @author Rob Church <robchur@gmail.com>, Ilmari Karonen |
9 | 9 | * @license GNU General Public Licence 2.0 or later |
10 | 10 | */ |
11 | | - |
12 | | -/** |
13 | | - * Main execution point |
14 | | - * @param $par Namespace to select the redirect from |
15 | | - */ |
16 | | -function wfSpecialRandomredirect( $par = null ) { |
17 | | - global $wgOut, $wgContLang; |
18 | | - |
19 | | - $rnd = new RandomPage(); |
20 | | - $rnd->setNamespace( $wgContLang->getNsIndex( $par ) ); |
21 | | - $rnd->setRedirect( true ); |
22 | | - |
23 | | - $title = $rnd->getRandomTitle(); |
24 | | - |
25 | | - if( is_null( $title ) ) { |
26 | | - $wgOut->addWikiText( wfMsg( 'randomredirect-nopages' ) ); |
27 | | - return; |
| 11 | +class SpecialRandomredirect extends RandomPage { |
| 12 | + function __construct(){ |
| 13 | + parent::__construct( 'Randomredirect' ); |
28 | 14 | } |
29 | 15 | |
30 | | - $wgOut->reportTime(); |
31 | | - $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) ); |
| 16 | + // Override parent::isRedirect() |
| 17 | + public function isRedirect(){ |
| 18 | + return true; |
| 19 | + } |
32 | 20 | } |
33 | 21 | |
34 | | - |
Index: trunk/phase3/includes/SpecialRandompage.php |
— | — | @@ -15,49 +15,42 @@ |
16 | 16 | */ |
17 | 17 | class RandomPage extends SpecialPage { |
18 | 18 | private $namespace = NS_MAIN; // namespace to select pages from |
19 | | - private $redirect = false; // select redirects instead of normal pages? |
20 | 19 | |
21 | | - public function getNamespace ( ) { |
| 20 | + function __construct( $name = 'Randompage' ){ |
| 21 | + parent::__construct( $name ); |
| 22 | + } |
| 23 | + |
| 24 | + public function getNamespace() { |
22 | 25 | return $this->namespace; |
23 | 26 | } |
24 | 27 | |
25 | | - function getTitle($par=null) { |
26 | | - return SpecialPage::getTitleFor("Randompage"); |
27 | | - } |
28 | | - |
29 | | - function getLocalName() { |
30 | | - return SpecialPage::getLocalNameFor("Randompage"); |
31 | | - } |
32 | | - |
33 | | - public function setHeaders() {} |
34 | | - public function outputHeader() {} |
35 | | - |
36 | 28 | public function setNamespace ( $ns ) { |
37 | 29 | if( $ns < NS_MAIN ) $ns = NS_MAIN; |
38 | 30 | $this->namespace = $ns; |
39 | 31 | } |
40 | | - public function getRedirect ( ) { |
41 | | - return $this->redirect; |
| 32 | + |
| 33 | + // select redirects instead of normal pages? |
| 34 | + // Overriden by SpecialRandomredirect |
| 35 | + public function isRedirect(){ |
| 36 | + return false; |
42 | 37 | } |
43 | | - public function setRedirect ( $redirect ) { |
44 | | - $this->redirect = $redirect; |
45 | | - } |
46 | 38 | |
47 | | - public function execute( $par = null ) { |
| 39 | + public function execute( $par ) { |
48 | 40 | global $wgOut, $wgContLang; |
49 | 41 | |
50 | 42 | if ($par) |
51 | 43 | $this->setNamespace( $wgContLang->getNsIndex( $par ) ); |
52 | | - $this->setRedirect( false ); |
53 | 44 | |
54 | 45 | $title = $this->getRandomTitle(); |
55 | 46 | |
56 | 47 | if( is_null( $title ) ) { |
57 | | - $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) ); |
| 48 | + $this->setHeaders(); |
| 49 | + $wgOut->addWikiText( wfMsg( strtolower( $this->mName ) . '-nopages' ) ); |
58 | 50 | return; |
59 | 51 | } |
60 | 52 | |
61 | | - $wgOut->redirect( $title->getFullUrl() ); |
| 53 | + $query = $this->isRedirect() ? 'redirect=no' : ''; |
| 54 | + $wgOut->redirect( $title->getFullUrl( $query ) ); |
62 | 55 | } |
63 | 56 | |
64 | 57 | |
— | — | @@ -65,7 +58,7 @@ |
66 | 59 | * Choose a random title. |
67 | 60 | * @return Title object (or null if nothing to choose from) |
68 | 61 | */ |
69 | | - public function getRandomTitle ( ) { |
| 62 | + public function getRandomTitle() { |
70 | 63 | $randstr = wfRandom(); |
71 | 64 | $row = $this->selectRandomPageFromDB( $randstr ); |
72 | 65 | |
— | — | @@ -85,7 +78,7 @@ |
86 | 79 | return null; |
87 | 80 | } |
88 | 81 | |
89 | | - private function selectRandomPageFromDB ( $randstr ) { |
| 82 | + private function selectRandomPageFromDB( $randstr ) { |
90 | 83 | global $wgExtraRandompageSQL; |
91 | 84 | $fname = 'RandomPage::selectRandomPageFromDB'; |
92 | 85 | |
— | — | @@ -95,7 +88,7 @@ |
96 | 89 | $page = $dbr->tableName( 'page' ); |
97 | 90 | |
98 | 91 | $ns = (int) $this->namespace; |
99 | | - $redirect = $this->redirect ? 1 : 0; |
| 92 | + $redirect = $this->isRedirect() ? 1 : 0; |
100 | 93 | |
101 | 94 | $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : ""; |
102 | 95 | $sql = "SELECT page_title |