Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | * |
55 | 55 | * TODO: Document 'section' / 'subsection' stuff |
56 | 56 | */ |
57 | | -class HTMLForm extends ContextSource { |
| 57 | +class HTMLForm { |
58 | 58 | |
59 | 59 | # A mapping of 'type' inputs onto standard HTMLFormField subclasses |
60 | 60 | static $typeMappings = array( |
— | — | @@ -102,6 +102,7 @@ |
103 | 103 | protected $mSubmitText; |
104 | 104 | protected $mSubmitTooltip; |
105 | 105 | |
| 106 | + protected $mContext; // <! RequestContext |
106 | 107 | protected $mTitle; |
107 | 108 | protected $mMethod = 'post'; |
108 | 109 | |
— | — | @@ -120,11 +121,10 @@ |
121 | 122 | */ |
122 | 123 | public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) { |
123 | 124 | if( $context instanceof RequestContext ){ |
124 | | - $this->setContext( $context ); |
| 125 | + $this->mContext = $context; |
125 | 126 | $this->mTitle = false; // We don't need them to set a title |
126 | 127 | $this->mMessagePrefix = $messagePrefix; |
127 | 128 | } else { |
128 | | - $this->setContext( RequestContext::getMain() ); |
129 | 129 | // B/C since 1.18 |
130 | 130 | if( is_string( $context ) && $messagePrefix === '' ){ |
131 | 131 | // it's actually $messagePrefix |
— | — | @@ -623,11 +623,41 @@ |
624 | 624 | */ |
625 | 625 | function getTitle() { |
626 | 626 | return $this->mTitle === false |
627 | | - ? parent::getTitle() |
| 627 | + ? $this->getContext()->title |
628 | 628 | : $this->mTitle; |
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
| 632 | + * @return RequestContext |
| 633 | + */ |
| 634 | + public function getContext(){ |
| 635 | + return $this->mContext instanceof RequestContext |
| 636 | + ? $this->mContext |
| 637 | + : RequestContext::getMain(); |
| 638 | + } |
| 639 | + |
| 640 | + /** |
| 641 | + * @return OutputPage |
| 642 | + */ |
| 643 | + public function getOutput(){ |
| 644 | + return $this->getContext()->output; |
| 645 | + } |
| 646 | + |
| 647 | + /** |
| 648 | + * @return WebRequest |
| 649 | + */ |
| 650 | + public function getRequest(){ |
| 651 | + return $this->getContext()->request; |
| 652 | + } |
| 653 | + |
| 654 | + /** |
| 655 | + * @return User |
| 656 | + */ |
| 657 | + public function getUser(){ |
| 658 | + return $this->getContext()->user; |
| 659 | + } |
| 660 | + |
| 661 | + /** |
632 | 662 | * Set the method used to submit the form |
633 | 663 | * @param $method String |
634 | 664 | */ |
Index: trunk/phase3/includes/RequestContext.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | * @file |
9 | 9 | */ |
10 | 10 | |
11 | | -class RequestContext implements IContextSource { |
| 11 | +class RequestContext { |
12 | 12 | private $mRequest; // / WebRequest object |
13 | 13 | private $mTitle; // / Title object |
14 | 14 | private $mOutput; // / OutputPage object |
— | — | @@ -205,134 +205,3 @@ |
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | | -/** |
210 | | - * Interface for objects which can provide a context on request. |
211 | | - */ |
212 | | -interface IContextSource { |
213 | | - |
214 | | - /** |
215 | | - * Get the WebRequest object |
216 | | - * |
217 | | - * @return WebRequest |
218 | | - */ |
219 | | - public function getRequest(); |
220 | | - |
221 | | - /** |
222 | | - * Get the Title object |
223 | | - * |
224 | | - * @return Title |
225 | | - */ |
226 | | - public function getTitle(); |
227 | | - |
228 | | - /** |
229 | | - * Get the OutputPage object |
230 | | - * |
231 | | - * @return OutputPage object |
232 | | - */ |
233 | | - public function getOutput(); |
234 | | - |
235 | | - /** |
236 | | - * Get the User object |
237 | | - * |
238 | | - * @return User |
239 | | - */ |
240 | | - public function getUser(); |
241 | | - |
242 | | - /** |
243 | | - * Get the Language object |
244 | | - * |
245 | | - * @return Language |
246 | | - */ |
247 | | - public function getLang(); |
248 | | - |
249 | | - /** |
250 | | - * Get the Skin object |
251 | | - * |
252 | | - * @return Skin |
253 | | - */ |
254 | | - public function getSkin(); |
255 | | -} |
256 | | - |
257 | | -/** |
258 | | - * The simplest way of implementing IContextSource is to hold a RequestContext as a |
259 | | - * member variable and provide accessors to it. |
260 | | - */ |
261 | | -abstract class ContextSource implements IContextSource { |
262 | | - |
263 | | - /** |
264 | | - * @var RequestContext |
265 | | - */ |
266 | | - private $context; |
267 | | - |
268 | | - /** |
269 | | - * Get the RequestContext object |
270 | | - * |
271 | | - * @return RequestContext |
272 | | - */ |
273 | | - public function getContext() { |
274 | | - return $this->context; |
275 | | - } |
276 | | - |
277 | | - /** |
278 | | - * Set the RequestContext object |
279 | | - * |
280 | | - * @param $context RequestContext |
281 | | - */ |
282 | | - public function setContext( RequestContext $context ) { |
283 | | - $this->context = $context; |
284 | | - } |
285 | | - |
286 | | - /** |
287 | | - * Get the WebRequest object |
288 | | - * |
289 | | - * @return WebRequest |
290 | | - */ |
291 | | - public function getRequest() { |
292 | | - return $this->context->getRequest(); |
293 | | - } |
294 | | - |
295 | | - /** |
296 | | - * Get the Title object |
297 | | - * |
298 | | - * @return Title |
299 | | - */ |
300 | | - public function getTitle() { |
301 | | - return $this->context->getTitle(); |
302 | | - } |
303 | | - |
304 | | - /** |
305 | | - * Get the OutputPage object |
306 | | - * |
307 | | - * @return OutputPage object |
308 | | - */ |
309 | | - public function getOutput() { |
310 | | - return $this->context->getOutput(); |
311 | | - } |
312 | | - |
313 | | - /** |
314 | | - * Get the User object |
315 | | - * |
316 | | - * @return User |
317 | | - */ |
318 | | - public function getUser() { |
319 | | - return $this->context->getUser(); |
320 | | - } |
321 | | - |
322 | | - /** |
323 | | - * Get the Language object |
324 | | - * |
325 | | - * @return Language |
326 | | - */ |
327 | | - public function getLang() { |
328 | | - return $this->context->getLang(); |
329 | | - } |
330 | | - |
331 | | - /** |
332 | | - * Get the Skin object |
333 | | - * |
334 | | - * @return Skin |
335 | | - */ |
336 | | - public function getSkin() { |
337 | | - return $this->context->getSkin(); |
338 | | - } |
339 | | -} |
\ No newline at end of file |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | * |
20 | 20 | * @todo document |
21 | 21 | */ |
22 | | -class OutputPage extends ContextSource { |
| 22 | +class OutputPage { |
23 | 23 | /// Should be private. Used with addMeta() which adds <meta> |
24 | 24 | var $mMetatags = array(); |
25 | 25 | |
— | — | @@ -220,13 +220,11 @@ |
221 | 221 | * a OutputPage tied to that context. |
222 | 222 | */ |
223 | 223 | function __construct( RequestContext $context = null ) { |
224 | | - if ( $context === null ) { |
| 224 | + if ( !isset($context) ) { |
225 | 225 | # Extensions should use `new RequestContext` instead of `new OutputPage` now. |
226 | 226 | wfDeprecated( __METHOD__ ); |
227 | | - $this->setContext( RequestContext::getMain() ); |
228 | | - } else { |
229 | | - $this->setContext( $context ); |
230 | 227 | } |
| 228 | + $this->mContext = $context; |
231 | 229 | } |
232 | 230 | |
233 | 231 | /** |
— | — | @@ -766,6 +764,29 @@ |
767 | 765 | } |
768 | 766 | |
769 | 767 | /** |
| 768 | + * Get the RequestContext used in this instance |
| 769 | + * |
| 770 | + * @return RequestContext |
| 771 | + */ |
| 772 | + private function getContext() { |
| 773 | + if ( !isset($this->mContext) ) { |
| 774 | + wfDebug( __METHOD__ . " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" ); |
| 775 | + $this->mContext = RequestContext::getMain(); |
| 776 | + } |
| 777 | + return $this->mContext; |
| 778 | + } |
| 779 | + |
| 780 | + /** |
| 781 | + * Get the WebRequest being used for this instance |
| 782 | + * |
| 783 | + * @return WebRequest |
| 784 | + * @since 1.18 |
| 785 | + */ |
| 786 | + public function getRequest() { |
| 787 | + return $this->getContext()->getRequest(); |
| 788 | + } |
| 789 | + |
| 790 | + /** |
770 | 791 | * Set the Title object to use |
771 | 792 | * |
772 | 793 | * @param $t Title object |
— | — | @@ -775,6 +796,35 @@ |
776 | 797 | } |
777 | 798 | |
778 | 799 | /** |
| 800 | + * Get the Title object used in this instance |
| 801 | + * |
| 802 | + * @return Title |
| 803 | + */ |
| 804 | + public function getTitle() { |
| 805 | + return $this->getContext()->getTitle(); |
| 806 | + } |
| 807 | + |
| 808 | + /** |
| 809 | + * Get the User object used in this instance |
| 810 | + * |
| 811 | + * @return User |
| 812 | + * @since 1.18 |
| 813 | + */ |
| 814 | + public function getUser() { |
| 815 | + return $this->getContext()->getUser(); |
| 816 | + } |
| 817 | + |
| 818 | + /** |
| 819 | + * Get the Skin object used to render this instance |
| 820 | + * |
| 821 | + * @return Skin |
| 822 | + * @since 1.18 |
| 823 | + */ |
| 824 | + public function getSkin() { |
| 825 | + return $this->getContext()->getSkin(); |
| 826 | + } |
| 827 | + |
| 828 | + /** |
779 | 829 | * Replace the subtile with $str |
780 | 830 | * |
781 | 831 | * @param $str String: new value of the subtitle |
— | — | @@ -2127,7 +2177,7 @@ |
2128 | 2178 | ? 'lag-warn-normal' |
2129 | 2179 | : 'lag-warn-high'; |
2130 | 2180 | $wrap = Html::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" ); |
2131 | | - $this->wrapWikiMsg( "$wrap\n", array( $message, $this->getLang()->formatNum( $lag ) ) ); |
| 2181 | + $this->wrapWikiMsg( "$wrap\n", array( $message, $this->getContext()->getLang()->formatNum( $lag ) ) ); |
2132 | 2182 | } |
2133 | 2183 | } |
2134 | 2184 | |
— | — | @@ -2273,7 +2323,7 @@ |
2274 | 2324 | $dir = wfUILang()->getDir(); |
2275 | 2325 | $bodyAttrs['class'] = "mediawiki $dir"; |
2276 | 2326 | |
2277 | | - if ( $this->getLang()->capitalizeAllNouns() ) { |
| 2327 | + if ( $this->getContext()->getLang()->capitalizeAllNouns() ) { |
2278 | 2328 | # A <body> class is probably not the best way to do this . . . |
2279 | 2329 | $bodyAttrs['class'] .= ' capitalize-all-nouns'; |
2280 | 2330 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -49,7 +49,6 @@ |
50 | 50 | 'ConfEditorParseError' => 'includes/ConfEditor.php', |
51 | 51 | 'ConfEditorToken' => 'includes/ConfEditor.php', |
52 | 52 | 'ConstantDependency' => 'includes/CacheDependency.php', |
53 | | - 'ContextSource' => 'includes/RequestContext.php', |
54 | 53 | 'Cookie' => 'includes/Cookie.php', |
55 | 54 | 'CookieJar' => 'includes/Cookie.php', |
56 | 55 | 'CreativeCommonsRdf' => 'includes/Metadata.php', |
— | — | @@ -124,7 +123,6 @@ |
125 | 124 | 'HTMLTextField' => 'includes/HTMLForm.php', |
126 | 125 | 'Http' => 'includes/HttpFunctions.php', |
127 | 126 | 'HttpRequest' => 'includes/HttpFunctions.old.php', |
128 | | - 'IContextSource' => 'includes/RequestContext.php', |
129 | 127 | 'IcuCollation' => 'includes/Collation.php', |
130 | 128 | 'ImageGallery' => 'includes/ImageGallery.php', |
131 | 129 | 'ImageHistoryList' => 'includes/ImagePage.php', |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | * |
17 | 17 | * @ingroup Skins |
18 | 18 | */ |
19 | | -abstract class Skin extends ContextSource { |
| 19 | +abstract class Skin { |
20 | 20 | /**#@+ |
21 | 21 | * @private |
22 | 22 | */ |
— | — | @@ -190,8 +190,10 @@ |
191 | 191 | * Preload the existence of three commonly-requested pages in a single query |
192 | 192 | */ |
193 | 193 | function preloadExistence() { |
| 194 | + $user = $this->getContext()->getUser(); |
| 195 | + |
194 | 196 | // User/talk link |
195 | | - $titles = array( $this->getUser()->getUserPage(), $this->getUser()->getTalkPage() ); |
| 197 | + $titles = array( $user->getUserPage(), $user->getTalkPage() ); |
196 | 198 | |
197 | 199 | // Other tab link |
198 | 200 | if ( $this->getTitle()->getNamespace() == NS_SPECIAL ) { |
— | — | @@ -211,7 +213,7 @@ |
212 | 214 | * Set some local variables |
213 | 215 | */ |
214 | 216 | protected function setMembers() { |
215 | | - $this->userpage = $this->getUser()->getUserPage()->getPrefixedText(); |
| 217 | + $this->userpage = $this->getContext()->getUser()->getUserPage()->getPrefixedText(); |
216 | 218 | $this->usercss = false; |
217 | 219 | } |
218 | 220 | |
— | — | @@ -225,18 +227,43 @@ |
226 | 228 | } |
227 | 229 | |
228 | 230 | /** |
| 231 | + * Set the RequestContext used in this instance |
| 232 | + * |
| 233 | + * @param RequestContext $context |
| 234 | + */ |
| 235 | + public function setContext( RequestContext $context ) { |
| 236 | + $this->mContext = $context; |
| 237 | + } |
| 238 | + |
| 239 | + /** |
229 | 240 | * Get the RequestContext used in this instance |
230 | 241 | * |
231 | 242 | * @return RequestContext |
232 | 243 | */ |
233 | 244 | public function getContext() { |
234 | | - if ( !parent::getContext() instanceof RequestContext ) { |
| 245 | + if ( !isset($this->mContext) ) { |
235 | 246 | wfDebug( __METHOD__ . " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" ); |
236 | | - $this->setContext( RequestContext::getMain() ); |
| 247 | + $this->mContext = RequestContext::getMain(); |
237 | 248 | } |
238 | | - return parent::getContext(); |
| 249 | + return $this->mContext; |
239 | 250 | } |
240 | 251 | |
| 252 | + /** Get the title |
| 253 | + * |
| 254 | + * @return Title |
| 255 | + */ |
| 256 | + public function getTitle() { |
| 257 | + return $this->getContext()->getTitle(); |
| 258 | + } |
| 259 | + |
| 260 | + /** Get the user |
| 261 | + * |
| 262 | + * @return User |
| 263 | + */ |
| 264 | + public function getUser() { |
| 265 | + return $this->getContext()->getUser(); |
| 266 | + } |
| 267 | + |
241 | 268 | /** |
242 | 269 | * Set the "relevant" title |
243 | 270 | * @see self::getRelevantTitle() |
— | — | @@ -328,7 +355,7 @@ |
329 | 356 | if ( $action != 'submit' ) { |
330 | 357 | return false; |
331 | 358 | } |
332 | | - if ( !$this->getRequest()->wasPosted() ) { |
| 359 | + if ( !$this->getContext()->getRequest()->wasPosted() ) { |
333 | 360 | return false; |
334 | 361 | } |
335 | 362 | if ( !$this->getTitle()->userCanEditCssSubpage() ) { |
— | — | @@ -338,8 +365,8 @@ |
339 | 366 | return false; |
340 | 367 | } |
341 | 368 | |
342 | | - return $this->getUser()->matchEditToken( |
343 | | - $this->getRequest()->getVal( 'wpEditToken' ) ); |
| 369 | + return $this->getContext()->getUser()->matchEditToken( |
| 370 | + $this->getContext()->getRequest()->getVal( 'wpEditToken' ) ); |
344 | 371 | } |
345 | 372 | |
346 | 373 | /** |
— | — | @@ -401,16 +428,16 @@ |
402 | 429 | // Per-site custom styles |
403 | 430 | if ( $wgUseSiteCss ) { |
404 | 431 | $out->addModuleStyles( array( 'site', 'noscript' ) ); |
405 | | - if( $this->getUser()->isLoggedIn() ){ |
| 432 | + if( $this->getContext()->getUser()->isLoggedIn() ){ |
406 | 433 | $out->addModuleStyles( 'user.groups' ); |
407 | 434 | } |
408 | 435 | } |
409 | 436 | |
410 | 437 | // Per-user custom styles |
411 | 438 | if ( $wgAllowUserCss ) { |
412 | | - if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getRequest()->getVal( 'action' ) ) ) { |
| 439 | + if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) { |
413 | 440 | // @FIXME: properly escape the cdata! |
414 | | - $out->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) ); |
| 441 | + $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) ); |
415 | 442 | } else { |
416 | 443 | $out->addModuleStyles( 'user' ); |
417 | 444 | } |
— | — | @@ -500,7 +527,7 @@ |
501 | 528 | global $wgUseCategoryBrowser, $wgContLang; |
502 | 529 | |
503 | 530 | if( $out === null ){ |
504 | | - $out = $this->getOutput(); |
| 531 | + $out = $this->getContext()->output; |
505 | 532 | } |
506 | 533 | |
507 | 534 | if ( count( $out->mCategoryLinks ) == 0 ) { |
— | — | @@ -531,7 +558,7 @@ |
532 | 559 | |
533 | 560 | # Hidden categories |
534 | 561 | if ( isset( $allCats['hidden'] ) ) { |
535 | | - if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) { |
| 562 | + if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) { |
536 | 563 | $class = 'mw-hidden-cats-user-shown'; |
537 | 564 | } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) { |
538 | 565 | $class = 'mw-hidden-cats-ns-shown'; |
— | — | @@ -602,7 +629,7 @@ |
603 | 630 | |
604 | 631 | // Check what we're showing |
605 | 632 | $allCats = $out->getCategoryLinks(); |
606 | | - $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) || |
| 633 | + $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) || |
607 | 634 | $this->getTitle()->getNamespace() == NS_CATEGORY; |
608 | 635 | |
609 | 636 | if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) { |
— | — | @@ -736,14 +763,14 @@ |
737 | 764 | } |
738 | 765 | |
739 | 766 | function getUndeleteLink() { |
740 | | - $action = $this->getRequest()->getVal( 'action', 'view' ); |
| 767 | + $action = $this->getContext()->getRequest()->getVal( 'action', 'view' ); |
741 | 768 | |
742 | | - if ( $this->getUser()->isAllowed( 'deletedhistory' ) && |
| 769 | + if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) && |
743 | 770 | ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) { |
744 | 771 | $n = $this->getTitle()->isDeleted(); |
745 | 772 | |
746 | 773 | if ( $n ) { |
747 | | - if ( $this->getUser()->isAllowed( 'undelete' ) ) { |
| 774 | + if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) { |
748 | 775 | $msg = 'thisisdeleted'; |
749 | 776 | } else { |
750 | 777 | $msg = 'viewdeleted'; |
— | — | @@ -753,7 +780,7 @@ |
754 | 781 | $msg, |
755 | 782 | Linker::link( |
756 | 783 | SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ), |
757 | | - wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) ), |
| 784 | + wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ), |
758 | 785 | array(), |
759 | 786 | array(), |
760 | 787 | array( 'known', 'noclasses' ) |
— | — | @@ -766,10 +793,10 @@ |
767 | 794 | } |
768 | 795 | |
769 | 796 | /** |
770 | | - * The format with an explicit $out argument is deprecated |
| 797 | + * The format without an explicit $out argument is deprecated |
771 | 798 | */ |
772 | 799 | function subPageSubtitle( OutputPage $out=null ) { |
773 | | - $out = $this->getOutput(); |
| 800 | + $out = $this->getContext()->getOutput(); |
774 | 801 | $subpages = ''; |
775 | 802 | |
776 | 803 | if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) { |
— | — | @@ -791,7 +818,7 @@ |
792 | 819 | $linkObj = Title::newFromText( $growinglink ); |
793 | 820 | |
794 | 821 | if ( is_object( $linkObj ) && $linkObj->exists() ) { |
795 | | - $getlink = Linker::link( |
| 822 | + $getlink = $this->link( |
796 | 823 | $linkObj, |
797 | 824 | htmlspecialchars( $display ), |
798 | 825 | array(), |
— | — | @@ -841,7 +868,7 @@ |
842 | 869 | global $wgRightsPage, $wgRightsUrl, $wgRightsText; |
843 | 870 | |
844 | 871 | if ( $type == 'detect' ) { |
845 | | - $diff = $this->getRequest()->getVal( 'diff' ); |
| 872 | + $diff = $this->getContext()->getRequest()->getVal( 'diff' ); |
846 | 873 | |
847 | 874 | if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) { |
848 | 875 | $type = 'history'; |
— | — | @@ -937,8 +964,8 @@ |
938 | 965 | } |
939 | 966 | |
940 | 967 | if ( $timestamp ) { |
941 | | - $d = $this->getLang()->date( $timestamp, true ); |
942 | | - $t = $this->getLang()->time( $timestamp, true ); |
| 968 | + $d = $this->getContext()->getLang()->date( $timestamp, true ); |
| 969 | + $t = $this->getContext()->getLang()->time( $timestamp, true ); |
943 | 970 | $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t ); |
944 | 971 | } else { |
945 | 972 | $s = ''; |
— | — | @@ -1065,7 +1092,7 @@ |
1066 | 1093 | |
1067 | 1094 | function showEmailUser( $id ) { |
1068 | 1095 | $targetUser = User::newFromId( $id ); |
1069 | | - return $this->getUser()->canSendEmail() && # the sending user must have a confirmed email address |
| 1096 | + return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address |
1070 | 1097 | $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users |
1071 | 1098 | } |
1072 | 1099 | |
— | — | @@ -1187,7 +1214,7 @@ |
1188 | 1215 | global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry; |
1189 | 1216 | wfProfileIn( __METHOD__ ); |
1190 | 1217 | |
1191 | | - $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() ); |
| 1218 | + $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() ); |
1192 | 1219 | |
1193 | 1220 | if ( $wgEnableSidebarCache ) { |
1194 | 1221 | $cachedsidebar = $parserMemc->get( $key ); |
— | — | @@ -1323,9 +1350,9 @@ |
1324 | 1351 | * @return MediaWiki message or if no new talk page messages, nothing |
1325 | 1352 | */ |
1326 | 1353 | function getNewtalks() { |
1327 | | - $out = $this->getOutput(); |
| 1354 | + $out = $this->getContext()->getOutput(); |
1328 | 1355 | |
1329 | | - $newtalks = $this->getUser()->getNewMessageLinks(); |
| 1356 | + $newtalks = $this->getContext()->getUser()->getNewMessageLinks(); |
1330 | 1357 | $ntl = ''; |
1331 | 1358 | |
1332 | 1359 | if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) { |
— | — | @@ -1333,7 +1360,7 @@ |
1334 | 1361 | $userTalkTitle = $userTitle->getTalkPage(); |
1335 | 1362 | |
1336 | 1363 | if ( !$userTalkTitle->equals( $out->getTitle() ) ) { |
1337 | | - $newMessagesLink = Linker::link( |
| 1364 | + $newMessagesLink = $this->link( |
1338 | 1365 | $userTalkTitle, |
1339 | 1366 | wfMsgHtml( 'newmessageslink' ), |
1340 | 1367 | array(), |
— | — | @@ -1341,7 +1368,7 @@ |
1342 | 1369 | array( 'known', 'noclasses' ) |
1343 | 1370 | ); |
1344 | 1371 | |
1345 | | - $newMessagesDiffLink = Linker::link( |
| 1372 | + $newMessagesDiffLink = $this->link( |
1346 | 1373 | $userTalkTitle, |
1347 | 1374 | wfMsgHtml( 'newmessagesdifflink' ), |
1348 | 1375 | array(), |
— | — | @@ -1420,7 +1447,7 @@ |
1421 | 1448 | } |
1422 | 1449 | |
1423 | 1450 | if ( $needParse ) { |
1424 | | - $parsed = $this->getOutput()->parse( $notice ); |
| 1451 | + $parsed = $this->getContext()->getOutput()->parse( $notice ); |
1425 | 1452 | $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 ); |
1426 | 1453 | $notice = $parsed; |
1427 | 1454 | } |
— | — | @@ -1460,7 +1487,7 @@ |
1461 | 1488 | $siteNotice = ''; |
1462 | 1489 | |
1463 | 1490 | if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) { |
1464 | | - if ( $this->getUser() instanceof User && $this->getUser()->isLoggedIn() ) { |
| 1491 | + if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) { |
1465 | 1492 | $siteNotice = $this->getCachedNotice( 'sitenotice' ); |
1466 | 1493 | } else { |
1467 | 1494 | $anonNotice = $this->getCachedNotice( 'anonnotice' ); |
Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | * page list. |
29 | 29 | * @ingroup SpecialPage |
30 | 30 | */ |
31 | | -class SpecialPage extends ContextSource { |
| 31 | +class SpecialPage { |
32 | 32 | |
33 | 33 | // The canonical name of this special page |
34 | 34 | // Also used for the default <h1> heading, @see getDescription() |
— | — | @@ -572,6 +572,16 @@ |
573 | 573 | function getTitle( $subpage = false ) { |
574 | 574 | return self::getTitleFor( $this->mName, $subpage ); |
575 | 575 | } |
| 576 | + |
| 577 | + /** |
| 578 | + * Sets the context this SpecialPage is executed in |
| 579 | + * |
| 580 | + * @param $context RequestContext |
| 581 | + * @since 1.18 |
| 582 | + */ |
| 583 | + public function setContext( $context ) { |
| 584 | + $this->mContext = $context; |
| 585 | + } |
576 | 586 | |
577 | 587 | /** |
578 | 588 | * Gets the context this SpecialPage is executed in |
— | — | @@ -580,8 +590,8 @@ |
581 | 591 | * @since 1.18 |
582 | 592 | */ |
583 | 593 | public function getContext() { |
584 | | - if ( parent::getContext() instanceof RequestContext ) { |
585 | | - return parent::getContext(); |
| 594 | + if ( $this->mContext instanceof RequestContext ) { |
| 595 | + return $this->mContext; |
586 | 596 | } else { |
587 | 597 | wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" ); |
588 | 598 | return RequestContext::getMain(); |
— | — | @@ -589,6 +599,46 @@ |
590 | 600 | } |
591 | 601 | |
592 | 602 | /** |
| 603 | + * Get the WebRequest being used for this instance |
| 604 | + * |
| 605 | + * @return WebRequest |
| 606 | + * @since 1.18 |
| 607 | + */ |
| 608 | + public function getRequest() { |
| 609 | + return $this->getContext()->getRequest(); |
| 610 | + } |
| 611 | + |
| 612 | + /** |
| 613 | + * Get the OutputPage being used for this instance |
| 614 | + * |
| 615 | + * @return OutputPage |
| 616 | + * @since 1.18 |
| 617 | + */ |
| 618 | + public function getOutput() { |
| 619 | + return $this->getContext()->getOutput(); |
| 620 | + } |
| 621 | + |
| 622 | + /** |
| 623 | + * Shortcut to get the skin being used for this instance |
| 624 | + * |
| 625 | + * @return User |
| 626 | + * @since 1.18 |
| 627 | + */ |
| 628 | + public function getUser() { |
| 629 | + return $this->getContext()->getUser(); |
| 630 | + } |
| 631 | + |
| 632 | + /** |
| 633 | + * Shortcut to get the skin being used for this instance |
| 634 | + * |
| 635 | + * @return Skin |
| 636 | + * @since 1.18 |
| 637 | + */ |
| 638 | + public function getSkin() { |
| 639 | + return $this->getContext()->getSkin(); |
| 640 | + } |
| 641 | + |
| 642 | + /** |
593 | 643 | * Return the full title, including $par |
594 | 644 | * |
595 | 645 | * @return Title |
Index: trunk/phase3/includes/Action.php |
— | — | @@ -23,12 +23,16 @@ |
24 | 24 | * |
25 | 25 | * @file |
26 | 26 | */ |
27 | | -abstract class Action extends ContextSource { |
| 27 | +abstract class Action { |
28 | 28 | |
29 | 29 | // Page on which we're performing the action |
30 | 30 | // @var Article |
31 | 31 | protected $page; |
32 | 32 | |
| 33 | + // RequestContext if specified; otherwise we'll use the Context from the Page |
| 34 | + // @var RequestContext |
| 35 | + protected $context; |
| 36 | + |
33 | 37 | // The fields used to create the HTMLForm |
34 | 38 | // @var Array |
35 | 39 | protected $fields; |
— | — | @@ -87,13 +91,76 @@ |
88 | 92 | } |
89 | 93 | |
90 | 94 | /** |
| 95 | + * Get the RequestContext in use here |
| 96 | + * @return RequestContext |
| 97 | + */ |
| 98 | + protected final function getContext() { |
| 99 | + if ( $this->context instanceof RequestContext ) { |
| 100 | + return $this->context; |
| 101 | + } |
| 102 | + return $this->page->getContext(); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Get the WebRequest being used for this instance |
| 107 | + * |
| 108 | + * @return WebRequest |
| 109 | + */ |
| 110 | + protected final function getRequest() { |
| 111 | + return $this->getContext()->request; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Get the OutputPage being used for this instance |
| 116 | + * |
| 117 | + * @return OutputPage |
| 118 | + */ |
| 119 | + protected final function getOutput() { |
| 120 | + return $this->getContext()->output; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Shortcut to get the User being used for this instance |
| 125 | + * |
| 126 | + * @return User |
| 127 | + */ |
| 128 | + protected final function getUser() { |
| 129 | + return $this->getContext()->user; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Shortcut to get the Skin being used for this instance |
| 134 | + * |
| 135 | + * @return Skin |
| 136 | + */ |
| 137 | + protected final function getSkin() { |
| 138 | + return $this->getContext()->skin; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Shortcut to get the user Language being used for this instance |
| 143 | + * |
| 144 | + * @return Skin |
| 145 | + */ |
| 146 | + protected final function getLang() { |
| 147 | + return $this->getContext()->lang; |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Shortcut to get the Title object from the page |
| 152 | + * @return Title |
| 153 | + */ |
| 154 | + protected final function getTitle() { |
| 155 | + return $this->page->getTitle(); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
91 | 159 | * Protected constructor: use Action::factory( $action, $page ) to actually build |
92 | 160 | * these things in the real world |
93 | 161 | * @param Article $page |
94 | 162 | */ |
95 | 163 | protected function __construct( Article $page ) { |
96 | 164 | $this->page = $page; |
97 | | - $this->setContext( $page->getContext() ); |
98 | 165 | } |
99 | 166 | |
100 | 167 | /** |
— | — | @@ -282,7 +349,7 @@ |
283 | 350 | public function execute( array $data = null, $captureErrors = true ) { |
284 | 351 | try { |
285 | 352 | // Set a new context so output doesn't leak. |
286 | | - $this->setContext( clone $this->page->getContext() ); |
| 353 | + $this->context = clone $this->page->getContext(); |
287 | 354 | |
288 | 355 | // This will throw exceptions if there's a problem |
289 | 356 | $this->checkCanExecute( $this->getUser() ); |
— | — | @@ -364,11 +431,10 @@ |
365 | 432 | public function execute( array $data = null, $captureErrors = true ) { |
366 | 433 | try { |
367 | 434 | // Set a new context so output doesn't leak. |
368 | | - $context = clone $this->page->getContext(); |
| 435 | + $this->context = clone $this->page->getContext(); |
369 | 436 | if ( is_array( $data ) ) { |
370 | | - $context->setRequest( new FauxRequest( $data, false ) ); |
| 437 | + $this->context->setRequest( new FauxRequest( $data, false ) ); |
371 | 438 | } |
372 | | - $this->setContext( $context ); |
373 | 439 | |
374 | 440 | // This will throw exceptions if there's a problem |
375 | 441 | $this->checkCanExecute( $this->getUser() ); |