r86875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86874‎ | r86875 | r86876 >
Date:18:20, 25 April 2011
Author:siebrand
Status:ok
Tags:
Comment:
Revert r86872: Breaks LiquidThreads page moves with the below failure. Threads are lost and nowhere to be found any more.

[25-Apr-2011 18:12:45] /wiki/Special:MoveThread/Thread:User_talk:Siebrand/test/One_new_message: Exception: MWNamespace::getTalk does not make any sense for given namespace -1
#0 /www/w/includes/Namespace.php(81): MWNamespace::isMethodValidFor(-1, 'MWNamespace::ge...')
#1 /www/w/includes/WatchedItem.php(73): MWNamespace::getTalk(-1)
#2 /www/w/includes/User.php(2304): WatchedItem->addWatch()
#3 /www/w/includes/actions/WatchAction.php(53): User->addWatch(Object(Title))
#4 /www/w/includes/Action.php(376): WatchAction->onView()
#5 /www/w/extensions/LiquidThreads/classes/Thread.php(115): FormlessAction->execute()
#6 /www/w/extensions/LiquidThreads/classes/Thread.php(435): Thread::create(Object(Article), Object(Article), NULL, 1, 'One new message')
#7 /www/w/extensions/LiquidThreads/classes/Thread.php(414): Thread->leaveTrace('move test', Object(Title), Object(Title))
#8 /www/w/extensions/LiquidThreads/pages/SpecialMoveThread.php(107): Thread->moveToPage(Object(Title), 'move test', true)
#9 [internal function]: SpecialMoveThread->trySubmit(Array)
#10 /www/w/includes/HTMLForm.php(279): call_user_func(Array, Array)
#11 /www/w/includes/HTMLForm.php(228): HTMLForm->trySubmit()
#12 /www/w/includes/HTMLForm.php(242): HTMLForm->tryAuthorizedSubmit()
#13 /www/w/extensions/LiquidThreads/pages/ThreadActionPage.php(37): HTMLForm->show()
#14 /www/w/includes/SpecialPageFactory.php(459): ThreadActionPage->execute('Thread:User_tal...')
#15 /www/w/includes/Wiki.php(252): SpecialPageFactory::executePath(Object(Title), Object(RequestContext))
#16 /www/w/includes/Wiki.php(98): MediaWiki->handleSpecialCases()
#17 /www/w/index.php(145): MediaWiki->performRequestForTitle(NULL)
#18 {main}
Modified paths:
  • /trunk/phase3/includes/Action.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/RequestContext.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -53,7 +53,7 @@
5454 *
5555 * TODO: Document 'section' / 'subsection' stuff
5656 */
57 -class HTMLForm extends ContextSource {
 57+class HTMLForm {
5858
5959 # A mapping of 'type' inputs onto standard HTMLFormField subclasses
6060 static $typeMappings = array(
@@ -102,6 +102,7 @@
103103 protected $mSubmitText;
104104 protected $mSubmitTooltip;
105105
 106+ protected $mContext; // <! RequestContext
106107 protected $mTitle;
107108 protected $mMethod = 'post';
108109
@@ -120,11 +121,10 @@
121122 */
122123 public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) {
123124 if( $context instanceof RequestContext ){
124 - $this->setContext( $context );
 125+ $this->mContext = $context;
125126 $this->mTitle = false; // We don't need them to set a title
126127 $this->mMessagePrefix = $messagePrefix;
127128 } else {
128 - $this->setContext( RequestContext::getMain() );
129129 // B/C since 1.18
130130 if( is_string( $context ) && $messagePrefix === '' ){
131131 // it's actually $messagePrefix
@@ -623,11 +623,41 @@
624624 */
625625 function getTitle() {
626626 return $this->mTitle === false
627 - ? parent::getTitle()
 627+ ? $this->getContext()->title
628628 : $this->mTitle;
629629 }
630630
631631 /**
 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+ /**
632662 * Set the method used to submit the form
633663 * @param $method String
634664 */
Index: trunk/phase3/includes/RequestContext.php
@@ -7,7 +7,7 @@
88 * @file
99 */
1010
11 -class RequestContext implements IContextSource {
 11+class RequestContext {
1212 private $mRequest; // / WebRequest object
1313 private $mTitle; // / Title object
1414 private $mOutput; // / OutputPage object
@@ -205,134 +205,3 @@
206206 }
207207 }
208208
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 @@
1919 *
2020 * @todo document
2121 */
22 -class OutputPage extends ContextSource {
 22+class OutputPage {
2323 /// Should be private. Used with addMeta() which adds <meta>
2424 var $mMetatags = array();
2525
@@ -220,13 +220,11 @@
221221 * a OutputPage tied to that context.
222222 */
223223 function __construct( RequestContext $context = null ) {
224 - if ( $context === null ) {
 224+ if ( !isset($context) ) {
225225 # Extensions should use `new RequestContext` instead of `new OutputPage` now.
226226 wfDeprecated( __METHOD__ );
227 - $this->setContext( RequestContext::getMain() );
228 - } else {
229 - $this->setContext( $context );
230227 }
 228+ $this->mContext = $context;
231229 }
232230
233231 /**
@@ -766,6 +764,29 @@
767765 }
768766
769767 /**
 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+ /**
770791 * Set the Title object to use
771792 *
772793 * @param $t Title object
@@ -775,6 +796,35 @@
776797 }
777798
778799 /**
 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+ /**
779829 * Replace the subtile with $str
780830 *
781831 * @param $str String: new value of the subtitle
@@ -2127,7 +2177,7 @@
21282178 ? 'lag-warn-normal'
21292179 : 'lag-warn-high';
21302180 $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 ) ) );
21322182 }
21332183 }
21342184
@@ -2273,7 +2323,7 @@
22742324 $dir = wfUILang()->getDir();
22752325 $bodyAttrs['class'] = "mediawiki $dir";
22762326
2277 - if ( $this->getLang()->capitalizeAllNouns() ) {
 2327+ if ( $this->getContext()->getLang()->capitalizeAllNouns() ) {
22782328 # A <body> class is probably not the best way to do this . . .
22792329 $bodyAttrs['class'] .= ' capitalize-all-nouns';
22802330 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -49,7 +49,6 @@
5050 'ConfEditorParseError' => 'includes/ConfEditor.php',
5151 'ConfEditorToken' => 'includes/ConfEditor.php',
5252 'ConstantDependency' => 'includes/CacheDependency.php',
53 - 'ContextSource' => 'includes/RequestContext.php',
5453 'Cookie' => 'includes/Cookie.php',
5554 'CookieJar' => 'includes/Cookie.php',
5655 'CreativeCommonsRdf' => 'includes/Metadata.php',
@@ -124,7 +123,6 @@
125124 'HTMLTextField' => 'includes/HTMLForm.php',
126125 'Http' => 'includes/HttpFunctions.php',
127126 'HttpRequest' => 'includes/HttpFunctions.old.php',
128 - 'IContextSource' => 'includes/RequestContext.php',
129127 'IcuCollation' => 'includes/Collation.php',
130128 'ImageGallery' => 'includes/ImageGallery.php',
131129 'ImageHistoryList' => 'includes/ImagePage.php',
Index: trunk/phase3/includes/Skin.php
@@ -15,7 +15,7 @@
1616 *
1717 * @ingroup Skins
1818 */
19 -abstract class Skin extends ContextSource {
 19+abstract class Skin {
2020 /**#@+
2121 * @private
2222 */
@@ -190,8 +190,10 @@
191191 * Preload the existence of three commonly-requested pages in a single query
192192 */
193193 function preloadExistence() {
 194+ $user = $this->getContext()->getUser();
 195+
194196 // User/talk link
195 - $titles = array( $this->getUser()->getUserPage(), $this->getUser()->getTalkPage() );
 197+ $titles = array( $user->getUserPage(), $user->getTalkPage() );
196198
197199 // Other tab link
198200 if ( $this->getTitle()->getNamespace() == NS_SPECIAL ) {
@@ -211,7 +213,7 @@
212214 * Set some local variables
213215 */
214216 protected function setMembers() {
215 - $this->userpage = $this->getUser()->getUserPage()->getPrefixedText();
 217+ $this->userpage = $this->getContext()->getUser()->getUserPage()->getPrefixedText();
216218 $this->usercss = false;
217219 }
218220
@@ -225,18 +227,43 @@
226228 }
227229
228230 /**
 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+ /**
229240 * Get the RequestContext used in this instance
230241 *
231242 * @return RequestContext
232243 */
233244 public function getContext() {
234 - if ( !parent::getContext() instanceof RequestContext ) {
 245+ if ( !isset($this->mContext) ) {
235246 wfDebug( __METHOD__ . " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
236 - $this->setContext( RequestContext::getMain() );
 247+ $this->mContext = RequestContext::getMain();
237248 }
238 - return parent::getContext();
 249+ return $this->mContext;
239250 }
240251
 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+
241268 /**
242269 * Set the "relevant" title
243270 * @see self::getRelevantTitle()
@@ -328,7 +355,7 @@
329356 if ( $action != 'submit' ) {
330357 return false;
331358 }
332 - if ( !$this->getRequest()->wasPosted() ) {
 359+ if ( !$this->getContext()->getRequest()->wasPosted() ) {
333360 return false;
334361 }
335362 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
@@ -338,8 +365,8 @@
339366 return false;
340367 }
341368
342 - return $this->getUser()->matchEditToken(
343 - $this->getRequest()->getVal( 'wpEditToken' ) );
 369+ return $this->getContext()->getUser()->matchEditToken(
 370+ $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
344371 }
345372
346373 /**
@@ -401,16 +428,16 @@
402429 // Per-site custom styles
403430 if ( $wgUseSiteCss ) {
404431 $out->addModuleStyles( array( 'site', 'noscript' ) );
405 - if( $this->getUser()->isLoggedIn() ){
 432+ if( $this->getContext()->getUser()->isLoggedIn() ){
406433 $out->addModuleStyles( 'user.groups' );
407434 }
408435 }
409436
410437 // Per-user custom styles
411438 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' ) ) ) {
413440 // @FIXME: properly escape the cdata!
414 - $out->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
 441+ $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
415442 } else {
416443 $out->addModuleStyles( 'user' );
417444 }
@@ -500,7 +527,7 @@
501528 global $wgUseCategoryBrowser, $wgContLang;
502529
503530 if( $out === null ){
504 - $out = $this->getOutput();
 531+ $out = $this->getContext()->output;
505532 }
506533
507534 if ( count( $out->mCategoryLinks ) == 0 ) {
@@ -531,7 +558,7 @@
532559
533560 # Hidden categories
534561 if ( isset( $allCats['hidden'] ) ) {
535 - if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
 562+ if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
536563 $class = 'mw-hidden-cats-user-shown';
537564 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
538565 $class = 'mw-hidden-cats-ns-shown';
@@ -602,7 +629,7 @@
603630
604631 // Check what we're showing
605632 $allCats = $out->getCategoryLinks();
606 - $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
 633+ $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
607634 $this->getTitle()->getNamespace() == NS_CATEGORY;
608635
609636 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
@@ -736,14 +763,14 @@
737764 }
738765
739766 function getUndeleteLink() {
740 - $action = $this->getRequest()->getVal( 'action', 'view' );
 767+ $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
741768
742 - if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
 769+ if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
743770 ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) {
744771 $n = $this->getTitle()->isDeleted();
745772
746773 if ( $n ) {
747 - if ( $this->getUser()->isAllowed( 'undelete' ) ) {
 774+ if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
748775 $msg = 'thisisdeleted';
749776 } else {
750777 $msg = 'viewdeleted';
@@ -753,7 +780,7 @@
754781 $msg,
755782 Linker::link(
756783 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 ) ),
758785 array(),
759786 array(),
760787 array( 'known', 'noclasses' )
@@ -766,10 +793,10 @@
767794 }
768795
769796 /**
770 - * The format with an explicit $out argument is deprecated
 797+ * The format without an explicit $out argument is deprecated
771798 */
772799 function subPageSubtitle( OutputPage $out=null ) {
773 - $out = $this->getOutput();
 800+ $out = $this->getContext()->getOutput();
774801 $subpages = '';
775802
776803 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
@@ -791,7 +818,7 @@
792819 $linkObj = Title::newFromText( $growinglink );
793820
794821 if ( is_object( $linkObj ) && $linkObj->exists() ) {
795 - $getlink = Linker::link(
 822+ $getlink = $this->link(
796823 $linkObj,
797824 htmlspecialchars( $display ),
798825 array(),
@@ -841,7 +868,7 @@
842869 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
843870
844871 if ( $type == 'detect' ) {
845 - $diff = $this->getRequest()->getVal( 'diff' );
 872+ $diff = $this->getContext()->getRequest()->getVal( 'diff' );
846873
847874 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
848875 $type = 'history';
@@ -937,8 +964,8 @@
938965 }
939966
940967 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 );
943970 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
944971 } else {
945972 $s = '';
@@ -1065,7 +1092,7 @@
10661093
10671094 function showEmailUser( $id ) {
10681095 $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
10701097 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
10711098 }
10721099
@@ -1187,7 +1214,7 @@
11881215 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
11891216 wfProfileIn( __METHOD__ );
11901217
1191 - $key = wfMemcKey( 'sidebar', $this->getLang()->getCode() );
 1218+ $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
11921219
11931220 if ( $wgEnableSidebarCache ) {
11941221 $cachedsidebar = $parserMemc->get( $key );
@@ -1323,9 +1350,9 @@
13241351 * @return MediaWiki message or if no new talk page messages, nothing
13251352 */
13261353 function getNewtalks() {
1327 - $out = $this->getOutput();
 1354+ $out = $this->getContext()->getOutput();
13281355
1329 - $newtalks = $this->getUser()->getNewMessageLinks();
 1356+ $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
13301357 $ntl = '';
13311358
13321359 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
@@ -1333,7 +1360,7 @@
13341361 $userTalkTitle = $userTitle->getTalkPage();
13351362
13361363 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1337 - $newMessagesLink = Linker::link(
 1364+ $newMessagesLink = $this->link(
13381365 $userTalkTitle,
13391366 wfMsgHtml( 'newmessageslink' ),
13401367 array(),
@@ -1341,7 +1368,7 @@
13421369 array( 'known', 'noclasses' )
13431370 );
13441371
1345 - $newMessagesDiffLink = Linker::link(
 1372+ $newMessagesDiffLink = $this->link(
13461373 $userTalkTitle,
13471374 wfMsgHtml( 'newmessagesdifflink' ),
13481375 array(),
@@ -1420,7 +1447,7 @@
14211448 }
14221449
14231450 if ( $needParse ) {
1424 - $parsed = $this->getOutput()->parse( $notice );
 1451+ $parsed = $this->getContext()->getOutput()->parse( $notice );
14251452 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
14261453 $notice = $parsed;
14271454 }
@@ -1460,7 +1487,7 @@
14611488 $siteNotice = '';
14621489
14631490 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() ) {
14651492 $siteNotice = $this->getCachedNotice( 'sitenotice' );
14661493 } else {
14671494 $anonNotice = $this->getCachedNotice( 'anonnotice' );
Index: trunk/phase3/includes/SpecialPage.php
@@ -27,7 +27,7 @@
2828 * page list.
2929 * @ingroup SpecialPage
3030 */
31 -class SpecialPage extends ContextSource {
 31+class SpecialPage {
3232
3333 // The canonical name of this special page
3434 // Also used for the default <h1> heading, @see getDescription()
@@ -572,6 +572,16 @@
573573 function getTitle( $subpage = false ) {
574574 return self::getTitleFor( $this->mName, $subpage );
575575 }
 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+ }
576586
577587 /**
578588 * Gets the context this SpecialPage is executed in
@@ -580,8 +590,8 @@
581591 * @since 1.18
582592 */
583593 public function getContext() {
584 - if ( parent::getContext() instanceof RequestContext ) {
585 - return parent::getContext();
 594+ if ( $this->mContext instanceof RequestContext ) {
 595+ return $this->mContext;
586596 } else {
587597 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
588598 return RequestContext::getMain();
@@ -589,6 +599,46 @@
590600 }
591601
592602 /**
 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+ /**
593643 * Return the full title, including $par
594644 *
595645 * @return Title
Index: trunk/phase3/includes/Action.php
@@ -23,12 +23,16 @@
2424 *
2525 * @file
2626 */
27 -abstract class Action extends ContextSource {
 27+abstract class Action {
2828
2929 // Page on which we're performing the action
3030 // @var Article
3131 protected $page;
3232
 33+ // RequestContext if specified; otherwise we'll use the Context from the Page
 34+ // @var RequestContext
 35+ protected $context;
 36+
3337 // The fields used to create the HTMLForm
3438 // @var Array
3539 protected $fields;
@@ -87,13 +91,76 @@
8892 }
8993
9094 /**
 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+ /**
91159 * Protected constructor: use Action::factory( $action, $page ) to actually build
92160 * these things in the real world
93161 * @param Article $page
94162 */
95163 protected function __construct( Article $page ) {
96164 $this->page = $page;
97 - $this->setContext( $page->getContext() );
98165 }
99166
100167 /**
@@ -282,7 +349,7 @@
283350 public function execute( array $data = null, $captureErrors = true ) {
284351 try {
285352 // Set a new context so output doesn't leak.
286 - $this->setContext( clone $this->page->getContext() );
 353+ $this->context = clone $this->page->getContext();
287354
288355 // This will throw exceptions if there's a problem
289356 $this->checkCanExecute( $this->getUser() );
@@ -364,11 +431,10 @@
365432 public function execute( array $data = null, $captureErrors = true ) {
366433 try {
367434 // Set a new context so output doesn't leak.
368 - $context = clone $this->page->getContext();
 435+ $this->context = clone $this->page->getContext();
369436 if ( is_array( $data ) ) {
370 - $context->setRequest( new FauxRequest( $data, false ) );
 437+ $this->context->setRequest( new FauxRequest( $data, false ) );
371438 }
372 - $this->setContext( $context );
373439
374440 // This will throw exceptions if there's a problem
375441 $this->checkCanExecute( $this->getUser() );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86872Implement an interface and abstract class to hold the widely-reused get(Reque...happy-melon17:37, 25 April 2011

Status & tagging log