r93758 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93757‎ | r93758 | r93759 >
Date:15:40, 2 August 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* (bug 15558) Allow includable special pages to be parameterized using wiki syntax
* Changed SpecialPageFactory::capturePath() to take the same parameters as SpecialPageFactory::executePath() (except the last one) and made it always return a bool instead of bool-or-string. The result HTML can be fetched from the OutputPage object of the context.
* Added module styles, scritps and messages members to ParserOutput in addition to modules. The first one is needed to display Special:RecentChanges correctly when transcluded since EnhancedChangesList::beginRecentChangesList() calls addModuleStyles( 'mediawiki.special.changeslist' )

Yes, this means that you can use {{Special:Recentchanges|enhanced=0}} to use the old changes list. For the ones that wonder, {{Special:Recentchanges|uselang=something}} will not work since the Language object is forced to the one used by the parser.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPageFactory.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOutput.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -23,6 +23,8 @@
2424 * (bug 19052) Unicode space separator characters (Zs) now terminates external
2525 links and images links.
2626 * (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.
2729
2830 === Bug fixes in 1.19 ===
2931 * $wgUploadNavigationUrl should be used for file redlinks if
Index: trunk/phase3/includes/SpecialPageFactory.php
@@ -471,40 +471,47 @@
472472 }
473473
474474 /**
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
477478 * a redirect.
478479 *
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.
482483 *
483484 * @param $title Title
 485+ * @param $context RequestContext
484486 *
485487 * @return String: HTML fragment
486488 */
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;
489491
 492+ // Save current globals
490493 $oldTitle = $wgTitle;
491494 $oldOut = $wgOut;
492495 $oldRequest = $wgRequest;
 496+ $oldUser = $wgUser;
 497+ $oldLang = $wgLang;
493498
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;
500501 $wgOut = $context->getOutput();
 502+ $wgRequest = $context->getRequest();
 503+ $wgUser = $context->getUser();
 504+ $wgLang = $context->getLang();
501505
 506+ // The useful part
502507 $ret = self::executePath( $title, $context, true );
503 - if ( $ret === true ) {
504 - $ret = $wgOut->getHTML();
505 - }
 508+
 509+ // And restore that globals
506510 $wgTitle = $oldTitle;
507511 $wgOut = $oldOut;
508512 $wgRequest = $oldRequest;
 513+ $wgUser = $oldUser;
 514+ $wgLang = $oldLang;
 515+
509516 return $ret;
510517 }
511518
Index: trunk/phase3/includes/parser/Parser.php
@@ -3250,8 +3250,24 @@
32513251 && $this->mOptions->getAllowSpecialInclusion()
32523252 && $this->ot['html'] )
32533253 {
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() );
32563272 $found = true;
32573273 $isHTML = true;
32583274 $this->disableCache();
Index: trunk/phase3/includes/parser/ParserOutput.php
@@ -130,6 +130,9 @@
131131 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
132132 $mHeadItems = array(), # Items to put in the <head> section
133133 $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
134137 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
135138 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
136139 $mSections = array(), # Table of contents
@@ -195,6 +198,9 @@
196199 function getNoGallery() { return $this->mNoGallery; }
197200 function getHeadItems() { return $this->mHeadItems; }
198201 function getModules() { return $this->mModules; }
 202+ function getModuleScripts() { return $this->mModuleScripts; }
 203+ function getModuleStyles() { return $this->mModuleStyles; }
 204+ function getModuleMessages() { return $this->mModuleMessages; }
199205 function getOutputHooks() { return (array)$this->mOutputHooks; }
200206 function getWarnings() { return array_keys( $this->mWarnings ); }
201207 function getIndexPolicy() { return $this->mIndexPolicy; }
@@ -334,11 +340,37 @@
335341 }
336342 }
337343
338 - function addModules( $modules ) {
 344+ public function addModules( $modules ) {
339345 $this->mModules = array_merge( $this->mModules, (array) $modules );
340346 }
341347
 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+
342360 /**
 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+ /**
343375 * Override the title to be used for display
344376 * -- this is assumed to have been validated
345377 * (check equal normalisation, etc.)
Index: trunk/phase3/includes/OutputPage.php
@@ -526,6 +526,15 @@
527527 }
528528
529529 /**
 530+ * Get an array of head items
 531+ *
 532+ * @return Array
 533+ */
 534+ function getHeadItemsArray() {
 535+ return $this->mHeadItems;
 536+ }
 537+
 538+ /**
530539 * Get all header items in a string
531540 *
532541 * @return String
@@ -1405,6 +1414,9 @@
14061415 $this->mNoGallery = $parserOutput->getNoGallery();
14071416 $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
14081417 $this->addModules( $parserOutput->getModules() );
 1418+ $this->addModuleScripts( $parserOutput->getModuleScripts() );
 1419+ $this->addModuleStyles( $parserOutput->getModuleStyles() );
 1420+ $this->addModuleMessages( $parserOutput->getModuleMessages() );
14091421
14101422 // Template versioning...
14111423 foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) {

Sign-offs

UserFlagDate
Bawolfftested08:32, 1 September 2011
Aaron Schulzinspected21:48, 28 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r93766Per Platonides, follow-up r93758: rename ParserOutput::addOutputPage() to Par...ialex16:31, 2 August 2011
r94619Per Reedy, follow-up r93758: SpecialPage::capturePath() now has incorrect sig...ialex11:05, 16 August 2011
r977221.18wmf1: Partial merge of r93758: add addModule{Scripts,Styles,Messages}() t...catrope12:42, 21 September 2011
r977231.17wmf1: Merge r97722 (partial merge of r93758) from 1.18wmf1catrope12:54, 21 September 2011
r98410Per Aaron, follow-up r93758: add coments and fix typosialex15:14, 29 September 2011
r1011251.18: Merge r97722 from 1.18wmf1. This is a partial merge of r93758 that adds...catrope11:10, 28 October 2011

Comments

#Comment by Platonides (talk | contribs)   16:12, 2 August 2011

Use $this->getFunctionLang() not $this->mOptions->getUserLang()

The name addOutputPage() makes me think that it would add the page html, not just its metadata.

#Comment by IAlex (talk | contribs)   16:32, 2 August 2011

I used ParserOptions::getUserLang() to match current behaviour, i.e. showing it in user's language. Parser::getFunctionLang() returns about always content language when parsing page content.

Second one done in r93766.

#Comment by Reedy (talk | contribs)   23:29, 14 August 2011

A caller in SpecialPage.php needs updating to pass the $context parameter. Though, this isn't called from anywhere, and is deprecated from 1.18...

	static function capturePath( &$title ) {
		return SpecialPageFactory::capturePath( $title );
	}
#Comment by IAlex (talk | contribs)   11:05, 16 August 2011

Removed in r94619.

#Comment by IAlex (talk | contribs)   11:05, 16 August 2011

Removed in r94619.

#Comment by Bawolff (talk | contribs)   08:32, 1 September 2011

This is something I always wished special page transclusions would do :)

#Comment by G.Hagedorn (talk | contribs)   13:39, 22 September 2011

Should the partial changes made to 1.18wmf also be applied to 1.18? Tag for 1.18?

#Comment by Catrope (talk | contribs)   11:10, 28 October 2011

Partial merge was applied to 1.18 in r100125.

#Comment by G.Hagedorn (talk | contribs)   12:24, 28 October 2011

Perhaps in some other revision, but not in that one.

#Comment by Catrope (talk | contribs)   12:26, 28 October 2011

Bah, r101125.

#Comment by G.Hagedorn (talk | contribs)   12:28, 28 October 2011

Perhaps in some other revision, but not in that one :-)

#Comment by Catrope (talk | contribs)   12:31, 28 October 2011

CodeReview updating is broken, don't let that fool you. See http://svn.wikimedia.org/viewvc/mediawiki/?view=rev&rev=101125

#Comment by Aaron Schulz (talk | contribs)   21:37, 28 September 2011

Typos:

* the page in "inclusion" mode. Returns true if the excution was successful
And restore that globals
#Comment by Aaron Schulz (talk | contribs)   21:48, 28 September 2011

"For the ones that wonder,

List of abbreviations:
D
Wikidata edit
N
This edit created a new page (also see list of new pages)
m
This is a minor edit
b
This edit was performed by a bot
(±123)
The page size changed by this number of bytes
Temporarily watched page

7 December 2021

6 December 2021

will not work since the Language object is forced to the one used by the parser."

...please add comments about that to Parser.

#Comment by Aaron Schulz (talk | contribs)   21:50, 28 September 2011

...lol, forgot <nowiki>

#Comment by IAlex (talk | contribs)   15:14, 29 September 2011

Done in r98410.

#Comment by Catrope (talk | contribs)   11:11, 28 October 2011

Mark, why is this tagged 1.18&1.18wmf1? Is it because of Gregor's comment?

#Comment by G.Hagedorn (talk | contribs)   12:18, 28 October 2011

If so, I did not mean the entire patch, only the parts backported in http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97722 by you.

#Comment by Catrope (talk | contribs)   12:18, 28 October 2011

...and those same parts were backported to 1.18 in r100125, so that's all done.

#Comment by MarkAHershberger (talk | contribs)   17:10, 2 November 2011

Bug #31362 "Lost CSS styles in pages transcluding pages from the Special: namespace" reported on frwiki that this apparently fixes. Removing 1.18 tag per Catrope's comment.

#Comment by G.Hagedorn (talk | contribs)   20:30, 2 November 2011

1.18wmf1 tag should then be removed as well, both have the same partial backport applied now.

Status & tagging log