Bartosz Dziewoński has uploaded a new change for review.

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

Change subject: Initial extension code
......................................................................

Initial extension code

Change-Id: Idace81fc12d10cf4581f0e6fe90ba08f31c79eef
---
A SandboxLink.php
A SandboxLinkHooks.php
A i18n/en.json
3 files changed, 125 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SandboxLink 
refs/changes/96/157296/1

diff --git a/SandboxLink.php b/SandboxLink.php
new file mode 100644
index 0000000..da28985
--- /dev/null
+++ b/SandboxLink.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ *
+ *
+ * https://www.mediawiki.org/wiki/Extension:SandboxLink
+ *
+ * @file
+ * @license MIT
+ */
+
+$wgExtensionCredits['other'][] = array(
+       'path' => __FILE__,
+       'name' => 'SandboxLink',
+       'author' => array(
+               'Bartosz Dziewoński',
+       ),
+       'url' => 'https://www.mediawiki.org/wiki/Extension:SandboxLink',
+       'descriptionmsg' => 'sandboxlink-desc',
+);
+
+$wgMessagesDirs['SandboxLink'] = __DIR__ . '/i18n';
+$wgAutoloadClasses['SandboxLinkHooks'] = __DIR__ . '/SandboxLinkHooks.php';
+
+$wgHooks['SkinPreloadExistence'][] = 
'SandboxLinkHooks::onSkinPreloadExistence';
+$wgHooks['PersonalUrls'][] = 'SandboxLinkHooks::onPersonalUrls';
+
+// Configuration settings
+$wgSandboxLinkDisableAnon = true;
diff --git a/SandboxLinkHooks.php b/SandboxLinkHooks.php
new file mode 100644
index 0000000..7938835
--- /dev/null
+++ b/SandboxLinkHooks.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ *
+ *
+ * https://www.mediawiki.org/wiki/Extension:SandboxLink
+ *
+ * @file
+ * @license MIT
+ */
+
+class SandboxLinkHooks {
+       private static function getSandboxTitle( User $user ) {
+               $subpageMsg = wfMessage( 'sandboxlink-subpage-name' );
+               if ( $subpageMsg->isDisabled() ) {
+                       return null;
+               }
+               return Title::makeTitleSafe( NS_USER, $user->getName() . '/' . 
$subpageMsg->plain() );
+       }
+
+       private static function makeSandboxLink( User $user, Title 
$currentTitle ) {
+               $title = self::getSandboxTitle( $user );
+               if ( !$title ) {
+                       return null;
+               }
+
+               if ( $title->exists() ) {
+                       $href = $title->getLocalURL();
+               } else {
+                       $query = array( 'action' => 'edit', 'redlink' => '1' );
+
+                       $editintroMsg = wfMessage( 
'sandboxlink-editintro-pagename' );
+                       if ( !$editintroMsg->isDisabled() ) {
+                               $query['editintro'] = $editintroMsg->plain();
+                       }
+
+                       $preloadMsg = wfMessage( 'sandboxlink-preload-pagename' 
);
+                       if ( !$preloadMsg->isDisabled() ) {
+                               $query['preload'] = $preloadMsg->plain();
+                       }
+
+                       $href = $title->getLocalURL( $query );
+               }
+
+               return array(
+                       'id' => 'pt-mysandbox',
+                       'text' => wfMessage( 'sandboxlink-portlet-label' 
)->text(),
+                       'href' => $href,
+                       'class' => $title->exists() ? false : 'new',
+                       'active' => $title->equals( $currentTitle ),
+               );
+       }
+
+       public static function onSkinPreloadExistence( &$titles, $skin ) {
+               $title = self::getSandboxTitle( $skin->getUser() );
+               if ( $title ) {
+                       $titles[] = $title;
+               }
+               return true;
+       }
+
+       public static function onPersonalUrls( &$personalUrls, &$title, $skin ) 
{
+               if ( $skin->getConfig()->get( 'SandboxLinkDisableAnon' ) && 
$skin->getUser()->isAnon() ) {
+                       return true;
+               }
+
+               $link = self::makeSandboxLink( $skin->getUser(), 
$skin->getTitle() );
+               if ( !$link ) {
+                       return true;
+               }
+
+               $newPersonalUrls = array();
+               $done = false;
+
+               // Insert our link before the link to user preferences.
+               // If the link to preferences is missing, insert at the end.
+               foreach ( $personalUrls as $key => $value ) {
+                       if ( $key === 'preferences' ) {
+                               $newPersonalUrls['sandbox'] = $link;
+                               $done = true;
+                       }
+                       $newPersonalUrls[$key] = $value;
+               }
+               if ( !$done ) {
+                       $newPersonalUrls['sandbox'] = $link;
+               }
+
+               $personalUrls = $newPersonalUrls;
+               return true;
+       }
+}
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..f9f4262
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,7 @@
+{
+       "sandboxlink-subpage-name": "sandbox",
+       "sandboxlink-portlet-label": "Sandbox",
+       "tooltip-pt-sandbox": "Your sandbox",
+       "sandboxlink-editintro-pagename": "-",
+       "sandboxlink-preload-pagename": "-"
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idace81fc12d10cf4581f0e6fe90ba08f31c79eef
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SandboxLink
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

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

Reply via email to