Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -74,20 +74,10 @@ |
75 | 75 | */ |
76 | 76 | var $mAddedRedirectParams = array(); |
77 | 77 | /** |
78 | | - * Current request |
79 | | - * @var WebRequest |
| 78 | + * Current request context |
| 79 | + * @var RequestContext |
80 | 80 | */ |
81 | | - protected $mRequest; |
82 | | - /** |
83 | | - * Current output page |
84 | | - * @var OutputPage |
85 | | - */ |
86 | | - protected $mOutput; |
87 | | - /** |
88 | | - * Full title including $par |
89 | | - * @var Title |
90 | | - */ |
91 | | - protected $mFullTitle; |
| 81 | + protected $mContext; |
92 | 82 | |
93 | 83 | /** |
94 | 84 | * List of special pages, followed by parameters. |
— | — | @@ -556,7 +546,7 @@ |
557 | 547 | } |
558 | 548 | |
559 | 549 | # Page exists, set the context |
560 | | - $page->setContext( $wgRequest, $wgOut ); |
| 550 | + $page->setContext( $wgOut->getContext() ); |
561 | 551 | |
562 | 552 | # Check for redirect |
563 | 553 | if ( !$including ) { |
— | — | @@ -629,9 +619,10 @@ |
630 | 620 | |
631 | 621 | $oldTitle = $wgTitle; |
632 | 622 | $oldOut = $wgOut; |
633 | | - $wgOut = new OutputPage; |
634 | | - $wgOut->setTitle( $title ); |
635 | | - $wgOut->setUser( $wgUser ); # for now, there may be a better idea in the future |
| 623 | + |
| 624 | + $context = new RequestContext; |
| 625 | + $context->setTitle( $title ); |
| 626 | + $wgOut = $context->getOutput(); |
636 | 627 | |
637 | 628 | $ret = SpecialPage::executePath( $title, true ); |
638 | 629 | if ( $ret === true ) { |
— | — | @@ -888,11 +879,9 @@ |
889 | 880 | * This may be overridden by subclasses. |
890 | 881 | */ |
891 | 882 | function execute( $par ) { |
892 | | - global $wgUser; |
893 | | - |
894 | 883 | $this->setHeaders(); |
895 | 884 | |
896 | | - if ( $this->userCanExecute( $wgUser ) ) { |
| 885 | + if ( $this->userCanExecute( $this->getUser() ) ) { |
897 | 886 | $func = $this->mFunction; |
898 | 887 | // only load file if the function does not exist |
899 | 888 | if(!is_callable($func) and $this->mFile) { |
— | — | @@ -993,28 +982,36 @@ |
994 | 983 | /** |
995 | 984 | * Sets the context this SpecialPage is executed in |
996 | 985 | * |
997 | | - * @param $request WebRequest |
998 | | - * @param $output OutputPage |
| 986 | + * @param $context RequestContext |
| 987 | + * @since 1.18 |
999 | 988 | */ |
1000 | | - protected function setContext( $request, $output ) { |
1001 | | - $this->mRequest = $request; |
1002 | | - $this->mOutput = $output; |
1003 | | - $this->mFullTitle = $output->getTitle(); |
| 989 | + protected function setContext( $context ) { |
| 990 | + $this->mContext = $context; |
1004 | 991 | } |
1005 | 992 | |
1006 | 993 | /** |
| 994 | + * Gets the context this SpecialPage is executed in |
| 995 | + * |
| 996 | + * @return RequestContext |
| 997 | + * @since 1.18 |
| 998 | + */ |
| 999 | + public function getContext() { |
| 1000 | + if ( $this->mContext instanceof RequestContext ) { |
| 1001 | + return $this->mContext; |
| 1002 | + } else { |
| 1003 | + wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" ); |
| 1004 | + return RequestContext::getMain(); |
| 1005 | + } |
| 1006 | + } |
| 1007 | + |
| 1008 | + /** |
1007 | 1009 | * Get the WebRequest being used for this instance |
1008 | 1010 | * |
1009 | 1011 | * @return WebRequest |
1010 | 1012 | * @since 1.18 |
1011 | 1013 | */ |
1012 | 1014 | public function getRequest() { |
1013 | | - if ( !isset($this->mRequest) ) { |
1014 | | - wfDebug( __METHOD__ . " called and \$mRequest is null. Return \$wgRequest for sanity\n" ); |
1015 | | - global $wgRequest; |
1016 | | - return $wgRequest; |
1017 | | - } |
1018 | | - return $this->mRequest; |
| 1015 | + return $this->getContext()->getRequest(); |
1019 | 1016 | } |
1020 | 1017 | |
1021 | 1018 | /** |
— | — | @@ -1024,12 +1021,7 @@ |
1025 | 1022 | * @since 1.18 |
1026 | 1023 | */ |
1027 | 1024 | public function getOutput() { |
1028 | | - if ( !isset($this->mOutput) ) { |
1029 | | - wfDebug( __METHOD__ . " called and \$mOutput is null. Return \$wgOut for sanity\n" ); |
1030 | | - global $wgOut; |
1031 | | - return $wgOut; |
1032 | | - } |
1033 | | - return $this->mOutput; |
| 1025 | + return $this->getContext()->getOutput(); |
1034 | 1026 | } |
1035 | 1027 | |
1036 | 1028 | /** |
— | — | @@ -1039,7 +1031,7 @@ |
1040 | 1032 | * @since 1.18 |
1041 | 1033 | */ |
1042 | 1034 | public function getUser() { |
1043 | | - return $this->getOutput()->getUser(); |
| 1035 | + return $this->getContext()->getUser(); |
1044 | 1036 | } |
1045 | 1037 | |
1046 | 1038 | /** |
— | — | @@ -1049,17 +1041,27 @@ |
1050 | 1042 | * @since 1.18 |
1051 | 1043 | */ |
1052 | 1044 | public function getSkin() { |
1053 | | - return $this->getOutput()->getSkin(); |
| 1045 | + return $this->getContext()->getSkin(); |
1054 | 1046 | } |
1055 | 1047 | |
1056 | 1048 | /** |
| 1049 | + * Return the full title, including $par |
| 1050 | + * |
| 1051 | + * @return Title |
| 1052 | + * @since 1.18 |
| 1053 | + */ |
| 1054 | + public function getFullTitle() { |
| 1055 | + return $this->getContext()->getTitle(); |
| 1056 | + } |
| 1057 | + |
| 1058 | + /** |
1057 | 1059 | * Wrapper around wfMessage that sets the current context. Currently this |
1058 | 1060 | * is only the title. |
1059 | 1061 | * |
1060 | 1062 | * @see wfMessage |
1061 | 1063 | */ |
1062 | 1064 | public function msg( /* $args */ ) { |
1063 | | - return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->mFullTitle ); |
| 1065 | + return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() ); |
1064 | 1066 | } |
1065 | 1067 | } |
1066 | 1068 | |
Index: trunk/phase3/includes/StubObject.php |
— | — | @@ -131,39 +131,44 @@ |
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | | - * Stub object for the user language. It depends of the user preferences and |
136 | | - * "uselang" parameter that can be passed to index.php. This object have to be |
137 | | - * in $wgLang global. |
| 135 | + * Stub object for the $wg globals replaced by RequestContext |
138 | 136 | */ |
139 | | -class StubUserLang extends StubObject { |
140 | | - |
141 | | - function __construct() { |
142 | | - parent::__construct( 'wgLang' ); |
| 137 | +class StubRequestContext extends StubObject { |
| 138 | + |
| 139 | + private $method = null; |
| 140 | + |
| 141 | + function __construct( $global, $method ) { |
| 142 | + parent::__construct( $global, 'RequestContext' ); |
| 143 | + $this->method = $method; |
143 | 144 | } |
144 | | - |
| 145 | + |
145 | 146 | function __call( $name, $args ) { |
146 | 147 | return $this->_call( $name, $args ); |
147 | 148 | } |
| 149 | + |
| 150 | + function __get( $name ) { |
| 151 | + // __get doesn't seam to play nice with _unstub |
| 152 | + return RequestContext::getMain()->{$this->method}()->{$name}; |
| 153 | + } |
148 | 154 | |
149 | | - function _newObject() { |
150 | | - global $wgLanguageCode, $wgRequest, $wgUser, $wgContLang; |
151 | | - $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); |
152 | | - // BCP 47 - letter case MUST NOT carry meaning |
153 | | - $code = strtolower( $code ); |
| 155 | + function __set( $name, $val ) { |
| 156 | + // __set doesn't seam to play nice with _unstub |
| 157 | + RequestContext::getMain()->{$this->method}()->{$name} = $val; |
| 158 | + } |
154 | 159 | |
155 | | - # Validate $code |
156 | | - if( empty( $code ) || !Language::isValidCode( $code ) || ( $code === 'qqq' ) ) { |
157 | | - wfDebug( "Invalid user language code\n" ); |
158 | | - $code = $wgLanguageCode; |
159 | | - } |
| 160 | + function __isset( $name ) { |
| 161 | + // __isset doesn't seam to play nice with _unstub |
| 162 | + return isset( RequestContext::getMain()->{$this->method}()->{$name} ); |
| 163 | + } |
160 | 164 | |
161 | | - wfRunHooks( 'UserGetLanguageObject', array( $wgUser, &$code ) ); |
| 165 | + function __unset( $name ) { |
| 166 | + // __unset doesn't seam to play nice with _unstub |
| 167 | + unset( RequestContext::getMain()->{$this->method}()->{$name} ); |
| 168 | + } |
162 | 169 | |
163 | | - if( $code === $wgLanguageCode ) { |
164 | | - return $wgContLang; |
165 | | - } else { |
166 | | - $obj = Language::factory( $code ); |
167 | | - return $obj; |
168 | | - } |
| 170 | + function _newObject() { |
| 171 | + return RequestContext::getMain()->{$this->method}(); |
169 | 172 | } |
| 173 | + |
170 | 174 | } |
| 175 | + |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -752,52 +752,53 @@ |
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
756 | | - * Set the Title object to use |
| 756 | + * Set the RequestContext used in this instance |
757 | 757 | * |
758 | | - * @param $t Title object |
| 758 | + * @param RequestContext $context |
759 | 759 | */ |
760 | | - public function setTitle( $t ) { |
761 | | - $this->mTitle = $t; |
| 760 | + public function setContext( RequestContext $context ) { |
| 761 | + $this->mContext = $context; |
762 | 762 | } |
763 | 763 | |
764 | 764 | /** |
765 | | - * Get the Title object used in this instance |
| 765 | + * Get the RequestContext used in this instance |
766 | 766 | * |
767 | | - * @return Title |
| 767 | + * @return RequestContext |
768 | 768 | */ |
769 | | - public function getTitle() { |
770 | | - if ( $this->mTitle instanceof Title ) { |
771 | | - return $this->mTitle; |
772 | | - } else { |
773 | | - wfDebug( __METHOD__ . " called and \$mTitle is null. Return \$wgTitle for sanity\n" ); |
774 | | - global $wgTitle; |
775 | | - return $wgTitle; |
| 769 | + public function getContext() { |
| 770 | + if ( !isset($this->mContext) ) { |
| 771 | + wfDebug( __METHOD__ . " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" ); |
| 772 | + $this->mContext = RequestContext::getMain(); |
776 | 773 | } |
| 774 | + return $this->mContext; |
777 | 775 | } |
778 | 776 | |
779 | 777 | /** |
780 | | - * Set the User object to use |
| 778 | + * Set the Title object to use |
781 | 779 | * |
782 | | - * @param $u User object |
783 | | - * @since 1.18 |
| 780 | + * @param $t Title object |
784 | 781 | */ |
785 | | - public function setUser( $u ) { |
786 | | - $this->mUser = $u; |
| 782 | + public function setTitle( $t ) { |
| 783 | + $this->getContext()->setTitle($t); |
787 | 784 | } |
788 | 785 | |
789 | 786 | /** |
| 787 | + * Get the Title object used in this instance |
| 788 | + * |
| 789 | + * @return Title |
| 790 | + */ |
| 791 | + public function getTitle() { |
| 792 | + return $this->getContext()->getTitle(); |
| 793 | + } |
| 794 | + |
| 795 | + /** |
790 | 796 | * Get the User object used in this instance |
791 | 797 | * |
792 | 798 | * @return User |
793 | 799 | * @since 1.18 |
794 | 800 | */ |
795 | 801 | public function getUser() { |
796 | | - if ( !isset($this->mUser) ) { |
797 | | - wfDebug( __METHOD__ . " called and \$mUser is null. Return \$wgUser for sanity\n" ); |
798 | | - global $wgUser; |
799 | | - return $wgUser; |
800 | | - } |
801 | | - return $this->mUser; |
| 802 | + return $this->getContext()->getUser(); |
802 | 803 | } |
803 | 804 | |
804 | 805 | /** |
— | — | @@ -807,9 +808,7 @@ |
808 | 809 | * @since 1.18 |
809 | 810 | */ |
810 | 811 | public function getSkin() { |
811 | | - // For now we'll just proxy to the user. In the future a saner location for |
812 | | - // organizing what skin to use may be chosen |
813 | | - return $this->getUser()->getSkin(); |
| 812 | + return $this->getContext()->getSkin(); |
814 | 813 | } |
815 | 814 | |
816 | 815 | /** |
— | — | @@ -2628,7 +2627,7 @@ |
2629 | 2628 | // Add user JS if enabled |
2630 | 2629 | if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) { |
2631 | 2630 | $action = $wgRequest->getVal( 'action', 'view' ); |
2632 | | - if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) { |
| 2631 | + if( $this->getTitle() && $this->getTitle()->isJsSubpage() && $sk->userCanPreview( $action ) ) { |
2633 | 2632 | # XXX: additional security check/prompt? |
2634 | 2633 | $scripts .= Html::inlineScript( "\n" . $wgRequest->getText( 'wpTextbox1' ) . "\n" ) . "\n"; |
2635 | 2634 | } else { |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -197,6 +197,7 @@ |
198 | 198 | 'RegexlikeReplacer' => 'includes/StringUtils.php', |
199 | 199 | 'ReplacementArray' => 'includes/StringUtils.php', |
200 | 200 | 'Replacer' => 'includes/StringUtils.php', |
| 201 | + 'RequestContext' => 'includes/RequestContext.php', |
201 | 202 | 'ResourceLoader' => 'includes/resourceloader/ResourceLoader.php', |
202 | 203 | 'ResourceLoaderContext' => 'includes/resourceloader/ResourceLoaderContext.php', |
203 | 204 | 'ResourceLoaderModule' => 'includes/resourceloader/ResourceLoaderModule.php', |
— | — | @@ -231,8 +232,8 @@ |
232 | 233 | 'SquidPurgeClientPool' => 'includes/SquidPurgeClient.php', |
233 | 234 | 'Status' => 'includes/Status.php', |
234 | 235 | 'StubContLang' => 'includes/StubObject.php', |
235 | | - 'StubUserLang' => 'includes/StubObject.php', |
236 | 236 | 'StubObject' => 'includes/StubObject.php', |
| 237 | + 'StubRequestContext' => 'includes/StubObject.php', |
237 | 238 | 'StringUtils' => 'includes/StringUtils.php', |
238 | 239 | 'TablePager' => 'includes/Pager.php', |
239 | 240 | 'TitleDependency' => 'includes/CacheDependency.php', |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -365,17 +365,17 @@ |
366 | 366 | |
367 | 367 | // Now that variant lists may be available... |
368 | 368 | $wgRequest->interpolateTitle(); |
369 | | -$wgUser = $wgCommandLineMode ? new User : User::newFromSession(); |
| 369 | +$wgUser = new StubRequestContext( 'wgUser', 'getUser' ); |
370 | 370 | |
371 | 371 | /** |
372 | 372 | * @var Language |
373 | 373 | */ |
374 | | -$wgLang = new StubUserLang; |
| 374 | +$wgLang = new StubRequestContext( 'wgLang', 'getLang' ); |
375 | 375 | |
376 | 376 | /** |
377 | 377 | * @var OutputPage |
378 | 378 | */ |
379 | | -$wgOut = new StubObject( 'wgOut', 'OutputPage' ); |
| 379 | +$wgOut = new StubRequestContext( 'wgOut', 'getOutput' ); |
380 | 380 | |
381 | 381 | /** |
382 | 382 | * @var Parser |