Last modified: 2013-04-23 13:23:54 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T48851, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 46851 - Support Message instances as Message instance params
Support Message instances as Message instance params
Status: NEW
Product: MediaWiki
Classification: Unclassified
Internationalization (Other open bugs)
1.22.0
All All
: Low normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-04-03 18:23 UTC by Daniel Friesen
Modified: 2013-04-23 13:23 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Daniel Friesen 2013-04-03 18:23:22 UTC
Random idea from something PleaseStand said.

Message instances could explicitly support taking a message object as a parameter. This way the message could inherit the context it's parent is in (eg: language). Especially useful if the message instance is going to be passed somewhere else and the context changed.

$this->msg( 'foo' )->params( wfMessage( 'bar' )->params( 'foo' ) )->inLanguage( 'en_CA' );
Comment 1 Niklas Laxström 2013-04-03 18:39:35 UTC
That looks potentially confusing to unaware reader.
Comment 2 Daniel Friesen 2013-04-03 18:46:24 UTC
Is it?

It's basically:

wfMessage( 'foo' )
  ->inLanguage( 'en_CA' )
  ->params(
    wfMessage( 'bar' )
      ->params( 'foo' ) );

vs.

wfMessage( 'foo' )
  ->inLanguage( 'en_CA' )
  ->params(
    wfMessage( 'bar' )
      ->params( 'foo' )
      ->inLanguage( 'en_CA' ) );
Comment 3 Daniel Friesen 2013-04-03 18:50:56 UTC
Well... actually right now you kind of need to do:

wfMessage( 'foo' )
  ->inLanguage( 'en_CA' )
  ->params(
    wfMessage( 'bar' )
      ->params( 'foo' )
      ->inLanguage( 'en_CA' )
      ->plain() );

Since __toString defaults to parse.
Comment 4 Kevin Israel (PleaseStand) 2013-04-03 20:32:07 UTC
This could be further extended by allowing use of closures.

Simple example (using a helper function textCB()):

wfMessage( 'foo',  wfMessage( 'bar', 'foo' )->textCB() )->inLanguage( 'en_CA' );

More complex example:

$tsHTML = function ( $ctx ) use ( $ts ) {
    return Html::element( 'span',
        array( 'title' => wfTimestamp( TS_ISO_8601, $ts ) ),
            $ctx->getLanguage()->timeanddate( $ts ),
        );
    );
};

wfMessage( 'bar' )->rawParams( $tsHTML )->inLanguage( 'en_CA' );

where MessageContext $ctx would only implement msg(), getLanguage(), getContentLanguage(), and getTitle(), to ensure that all relevant information is actually included in the Message object being passed around.

Unfortunately, my specific case (the one I discussed with Daniel Friesen on IRC) requires $ctx->getRequest()->getIP(); however, this may come in handy elsewhere.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links