jenkins-bot has submitted this change and it was merged.

Change subject: Fix initialization of Context in Action class.
......................................................................


Fix initialization of Context in Action class.

When Action::getActionName calls Action::factory, $context
must be passed explicitly, since WikiPage does not have a getContext()
method (only Article does).

As a failsafe in Article::getContext(), use $this->page->getContext()
only if $this->page is an Article. If $this->context is null and $this->page
is not an article, fall back to RequestContext::getMain()

Change-Id: I6d8db29dfd1aaa68f3de4f8f418841205c2379af
---
M includes/Action.php
1 file changed, 16 insertions(+), 4 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Action.php b/includes/Action.php
index 23b648f..4b6e446 100644
--- a/includes/Action.php
+++ b/includes/Action.php
@@ -142,7 +142,7 @@
                        return 'view';
                }
 
-               $action = Action::factory( $actionName, $context->getWikiPage() 
);
+               $action = Action::factory( $actionName, 
$context->getWikiPage(), $context );
                if ( $action instanceof Action ) {
                        return $action->getName();
                }
@@ -167,8 +167,14 @@
        final public function getContext() {
                if ( $this->context instanceof IContextSource ) {
                        return $this->context;
+               } else if ( $this->page instanceof Article ) {
+                       // NOTE: $this->page can be a WikiPage, which does not 
have a context.
+                       wfDebug( __METHOD__ . ': no context known, falling back 
to Article\'s context.' );
+                       return $this->page->getContext();
                }
-               return $this->page->getContext();
+
+               wfWarn( __METHOD__ . ': no context known, falling back to 
RequestContext::getMain().' );
+               return RequestContext::getMain();
        }
 
        /**
@@ -255,6 +261,12 @@
         * @param $context IContextSource
         */
        public function __construct( Page $page, IContextSource $context = null 
) {
+               if ( $context === null ) {
+                       wfWarn( __METHOD__ . ' called without providing a 
Context object.' );
+                       // NOTE: We could try to initialize $context using 
$page->getContext(),
+                       //      if $page is an Article. That however seems to 
not work seamlessly.
+               }
+
                $this->page = $page;
                $this->context = $context;
        }
@@ -477,7 +489,7 @@
        public function execute( array $data = null, $captureErrors = true ) {
                try {
                        // Set a new context so output doesn't leak.
-                       $this->context = clone $this->page->getContext();
+                       $this->context = clone $this->getContext();
 
                        // This will throw exceptions if there's a problem
                        $this->checkCanExecute( $this->getUser() );
@@ -566,7 +578,7 @@
        public function execute( array $data = null, $captureErrors = true ) {
                try {
                        // Set a new context so output doesn't leak.
-                       $this->context = clone $this->page->getContext();
+                       $this->context = clone $this->getContext();
                        if ( is_array( $data ) ) {
                                $this->context->setRequest( new FauxRequest( 
$data, false ) );
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/84965
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6d8db29dfd1aaa68f3de4f8f418841205c2379af
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: Daniel Friesen <dan...@nadir-seen-fire.com>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Platonides <platoni...@gmail.com>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to