Index: trunk/extensions/TitleKey/TitleKey.php |
— | — | @@ -57,3 +57,4 @@ |
58 | 58 | $dir = dirname(__FILE__) . '/'; |
59 | 59 | $wgExtensionMessagesFiles['TitleKey'] = $dir . 'TitleKey.i18n.php'; |
60 | 60 | $wgAutoloadClasses['TitleKey'] = $dir . 'TitleKey_body.php'; |
| 61 | +$wgAutoloadClasses['RebuildTitleKeys'] = $dir . 'rebuildTitleKeys.php'; |
Index: trunk/extensions/TitleKey/rebuildTitleKeys.php |
— | — | @@ -1,18 +1,63 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once dirname( dirname( dirname( __FILE__ ) ) ) . "/maintenance/commandLine.inc"; |
| 4 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 5 | +if ( $IP === false ) |
| 6 | + $IP = dirname( __FILE__ ) . '/../..'; |
5 | 7 | |
| 8 | +require_once( "$IP/maintenance/Maintenance.php" ); |
| 9 | + |
6 | 10 | // In case we want to do offline initialization... |
7 | 11 | if( !class_exists( 'TitleKey' ) ) { |
8 | 12 | require dirname( __FILE__ ) . '/TitleKey_body.php'; |
9 | 13 | } |
10 | 14 | |
11 | | -if( isset( $options['help'] ) ) { |
12 | | - echo "Rebuilds titlekey table entries for all pages in DB.\n"; |
13 | | - echo "Usage:\n"; |
14 | | - echo " php extensions/TitleKey/rebuildTitleKeys.php [--start=<page_id>]\n"; |
15 | | -} else { |
16 | | - $start = intval( @$options['start'] ); |
17 | | - echo "Rebuilding titlekey table...\n"; |
18 | | - TitleKey::populateKeys( $start ); |
19 | | -} |
\ No newline at end of file |
| 15 | +class RebuildTitleKeys extends Maintenance { |
| 16 | + function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Rebuilds titlekey table entries for all pages in DB."; |
| 19 | + $this->addOption( 'start', 'Page ID to start from', false, true ); |
| 20 | + } |
| 21 | + |
| 22 | + function execute() { |
| 23 | + $start = $this->getOption( 'start', 0 ); |
| 24 | + $this->output( "Rebuilding titlekey table...\n" ); |
| 25 | + $dbr = $this->getDB( DB_SLAVE ); |
| 26 | + |
| 27 | + $maxId = $dbr->selectField( 'page', 'MAX(page_id)', '', __METHOD__ ); |
| 28 | + $chunkSize = 1000; |
| 29 | + |
| 30 | + $lastId = 0; |
| 31 | + for( ; $start <= $maxId; $start += $chunkSize ) { |
| 32 | + if( $start != 0 ) { |
| 33 | + $this->output( "... $start...\n" ); |
| 34 | + } |
| 35 | + $result = $dbr->select( 'page', |
| 36 | + array( 'page_id', 'page_namespace', 'page_title' ), |
| 37 | + array( 'page_id > ' . intval( $start ) ), |
| 38 | + __METHOD__, |
| 39 | + array( |
| 40 | + 'ORDER BY' => 'page_id', |
| 41 | + 'LIMIT' => $chunkSize ) ); |
| 42 | + |
| 43 | + $titles = array(); |
| 44 | + foreach( $result as $row ) { |
| 45 | + $titles[$row->page_id] = |
| 46 | + Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 47 | + $lastId = $row->page_id; |
| 48 | + } |
| 49 | + $result->free(); |
| 50 | + |
| 51 | + TitleKey::setBatchKeys( $titles ); |
| 52 | + |
| 53 | + wfWaitForSlaves( 20 ); |
| 54 | + } |
| 55 | + if( $lastId ) { |
| 56 | + $this->output( "... $lastId ok.\n" ); |
| 57 | + } else { |
| 58 | + $this->output( "... no pages.\n" ); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +$maintClass = 'RebuildTitleKeys'; |
| 64 | +require_once( DO_MAINTENANCE ); |
Index: trunk/extensions/TitleKey/TitleKey_body.php |
— | — | @@ -108,82 +108,30 @@ |
109 | 109 | * |
110 | 110 | * Status info is sent to stdout. |
111 | 111 | */ |
112 | | - static function schemaUpdates( $updater = null ) { |
113 | | - if ( $updater === null ) { // < 1.17 |
114 | | - self::runUpdates( wfGetDB( DB_MASTER ) ); |
115 | | - } else { |
116 | | - $updater->addExtensionUpdate( array( array( __CLASS__, 'addDBtable' ) ) ); |
117 | | - } |
| 112 | + public static function schemaUpdates( $updater = null ) { |
| 113 | + $updater->addExtensionUpdate( array( array( __CLASS__, 'runUpdates' ) ) ); |
118 | 114 | return true; |
119 | 115 | } |
120 | 116 | |
121 | | - public static function addDBtable( $updater ) { |
122 | | - self::runUpdates( $updater->getDB() ); |
123 | | - } |
124 | | - |
125 | | - private static function runUpdates( $db ) { |
| 117 | + public static function runUpdates( $updater ) { |
| 118 | + $db = $updater->getDB(); |
126 | 119 | if( $db->tableExists( 'titlekey' ) ) { |
127 | | - wfOut( "...titlekey table already exists.\n" ); |
| 120 | + $updater->output( "...titlekey table already exists.\n" ); |
128 | 121 | } else { |
129 | | - wfOut( "Creating titlekey table..." ); |
| 122 | + $updater->output( "Creating titlekey table..." ); |
130 | 123 | $sourcefile = $db->getType() == 'postgres' ? '/titlekey.pg.sql' : '/titlekey.sql'; |
131 | 124 | $err = $db->sourceFile( dirname( __FILE__ ) . $sourcefile ); |
132 | 125 | if( $err !== true ) { |
133 | 126 | throw new MWException( $err ); |
134 | 127 | } |
135 | 128 | |
136 | | - wfOut( "ok.\nPopulating titlekey table...\n" ); |
137 | | - self::populateKeys(); |
| 129 | + $updater->output( "ok.\n" ); |
| 130 | + $task = $updater->maintenance->runChild( 'RebuildTitleKeys' ); |
| 131 | + $task->execute(); |
138 | 132 | } |
139 | 133 | } |
140 | 134 | |
141 | 135 | /** |
142 | | - * (Re)populate the titlekeys table with all page titles, |
143 | | - * optionally starting from a given page id. |
144 | | - * |
145 | | - * Status info is sent to stdout. |
146 | | - * |
147 | | - * @param $start int page_id |
148 | | - */ |
149 | | - static function populateKeys( $start=0 ) { |
150 | | - $dbr = wfGetDB( DB_SLAVE ); |
151 | | - |
152 | | - $maxId = $dbr->selectField( 'page', 'MAX(page_id)', '', __METHOD__ ); |
153 | | - $chunkSize = 1000; |
154 | | - |
155 | | - $lastId = 0; |
156 | | - for( ; $start <= $maxId; $start += $chunkSize ) { |
157 | | - if( $start != 0 ) { |
158 | | - echo "... $start...\n"; |
159 | | - } |
160 | | - $result = $dbr->select( 'page', |
161 | | - array( 'page_id', 'page_namespace', 'page_title' ), |
162 | | - array( 'page_id > ' . intval( $start ) ), |
163 | | - __METHOD__, |
164 | | - array( |
165 | | - 'ORDER BY' => 'page_id', |
166 | | - 'LIMIT' => $chunkSize ) ); |
167 | | - |
168 | | - $titles = array(); |
169 | | - foreach( $result as $row ) { |
170 | | - $titles[$row->page_id] = |
171 | | - Title::makeTitle( $row->page_namespace, $row->page_title ); |
172 | | - $lastId = $row->page_id; |
173 | | - } |
174 | | - $result->free(); |
175 | | - |
176 | | - self::setBatchKeys( $titles ); |
177 | | - |
178 | | - wfWaitForSlaves( 20 ); |
179 | | - } |
180 | | - if( $lastId ) { |
181 | | - echo "... $lastId ok.\n"; |
182 | | - } else { |
183 | | - echo "... no pages.\n"; |
184 | | - } |
185 | | - } |
186 | | - |
187 | | - /** |
188 | 136 | * Override the default OpenSearch backend... |
189 | 137 | * @param string $search term |
190 | 138 | * @param int $limit max number of items to return |