Pwirth has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/190451

Change subject: BsCAIContext: CommonAjaxInterface preparation for later use
......................................................................

BsCAIContext: CommonAjaxInterface preparation for later use

* Added Hock
* Added static instance
* Did some small improvements

Change-Id: I3ffe56be1abb59020adc4ddf6f2716b0f5413ae5
---
M includes/CAContext.php
1 file changed, 46 insertions(+), 19 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/51/190451/1

diff --git a/includes/CAContext.php b/includes/CAContext.php
index 8bd3dc7..c8c5ff3 100644
--- a/includes/CAContext.php
+++ b/includes/CAContext.php
@@ -4,6 +4,12 @@
 
        /**
         *
+        * @var BsCAContext
+        */
+       protected static $oInstance = null;
+
+       /**
+        *
         * @var Title
         */
        protected $oTitle = null;
@@ -28,34 +34,47 @@
 
        /**
         *
+        * @var Array
+        */
+       protected $aRequestParams = array();
+
+       /**
+        *
         * @return BsCAContext
         */
        public static function newFromRequest(){
+               if( self::$oInstance instanceof BsCAIContext ) {
+                       return self::$oInstance;
+               }
+
                $oRequest = RequestContext::getMain()->getRequest();
+               $aParams = array();
 
                //TODO: Lazy init?
-               $aRequestParams = array(
-                       'wgAction'                   => 
$oRequest->getVal('wgAction'),
-                       'wgArticleId'                => 
$oRequest->getVal('wgArticleId'),
-                       'wgCanonicalNamespace'       => 
$oRequest->getVal('wgCanonicalNamespace'),
-                       'wgCanonicalSpecialPageName' => 
$oRequest->getVal('wgCanonicalSpecialPageName'),
-                       'wgCurRevisionId'    => 
$oRequest->getVal('wgCurRevisionId'),
-                       //'wgIsArticle' => $oRequest->getVal('wgisArticle'),
-                       'wgNamespaceNumber'  => 
$oRequest->getVal('wgNamespaceNumber'),
-                       'wgPageName'         => $oRequest->getVal('wgPageName'),
-                       'wgRedirectedFrom'   => 
$oRequest->getVal('wgRedirectedFrom'),
-                       'wgRelevantPageName' => 
$oRequest->getVal('wgRelevantPageName'),
-                       'wgTitle'            => $oRequest->getVal('wgTitle')
+               $this->aRequestParams = array(
+                       'wgTitle'                    => $oRequest->getVal( 
'wgTitle', '' ),
+                       'wgAction'                   => $oRequest->getVal( 
'wgAction', 'view' ),
+                       'wgPageName'                 => $oRequest->getVal( 
'wgPageName', ''),
+                       'wgArticleId'                => $oRequest->getInt( 
'wgArticleId', 0 ),
+                       'wgCurRevisionId'            => $oRequest->getInt( 
'wgCurRevisionId', 0 ),
+                       'wgRedirectedFrom'           => $oRequest->getVal( 
'wgRedirectedFrom', '' ),
+                       'wgNamespaceNumber'          => $oRequest->getInt( 
'wgNamespaceNumber', 0 ),
+                       'wgRelevantPageName'         => $oRequest->getVal( 
'wgRelevantPageName', '' ),
+                       'wgCanonicalNamespace'       => $oRequest->getVal( 
'wgCanonicalNamespace', '' ),
+                       'wgCanonicalSpecialPageName' => $oRequest->getVal( 
'wgCanonicalSpecialPageName', false ),
                );
 
-               $aParams = array(
-                       'title'        => 
Title::newFromID($aRequestParams['wgArticleId']),
-                       'revision'     => 
Revision::newFromId($aRequestParams['wgCurRevisionId']),
-                       'specialpage'  => 
SpecialPageFactory::getPage($aRequestParams['wgCanonicalSpecialPageName']),
-                       'relevantpage' => 
Title::newFromText($aRequestParams['wgRelevantPageName']),
-               );
+               wfRunHooks( 'BsCAIContextNewFromRequest' , array( $oRequest, 
&$this->aRequestParams, &$aParams) );
 
-               return new self( $aParams );
+               $aParams = array_merge( array(
+                       'title'        => Title::newFromID( 
$this->aRequestParams['wgArticleId'] ),
+                       'revision'     => Revision::newFromId( 
$this->aRequestParams['wgCurRevisionId'] ),
+                       'specialpage'  => SpecialPageFactory::getPage( 
$this->aRequestParams['wgCanonicalSpecialPageName'] ),
+                       'relevantpage' => Title::newFromText( 
$this->aRequestParams['wgRelevantPageName'] ),
+               ), $aParams );
+
+               static::$oInstance = new self( $aParams );
+               return static::$oInstance;
        }
 
        private function __construct( $aParams ) {
@@ -96,6 +115,14 @@
        public function getSpecialPage(){
                return $this->oSpecialPage;
        }
+
+       /**
+        * 
+        * @return Array
+        */
+       public function getRequestParams() {
+               return $this->aRequestParams;
+       }
 }
 
 class BsCAContext extends BsCAIContext {}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ffe56be1abb59020adc4ddf6f2716b0f5413ae5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Pwirth <wi...@hallowelt.biz>

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

Reply via email to