r92526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92525‎ | r92526 | r92527 >
Date:11:42, 19 July 2011
Author:ashley
Status:ok
Tags:
Comment:
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/SpecialRemoveMasterSystemGift.php (added) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGift.css (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php
@@ -0,0 +1,147 @@
 2+<?php
 3+/**
 4+ * A special page for removing system gifts permanently.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+class RemoveMasterSystemGift extends UnlistedSpecialPage {
 10+
 11+ /**
 12+ * Constructor
 13+ */
 14+ public function __construct() {
 15+ parent::__construct( 'RemoveMasterSystemGift' );
 16+ }
 17+
 18+ /**
 19+ * Deletes a gift image from $wgUploadDirectory/awards/
 20+ *
 21+ * @param $id Integer: internal ID number of the gift whose image we want to delete
 22+ * @param $size String: size of the image to delete (s for small, m for
 23+ * medium, ml for medium-large and l for large)
 24+ */
 25+ function deleteImage( $id, $size ) {
 26+ global $wgUploadDirectory;
 27+ $files = glob( $wgUploadDirectory . '/awards/' . $id . "_{$size}*" );
 28+ if ( $files && $files[0] ) {
 29+ $img = basename( $files[0] );
 30+ unlink( $wgUploadDirectory . '/awards/' . $img );
 31+ }
 32+ }
 33+
 34+ /**
 35+ * Show the special page
 36+ *
 37+ * @param $par Mixed: parameter passed to the page or null
 38+ */
 39+ public function execute( $par ) {
 40+ global $wgUser, $wgOut, $wgRequest, $wgSystemGiftsScripts;
 41+
 42+ // If the user doesn't have the required 'awardsmanage' permission, display an error
 43+ if ( !$wgUser->isAllowed( 'awardsmanage' ) ) {
 44+ $wgOut->permissionRequired( 'awardsmanage' );
 45+ return;
 46+ }
 47+
 48+ // Show a message if the database is in read-only mode
 49+ if ( wfReadOnly() ) {
 50+ $wgOut->readOnlyPage();
 51+ return;
 52+ }
 53+
 54+ // If user is blocked, s/he doesn't need to access this page
 55+ if ( $wgUser->isBlocked() ) {
 56+ $wgOut->blockedPage();
 57+ return;
 58+ }
 59+
 60+ // Add CSS
 61+ $wgOut->addExtensionStyle( $wgSystemGiftsScripts . '/SystemGift.css' );
 62+
 63+ $this->gift_id = $wgRequest->getInt( 'gift_id', $par );
 64+
 65+ if ( !$this->gift_id || !is_numeric( $this->gift_id ) ) {
 66+ $wgOut->setPageTitle( wfMsg( 'ga-error-title' ) );
 67+ $wgOut->addHTML( wfMsg( 'ga-error-message-invalid-link' ) );
 68+ return false;
 69+ }
 70+
 71+ if ( $wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false ) {
 72+ $_SESSION['alreadysubmitted'] = true;
 73+
 74+ $dbw = wfGetDB( DB_MASTER );
 75+ $gift = SystemGifts::getGift( $this->gift_id );
 76+
 77+ $dbw->delete(
 78+ 'system_gift',
 79+ array( 'gift_id' => $this->gift_id ),
 80+ __METHOD__
 81+ );
 82+ $dbw->delete(
 83+ 'user_system_gift',
 84+ array( 'sg_gift_id' => $this->gift_id ),
 85+ __METHOD__
 86+ );
 87+
 88+ $this->deleteImage( $this->gift_id, 's' );
 89+ $this->deleteImage( $this->gift_id, 'm' );
 90+ $this->deleteImage( $this->gift_id, 'l' );
 91+ $this->deleteImage( $this->gift_id, 'ml' );
 92+
 93+ $wgOut->setPageTitle( wfMsg( 'ga-remove-success-title', $gift['gift_name'] ) );
 94+
 95+ $out = '<div class="back-links">
 96+ <a href="' . SpecialPage::getTitleFor( 'SystemGiftManager' )->escapeFullURL() . '">' .
 97+ wfMsg( 'ga-viewlist' ) . '</a>
 98+ </div>
 99+ <div class="ga-container">' .
 100+ wfMsg( 'ga-remove-success-message', $gift['gift_name'] ) .
 101+ '<div class="cleared"></div>
 102+ </div>';
 103+
 104+ $wgOut->addHTML( $out );
 105+ } else {
 106+ $_SESSION['alreadysubmitted'] = false;
 107+ $wgOut->addHTML( $this->displayForm() );
 108+ }
 109+ }
 110+
 111+ /**
 112+ * Displays the main form for removing a system gift permanently.
 113+ *
 114+ * @return String: HTML output
 115+ */
 116+ function displayForm() {
 117+ global $wgOut, $wgUploadPath;
 118+
 119+ $gift = SystemGifts::getGift( $this->gift_id );
 120+
 121+ $giftImage = '<img src="' . $wgUploadPath . '/awards/' .
 122+ SystemGifts::getGiftImage( $this->gift_id, 'l' ) .
 123+ '" border="0" alt="gift" />';
 124+
 125+ $wgOut->setPageTitle( wfMsg( 'ga-remove-title', $gift['gift_name'] ) );
 126+
 127+ $output = '<div class="back-links">
 128+ <a href="' . SpecialPage::getTitleFor( 'SystemGiftManager' )->escapeFullURL() . '">' .
 129+ wfMsg( 'ga-viewlist' ) . '</a>
 130+ </div>
 131+ <form action="" method="post" enctype="multipart/form-data" name="form1">
 132+ <div class="ga-remove-message">' .
 133+ wfMsg( 'ga-delete-message', $gift['gift_name'] ) .
 134+ '</div>
 135+ <div class="ga-container">' .
 136+ $giftImage .
 137+ '<div class="ga-name">' . $gift['gift_name'] . '</div>
 138+ </div>
 139+ <div class="cleared"></div>
 140+ <div class="ga-buttons">
 141+ <input type="button" class="site-button" value="' . wfMsg( 'ga-remove' ) . '" size="20" onclick="document.form1.submit()" />
 142+ <input type="button" class="site-button" value="' . wfMsg( 'ga-cancel' ) . '" size="20" onclick="history.go(-1)" />
 143+ </div>
 144+ </form>';
 145+
 146+ return $output;
 147+ }
 148+}
Property changes on: trunk/extensions/SocialProfile/SystemGifts/SpecialRemoveMasterSystemGift.php
___________________________________________________________________
Added: svn:eol-style
1149 + native
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php
@@ -93,17 +93,33 @@
9494 }
9595 }
9696
 97+ /**
 98+ * Display the text list of all existing system gifts and a delete link to
 99+ * users who are allowed to delete gifts.
 100+ *
 101+ * @return String: HTML
 102+ */
97103 function displayGiftList() {
 104+ global $wgUser;
98105 $output = ''; // Prevent E_NOTICE
99106 $page = 0;
100107 $per_page = 50;
101108 $gifts = SystemGifts::getGiftList( $per_page, $page );
102109 if ( $gifts ) {
103110 foreach ( $gifts as $gift ) {
 111+ $deleteLink = '';
 112+ if ( $wgUser->isAllowed( 'awardsmanage' ) ) {
 113+ $removePage = SpecialPage::getTitleFor( 'RemoveMasterSystemGift' );
 114+ $deleteLink = '<a href="' .
 115+ $removePage->escapeFullURL( "gift_id={$gift['id']}" ) .
 116+ '" style="font-size:10px; color:red;">' .
 117+ wfMsg( 'delete' ) . '</a>';
 118+ }
 119+
104120 $output .= '<div class="Item">
105121 <a href="' . $this->getTitle()->escapeFullURL( 'id=' . $gift['id'] ) . '">' .
106 - $gift['gift_name'] . '</a>
107 - </div>' . "\n";
 122+ $gift['gift_name'] . '</a> ' .
 123+ $deleteLink . '</div>' . "\n";
108124 }
109125 }
110126 return '<div id="views">' . $output . '</div>';
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
@@ -50,6 +50,13 @@
5151 'ga-title' => '$1\'s awards',
5252 'ga-uploadsuccess' => 'Upload successful',
5353 'ga-viewlist' => 'View gift list',
 54+ 'ga-cancel' => 'Cancel',
 55+ 'ga-remove' => 'Remove',
 56+ 'ga-remove-title' => 'Remove "$1"?',
 57+ 'ga-delete-message' => 'Are you sure you want to delete the gift "$1"?
 58+This will also delete it from users who may have received it.',
 59+ 'ga-remove-success-title' => 'You have successfully removed the gift "$1"',
 60+ 'ga-remove-success-message' => 'The gift "$1" has been removed.',
5461 'system_gift_received_subject' => 'You have received the $1 award on {{SITENAME}}!',
5562 'system_gift_received_body' => 'Hi $1.
5663
@@ -1019,6 +1026,13 @@
10201027 'ga-title' => 'Käyttäjän $1 palkinnot',
10211028 'ga-uploadsuccess' => 'Tallentaminen onnistui',
10221029 'ga-viewlist' => 'Katso lahjalista',
 1030+ 'ga-cancel' => 'Peruuta',
 1031+ 'ga-remove' => 'Poista',
 1032+ 'ga-remove-title' => 'Poista "$1"?',
 1033+ 'ga-delete-message' => 'Oletko varma, että haluat poistaa lahjan "$1"?
 1034+Tämä poistaa sen myös käyttäjiltä, jotka ovat saattaneet saada sen.',
 1035+ 'ga-remove-success-title' => 'Olet onnistuneesti poistanut lahjan "$1"',
 1036+ 'ga-remove-success-message' => 'Lahja "$1" on poistettu.',
10231037 'system_gift_received_subject' => 'Olet saanut palkinnon $1 {{GRAMMAR:inessive|{{SITENAME}}}}!',
10241038 'system_gift_received_body' => 'Hei $1:
10251039
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGift.css
@@ -192,4 +192,22 @@
193193 font-size: 16px;
194194 font-weight: bold;
195195 text-decoration: none;
 196+}
 197+
 198+/* Special:RemoveMasterSystemGift */
 199+.ga-container {
 200+ margin: 15px 0px 0px 0px;
 201+}
 202+
 203+.ga-container img {
 204+ border: 1px solid #dcdcdc;
 205+ background-color: #fff;
 206+ padding: 3px;
 207+ display: block;
 208+ float: left;
 209+ margin: 0px 10px 0px 0px;
 210+}
 211+
 212+.ga-buttons {
 213+ padding: 15px 0px 0px 0px;
196214 }
\ No newline at end of file
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGifts.php
@@ -29,6 +29,9 @@
3030 $wgAutoloadClasses['SystemGiftManagerLogo'] = "{$wgSystemGiftsDirectory}/SpecialSystemGiftManagerLogo.php";
3131 $wgSpecialPages['SystemGiftManagerLogo'] = 'SystemGiftManagerLogo';
3232
 33+$wgAutoloadClasses['RemoveMasterSystemGift'] = "{$wgSystemGiftsDirectory}/SpecialRemoveMasterSystemGift.php";
 34+$wgSpecialPages['RemoveMasterSystemGift'] = 'RemoveMasterSystemGift';
 35+
3336 $wgAutoloadClasses['PopulateAwards'] = "{$wgSystemGiftsDirectory}/SpecialPopulateAwards.php";
3437 $wgSpecialPages['PopulateAwards'] = 'PopulateAwards';
3538

Follow-up revisions

RevisionCommit summaryAuthorDate
r93195SocialProfile: follow-up to r92526: award (system gift) images are prefixed w...ashley15:38, 26 July 2011

Status & tagging log