r29736 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29735‎ | r29736 | r29737 >
Date:12:50, 14 January 2008
Author:midom
Status:old
Tags:
Comment:
Cleanup for Special:Randompage and Special: Randomredirect after r29725 - http://bugzilla.wikimedia.org/show_bug.cgi?id=12624
Thanks to: alex.emsenhuber
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialRandompage.php (modified) (history)
  • /trunk/phase3/includes/SpecialRandomredirect.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -213,6 +213,7 @@
214214 'PreferencesForm' => 'includes/SpecialPreferences.php',
215215 'SpecialPrefixindex' => 'includes/SpecialPrefixindex.php',
216216 'RandomPage' => 'includes/SpecialRandompage.php',
 217+ 'SpecialRandomredirect' => 'includes/SpecialRandomredirect.php',
217218 'PasswordResetForm' => 'includes/SpecialResetpass.php',
218219 'RevisionDeleteForm' => 'includes/SpecialRevisiondelete.php',
219220 'RevisionDeleter' => 'includes/SpecialRevisiondelete.php',
Index: trunk/phase3/includes/SpecialPage.php
@@ -141,7 +141,7 @@
142142 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
143143 'Revisiondelete' => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ),
144144 'Unusedtemplates' => array( 'SpecialPage', 'Unusedtemplates' ),
145 - 'Randomredirect' => array( 'SpecialPage', 'Randomredirect' ),
 145+ 'Randomredirect' => 'SpecialRandomredirect',
146146 'Withoutinterwiki' => array( 'SpecialPage', 'Withoutinterwiki' ),
147147
148148 'Mypage' => array( 'SpecialMypage' ),
Index: trunk/phase3/includes/SpecialRandomredirect.php
@@ -7,27 +7,14 @@
88 * @author Rob Church <robchur@gmail.com>, Ilmari Karonen
99 * @license GNU General Public Licence 2.0 or later
1010 */
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' );
2814 }
2915
30 - $wgOut->reportTime();
31 - $wgOut->redirect( $title->getFullUrl( 'redirect=no' ) );
 16+ // Override parent::isRedirect()
 17+ public function isRedirect(){
 18+ return true;
 19+ }
3220 }
3321
34 -
Index: trunk/phase3/includes/SpecialRandompage.php
@@ -15,49 +15,42 @@
1616 */
1717 class RandomPage extends SpecialPage {
1818 private $namespace = NS_MAIN; // namespace to select pages from
19 - private $redirect = false; // select redirects instead of normal pages?
2019
21 - public function getNamespace ( ) {
 20+ function __construct( $name = 'Randompage' ){
 21+ parent::__construct( $name );
 22+ }
 23+
 24+ public function getNamespace() {
2225 return $this->namespace;
2326 }
2427
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 -
3628 public function setNamespace ( $ns ) {
3729 if( $ns < NS_MAIN ) $ns = NS_MAIN;
3830 $this->namespace = $ns;
3931 }
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;
4237 }
43 - public function setRedirect ( $redirect ) {
44 - $this->redirect = $redirect;
45 - }
4638
47 - public function execute( $par = null ) {
 39+ public function execute( $par ) {
4840 global $wgOut, $wgContLang;
4941
5042 if ($par)
5143 $this->setNamespace( $wgContLang->getNsIndex( $par ) );
52 - $this->setRedirect( false );
5344
5445 $title = $this->getRandomTitle();
5546
5647 if( is_null( $title ) ) {
57 - $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) );
 48+ $this->setHeaders();
 49+ $wgOut->addWikiText( wfMsg( strtolower( $this->mName ) . '-nopages' ) );
5850 return;
5951 }
6052
61 - $wgOut->redirect( $title->getFullUrl() );
 53+ $query = $this->isRedirect() ? 'redirect=no' : '';
 54+ $wgOut->redirect( $title->getFullUrl( $query ) );
6255 }
6356
6457
@@ -65,7 +58,7 @@
6659 * Choose a random title.
6760 * @return Title object (or null if nothing to choose from)
6861 */
69 - public function getRandomTitle ( ) {
 62+ public function getRandomTitle() {
7063 $randstr = wfRandom();
7164 $row = $this->selectRandomPageFromDB( $randstr );
7265
@@ -85,7 +78,7 @@
8679 return null;
8780 }
8881
89 - private function selectRandomPageFromDB ( $randstr ) {
 82+ private function selectRandomPageFromDB( $randstr ) {
9083 global $wgExtraRandompageSQL;
9184 $fname = 'RandomPage::selectRandomPageFromDB';
9285
@@ -95,7 +88,7 @@
9689 $page = $dbr->tableName( 'page' );
9790
9891 $ns = (int) $this->namespace;
99 - $redirect = $this->redirect ? 1 : 0;
 92+ $redirect = $this->isRedirect() ? 1 : 0;
10093
10194 $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : "";
10295 $sql = "SELECT page_title

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r29725* Shortcutted Title::userCanRead() for public wikis...midom10:23, 14 January 2008

Status & tagging log