Yurik has uploaded a new change for review.

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

Change subject: Allow portal= parameter for Special:ZeroPortal
......................................................................

Allow portal= parameter for Special:ZeroPortal

* Allows admin users to specify alternative startup module

Change-Id: If8d45e3a2a8e3ef97cbf78ccb19022dd0605ffc8
---
M includes/LuaLibrary.php
M includes/PortalSpecialPage.php
2 files changed, 34 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroPortal 
refs/changes/95/178795/1

diff --git a/includes/LuaLibrary.php b/includes/LuaLibrary.php
index c666888..0731607 100644
--- a/includes/LuaLibrary.php
+++ b/includes/LuaLibrary.php
@@ -265,7 +265,7 @@
         * @throws Scribunto_LuaError
         */
        private function isSiteAdminInt() {
-               return self::getContext()->getUser()->isAllowed( 'zero-edit' );
+               return PortalSpecialPage::isUserZeroAdmin( 
self::getContext()->getUser() );
        }
 
        /**
diff --git a/includes/PortalSpecialPage.php b/includes/PortalSpecialPage.php
index 5b37b73..39bb957 100644
--- a/includes/PortalSpecialPage.php
+++ b/includes/PortalSpecialPage.php
@@ -2,8 +2,11 @@
 
 namespace ZeroPortal;
 
+use Exception;
 use FormatJson;
+use TitleValue;
 use UnlistedSpecialPage;
+use User;
 use ZeroBanner\ZeroConfig;
 
 /**
@@ -22,6 +25,15 @@
        }
 
        /**
+        * Returns true if the given user has been given the right to 
administer zero portal
+        * @param User $user
+        * @return bool
+        */
+       public static function isUserZeroAdmin( $user ) {
+               return $user->isAllowed( 'zero-edit' );
+       }
+
+       /**
         * Show the special page
         *
         * @param null|string $par parameter passed to the special page or null
@@ -32,11 +44,13 @@
 //             $out->addModules( 'zeroportal.special.scripts' );
 //             $out->addModuleStyles( 'zeroportal.special.styles' );
 
-               // todo: delete all parameter handling once we start using Lua 
extension functions
                $user = $this->getUser();
+               $isUserZeroAdmin = self::isUserZeroAdmin( $user );
+
+               // todo: delete all parameter handling once we start using Lua 
extension functions
                if ( !$user->isAnon() ) {
                        // Include all zero-config ids if this is an admin
-                       $name = !$user->isAllowed( 'zero-edit' ) ? 
$user->getName() : true;
+                       $name = !$isUserZeroAdmin ? $user->getName() : true;
                        $configs = array();
                        ApiZeroPortal::iterateAllConfigs( false, function ( 
ZeroConfig $content, $title ) use ( $name, &$configs ) {
                                if ( $name === true || in_array( $name, 
$content->admins() ) ) {
@@ -55,9 +69,25 @@
                $user = self::encodeParameter( $user->isAnon() ? false : 
$user->getName() );
 
 
+               $module = 'Portal';
+               if ( $isUserZeroAdmin ) {
+                       // Zero administrators can use 'portal' parameter to 
change title of the startup module
+                       $portal = $this->getRequest()->getVal( 'portal' );
+                       if ( $portal ) {
+                               try {
+                                       $t = new TitleValue( NS_MODULE, $portal 
);
+                               } catch ( Exception $e ) {
+                                       $out->addHTML( '<h1>Error: ' . 
htmlspecialchars( $e->getMessage() ) . '</h1>' );
+                                       return;
+                               }
+                               $out->setHTMLTitle( 'Module:' . $t->getText() );
+                               $module = $t->getDBkey();
+                       }
+               }
+
                LuaLibrary::setContext( $this->getContext() );
                // todo: delete all extra parameters once we start using Lua 
extension functions
-               $out->addWikiText( 
"{{#invoke:Portal|main|$configs|$state|$user}}" );
+               $out->addWikiText( 
"{{#invoke:$module|main|$configs|$state|$user}}" );
                $done = LuaLibrary::endInvoke();
 
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8d45e3a2a8e3ef97cbf78ccb19022dd0605ffc8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroPortal
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to