r97159 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97158‎ | r97159 | r97160 >
Date:15:19, 15 September 2011
Author:dantman
Status:ok (Comments)
Tags:
Comment:
Use IContextSource instead of RequestContext inside type hints and instanceof checks. All we need is something that implements IContextSource and it's possible we may want to implement types of RequestContext that don't directly extend RequestContext but are perfectly valid to be passed to classes.
Modified paths:
  • /trunk/phase3/includes/Action.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/ChangesList.php (modified) (history)
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/includes/RequestContext.php (modified) (history)
  • /trunk/phase3/includes/RevisionList.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPageFactory.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/logging/LogFormatter.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDeleteAbstracts.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialPageFactory.php
@@ -409,12 +409,12 @@
410410 * page, and true if it was successful.
411411 *
412412 * @param $title Title object
413 - * @param $context RequestContext
 413+ * @param $context IContextSource
414414 * @param $including Bool output is being captured for use in {{special:whatever}}
415415 *
416416 * @return bool
417417 */
418 - public static function executePath( Title &$title, RequestContext &$context, $including = false ) {
 418+ public static function executePath( Title &$title, IContextSource &$context, $including = false ) {
419419 wfProfileIn( __METHOD__ );
420420
421421 // @todo FIXME: Redirects broken due to this call
@@ -485,11 +485,11 @@
486486 * normal request, and then restores them to their previous values after.
487487 *
488488 * @param $title Title
489 - * @param $context RequestContext
 489+ * @param $context IContextSource
490490 *
491491 * @return String: HTML fragment
492492 */
493 - static function capturePath( Title $title, RequestContext $context ) {
 493+ static function capturePath( Title $title, IContextSource $context ) {
494494 global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang;
495495
496496 // Save current globals
Index: trunk/phase3/includes/Article.php
@@ -23,7 +23,7 @@
2424 */
2525
2626 /**
27 - * @var RequestContext
 27+ * @var IContextSource
2828 */
2929 protected $mContext;
3030
@@ -88,10 +88,10 @@
8989 * Create an Article object of the appropriate class for the given page.
9090 *
9191 * @param $title Title
92 - * @param $context RequestContext
 92+ * @param $context IContextSource
9393 * @return Article object
9494 */
95 - public static function newFromTitle( $title, RequestContext $context ) {
 95+ public static function newFromTitle( $title, IContextSource $context ) {
9696 if ( NS_MEDIA == $title->getNamespace() ) {
9797 // FIXME: where should this go?
9898 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
@@ -1856,7 +1856,7 @@
18571857 /**
18581858 * Sets the context this Article is executed in
18591859 *
1860 - * @param $context RequestContext
 1860+ * @param $context IContextSource
18611861 * @since 1.18
18621862 */
18631863 public function setContext( $context ) {
@@ -1866,11 +1866,11 @@
18671867 /**
18681868 * Gets the context this Article is executed in
18691869 *
1870 - * @return RequestContext
 1870+ * @return IContextSource
18711871 * @since 1.18
18721872 */
18731873 public function getContext() {
1874 - if ( $this->mContext instanceof RequestContext ) {
 1874+ if ( $this->mContext instanceof IContextSource ) {
18751875 return $this->mContext;
18761876 } else {
18771877 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
Index: trunk/phase3/includes/HTMLForm.php
@@ -102,7 +102,7 @@
103103 protected $mSubmitText;
104104 protected $mSubmitTooltip;
105105
106 - protected $mContext; // <! RequestContext
 106+ protected $mContext; // <! IContextSource
107107 protected $mTitle;
108108 protected $mMethod = 'post';
109109
@@ -115,12 +115,12 @@
116116 /**
117117 * Build a new HTMLForm from an array of field attributes
118118 * @param $descriptor Array of Field constructs, as described above
119 - * @param $context RequestContext available since 1.18, will become compulsory in 1.18.
 119+ * @param $context IContextSource available since 1.18, will become compulsory in 1.18.
120120 * Obviates the need to call $form->setTitle()
121121 * @param $messagePrefix String a prefix to go in front of default messages
122122 */
123 - public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) {
124 - if( $context instanceof RequestContext ){
 123+ public function __construct( $descriptor, /*IContextSource*/ $context = null, $messagePrefix = '' ) {
 124+ if( $context instanceof IContextSource ){
125125 $this->mContext = $context;
126126 $this->mTitle = false; // We don't need them to set a title
127127 $this->mMessagePrefix = $messagePrefix;
@@ -638,10 +638,10 @@
639639 }
640640
641641 /**
642 - * @return RequestContext
 642+ * @return IContextSource
643643 */
644644 public function getContext(){
645 - return $this->mContext instanceof RequestContext
 645+ return $this->mContext instanceof IContextSource
646646 ? $this->mContext
647647 : RequestContext::getMain();
648648 }
Index: trunk/phase3/includes/revisiondelete/RevisionDeleteAbstracts.php
@@ -7,7 +7,7 @@
88 * to wrap bulk update operations.
99 */
1010 abstract class RevDel_List extends RevisionListBase {
11 - function __construct( RequestContext $context, Title $title, array $ids ) {
 11+ function __construct( IContextSource $context, Title $title, array $ids ) {
1212 parent::__construct( $context, $title );
1313 $this->ids = $ids;
1414 }
Index: trunk/phase3/includes/RequestContext.php
@@ -353,14 +353,14 @@
354354 abstract class ContextSource implements IContextSource {
355355
356356 /**
357 - * @var RequestContext
 357+ * @var IContextSource
358358 */
359359 private $context;
360360
361361 /**
362 - * Get the RequestContext object
 362+ * Get the IContextSource object
363363 *
364 - * @return RequestContext
 364+ * @return IContextSource
365365 */
366366 public function getContext() {
367367 if ( $this->context === null ) {
@@ -372,11 +372,11 @@
373373 }
374374
375375 /**
376 - * Set the RequestContext object
 376+ * Set the IContextSource object
377377 *
378 - * @param $context RequestContext
 378+ * @param $context IContextSource
379379 */
380 - public function setContext( RequestContext $context ) {
 380+ public function setContext( IContextSource $context ) {
381381 $this->context = $context;
382382 }
383383
Index: trunk/phase3/includes/OutputPage.php
@@ -223,7 +223,7 @@
224224 * Instead a new RequestContext should be created and it will implicitly create
225225 * a OutputPage tied to that context.
226226 */
227 - function __construct( RequestContext $context = null ) {
 227+ function __construct( IContextSource $context = null ) {
228228 if ( $context === null ) {
229229 # Extensions should use `new RequestContext` instead of `new OutputPage` now.
230230 wfDeprecated( __METHOD__ );
Index: trunk/phase3/includes/logging/LogFormatter.php
@@ -78,9 +78,9 @@
7979
8080 /**
8181 * Replace the default context
82 - * @param $context RequestContext
 82+ * @param $context IContextSource
8383 */
84 - public function setContext( RequestContext $context ) {
 84+ public function setContext( IContextSource $context ) {
8585 $this->context = $context;
8686 }
8787
Index: trunk/phase3/includes/Wiki.php
@@ -29,7 +29,7 @@
3030
3131 /**
3232 * TODO: fold $output, etc, into this
33 - * @var RequestContext
 33+ * @var IContextSource
3434 */
3535 private $context;
3636
@@ -45,7 +45,7 @@
4646 return $old;
4747 }
4848
49 - public function __construct( RequestContext $context = null ) {
 49+ public function __construct( IContextSource $context = null ) {
5050 if ( !$context ) {
5151 $context = RequestContext::getMain();
5252 }
@@ -256,10 +256,10 @@
257257 *
258258 * @deprecated in 1.18; use Article::newFromTitle() instead
259259 * @param $title Title
260 - * @param $context RequestContext
 260+ * @param $context IContextSource
261261 * @return Article object
262262 */
263 - public static function articleFromTitle( $title, RequestContext $context ) {
 263+ public static function articleFromTitle( $title, IContextSource $context ) {
264264 return Article::newFromTitle( $title, $context );
265265 }
266266
Index: trunk/phase3/includes/ChangesList.php
@@ -45,10 +45,10 @@
4646 /**
4747 * Changeslist contructor
4848 *
49 - * @param $obj Skin or RequestContext
 49+ * @param $obj Skin or IContextSource
5050 */
5151 public function __construct( $obj ) {
52 - if ( $obj instanceof RequestContext ) {
 52+ if ( $obj instanceof IContextSource ) {
5353 $this->setContext( $obj );
5454 $this->skin = $obj->getSkin();
5555 } else {
@@ -74,10 +74,10 @@
7575 * Fetch an appropriate changes list class for the specified context
7676 * Some users might want to use an enhanced list format, for instance
7777 *
78 - * @param $context RequestContext to use
 78+ * @param $context IContextSource to use
7979 * @return ChangesList|EnhancedChangesList|OldChangesList derivative
8080 */
81 - public static function newFromContext( RequestContext $context ) {
 81+ public static function newFromContext( IContextSource $context ) {
8282 $user = $context->getUser();
8383 $sk = $context->getSkin();
8484 $list = null;
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -758,7 +758,7 @@
759759
760760 protected $mMaxFileSize = array();
761761
762 - public function __construct( array $options = array(), RequestContext $context = null ) {
 762+ public function __construct( array $options = array(), IContextSource $context = null ) {
763763 $this->mWatch = !empty( $options['watch'] );
764764 $this->mForReUpload = !empty( $options['forreupload'] );
765765 $this->mSessionKey = isset( $options['sessionkey'] )
Index: trunk/phase3/includes/RevisionList.php
@@ -8,7 +8,7 @@
99 */
1010 var $title;
1111 /**
12 - * @var RequestContext
 12+ * @var IContextSource
1313 */
1414 var $context;
1515
@@ -16,10 +16,10 @@
1717
1818 /**
1919 * Construct a revision list for a given title
20 - * @param $context RequestContext
 20+ * @param $context IContextSource
2121 * @param $title Title
2222 */
23 - function __construct( RequestContext $context, Title $title ) {
 23+ function __construct( IContextSource $context, Title $title ) {
2424 $this->context = $context;
2525 $this->title = $title;
2626 }
Index: trunk/phase3/includes/Preferences.php
@@ -1212,11 +1212,11 @@
12131213
12141214 /**
12151215 * @param $user User
1216 - * @param $context RequestContext
 1216+ * @param $context IContextSource
12171217 * @param $formClass string
12181218 * @return HtmlForm
12191219 */
1220 - static function getFormObject( $user, RequestContext $context, $formClass = 'PreferencesForm' ) {
 1220+ static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm' ) {
12211221 $formDescriptor = Preferences::getPreferences( $user );
12221222 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
12231223
Index: trunk/phase3/includes/SpecialPage.php
@@ -57,7 +57,7 @@
5858
5959 /**
6060 * Current request context
61 - * @var RequestContext
 61+ * @var IContextSource
6262 */
6363 protected $mContext;
6464
@@ -226,12 +226,12 @@
227227 * page, and true if it was successful.
228228 *
229229 * @param $title Title object
230 - * @param $context RequestContext
 230+ * @param $context IContextSource
231231 * @param $including Bool output is being captured for use in {{special:whatever}}
232232 * @return Bool
233233 * @deprecated since 1.18 call SpecialPageFactory method directly
234234 */
235 - public static function executePath( &$title, RequestContext &$context, $including = false ) {
 235+ public static function executePath( &$title, IContextSource &$context, $including = false ) {
236236 return SpecialPageFactory::executePath( $title, $context, $including );
237237 }
238238
@@ -592,7 +592,7 @@
593593 /**
594594 * Sets the context this SpecialPage is executed in
595595 *
596 - * @param $context RequestContext
 596+ * @param $context IContextSource
597597 * @since 1.18
598598 */
599599 public function setContext( $context ) {
@@ -602,11 +602,11 @@
603603 /**
604604 * Gets the context this SpecialPage is executed in
605605 *
606 - * @return RequestContext
 606+ * @return IContextSource
607607 * @since 1.18
608608 */
609609 public function getContext() {
610 - if ( $this->mContext instanceof RequestContext ) {
 610+ if ( $this->mContext instanceof IContextSource ) {
611611 return $this->mContext;
612612 } else {
613613 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
Index: trunk/phase3/includes/Action.php
@@ -32,8 +32,8 @@
3333 protected $page;
3434
3535 /**
36 - * RequestContext if specified; otherwise we'll use the Context from the Page
37 - * @var RequestContext
 36+ * IContextSource if specified; otherwise we'll use the Context from the Page
 37+ * @var IContextSource
3838 */
3939 protected $context;
4040
@@ -96,11 +96,11 @@
9797 }
9898
9999 /**
100 - * Get the RequestContext in use here
101 - * @return RequestContext
 100+ * Get the IContextSource in use here
 101+ * @return IContextSource
102102 */
103103 protected final function getContext() {
104 - if ( $this->context instanceof RequestContext ) {
 104+ if ( $this->context instanceof IContextSource ) {
105105 return $this->context;
106106 }
107107 return $this->page->getContext();

Follow-up revisions

RevisionCommit summaryAuthorDate
r97173Merged revisions 97087,97091-97092,97094,97096-97098,97100-97101,97103,97136,...dantman16:19, 15 September 2011
r97283REL1_18 MFT r97159 where appropriatereedy15:01, 16 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   16:56, 15 September 2011

Not sure if I like the name IContextSource, but the idea is correct.

#Comment by Dantman (talk | contribs)   00:47, 20 September 2011

May need another 1.18 MTF over r93557.

Status & tagging log