Index: trunk/phase3/maintenance/updateArticleCount.php |
— | — | @@ -27,9 +27,6 @@ |
28 | 28 | |
29 | 29 | class UpdateArticleCount extends Maintenance { |
30 | 30 | |
31 | | - // Content namespaces |
32 | | - private $namespaces; |
33 | | - |
34 | 31 | public function __construct() { |
35 | 32 | parent::__construct(); |
36 | 33 | $this->mDescription = "Count of the number of articles and update the site statistics table"; |
— | — | @@ -37,8 +34,6 @@ |
38 | 35 | } |
39 | 36 | |
40 | 37 | public function execute() { |
41 | | - global $wgContentNamespaces; |
42 | | - $this->namespaces = $wgContentNamespaces; |
43 | 38 | $this->output( "Counting articles..." ); |
44 | 39 | $result = $this->count(); |
45 | 40 | |
— | — | @@ -58,42 +53,22 @@ |
59 | 54 | } |
60 | 55 | |
61 | 56 | /** |
62 | | - * Produce a comma-delimited set of namespaces |
63 | | - * Includes paranoia |
64 | | - * |
65 | | - * @return string |
66 | | - */ |
67 | | - private function makeNsSet() { |
68 | | - foreach ( $this->namespaces as $namespace ) |
69 | | - $namespaces[] = intval( $namespace ); |
70 | | - return implode( ', ', $namespaces ); |
71 | | - } |
72 | | - |
73 | | - /** |
74 | | - * Produce SQL for the query |
75 | | - * |
76 | | - * @param $dbr Database handle |
77 | | - * @return string |
78 | | - */ |
79 | | - private function makeSql( $dbr ) { |
80 | | - list( $page, $pagelinks ) = $dbr->tableNamesN( 'page', 'pagelinks' ); |
81 | | - $nsset = $this->makeNsSet(); |
82 | | - return "SELECT COUNT(DISTINCT page_id) AS pagecount " . |
83 | | - "FROM $page, $pagelinks " . |
84 | | - "WHERE pl_from=page_id and page_namespace IN ( $nsset ) " . |
85 | | - "AND page_is_redirect = 0 AND page_len > 0"; |
86 | | - } |
87 | | - |
88 | | - /** |
89 | 57 | * Count the number of valid content pages in the wiki |
90 | 58 | * |
91 | 59 | * @return mixed Integer, or false if there's a problem |
92 | 60 | */ |
93 | 61 | private function count() { |
94 | | - $dbr = wfGetDB( DB_SLAVE ); |
95 | | - $res = $dbr->query( $this->makeSql( $dbr ), __METHOD__ ); |
96 | | - $row = $dbr->fetchObject( $res ); |
97 | | - return $row ? $row->pagecount : false; |
| 62 | + return wfGetDB( DB_SLAVE )->selectField( |
| 63 | + array( 'page', 'pagelinks' ), |
| 64 | + 'COUNT(DISTINCT page_id)', |
| 65 | + array( |
| 66 | + 'pl_from=page_id', |
| 67 | + 'page_namespace' => MWNamespace::getContentNamespaces(), |
| 68 | + 'page_is_redirect' => 0, |
| 69 | + 'page_len > 0', |
| 70 | + ), |
| 71 | + __METHOD__ |
| 72 | + ); |
98 | 73 | } |
99 | 74 | } |
100 | 75 | |