r87598 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87597‎ | r87598 | r87599 >
Date:23:25, 6 May 2011
Author:reedy
Status:ok
Tags:
Comment:
Kill $wgExtraRandompageSQL

Rewrote extension using them to subclass SpecialRandompage
Modified paths:
  • /trunk/extensions/PureWikiDeletion/SpecialPureWikiDeletion.php (modified) (history)
  • /trunk/extensions/Randomrootpage/Randomrootpage_body.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRandompage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -4986,12 +4986,6 @@
49874987 $wgSortSpecialPages = true;
49884988
49894989 /**
4990 - * Filter for Special:Randompage. Part of a WHERE clause
4991 - * @deprecated as of 1.16, use the SpecialRandomGetRandomTitle hook
4992 - */
4993 -$wgExtraRandompageSQL = false;
4994 -
4995 -/**
49964990 * On Special:Unusedimages, consider images "used", if they are put
49974991 * into a category. Default (false) is not to count those as used.
49984992 */
Index: trunk/phase3/includes/specials/SpecialRandompage.php
@@ -126,13 +126,8 @@
127127 }
128128
129129 protected function getQueryInfo( $randstr ) {
130 - global $wgExtraRandompageSQL;
131130 $redirect = $this->isRedirect() ? 1 : 0;
132131
133 - if ( $wgExtraRandompageSQL ) {
134 - $this->extra[] = $wgExtraRandompageSQL;
135 - }
136 -
137132 return array(
138133 'tables' => array( 'page' ),
139134 'fields' => array( 'page_title', 'page_namespace' ),
Index: trunk/extensions/Randomrootpage/Randomrootpage_body.php
@@ -1,97 +1,15 @@
22 <?php
33 if (!defined('MEDIAWIKI')) die();
44
5 -class SpecialRandomrootpage extends SpecialPage {
 5+class SpecialRandomrootpage extends RandomPage {
66
77 public function __construct() {
88 parent::__construct( 'Randomrootpage' );
 9+ $this->extra[] = "page_title NOT LIKE '%/%'";
910 }
1011
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 -
2212 // Don't select redirects
2313 public function isRedirect(){
2414 return false;
2515 }
26 -
27 - public function execute( $par ) {
28 - global $wgOut, $wgContLang;
29 -
30 -
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 - }
9816 }
Index: trunk/extensions/PureWikiDeletion/SpecialPureWikiDeletion.php
@@ -9,7 +9,7 @@
1010 * @license GNU General Public Licence 2.0 or later
1111 * @modified by Tisane
1212 */
13 -class RandomExcludeBlank extends SpecialPage {
 13+class RandomExcludeBlank extends RandomPage {
1414 private $namespaces; // namespaces to select pages from
1515 function __construct( $name = 'RandomExcludeBlank' ){
1616 global $wgContentNamespaces;
@@ -17,19 +17,9 @@
1818 $this->namespaces = $wgContentNamespaces;
1919
2020 parent::__construct( $name );
21 - $this->setGroup('RandomExcludeBlank'
22 - ,'redirects');
 21+ SpecialPageFactory::setGroup( 'RandomExcludeBlank','redirects' );
2322 }
2423
25 - public function getNamespaces() {
26 - return $this->namespaces;
27 - }
28 -
29 - public function setNamespace ( $ns ) {
30 - if( !$ns || $ns < NS_MAIN ) $ns = NS_MAIN;
31 - $this->namespaces = array( $ns );
32 - }
33 -
3424 // select redirects instead of normal pages?
3525 // Overriden by SpecialRandomredirect
3626 public function isRedirect(){
@@ -39,8 +29,9 @@
4030 public function execute( $par ) {
4131 global $wgOut, $wgContLang;
4232
43 - if ($par)
 33+ if ($par) {
4434 $this->setNamespace( $wgContLang->getNsIndex( $par ) );
 35+ }
4536
4637 $isBlank=true;
4738 $dbr = wfGetDB( DB_SLAVE );
@@ -48,7 +39,7 @@
4940 $title = $this->getRandomTitle();
5041 $result=$dbr->selectRow('blanked_page','blank_page_id'
5142 ,array("blank_page_id" => $title->getArticleID()));
52 - if (!$result && !$title->isRedirect()){
 43+ if ( !$result && !$title->isRedirect() ) {
5344 $isBlank=false;
5445 }
5546 }
@@ -62,58 +53,6 @@
6354 $query = $this->isRedirect() ? 'redirect=no' : '';
6455 $wgOut->redirect( $title->getFullUrl( $query ) );
6556 }
66 -
67 -
68 - /**
69 - * Choose a random title.
70 - * @return Title object (or null if nothing to choose from)
71 - */
72 - public function getRandomTitle() {
73 -
74 - $randstr = wfRandom();
75 - $row = $this->selectRandomPageFromDB( $randstr );
76 -
77 - /* If we picked a value that was higher than any in
78 - * the DB, wrap around and select the page with the
79 - * lowest value instead! One might think this would
80 - * skew the distribution, but in fact it won't cause
81 - * any more bias than what the page_random scheme
82 - * causes anyway. Trust me, I'm a mathematician. :)
83 - */
84 - if( !$row )
85 - $row = $this->selectRandomPageFromDB( "0" );
86 -
87 - if( $row )
88 - return Title::makeTitleSafe( $row->page_namespace, $row->page_title );
89 - else
90 - return null;
91 - }
92 -
93 - private function selectRandomPageFromDB( $randstr ) {
94 - global $wgExtraRandompageSQL;
95 - $fname = 'RandomPage::selectRandomPageFromDB';
96 -
97 - $dbr = wfGetDB( DB_SLAVE );
98 -
99 - $use_index = $dbr->useIndexClause( 'page_random' );
100 - $page = $dbr->tableName( 'page' );
101 -
102 - $ns = implode( ",", $this->namespaces );
103 - $redirect = $this->isRedirect() ? 1 : 0;
104 -
105 - $extra = $wgExtraRandompageSQL ? "AND ($wgExtraRandompageSQL)" : "";
106 - $sql = "SELECT page_title, page_namespace
107 - FROM $page $use_index
108 - WHERE page_namespace IN ( $ns )
109 - AND page_is_redirect = $redirect
110 - AND page_random >= $randstr
111 - $extra
112 - ORDER BY page_random";
113 -
114 - $sql = $dbr->limitResult( $sql, 1, 0 );
115 - $res = $dbr->query( $sql, $fname );
116 - return $dbr->fetchObject( $res );
117 - }
11857 }
11958
12059 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r87604List all removed globals in my recent commits in RELEASE-NOTESreedy23:39, 6 May 2011

Status & tagging log