http://www.mediawiki.org/wiki/Special:Code/MediaWiki/92526

Revision: 92526
Author:   ashley
Date:     2011-07-19 11:42:14 +0000 (Tue, 19 Jul 2011)
Log Message:
-----------
SocialProfile: new special page, Special:RemoveMasterSystemGift, to allow 
awards to be permanently deleted (by users who have the 'awardsmanage' 
permission). It's mostly copied from UserGifts/SpecialRemoveMasterGift.php, 
with s/g-/ga-/

Modified Paths:
--------------
    trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
    trunk/extensions/SocialProfile/SystemGifts/SystemGift.css
    trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
    trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php

Added Paths:
-----------
    trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php

Added: 
trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php
===================================================================
--- 
trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php    
                            (rev 0)
+++ 
trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php    
    2011-07-19 11:42:14 UTC (rev 92526)
@@ -0,0 +1,147 @@
+<?php
+/**
+ * A special page for removing system gifts permanently.
+ *
+ * @file
+ * @ingroup Extensions
+ */
+class RemoveMasterSystemGift extends UnlistedSpecialPage {
+
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               parent::__construct( 'RemoveMasterSystemGift' );
+       }
+
+       /**
+        * Deletes a gift image from $wgUploadDirectory/awards/
+        *
+        * @param $id Integer: internal ID number of the gift whose image we 
want to delete
+        * @param $size String: size of the image to delete (s for small, m for
+        *                      medium, ml for medium-large and l for large)
+        */
+       function deleteImage( $id, $size ) {
+               global $wgUploadDirectory;
+               $files = glob( $wgUploadDirectory . '/awards/' . $id . 
"_{$size}*" );
+               if ( $files && $files[0] ) {
+                       $img = basename( $files[0] );
+                       unlink( $wgUploadDirectory . '/awards/' .  $img );
+               }
+       }
+
+       /**
+        * Show the special page
+        *
+        * @param $par Mixed: parameter passed to the page or null
+        */
+       public function execute( $par ) {
+               global $wgUser, $wgOut, $wgRequest, $wgSystemGiftsScripts;
+
+               // If the user doesn't have the required 'awardsmanage' 
permission, display an error
+               if ( !$wgUser->isAllowed( 'awardsmanage' ) ) {
+                       $wgOut->permissionRequired( 'awardsmanage' );
+                       return;
+               }
+
+               // Show a message if the database is in read-only mode
+               if ( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+
+               // If user is blocked, s/he doesn't need to access this page
+               if ( $wgUser->isBlocked() ) {
+                       $wgOut->blockedPage();
+                       return;
+               }
+
+               // Add CSS
+               $wgOut->addExtensionStyle( $wgSystemGiftsScripts . 
'/SystemGift.css' );
+
+               $this->gift_id = $wgRequest->getInt( 'gift_id', $par );
+
+               if ( !$this->gift_id || !is_numeric( $this->gift_id ) ) {
+                       $wgOut->setPageTitle( wfMsg( 'ga-error-title' ) );
+                       $wgOut->addHTML( wfMsg( 'ga-error-message-invalid-link' 
) );
+                       return false;
+               }
+
+               if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] 
== false ) {
+                       $_SESSION['alreadysubmitted'] = true;
+
+                       $dbw = wfGetDB( DB_MASTER );
+                       $gift = SystemGifts::getGift( $this->gift_id );
+
+                       $dbw->delete(
+                               'system_gift',
+                               array( 'gift_id' => $this->gift_id ),
+                               __METHOD__
+                       );
+                       $dbw->delete(
+                               'user_system_gift',
+                               array( 'sg_gift_id' => $this->gift_id ),
+                               __METHOD__
+                       );
+
+                       $this->deleteImage( $this->gift_id, 's' );
+                       $this->deleteImage( $this->gift_id, 'm' );
+                       $this->deleteImage( $this->gift_id, 'l' );
+                       $this->deleteImage( $this->gift_id, 'ml' );
+
+                       $wgOut->setPageTitle( wfMsg( 'ga-remove-success-title', 
$gift['gift_name'] ) );
+
+                       $out = '<div class="back-links">
+                               <a href="' . SpecialPage::getTitleFor( 
'SystemGiftManager' )->escapeFullURL() . '">' .
+                                       wfMsg( 'ga-viewlist' ) . '</a>
+                       </div>
+                       <div class="ga-container">' .
+                               wfMsg( 'ga-remove-success-message', 
$gift['gift_name'] ) .
+                               '<div class="cleared"></div>
+                       </div>';
+
+                       $wgOut->addHTML( $out );
+               } else {
+                       $_SESSION['alreadysubmitted'] = false;
+                       $wgOut->addHTML( $this->displayForm() );
+               }
+       }
+
+       /**
+        * Displays the main form for removing a system gift permanently.
+        *
+        * @return String: HTML output
+        */
+       function displayForm() {
+               global $wgOut, $wgUploadPath;
+
+               $gift = SystemGifts::getGift( $this->gift_id );
+
+               $giftImage = '<img src="' . $wgUploadPath . '/awards/' .
+                       SystemGifts::getGiftImage( $this->gift_id, 'l' ) .
+                       '" border="0" alt="gift" />';
+
+               $wgOut->setPageTitle( wfMsg( 'ga-remove-title', 
$gift['gift_name'] ) );
+
+               $output = '<div class="back-links">
+                       <a href="' . SpecialPage::getTitleFor( 
'SystemGiftManager' )->escapeFullURL() . '">' .
+                               wfMsg( 'ga-viewlist' ) . '</a>
+               </div>
+               <form action="" method="post" enctype="multipart/form-data" 
name="form1">
+                       <div class="ga-remove-message">' .
+                               wfMsg( 'ga-delete-message', $gift['gift_name'] 
) .
+                       '</div>
+                       <div class="ga-container">' .
+                               $giftImage .
+                               '<div class="ga-name">' . $gift['gift_name'] . 
'</div>
+                       </div>
+                       <div class="cleared"></div>
+                       <div class="ga-buttons">
+                               <input type="button" class="site-button" 
value="' . wfMsg( 'ga-remove' ) . '" size="20" 
onclick="document.form1.submit()" />
+                               <input type="button" class="site-button" 
value="' . wfMsg( 'ga-cancel' ) . '" size="20" onclick="history.go(-1)" />
+                       </div>
+               </form>';
+
+               return $output;
+       }
+}


Property changes on: 
trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: 
trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php     
2011-07-19 11:37:09 UTC (rev 92525)
+++ trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php     
2011-07-19 11:42:14 UTC (rev 92526)
@@ -93,17 +93,33 @@
                }
        }
 
+       /**
+        * Display the text list of all existing system gifts and a delete link 
to
+        * users who are allowed to delete gifts.
+        *
+        * @return String: HTML
+        */
        function displayGiftList() {
+               global $wgUser;
                $output = ''; // Prevent E_NOTICE
                $page = 0;
                $per_page = 50;
                $gifts = SystemGifts::getGiftList( $per_page, $page );
                if ( $gifts ) {
                        foreach ( $gifts as $gift ) {
+                               $deleteLink = '';
+                               if ( $wgUser->isAllowed( 'awardsmanage' ) ) {
+                                       $removePage = SpecialPage::getTitleFor( 
'RemoveMasterSystemGift' );
+                                       $deleteLink = '<a href="' .
+                                               $removePage->escapeFullURL( 
"gift_id={$gift['id']}" ) .
+                                               '" style="font-size:10px; 
color:red;">' .
+                                               wfMsg( 'delete' ) . '</a>';
+                               }
+
                                $output .= '<div class="Item">
                                        <a href="' . 
$this->getTitle()->escapeFullURL( 'id=' . $gift['id'] ) . '">' .
-                                               $gift['gift_name'] . '</a>
-                               </div>' . "\n";
+                                               $gift['gift_name'] . '</a> ' .
+                                               $deleteLink . '</div>' . "\n";
                        }
                }
                return '<div id="views">' . $output . '</div>';

Modified: trunk/extensions/SocialProfile/SystemGifts/SystemGift.css
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGift.css   2011-07-19 
11:37:09 UTC (rev 92525)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGift.css   2011-07-19 
11:42:14 UTC (rev 92526)
@@ -192,4 +192,22 @@
        font-size: 16px;
        font-weight: bold;
        text-decoration: none;
+}
+
+/* Special:RemoveMasterSystemGift */
+.ga-container {
+       margin: 15px 0px 0px 0px;
+}
+
+.ga-container img {
+       border: 1px solid #dcdcdc;
+       background-color: #fff;
+       padding: 3px;
+       display: block;
+       float: left;
+       margin: 0px 10px 0px 0px;
+}
+
+.ga-buttons {
+       padding: 15px 0px 0px 0px;
 }
\ No newline at end of file

Modified: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php      
2011-07-19 11:37:09 UTC (rev 92525)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php      
2011-07-19 11:42:14 UTC (rev 92526)
@@ -50,6 +50,13 @@
        'ga-title' => '$1\'s awards',
        'ga-uploadsuccess' => 'Upload successful',
        'ga-viewlist' => 'View gift list',
+       'ga-cancel' => 'Cancel',
+       'ga-remove' => 'Remove',
+       'ga-remove-title' => 'Remove "$1"?',
+       'ga-delete-message' => 'Are you sure you want to delete the gift "$1"?
+This will also delete it from users who may have received it.',
+       'ga-remove-success-title' => 'You have successfully removed the gift 
"$1"',
+       'ga-remove-success-message' => 'The gift "$1" has been removed.',
        'system_gift_received_subject' => 'You have received the $1 award on 
{{SITENAME}}!',
        'system_gift_received_body' => 'Hi $1.
 
@@ -1019,6 +1026,13 @@
        'ga-title' => 'Käyttäjän $1 palkinnot',
        'ga-uploadsuccess' => 'Tallentaminen onnistui',
        'ga-viewlist' => 'Katso lahjalista',
+       'ga-cancel' => 'Peruuta',
+       'ga-remove' => 'Poista',
+       'ga-remove-title' => 'Poista "$1"?',
+       'ga-delete-message' => 'Oletko varma, että haluat poistaa lahjan "$1"?
+Tämä poistaa sen myös käyttäjiltä, jotka ovat saattaneet saada sen.',
+       'ga-remove-success-title' => 'Olet onnistuneesti poistanut lahjan "$1"',
+       'ga-remove-success-message' => 'Lahja "$1" on poistettu.',
        'system_gift_received_subject' => 'Olet saanut palkinnon $1 
{{GRAMMAR:inessive|{{SITENAME}}}}!',
        'system_gift_received_body' => 'Hei $1:
 

Modified: trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php  2011-07-19 
11:37:09 UTC (rev 92525)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php  2011-07-19 
11:42:14 UTC (rev 92526)
@@ -29,6 +29,9 @@
 $wgAutoloadClasses['SystemGiftManagerLogo'] = 
"{$wgSystemGiftsDirectory}/SpecialSystemGiftManagerLogo.php";
 $wgSpecialPages['SystemGiftManagerLogo'] = 'SystemGiftManagerLogo';
 
+$wgAutoloadClasses['RemoveMasterSystemGift'] = 
"{$wgSystemGiftsDirectory}/SpecialRemoveMasterSystemGift.php";
+$wgSpecialPages['RemoveMasterSystemGift'] = 'RemoveMasterSystemGift';
+
 $wgAutoloadClasses['PopulateAwards'] = 
"{$wgSystemGiftsDirectory}/SpecialPopulateAwards.php";
 $wgSpecialPages['PopulateAwards'] = 'PopulateAwards';
 


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

Reply via email to