Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -23,6 +23,8 @@ |
24 | 24 | * (bug 19052) Unicode space separator characters (Zs) now terminates external |
25 | 25 | links and images links. |
26 | 26 | * (bug 30160) Add public method to mw.loader to get module names from registry. |
| 27 | +* (bug 15558) Parameters to special pages included in wikitext can now be passed |
| 28 | + as with templates. |
27 | 29 | |
28 | 30 | === Bug fixes in 1.19 === |
29 | 31 | * $wgUploadNavigationUrl should be used for file redlinks if |
Index: trunk/phase3/includes/SpecialPageFactory.php |
— | — | @@ -471,40 +471,47 @@ |
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
475 | | - * Just like executePath() except it returns the HTML instead of outputting it |
476 | | - * Returns false if there was no such special page, or a title object if it was |
| 475 | + * Just like executePath() but will override global variables and execute |
| 476 | + * the page in "inclusion" mode. Returns true if the excution was successful |
| 477 | + * or false if there was no such special page, or a title object if it was |
477 | 478 | * a redirect. |
478 | 479 | * |
479 | | - * Also saves the current $wgTitle, $wgOut, and $wgRequest variables so that |
480 | | - * the special page will get the context it'd expect on a normal request, |
481 | | - * and then restores them to their previous values after. |
| 480 | + * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang |
| 481 | + * variables so that the special page will get the context it'd expect on a |
| 482 | + * normal request, and then restores them to their previous values after. |
482 | 483 | * |
483 | 484 | * @param $title Title |
| 485 | + * @param $context RequestContext |
484 | 486 | * |
485 | 487 | * @return String: HTML fragment |
486 | 488 | */ |
487 | | - static function capturePath( &$title ) { |
488 | | - global $wgOut, $wgTitle, $wgRequest; |
| 489 | + static function capturePath( Title $title, RequestContext $context ) { |
| 490 | + global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang; |
489 | 491 | |
| 492 | + // Save current globals |
490 | 493 | $oldTitle = $wgTitle; |
491 | 494 | $oldOut = $wgOut; |
492 | 495 | $oldRequest = $wgRequest; |
| 496 | + $oldUser = $wgUser; |
| 497 | + $oldLang = $wgLang; |
493 | 498 | |
494 | | - // Don't want special pages interpreting ?feed=atom parameters. |
495 | | - $wgRequest = new FauxRequest( array() ); |
496 | | - |
497 | | - $context = new RequestContext; |
498 | | - $context->setTitle( $title ); |
499 | | - $context->setRequest( $wgRequest ); |
| 499 | + // Set the globals to the current context |
| 500 | + $wgTitle = $title; |
500 | 501 | $wgOut = $context->getOutput(); |
| 502 | + $wgRequest = $context->getRequest(); |
| 503 | + $wgUser = $context->getUser(); |
| 504 | + $wgLang = $context->getLang(); |
501 | 505 | |
| 506 | + // The useful part |
502 | 507 | $ret = self::executePath( $title, $context, true ); |
503 | | - if ( $ret === true ) { |
504 | | - $ret = $wgOut->getHTML(); |
505 | | - } |
| 508 | + |
| 509 | + // And restore that globals |
506 | 510 | $wgTitle = $oldTitle; |
507 | 511 | $wgOut = $oldOut; |
508 | 512 | $wgRequest = $oldRequest; |
| 513 | + $wgUser = $oldUser; |
| 514 | + $wgLang = $oldLang; |
| 515 | + |
509 | 516 | return $ret; |
510 | 517 | } |
511 | 518 | |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -3250,8 +3250,24 @@ |
3251 | 3251 | && $this->mOptions->getAllowSpecialInclusion() |
3252 | 3252 | && $this->ot['html'] ) |
3253 | 3253 | { |
3254 | | - $text = SpecialPageFactory::capturePath( $title ); |
3255 | | - if ( is_string( $text ) ) { |
| 3254 | + $pageArgs = array(); |
| 3255 | + for ( $i = 0; $i < $args->getLength(); $i++ ) { |
| 3256 | + $bits = $args->item( $i )->splitArg(); |
| 3257 | + if ( strval( $bits['index'] ) === '' ) { |
| 3258 | + $name = trim( $frame->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) ); |
| 3259 | + $value = trim( $frame->expand( $bits['value'] ) ); |
| 3260 | + $pageArgs[$name] = $value; |
| 3261 | + } |
| 3262 | + } |
| 3263 | + $context = new RequestContext; |
| 3264 | + $context->setTitle( $title ); |
| 3265 | + $context->setRequest( new FauxRequest( $pageArgs ) ); |
| 3266 | + $context->setUser( $this->getUser() ); |
| 3267 | + $context->setLang( Language::factory( $this->mOptions->getUserLang() ) ); |
| 3268 | + $ret = SpecialPageFactory::capturePath( $title, $context ); |
| 3269 | + if ( $ret ) { |
| 3270 | + $text = $context->getOutput()->getHTML(); |
| 3271 | + $this->mOutput->addOutputPage( $context->getOutput() ); |
3256 | 3272 | $found = true; |
3257 | 3273 | $isHTML = true; |
3258 | 3274 | $this->disableCache(); |
Index: trunk/phase3/includes/parser/ParserOutput.php |
— | — | @@ -130,6 +130,9 @@ |
131 | 131 | $mNoGallery = false, # No gallery on category page? (__NOGALLERY__) |
132 | 132 | $mHeadItems = array(), # Items to put in the <head> section |
133 | 133 | $mModules = array(), # Modules to be loaded by the resource loader |
| 134 | + $mModuleScripts = array(), # Modules of which only the JS will be loaded by the resource loader |
| 135 | + $mModuleStyles = array(), # Modules of which only the CSSS will be loaded by the resource loader |
| 136 | + $mModuleMessages = array(), # Modules of which only the messages will be loaded by the resource loader |
134 | 137 | $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks |
135 | 138 | $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only |
136 | 139 | $mSections = array(), # Table of contents |
— | — | @@ -195,6 +198,9 @@ |
196 | 199 | function getNoGallery() { return $this->mNoGallery; } |
197 | 200 | function getHeadItems() { return $this->mHeadItems; } |
198 | 201 | function getModules() { return $this->mModules; } |
| 202 | + function getModuleScripts() { return $this->mModuleScripts; } |
| 203 | + function getModuleStyles() { return $this->mModuleStyles; } |
| 204 | + function getModuleMessages() { return $this->mModuleMessages; } |
199 | 205 | function getOutputHooks() { return (array)$this->mOutputHooks; } |
200 | 206 | function getWarnings() { return array_keys( $this->mWarnings ); } |
201 | 207 | function getIndexPolicy() { return $this->mIndexPolicy; } |
— | — | @@ -334,11 +340,37 @@ |
335 | 341 | } |
336 | 342 | } |
337 | 343 | |
338 | | - function addModules( $modules ) { |
| 344 | + public function addModules( $modules ) { |
339 | 345 | $this->mModules = array_merge( $this->mModules, (array) $modules ); |
340 | 346 | } |
341 | 347 | |
| 348 | + public function addModuleScripts( $modules ) { |
| 349 | + $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules ); |
| 350 | + } |
| 351 | + |
| 352 | + public function addModuleStyles( $modules ) { |
| 353 | + $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules ); |
| 354 | + } |
| 355 | + |
| 356 | + public function addModuleMessages( $modules ) { |
| 357 | + $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules ); |
| 358 | + } |
| 359 | + |
342 | 360 | /** |
| 361 | + * Copy items from the OutputPage object into this one |
| 362 | + * |
| 363 | + * @param $out OutputPage object |
| 364 | + */ |
| 365 | + public function addOutputPage( OutputPage $out ) { |
| 366 | + $this->addModules( $out->getModules() ); |
| 367 | + $this->addModuleScripts( $out->getModuleScripts() ); |
| 368 | + $this->addModuleStyles( $out->getModuleStyles() ); |
| 369 | + $this->addModuleMessages( $out->getModuleMessages() ); |
| 370 | + |
| 371 | + $this->mHeadItems = array_merge( $this->mHeadItems, $out->getHeadItemsArray() ); |
| 372 | + } |
| 373 | + |
| 374 | + /** |
343 | 375 | * Override the title to be used for display |
344 | 376 | * -- this is assumed to have been validated |
345 | 377 | * (check equal normalisation, etc.) |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -526,6 +526,15 @@ |
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
| 530 | + * Get an array of head items |
| 531 | + * |
| 532 | + * @return Array |
| 533 | + */ |
| 534 | + function getHeadItemsArray() { |
| 535 | + return $this->mHeadItems; |
| 536 | + } |
| 537 | + |
| 538 | + /** |
530 | 539 | * Get all header items in a string |
531 | 540 | * |
532 | 541 | * @return String |
— | — | @@ -1405,6 +1414,9 @@ |
1406 | 1415 | $this->mNoGallery = $parserOutput->getNoGallery(); |
1407 | 1416 | $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() ); |
1408 | 1417 | $this->addModules( $parserOutput->getModules() ); |
| 1418 | + $this->addModuleScripts( $parserOutput->getModuleScripts() ); |
| 1419 | + $this->addModuleStyles( $parserOutput->getModuleStyles() ); |
| 1420 | + $this->addModuleMessages( $parserOutput->getModuleMessages() ); |
1409 | 1421 | |
1410 | 1422 | // Template versioning... |
1411 | 1423 | foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) { |