Index: branches/maintenance-work/maintenance/refreshLinks.inc |
— | — | @@ -1,202 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @todo document |
5 | | - * @file |
6 | | - * @ingroup Maintenance |
7 | | - */ |
8 | | - |
9 | | -function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false ) { |
10 | | - global $wgUser, $wgParser, $wgUseTidy; |
11 | | - |
12 | | - $reportingInterval = 100; |
13 | | - $fname = 'refreshLinks'; |
14 | | - $dbr = wfGetDB( DB_SLAVE ); |
15 | | - $start = intval( $start ); |
16 | | - |
17 | | - # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway) |
18 | | - $wgUser->setOption('math', MW_MATH_SOURCE); |
19 | | - |
20 | | - # Don't generate extension images (e.g. Timeline) |
21 | | - if( method_exists( $wgParser, "clearTagHooks" ) ) { |
22 | | - $wgParser->clearTagHooks(); |
23 | | - } |
24 | | - |
25 | | - # Don't use HTML tidy |
26 | | - $wgUseTidy = false; |
27 | | - |
28 | | - $what = $redirectsOnly ? "redirects" : "links"; |
29 | | - |
30 | | - if( $oldRedirectsOnly ) { |
31 | | - # This entire code path is cut-and-pasted from below. Hurrah. |
32 | | - $res = $dbr->query( |
33 | | - "SELECT page_id ". |
34 | | - "FROM page ". |
35 | | - "LEFT JOIN redirect ON page_id=rd_from ". |
36 | | - "WHERE page_is_redirect=1 AND rd_from IS NULL AND ". |
37 | | - ($end == 0 ? "page_id >= $start" |
38 | | - : "page_id BETWEEN $start AND $end"), |
39 | | - $fname |
40 | | - ); |
41 | | - $num = $dbr->numRows( $res ); |
42 | | - print "Refreshing $num old redirects from $start...\n"; |
43 | | - |
44 | | - while( $row = $dbr->fetchObject( $res ) ) { |
45 | | - if ( !( ++$i % $reportingInterval ) ) { |
46 | | - print "$i\n"; |
47 | | - wfWaitForSlaves( $maxLag ); |
48 | | - } |
49 | | - fixRedirect( $row->page_id ); |
50 | | - } |
51 | | - } elseif( $newOnly ) { |
52 | | - print "Refreshing $what from "; |
53 | | - $res = $dbr->select( 'page', |
54 | | - array( 'page_id' ), |
55 | | - array( |
56 | | - 'page_is_new' => 1, |
57 | | - "page_id >= $start" ), |
58 | | - $fname |
59 | | - ); |
60 | | - $num = $dbr->numRows( $res ); |
61 | | - print "$num new articles...\n"; |
62 | | - |
63 | | - $i = 0; |
64 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
65 | | - if ( !( ++$i % $reportingInterval ) ) { |
66 | | - print "$i\n"; |
67 | | - wfWaitForSlaves( $maxLag ); |
68 | | - } |
69 | | - if($redirectsOnly) |
70 | | - fixRedirect( $row->page_id ); |
71 | | - else |
72 | | - fixLinksFromArticle( $row->page_id ); |
73 | | - } |
74 | | - } else { |
75 | | - print "Refreshing $what table.\n"; |
76 | | - if ( !$end ) { |
77 | | - $end = $dbr->selectField( 'page', 'max(page_id)', false ); |
78 | | - } |
79 | | - print("Starting from page_id $start of $end.\n"); |
80 | | - |
81 | | - for ($id = $start; $id <= $end; $id++) { |
82 | | - |
83 | | - if ( !($id % $reportingInterval) ) { |
84 | | - print "$id\n"; |
85 | | - wfWaitForSlaves( $maxLag ); |
86 | | - } |
87 | | - if($redirectsOnly) |
88 | | - fixRedirect( $id ); |
89 | | - else |
90 | | - fixLinksFromArticle( $id ); |
91 | | - } |
92 | | - } |
93 | | -} |
94 | | - |
95 | | -function fixRedirect( $id ){ |
96 | | - global $wgTitle, $wgArticle; |
97 | | - |
98 | | - $wgTitle = Title::newFromID( $id ); |
99 | | - $dbw = wfGetDB( DB_MASTER ); |
100 | | - |
101 | | - if ( is_null( $wgTitle ) ) { |
102 | | - return; |
103 | | - } |
104 | | - $wgArticle = new Article($wgTitle); |
105 | | - |
106 | | - $rt = $wgArticle->followRedirect(); |
107 | | - |
108 | | - if($rt == false || !is_object($rt)) |
109 | | - return; |
110 | | - |
111 | | - $wgArticle->updateRedirectOn($dbw,$rt); |
112 | | -} |
113 | | - |
114 | | -function fixLinksFromArticle( $id ) { |
115 | | - global $wgTitle, $wgParser; |
116 | | - |
117 | | - $wgTitle = Title::newFromID( $id ); |
118 | | - $dbw = wfGetDB( DB_MASTER ); |
119 | | - |
120 | | - $linkCache =& LinkCache::singleton(); |
121 | | - $linkCache->clear(); |
122 | | - |
123 | | - if ( is_null( $wgTitle ) ) { |
124 | | - return; |
125 | | - } |
126 | | - $dbw->begin(); |
127 | | - |
128 | | - $revision = Revision::newFromTitle( $wgTitle ); |
129 | | - if ( !$revision ) { |
130 | | - return; |
131 | | - } |
132 | | - |
133 | | - $options = new ParserOptions; |
134 | | - $parserOutput = $wgParser->parse( $revision->getText(), $wgTitle, $options, true, true, $revision->getId() ); |
135 | | - $update = new LinksUpdate( $wgTitle, $parserOutput, false ); |
136 | | - $update->doUpdate(); |
137 | | - $dbw->immediateCommit(); |
138 | | -} |
139 | | - |
140 | | -/* |
141 | | - * Removes non-existing links from pages from pagelinks, imagelinks, |
142 | | - * categorylinks, templatelinks and externallinks tables. |
143 | | - * |
144 | | - * @param $maxLag |
145 | | - * @param $batchSize The size of deletion batches |
146 | | - * |
147 | | - * @author Merlijn van Deen <valhallasw@arctus.nl> |
148 | | - */ |
149 | | -function deleteLinksFromNonexistent( $maxLag = 0, $batchSize = 100 ) { |
150 | | - wfWaitForSlaves( $maxLag ); |
151 | | - |
152 | | - $dbw = wfGetDB( DB_MASTER ); |
153 | | - |
154 | | - $lb = wfGetLBFactory()->newMainLB(); |
155 | | - $dbr = $lb->getConnection( DB_SLAVE ); |
156 | | - $dbr->bufferResults( false ); |
157 | | - |
158 | | - $linksTables = array( // table name => page_id field |
159 | | - 'pagelinks' => 'pl_from', |
160 | | - 'imagelinks' => 'il_from', |
161 | | - 'categorylinks' => 'cl_from', |
162 | | - 'templatelinks' => 'tl_from', |
163 | | - 'externallinks' => 'el_from', |
164 | | - ); |
165 | | - |
166 | | - foreach ( $linksTables as $table => $field ) { |
167 | | - print "Retrieving illegal entries from $table... "; |
168 | | - |
169 | | - // SELECT DISTINCT( $field ) FROM $table LEFT JOIN page ON $field=page_id WHERE page_id IS NULL; |
170 | | - $results = $dbr->select( array( $table, 'page' ), |
171 | | - $field, |
172 | | - array('page_id' => null ), |
173 | | - __METHOD__, |
174 | | - 'DISTINCT', |
175 | | - array( 'page' => array( 'LEFT JOIN', "$field=page_id")) |
176 | | - ); |
177 | | - |
178 | | - $counter = 0; |
179 | | - $list = array(); |
180 | | - print "0.."; |
181 | | - |
182 | | - foreach( $results as $row ) { |
183 | | - $counter++; |
184 | | - $list[] = $row->$field; |
185 | | - if ( ( $counter % $batchSize ) == 0 ) { |
186 | | - wfWaitForSlaves(5); |
187 | | - $dbw->delete( $table, array( $field => $list ), __METHOD__ ); |
188 | | - |
189 | | - print $counter . ".."; |
190 | | - $list = array(); |
191 | | - } |
192 | | - } |
193 | | - |
194 | | - print $counter; |
195 | | - if (count($list) > 0) { |
196 | | - $dbw->delete( $table, array( $field => $list ), __METHOD__ ); |
197 | | - } |
198 | | - |
199 | | - print "\n"; |
200 | | - } |
201 | | - |
202 | | - $lb->closeAll(); |
203 | | -} |
Index: branches/maintenance-work/maintenance/stats.php |
— | — | @@ -1,15 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Show statistics from memcached |
| 4 | + * Show statistics from the cache |
5 | 5 | * @ingroup Maintenance |
6 | 6 | */ |
7 | 7 | |
8 | 8 | require_once( "Maintenance.php" ); |
9 | 9 | |
10 | | -class MemcachedStats extends Maintenance { |
| 10 | +class CacheStats extends Maintenance { |
11 | 11 | |
12 | 12 | public function __construct() { |
13 | | - $this->mDescription = "Show statistics from memcached"; |
| 13 | + $this->mDescription = "Show statistics from the cache"; |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function execute() { |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | $noSession = intval($wgMemc->get(wfMemcKey('stats','request_without_session'))); |
25 | 25 | $total = $session + $noSession; |
26 | 26 | if ( $total == 0 ) { |
27 | | - $this->error( "You either have no stats or memcached isn't running. Aborting.\n", true ); |
| 27 | + $this->error( "You either have no stats or the cache isn't running. Aborting.\n", true ); |
28 | 28 | } |
29 | 29 | $this->output( "Requests\n" ); |
30 | 30 | $this->output( sprintf( "with session: %-10d %6.2f%%\n", $session, $session/$total*100 ) ); |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | | -$maintClass = "MemcachedStats"; |
| 69 | +$maintClass = "CacheStats"; |
70 | 70 | require_once( DO_MAINTENANCE ); |
71 | 71 | |
72 | 72 | |
Index: branches/maintenance-work/maintenance/refreshLinks.php |
— | — | @@ -4,53 +4,245 @@ |
5 | 5 | * @ingroup Maintenance |
6 | 6 | */ |
7 | 7 | |
8 | | -/** */ |
9 | | -$optionsWithArgs = array('batch-size', 'm', 'e' ); |
| 8 | +require_once( "Maintenance.php" ); |
10 | 9 | |
11 | | -require_once( "commandLine.inc" ); |
12 | | -require_once( "refreshLinks.inc" ); |
| 10 | +class RefreshLinks extends Maintenance { |
| 11 | + public function __construct() { |
| 12 | + parent::__construct(); |
| 13 | + $this->mDescription = "Refresh link tables"; |
| 14 | + $this->addOption( 'dfn-only', 'Delete links from nonexistent articles only' ); |
| 15 | + $this->addOption( 'new-only', 'Only affect articles with just a single edit' ); |
| 16 | + $this->addOption( 'redirects-only', 'Only fix redirects, not all links' ); |
| 17 | + $this->addOption( 'old-redirects-only', 'Only fix redirects with no redirect table entry' ); |
| 18 | + $this->addOption( 'm', 'Maximum replication lag', false, true ); |
| 19 | + $this->addOption( 'e', 'Last page id to refresh', false, true ); |
| 20 | + $this->addArgs( array( 'start' => true ) ); |
| 21 | + $this->setBatchSize( 100 ); |
| 22 | + } |
13 | 23 | |
14 | | -if( isset( $options['help'] ) ) { |
15 | | - echo <<<TEXT |
16 | | -Usage: |
17 | | - php refreshLinks.php --help |
18 | | - php refreshLinks.php [<start>] [-e <end>] [-m <maxlag>] [--dfn-only] |
19 | | - [--batch-size <size>] [--new-only] [--redirects-only] |
20 | | - php refreshLinks.php [<start>] [-e <end>] [-m <maxlag>] --old-redirects-only |
| 24 | + public function execute() { |
| 25 | + if( !$this->hasOption( 'dfn-only' ) ) { |
| 26 | + $start = $this->getArg( 0, 1 ); |
| 27 | + $new = $this->getOption( 'new-only', false ); |
| 28 | + $max = $this->getOption( 'm', false ); |
| 29 | + $end = $this->getOption( 'e', 0 ); |
| 30 | + $redir = $this->getOption( 'redirects-only', false ); |
| 31 | + $oldRedir = $this->getOption( 'old-redirects-only', false ); |
| 32 | + $this->doRefreshLinks( $start, $new, $max, $end, $redir, $oldRedir ); |
| 33 | + } |
| 34 | + $this->deleteLinksFromNonexistent( $max, $this->mBatchSize ); |
| 35 | + } |
21 | 36 | |
22 | | - --help : This help message |
23 | | - --dfn-only : Delete links from nonexistent articles only |
24 | | - --batch-size <number> : The delete batch size when removing links from |
25 | | - nonexistent articles (defaults to 100) |
26 | | - --new-only : Only affect articles with just a single edit |
27 | | - --redirects-only : Only fix redirects, not all links |
28 | | - --old-redirects-only : Only fix redirects with no redirect table entry |
29 | | - -m <number> : Maximum replication lag |
30 | | - <start> : First page id to refresh |
31 | | - -e <number> : Last page id to refresh |
| 37 | + /** |
| 38 | + * Do the actual link refreshing. |
| 39 | + * @param $start int Page_id to start from |
| 40 | + * @param $newOnly bool Only do pages with 1 edit |
| 41 | + * @param $maxLag int Max DB replication lag |
| 42 | + * @param $end int Page_id to stop at |
| 43 | + * @param $redirectsOnly bool Only fix redirects |
| 44 | + * @param $oldRedirectsOnly bool Only fix redirects without redirect entries |
| 45 | + */ |
| 46 | + private function doRefreshLinks( $start, $newOnly = false, $maxLag = false, |
| 47 | + $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false ) { |
| 48 | + global $wgUser, $wgParser, $wgUseTidy; |
32 | 49 | |
33 | | -TEXT; |
34 | | - exit(0); |
35 | | -} |
| 50 | + $reportingInterval = 100; |
| 51 | + $dbr = wfGetDB( DB_SLAVE ); |
| 52 | + $start = intval( $start ); |
36 | 53 | |
37 | | -error_reporting( E_ALL & (~E_NOTICE) ); |
| 54 | + # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway) |
| 55 | + $wgUser->setOption('math', MW_MATH_SOURCE); |
38 | 56 | |
39 | | -if ( !$options['dfn-only'] ) { |
40 | | - if ( isset( $args[0] ) ) { |
41 | | - $start = (int)$args[0]; |
42 | | - } else { |
43 | | - $start = 1; |
| 57 | + # Don't generate extension images (e.g. Timeline) |
| 58 | + if( method_exists( $wgParser, "clearTagHooks" ) ) { |
| 59 | + $wgParser->clearTagHooks(); |
| 60 | + } |
| 61 | + |
| 62 | + # Don't use HTML tidy |
| 63 | + $wgUseTidy = false; |
| 64 | + |
| 65 | + $what = $redirectsOnly ? "redirects" : "links"; |
| 66 | + |
| 67 | + if( $oldRedirectsOnly ) { |
| 68 | + # This entire code path is cut-and-pasted from below. Hurrah. |
| 69 | + $res = $dbr->query( |
| 70 | + "SELECT page_id ". |
| 71 | + "FROM page ". |
| 72 | + "LEFT JOIN redirect ON page_id=rd_from ". |
| 73 | + "WHERE page_is_redirect=1 AND rd_from IS NULL AND ". |
| 74 | + ($end == 0 ? "page_id >= $start" |
| 75 | + : "page_id BETWEEN $start AND $end"), |
| 76 | + __METHOD__ |
| 77 | + ); |
| 78 | + $num = $dbr->numRows( $res ); |
| 79 | + $this->output( "Refreshing $num old redirects from $start...\n" ); |
| 80 | + |
| 81 | + while( $row = $dbr->fetchObject( $res ) ) { |
| 82 | + if ( !( ++$i % $reportingInterval ) ) { |
| 83 | + $this->output( "$i\n" ); |
| 84 | + wfWaitForSlaves( $maxLag ); |
| 85 | + } |
| 86 | + $this->fixRedirect( $row->page_id ); |
| 87 | + } |
| 88 | + } elseif( $newOnly ) { |
| 89 | + $this->output( "Refreshing $what from " ); |
| 90 | + $res = $dbr->select( 'page', |
| 91 | + array( 'page_id' ), |
| 92 | + array( |
| 93 | + 'page_is_new' => 1, |
| 94 | + "page_id >= $start" ), |
| 95 | + __METHOD__ |
| 96 | + ); |
| 97 | + $num = $dbr->numRows( $res ); |
| 98 | + $this->output( "$num new articles...\n" ); |
| 99 | + |
| 100 | + $i = 0; |
| 101 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 102 | + if ( !( ++$i % $reportingInterval ) ) { |
| 103 | + $this->output( "$i\n" ); |
| 104 | + wfWaitForSlaves( $maxLag ); |
| 105 | + } |
| 106 | + if($redirectsOnly) |
| 107 | + $this->fixRedirect( $row->page_id ); |
| 108 | + else |
| 109 | + $this->fixLinksFromArticle( $row->page_id ); |
| 110 | + } |
| 111 | + } else { |
| 112 | + $this->output( "Refreshing $what table.\n" ); |
| 113 | + if ( !$end ) { |
| 114 | + $end = $dbr->selectField( 'page', 'max(page_id)', false ); |
| 115 | + } |
| 116 | + $this->output( "Starting from page_id $start of $end.\n" ); |
| 117 | + |
| 118 | + for ($id = $start; $id <= $end; $id++) { |
| 119 | + |
| 120 | + if ( !($id % $reportingInterval) ) { |
| 121 | + $this->output( "$id\n" ); |
| 122 | + wfWaitForSlaves( $maxLag ); |
| 123 | + } |
| 124 | + if($redirectsOnly) |
| 125 | + $this->fixRedirect( $id ); |
| 126 | + else |
| 127 | + $this->fixLinksFromArticle( $id ); |
| 128 | + } |
| 129 | + } |
44 | 130 | } |
45 | 131 | |
46 | | - refreshLinks( $start, $options['new-only'], $options['m'], $options['e'], $options['redirects-only'], $options['old-redirects-only'] ); |
47 | | -} |
| 132 | + /** |
| 133 | + * Update the redirect entry for a given page |
| 134 | + * @param $id int The page_id of the redirect |
| 135 | + */ |
| 136 | + private function fixRedirect( $id ){ |
| 137 | + global $wgTitle, $wgArticle; |
| 138 | + |
| 139 | + $wgTitle = Title::newFromID( $id ); |
| 140 | + $dbw = wfGetDB( DB_MASTER ); |
| 141 | + |
| 142 | + if ( is_null( $wgTitle ) ) { |
| 143 | + return; |
| 144 | + } |
| 145 | + $wgArticle = new Article($wgTitle); |
| 146 | + |
| 147 | + $rt = $wgArticle->followRedirect(); |
| 148 | + |
| 149 | + if($rt == false || !is_object($rt)) |
| 150 | + return; |
| 151 | + |
| 152 | + $wgArticle->updateRedirectOn($dbw,$rt); |
| 153 | + } |
48 | 154 | |
49 | | -if ( !isset( $options['batch-size'] ) ) { |
50 | | - $options['batch-size'] = 100; |
51 | | -} |
| 155 | + /** |
| 156 | + * Run LinksUpdate for all links on a given page_id |
| 157 | + * @param $id int The page_id |
| 158 | + */ |
| 159 | + private function fixLinksFromArticle( $id ) { |
| 160 | + global $wgTitle, $wgParser; |
52 | 161 | |
53 | | -deleteLinksFromNonexistent($options['m'], $options['batch-size']); |
| 162 | + $wgTitle = Title::newFromID( $id ); |
| 163 | + $dbw = wfGetDB( DB_MASTER ); |
54 | 164 | |
55 | | -if ( $options['globals'] ) { |
56 | | - print_r( $GLOBALS ); |
| 165 | + $linkCache =& LinkCache::singleton(); |
| 166 | + $linkCache->clear(); |
| 167 | + |
| 168 | + if ( is_null( $wgTitle ) ) { |
| 169 | + return; |
| 170 | + } |
| 171 | + $dbw->begin(); |
| 172 | + |
| 173 | + $revision = Revision::newFromTitle( $wgTitle ); |
| 174 | + if ( !$revision ) { |
| 175 | + return; |
| 176 | + } |
| 177 | + |
| 178 | + $options = new ParserOptions; |
| 179 | + $parserOutput = $wgParser->parse( $revision->getText(), $wgTitle, $options, true, true, $revision->getId() ); |
| 180 | + $update = new LinksUpdate( $wgTitle, $parserOutput, false ); |
| 181 | + $update->doUpdate(); |
| 182 | + $dbw->immediateCommit(); |
| 183 | + } |
| 184 | + |
| 185 | + /* |
| 186 | + * Removes non-existing links from pages from pagelinks, imagelinks, |
| 187 | + * categorylinks, templatelinks and externallinks tables. |
| 188 | + * |
| 189 | + * @param $maxLag |
| 190 | + * @param $batchSize The size of deletion batches |
| 191 | + * |
| 192 | + * @author Merlijn van Deen <valhallasw@arctus.nl> |
| 193 | + */ |
| 194 | + private function deleteLinksFromNonexistent( $maxLag = 0, $batchSize = 100 ) { |
| 195 | + wfWaitForSlaves( $maxLag ); |
| 196 | + |
| 197 | + $dbw = wfGetDB( DB_MASTER ); |
| 198 | + |
| 199 | + $lb = wfGetLBFactory()->newMainLB(); |
| 200 | + $dbr = $lb->getConnection( DB_SLAVE ); |
| 201 | + $dbr->bufferResults( false ); |
| 202 | + |
| 203 | + $linksTables = array( // table name => page_id field |
| 204 | + 'pagelinks' => 'pl_from', |
| 205 | + 'imagelinks' => 'il_from', |
| 206 | + 'categorylinks' => 'cl_from', |
| 207 | + 'templatelinks' => 'tl_from', |
| 208 | + 'externallinks' => 'el_from', |
| 209 | + ); |
| 210 | + |
| 211 | + foreach ( $linksTables as $table => $field ) { |
| 212 | + $this->output( "Retrieving illegal entries from $table... " ); |
| 213 | + |
| 214 | + // SELECT DISTINCT( $field ) FROM $table LEFT JOIN page ON $field=page_id WHERE page_id IS NULL; |
| 215 | + $results = $dbr->select( array( $table, 'page' ), |
| 216 | + $field, |
| 217 | + array('page_id' => null ), |
| 218 | + __METHOD__, |
| 219 | + 'DISTINCT', |
| 220 | + array( 'page' => array( 'LEFT JOIN', "$field=page_id")) |
| 221 | + ); |
| 222 | + |
| 223 | + $counter = 0; |
| 224 | + $list = array(); |
| 225 | + $this->output( "0.." ); |
| 226 | + |
| 227 | + foreach( $results as $row ) { |
| 228 | + $counter++; |
| 229 | + $list[] = $row->$field; |
| 230 | + if ( ( $counter % $batchSize ) == 0 ) { |
| 231 | + wfWaitForSlaves(5); |
| 232 | + $dbw->delete( $table, array( $field => $list ), __METHOD__ ); |
| 233 | + |
| 234 | + $this->output( $counter . ".." ); |
| 235 | + $list = array(); |
| 236 | + } |
| 237 | + } |
| 238 | + $this->output( $counter ); |
| 239 | + if (count($list) > 0) { |
| 240 | + $dbw->delete( $table, array( $field => $list ), __METHOD__ ); |
| 241 | + } |
| 242 | + $this->output( "\n" ); |
| 243 | + } |
| 244 | + $lb->closeAll(); |
| 245 | + } |
57 | 246 | } |
| 247 | + |
| 248 | +$maintClass = 'RefreshLinks'; |
| 249 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/maintenance/clear_interwiki_cache.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * This script is used to clear the interwiki links for ALL languages in |
5 | | - * memcached. |
| 5 | + * the cache. |
6 | 6 | * |
7 | 7 | * @ingroup Maintenance |
8 | 8 | */ |
Index: branches/maintenance-work/maintenance/README |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | Immediately complete all jobs in the job queue |
96 | 96 | |
97 | 97 | stats.php |
98 | | - Show all statistics stored in memcached |
| 98 | + Show all statistics stored in the cache |
99 | 99 | |
100 | 100 | undelete.php |
101 | 101 | Undelete all revisions of a page |
Index: branches/maintenance-work/maintenance/rebuildall.php |
— | — | @@ -32,8 +32,8 @@ |
33 | 33 | |
34 | 34 | // Rebuild link tables |
35 | 35 | $this->output( "\n\n** Rebuilding links tables -- this can take a long time. It should be safe to abort via ctrl+C if you get bored.\n" ); |
36 | | -// $rebuildLinks = $this->spawnChild( 'RefreshLinks', 'refreshLinks.php' ); |
37 | | -// $rebuildLinks->execute(); |
| 36 | + $rebuildLinks = $this->spawnChild( 'RefreshLinks', 'refreshLinks.php' ); |
| 37 | + $rebuildLinks->execute(); |
38 | 38 | |
39 | 39 | $this->output( "Done.\n" ); |
40 | 40 | } |
Index: branches/maintenance-work/maintenance/clear_stats.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * This script remove all statistics tracking from memcached |
| 4 | + * This script remove all statistics tracking from the cache |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Maintenance |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | |
14 | 14 | public function __construct() { |
15 | 15 | parent::__construct(); |
16 | | - $this->mDescription = "Remove all statistics tracking from memcached"; |
| 16 | + $this->mDescription = "Remove all statistics tracking from the cache"; |
17 | 17 | } |
18 | 18 | |
19 | 19 | public function execute() { |
Index: branches/maintenance-work/maintenance/doMaintenance.php |
— | — | @@ -57,10 +57,15 @@ |
58 | 58 | require_once( "$IP/includes/Setup.php" ); |
59 | 59 | require_once( "$IP/install-utils.inc" ); |
60 | 60 | |
61 | | -$wgTitle = null; # Much much faster startup than creating a title object |
| 61 | +// Much much faster startup than creating a title object |
| 62 | +$wgTitle = null; |
62 | 63 | |
| 64 | +// Do the work |
63 | 65 | try { |
64 | 66 | $maintenance->execute(); |
65 | 67 | } catch( MWException $mwe ) { |
66 | 68 | echo( $mwe->getText() ); |
67 | | -} |
\ No newline at end of file |
| 69 | +} |
| 70 | + |
| 71 | +// Potentially debug globals |
| 72 | +$maintenance->globals(); |
Index: branches/maintenance-work/maintenance/Maintenance.php |
— | — | @@ -18,9 +18,9 @@ |
19 | 19 | * Constants for DB access type |
20 | 20 | * @see Maintenance::getDbType() |
21 | 21 | */ |
22 | | - const NO_DB = 0; |
23 | | - const NORMAL_DB = 1; |
24 | | - const ADMIN_DB = 2; |
| 22 | + const DB_NONE = 0; |
| 23 | + const DB_STD = 1; |
| 24 | + const DB_ADMIN = 2; |
25 | 25 | |
26 | 26 | // This is the desired params |
27 | 27 | private $mParams = array(); |
— | — | @@ -47,8 +47,9 @@ |
48 | 48 | // Have we already loaded our user input? |
49 | 49 | private $inputLoaded = false; |
50 | 50 | |
51 | | - // Batch size |
52 | | - protected $mBatchSize = 100; |
| 51 | + // Batch size. If a script supports this, they should set |
| 52 | + // a default with setBatchSize() |
| 53 | + protected $mBatchSize = null; |
53 | 54 | |
54 | 55 | /** |
55 | 56 | * Default constructor. Children should call this if implementing |
— | — | @@ -124,7 +125,7 @@ |
125 | 126 | * @return mixed |
126 | 127 | */ |
127 | 128 | protected function getArg( $argId = 0, $default = null ) { |
128 | | - return $this->hasArg($name) ? $this->mArgs[$name] : $default; |
| 129 | + return $this->hasArg($argId) ? $this->mArgs[$argId] : $default; |
129 | 130 | } |
130 | 131 | |
131 | 132 | /** |
— | — | @@ -191,13 +192,13 @@ |
192 | 193 | * scripts admin rights to the DB (when available). Sometimes, a script needs |
193 | 194 | * normal access for a reason and sometimes they want no access. Subclasses |
194 | 195 | * should override and return one of the following values, as needed: |
195 | | - * Maintenance::NO_DB - For no DB access at all |
196 | | - * Maintenance::NORMAL_DB - For normal DB access |
197 | | - * Maintenance::ADMIN_DB - For admin DB access, default |
| 196 | + * Maintenance::DB_NONE - For no DB access at all |
| 197 | + * Maintenance::DB_STD - For normal DB access |
| 198 | + * Maintenance::DB_ADMIN - For admin DB access, default |
198 | 199 | * @return int |
199 | 200 | */ |
200 | 201 | protected function getDbType() { |
201 | | - return Maintenance :: ADMIN_DB; |
| 202 | + return Maintenance :: DB_ADMIN; |
202 | 203 | } |
203 | 204 | |
204 | 205 | /** |
— | — | @@ -208,10 +209,17 @@ |
209 | 210 | $this->addOption( 'quiet', "Whether to supress non-error output" ); |
210 | 211 | $this->addOption( 'conf', "Location of LocalSettings.php, if not default", false, true ); |
211 | 212 | $this->addOption( 'wiki', "For specifying the wiki ID", false, true ); |
| 213 | + $this->addOption( 'globals', "Output globals at the end of processing for debugging" ); |
| 214 | + // If we support a DB, show the options |
212 | 215 | if( $this->getDbType() > 0 ) { |
213 | 216 | $this->addOption( 'dbuser', "The DB user to use for this script", false, true ); |
214 | 217 | $this->addOption( 'dbpass', "The password to use for this script", false, true ); |
215 | 218 | } |
| 219 | + // If we support $mBatchSize, show the option |
| 220 | + if( $this->mBatchSize ) { |
| 221 | + $this->addOption( 'batch-size', 'Run this many operations ' . |
| 222 | + 'per batch, default: ' . $this->mBatchSize , false, true ); |
| 223 | + } |
216 | 224 | } |
217 | 225 | |
218 | 226 | /** |
— | — | @@ -504,8 +512,18 @@ |
505 | 513 | |
506 | 514 | $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors |
507 | 515 | } |
508 | | - |
| 516 | + |
509 | 517 | /** |
| 518 | + * Potentially debug globals. Originally a feature only |
| 519 | + * for refreshLinks |
| 520 | + */ |
| 521 | + public function globals() { |
| 522 | + if( $this->hasOption( 'globals' ) ) { |
| 523 | + print_r( $GLOBALS ); |
| 524 | + } |
| 525 | + } |
| 526 | + |
| 527 | + /** |
510 | 528 | * Do setup specific to WMF |
511 | 529 | */ |
512 | 530 | public function loadWikimediaSettings() { |
Index: branches/maintenance-work/maintenance/deleteImageMemcached.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * This script delete image information from memcached. |
| 4 | + * This script delete image information from the cache. |
5 | 5 | * |
6 | 6 | * Usage example: |
7 | 7 | * php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0 |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | class DeleteImageCache extends Maintenance { |
16 | 16 | public function __construct() { |
17 | 17 | parent::__construct(); |
18 | | - $this->mDescription = "Delete image information from memcached"; |
| 18 | + $this->mDescription = "Delete image information from the cache"; |
19 | 19 | $this->addOption( 'sleep', 'How many seconds to sleep between deletions', true, true ); |
20 | 20 | $this->addOption( 'until', 'Timestamp to delete all entries prior to', true, true ); |
21 | 21 | } |
Index: branches/maintenance-work/maintenance/rebuildmessages.php |
— | — | @@ -1,22 +1,34 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * This script purges all language messages from memcached |
| 4 | + * This script purges all language messages from the cache |
5 | 5 | * @file |
6 | 6 | * @ingroup Maintenance |
7 | 7 | */ |
8 | 8 | |
9 | | -require_once( 'commandLine.inc' ); |
| 9 | +require_once( "Maintenance.php" ); |
10 | 10 | |
11 | | -if( $wgLocalDatabases ) { |
12 | | - $databases = $wgLocalDatabases; |
13 | | -} else { |
14 | | - $databases = array( $wgDBname ); |
| 11 | +class RebuildMessages extends Maintenance { |
| 12 | + public function __construct() { |
| 13 | + parent::__construct(); |
| 14 | + $this->mDescription = "Purge all language messages from the cache"; |
| 15 | + } |
| 16 | + |
| 17 | + public function execute() { |
| 18 | + global $wgLocalDatabases, $wgDBname, $wgEnableSidebarCache, $messageMemc; |
| 19 | + if( $wgLocalDatabases ) { |
| 20 | + $databases = $wgLocalDatabases; |
| 21 | + } else { |
| 22 | + $databases = array( $wgDBname ); |
| 23 | + } |
| 24 | + |
| 25 | + foreach( $databases as $db ) { |
| 26 | + $this->output( "Deleting message cache for {$db}... " ); |
| 27 | + $messageMemc->delete( "{$db}:messages" ); |
| 28 | + if( $wgEnableSidebarCache ) |
| 29 | + $messageMemc->delete( "{$db}:sidebar" ); |
| 30 | + $this->output( "Deleted\n" ); |
| 31 | + } |
| 32 | + } |
15 | 33 | } |
16 | 34 | |
17 | | -foreach( $databases as $db ) { |
18 | | - echo "Deleting message cache for {$db}... "; |
19 | | - $messageMemc->delete( "{$db}:messages" ); |
20 | | - if( $wgEnableSidebarCache ) |
21 | | - $messageMemc->delete( "{$db}:sidebar" ); |
22 | | - echo "Deleted\n"; |
23 | | -} |
| 35 | + |
Index: branches/maintenance-work/includes/SiteStats.php |
— | — | @@ -180,7 +180,7 @@ |
181 | 181 | * @param $update bool Whether to update the current stats write fresh |
182 | 182 | * @param $noViews bool When true, do not update the number of page views |
183 | 183 | */ |
184 | | - function init( $update, $noViews = false ) { |
| 184 | + public static function init( $update, $noViews = false ) { |
185 | 185 | $dbr = wfGetDB( DB_SLAVE ); |
186 | 186 | |
187 | 187 | wfOut( "Counting total edits..." ); |