Index: trunk/phase3/includes/specials/SpecialExport.php |
— | — | @@ -22,22 +22,22 @@ |
23 | 23 | */ |
24 | 24 | |
25 | 25 | class SpecialExport extends SpecialPage { |
26 | | - |
| 26 | + |
27 | 27 | private $curonly, $doExport, $pageLinkDepth, $templates; |
28 | 28 | private $images; |
29 | | - |
| 29 | + |
30 | 30 | public function __construct() { |
31 | 31 | parent::__construct( 'Export' ); |
32 | 32 | } |
33 | | - |
| 33 | + |
34 | 34 | public function execute( $par ) { |
35 | 35 | global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors; |
36 | 36 | global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth; |
37 | 37 | global $wgExportFromNamespaces; |
38 | | - |
| 38 | + |
39 | 39 | $this->setHeaders(); |
40 | 40 | $this->outputHeader(); |
41 | | - |
| 41 | + |
42 | 42 | // Set some variables |
43 | 43 | $this->curonly = true; |
44 | 44 | $this->doExport = false; |
— | — | @@ -46,11 +46,11 @@ |
47 | 47 | $this->pageLinkDepth = $this->validateLinkDepth( |
48 | 48 | $wgRequest->getIntOrNull( 'pagelink-depth' ) ); |
49 | 49 | $nsindex = ''; |
50 | | - |
| 50 | + |
51 | 51 | if ( $wgRequest->getCheck( 'addcat' ) ) { |
52 | 52 | $page = $wgRequest->getText( 'pages' ); |
53 | 53 | $catname = $wgRequest->getText( 'catname' ); |
54 | | - |
| 54 | + |
55 | 55 | if ( $catname !== '' && $catname !== null && $catname !== false ) { |
56 | 56 | $t = Title::makeTitleSafe( NS_MAIN, $catname ); |
57 | 57 | if ( $t ) { |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | else if( $wgRequest->getCheck( 'addns' ) && $wgExportFromNamespaces ) { |
69 | 69 | $page = $wgRequest->getText( 'pages' ); |
70 | 70 | $nsindex = $wgRequest->getText( 'nsindex', '' ); |
71 | | - |
| 71 | + |
72 | 72 | if ( strval( $nsindex ) !== '' ) { |
73 | 73 | /** |
74 | 74 | * Same implementation as above, so same @todo |
— | — | @@ -106,7 +106,7 @@ |
107 | 107 | $history['dir'] = 'desc'; |
108 | 108 | } |
109 | 109 | } |
110 | | - |
| 110 | + |
111 | 111 | if( $page != '' ) $this->doExport = true; |
112 | 112 | } else { |
113 | 113 | // Default to current-only for GET requests |
— | — | @@ -117,18 +117,18 @@ |
118 | 118 | } else { |
119 | 119 | $history = WikiExporter::CURRENT; |
120 | 120 | } |
121 | | - |
| 121 | + |
122 | 122 | if( $page != '' ) $this->doExport = true; |
123 | 123 | } |
124 | | - |
| 124 | + |
125 | 125 | if( !$wgExportAllowHistory ) { |
126 | 126 | // Override |
127 | 127 | $history = WikiExporter::CURRENT; |
128 | 128 | } |
129 | | - |
| 129 | + |
130 | 130 | $list_authors = $wgRequest->getCheck( 'listauthors' ); |
131 | 131 | if ( !$this->curonly || !$wgExportAllowListContributors ) $list_authors = false ; |
132 | | - |
| 132 | + |
133 | 133 | if ( $this->doExport ) { |
134 | 134 | $wgOut->disable(); |
135 | 135 | // Cancel output buffering and gzipping if set |
— | — | @@ -143,22 +143,22 @@ |
144 | 144 | $this->doExport( $page, $history, $list_authors ); |
145 | 145 | return; |
146 | 146 | } |
147 | | - |
| 147 | + |
148 | 148 | $wgOut->addWikiMsg( 'exporttext' ); |
149 | | - |
| 149 | + |
150 | 150 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
151 | 151 | 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) ); |
152 | 152 | $form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . ' '; |
153 | 153 | $form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />'; |
154 | | - |
| 154 | + |
155 | 155 | if ( $wgExportFromNamespaces ) { |
156 | 156 | $form .= Xml::namespaceSelector( $nsindex, null, 'nsindex', wfMsg( 'export-addnstext' ) ) . ' '; |
157 | 157 | $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />'; |
158 | 158 | } |
159 | | - |
| 159 | + |
160 | 160 | $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false ); |
161 | 161 | $form .= '<br />'; |
162 | | - |
| 162 | + |
163 | 163 | if( $wgExportAllowHistory ) { |
164 | 164 | $form .= Xml::checkLabel( wfMsg( 'exportcuronly' ), 'curonly', 'curonly', true ) . '<br />'; |
165 | 165 | } else { |
— | — | @@ -171,28 +171,31 @@ |
172 | 172 | // Enable this when we can do something useful exporting/importing image information. :) |
173 | 173 | //$form .= Xml::checkLabel( wfMsg( 'export-images' ), 'images', 'wpExportImages', false ) . '<br />'; |
174 | 174 | $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />'; |
175 | | - |
| 175 | + |
176 | 176 | $form .= Xml::submitButton( wfMsg( 'export-submit' ), array( 'accesskey' => 's' ) ); |
177 | 177 | $form .= Xml::closeElement( 'form' ); |
178 | 178 | $wgOut->addHTML( $form ); |
179 | 179 | } |
180 | | - |
| 180 | + |
181 | 181 | private function userCanOverrideExportDepth() { |
182 | | - global $wgUser; |
| 182 | + global $wgUser; |
183 | 183 | |
184 | 184 | return $wgUser->isAllowed( 'override-export-depth' ); |
185 | 185 | } |
186 | | - |
| 186 | + |
187 | 187 | /** |
188 | 188 | * Do the actual page exporting |
189 | | - * @param string $page User input on what page(s) to export |
190 | | - * @param mixed $history one of the WikiExporter history export constants |
| 189 | + * |
| 190 | + * @param $page String: user input on what page(s) to export |
| 191 | + * @param $history Mixed: one of the WikiExporter history export constants |
| 192 | + * @param $list_authors Boolean: Whether to add distinct author list (when |
| 193 | + * not returning full history) |
191 | 194 | */ |
192 | 195 | private function doExport( $page, $history, $list_authors ) { |
193 | 196 | global $wgExportMaxHistory; |
194 | | - |
| 197 | + |
195 | 198 | $pageSet = array(); // Inverted index of all pages to look up |
196 | | - |
| 199 | + |
197 | 200 | // Split up and normalize input |
198 | 201 | foreach( explode( "\n", $page ) as $pageName ) { |
199 | 202 | $pageName = trim( $pageName ); |
— | — | @@ -202,26 +205,26 @@ |
203 | 206 | $pageSet[$title->getPrefixedText()] = true; |
204 | 207 | } |
205 | 208 | } |
206 | | - |
| 209 | + |
207 | 210 | // Set of original pages to pass on to further manipulation... |
208 | 211 | $inputPages = array_keys( $pageSet ); |
209 | | - |
| 212 | + |
210 | 213 | // Look up any linked pages if asked... |
211 | 214 | if( $this->templates ) { |
212 | 215 | $pageSet = $this->getTemplates( $inputPages, $pageSet ); |
213 | 216 | } |
214 | | - |
| 217 | + |
215 | 218 | if( $linkDepth = $this->pageLinkDepth ) { |
216 | 219 | $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth ); |
217 | 220 | } |
218 | | - |
| 221 | + |
219 | 222 | /* |
220 | 223 | // Enable this when we can do something useful exporting/importing image information. :) |
221 | 224 | if( $this->images ) ) { |
222 | 225 | $pageSet = $this->getImages( $inputPages, $pageSet ); |
223 | 226 | } |
224 | 227 | */ |
225 | | - |
| 228 | + |
226 | 229 | $pages = array_keys( $pageSet ); |
227 | 230 | |
228 | 231 | // Normalize titles to the same format and remove dupes, see bug 17374 |
— | — | @@ -240,7 +243,7 @@ |
241 | 244 | $lb = wfGetLBFactory()->newMainLB(); |
242 | 245 | $db = $lb->getConnection( DB_SLAVE ); |
243 | 246 | $buffer = WikiExporter::STREAM; |
244 | | - |
| 247 | + |
245 | 248 | // This might take a while... :D |
246 | 249 | wfSuppressWarnings(); |
247 | 250 | set_time_limit(0); |
— | — | @@ -266,10 +269,10 @@ |
267 | 270 | $title = Title::newFromText( $page ); |
268 | 271 | if( is_null( $title ) ) continue; #TODO: perhaps output an <error> tag or something. |
269 | 272 | if( !$title->userCanRead() ) continue; #TODO: perhaps output an <error> tag or something. |
270 | | - |
| 273 | + |
271 | 274 | $exporter->pageByTitle( $title ); |
272 | 275 | } |
273 | | - |
| 276 | + |
274 | 277 | $exporter->closeStream(); |
275 | 278 | if( $lb ) { |
276 | 279 | $lb->closeAll(); |
— | — | @@ -278,15 +281,15 @@ |
279 | 282 | |
280 | 283 | private function getPagesFromCategory( $title ) { |
281 | 284 | global $wgContLang; |
282 | | - |
| 285 | + |
283 | 286 | $name = $title->getDBkey(); |
284 | | - |
| 287 | + |
285 | 288 | $dbr = wfGetDB( DB_SLAVE ); |
286 | 289 | $res = $dbr->select( array('page', 'categorylinks' ), |
287 | 290 | array( 'page_namespace', 'page_title' ), |
288 | 291 | array('cl_from=page_id', 'cl_to' => $name ), |
289 | 292 | __METHOD__, array('LIMIT' => '5000')); |
290 | | - |
| 293 | + |
291 | 294 | $pages = array(); |
292 | 295 | while ( $row = $dbr->fetchObject( $res ) ) { |
293 | 296 | $n = $row->page_title; |
— | — | @@ -294,22 +297,22 @@ |
295 | 298 | $ns = $wgContLang->getNsText( $row->page_namespace ); |
296 | 299 | $n = $ns . ':' . $n; |
297 | 300 | } |
298 | | - |
| 301 | + |
299 | 302 | $pages[] = $n; |
300 | 303 | } |
301 | 304 | $dbr->freeResult($res); |
302 | | - |
| 305 | + |
303 | 306 | return $pages; |
304 | 307 | } |
305 | | - |
| 308 | + |
306 | 309 | private function getPagesFromNamespace( $nsindex ) { |
307 | 310 | global $wgContLang; |
308 | | - |
| 311 | + |
309 | 312 | $dbr = wfGetDB( DB_SLAVE ); |
310 | 313 | $res = $dbr->select( 'page', array('page_namespace', 'page_title'), |
311 | 314 | array('page_namespace' => $nsindex), |
312 | 315 | __METHOD__, array('LIMIT' => '5000') ); |
313 | | - |
| 316 | + |
314 | 317 | $pages = array(); |
315 | 318 | while ( $row = $dbr->fetchObject( $res ) ) { |
316 | 319 | $n = $row->page_title; |
— | — | @@ -317,13 +320,14 @@ |
318 | 321 | $ns = $wgContLang->getNsText( $row->page_namespace ); |
319 | 322 | $n = $ns . ':' . $n; |
320 | 323 | } |
321 | | - |
| 324 | + |
322 | 325 | $pages[] = $n; |
323 | 326 | } |
324 | 327 | $dbr->freeResult($res); |
325 | | - |
| 328 | + |
326 | 329 | return $pages; |
327 | 330 | } |
| 331 | + |
328 | 332 | /** |
329 | 333 | * Expand a list of pages to include templates used in those pages. |
330 | 334 | * @param $inputPages array, list of titles to look up |
— | — | @@ -336,7 +340,7 @@ |
337 | 341 | array( 'tl_namespace AS namespace', 'tl_title AS title' ), |
338 | 342 | array( 'page_id=tl_from' ) ); |
339 | 343 | } |
340 | | - |
| 344 | + |
341 | 345 | /** |
342 | 346 | * Validate link depth setting, if available. |
343 | 347 | */ |
— | — | @@ -357,7 +361,7 @@ |
358 | 362 | */ |
359 | 363 | return intval( min( $depth, 5 ) ); |
360 | 364 | } |
361 | | - |
| 365 | + |
362 | 366 | /** Expand a list of pages to include pages linked to from that page. */ |
363 | 367 | private function getPageLinks( $inputPages, $pageSet, $depth ) { |
364 | 368 | for( $depth=$depth; $depth>0; --$depth ) { |
— | — | @@ -368,7 +372,7 @@ |
369 | 373 | } |
370 | 374 | return $pageSet; |
371 | 375 | } |
372 | | - |
| 376 | + |
373 | 377 | /** |
374 | 378 | * Expand a list of pages to include images used in those pages. |
375 | 379 | * @param $inputPages array, list of titles to look up |
— | — | @@ -381,7 +385,7 @@ |
382 | 386 | array( NS_FILE . ' AS namespace', 'il_to AS title' ), |
383 | 387 | array( 'page_id=il_from' ) ); |
384 | 388 | } |
385 | | - |
| 389 | + |
386 | 390 | /** |
387 | 391 | * Expand a list of pages to include items used in those pages. |
388 | 392 | * @private |