Index: trunk/extensions/UserWelcome/UserWelcome.php |
— | — | @@ -0,0 +1,198 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * UserWelcome extension |
| 5 | + * Adds <welcomeUser/> tag to display user-specific social information |
| 6 | + * Intended to use with SocialProfile extension version 1.3 or later, will fail without it |
| 7 | + * or if you have an older version of SocialProfile than 1.3. |
| 8 | + * |
| 9 | + * @author Wikia, Inc. |
| 10 | + * @version 1.0 |
| 11 | + * @link http://www.mediawiki.org/wiki/Extension:UserWelcome Documentation |
| 12 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 13 | + */ |
| 14 | + |
| 15 | +// Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 |
| 16 | +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
| 17 | + $wgHooks['ParserFirstCallInit'][] = 'wfWelcomeUser'; |
| 18 | +} else { |
| 19 | + $wgExtensionFunctions[] = 'wfWelcomeUser'; |
| 20 | +} |
| 21 | + |
| 22 | +// Extension credits that show up on Special:Version |
| 23 | +$wgExtensionCredits['parserhook'][] = array( |
| 24 | + 'name' => 'UserWelcome', |
| 25 | + 'version' => '1.0', |
| 26 | + 'description' => 'Adds <tt><welcomeUser></tt> tag to display user-specific social info to logged-in users', |
| 27 | + 'author' => 'Wikia New York Team', |
| 28 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:UserWelcome' |
| 29 | +); |
| 30 | + |
| 31 | +function wfWelcomeUser() { |
| 32 | + global $wgParser; |
| 33 | + $wgParser->setHook( 'welcomeUser', 'getWelcomeUser' ); |
| 34 | + return true; |
| 35 | +} |
| 36 | + |
| 37 | +$dir = dirname(__FILE__) . '/'; |
| 38 | +$wgExtensionMessagesFiles['UserWelcome'] = $dir . 'UserWelcome.i18n.php'; |
| 39 | + |
| 40 | +function getWelcomeUser( $input, $args, $parser ){ |
| 41 | + |
| 42 | + $parser->disableCache(); |
| 43 | + $output = ""; |
| 44 | + $output .= getWelcome(); |
| 45 | + |
| 46 | + return $output; |
| 47 | +} |
| 48 | + |
| 49 | +function getWelcome(){ |
| 50 | + global $wgUser, $IP, $wgUploadPath; |
| 51 | + wfLoadExtensionMessages('UserWelcome'); |
| 52 | + |
| 53 | + // Get stats and user level |
| 54 | + $stats = new UserStats($wgUser->getID(), $wgUser->getName()); |
| 55 | + $stats_data = $stats->getUserStats(); |
| 56 | + $user_level = new UserLevel($stats_data["points"]); |
| 57 | + |
| 58 | + // Safe links |
| 59 | + $level_link = Title::makeTitle(NS_HELP, wfMsgHtml('mp-userlevels-link')); |
| 60 | + $avatar_link = Title::makeTitle(NS_SPECIAL, 'UploadAvatar'); |
| 61 | + $invite_link = Title::makeTitle(NS_SPECIAL, 'InviteContacts'); |
| 62 | + |
| 63 | + // Make an avatar |
| 64 | + $avatar = new wAvatar($wgUser->getID(), "l"); |
| 65 | + |
| 66 | + $output = ""; |
| 67 | + |
| 68 | + // Profile top images/points |
| 69 | + $output .= "<div class=\"mp-welcome-logged-in\"> |
| 70 | + <h2>".wfMsg('mp-welcome-logged-in', $wgUser->getName())."</h2> |
| 71 | + <div class=\"mp-welcome-image\"> |
| 72 | + <a href=\"". $wgUser->getUserPage()->escapeFullURL(). "\" rel=\"nofollow\"><img src=\"{$wgUploadPath}/avatars/" . $avatar->getAvatarImage() . "\" alt=\"\" border=\"0\"/></a>"; |
| 73 | + if( strpos($avatar->getAvatarImage(), 'default_') !== false ) { |
| 74 | + $output .= "<div><a href=\"".$avatar_link->escapeFullURL()."\" rel=\"nofollow\">".wfMsg('mp-welcome-upload')."</a></div>"; |
| 75 | + } else { |
| 76 | + $output .= "<div><a href=\"".$avatar_link->escapeFullURL()."\" rel=\"nofollow\">".wfMsg('mp-welcome-edit')."</a></div>"; |
| 77 | + } |
| 78 | + $output .= "</div>"; |
| 79 | + |
| 80 | + global $wgUserLevels; |
| 81 | + if( $wgUserLevels ){ |
| 82 | + $output .= "<div class=\"mp-welcome-points\"> |
| 83 | + <div class=\"points-and-level\"> |
| 84 | + <div class=\"total-points\">".wfMsg('mp-welcome-points', $stats_data["points"])."</div> |
| 85 | + <div class=\"honorific-level\"><a href=\"".$level_link->escapeFullURL()."\">({$user_level->getLevelName()})</a></div> |
| 86 | + </div> |
| 87 | + <div class=\"cleared\"></div> |
| 88 | + <div class=\"needed-points\"> |
| 89 | + ".wfMsg('mp-welcome-needed-points', $level_link->escapeFullURL(), $user_level->getNextLevelName(), $user_level->getPointsNeededToAdvance())." |
| 90 | + </div> |
| 91 | + </div>"; |
| 92 | + } |
| 93 | + |
| 94 | + $output .= "<div class=\"cleared\"></div>"; |
| 95 | + |
| 96 | + $output .= getRequests(); |
| 97 | + |
| 98 | + $output .= "</div>"; |
| 99 | + |
| 100 | + return $output; |
| 101 | + } |
| 102 | + |
| 103 | + function getRequests(){ |
| 104 | + wfLoadExtensionMessages('UserWelcome'); |
| 105 | + |
| 106 | + //get requests |
| 107 | + $requests = getNewMessagesLink() . getRelationshipRequestLink() . getNewGiftLink() . getNewSystemGiftLink(); |
| 108 | + |
| 109 | + $output = ''; |
| 110 | + if( $requests ){ |
| 111 | + |
| 112 | + $output .= "<div class=\"mp-requests\"> |
| 113 | + <h3>".wfMsg('mp-requests-title')."</h3> |
| 114 | + <div class=\"mp-requests-message\"> |
| 115 | + ".wfMsg('mp-requests-message')." |
| 116 | + </div> |
| 117 | + $requests |
| 118 | + </div>"; |
| 119 | + |
| 120 | + } |
| 121 | + |
| 122 | + return $output; |
| 123 | + } |
| 124 | + |
| 125 | + function getRelationshipRequestLink(){ |
| 126 | + global $wgUser, $IP, $wgUploadPath; |
| 127 | + wfLoadExtensionMessages('UserWelcome'); |
| 128 | + require_once("$IP/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php"); |
| 129 | + $friend_request_count = UserRelationship::getOpenRequestCount($wgUser->getID(), 1); |
| 130 | + $foe_request_count = UserRelationship::getOpenRequestCount($wgUser->getID(), 2); |
| 131 | + $relationship_request_link = Title::makeTitle(NS_SPECIAL, 'ViewRelationshipRequests'); |
| 132 | + |
| 133 | + $rel_title = Title::makeTitle(NS_SPECIAL, 'ViewRelationshipRequests'); |
| 134 | + $output = ""; |
| 135 | + |
| 136 | + if( $friend_request_count ){ |
| 137 | + $output .= "<p> |
| 138 | + <img src=\"{$wgUploadPath}/common/addedFriendIcon.png\" alt=\"\" border=\"0\"/> |
| 139 | + <a href=\"".$relationship_request_link->escapeFullURL()."\" rel=\"nofollow\">".wfMsgExt('mp-request-new-friend', 'parsemag', $friend_request_count)."</a> |
| 140 | + </p>"; |
| 141 | + } |
| 142 | + |
| 143 | + if( $foe_request_count ){ |
| 144 | + $output .= "<p> |
| 145 | + <img src=\"{$wgUploadPath}/common/addedFoeIcon.png\" alt=\"\" border=\"0\"/> |
| 146 | + <a href=\"".$relationship_request_link->escapeFullURL()."\" rel=\"nofollow\">".wfMsgExt('mp-request-new-foe', 'parsemag', $foe_request_count)."</a> |
| 147 | + </p>"; |
| 148 | + } |
| 149 | + return $output; |
| 150 | + } |
| 151 | + |
| 152 | + function getNewGiftLink(){ |
| 153 | + global $wgUser, $IP, $wgUploadPath; |
| 154 | + wfLoadExtensionMessages('UserWelcome'); |
| 155 | + require_once("$IP/extensions/SocialProfile/UserGifts/UserGiftsClass.php"); |
| 156 | + $gift_count = UserGifts::getNewGiftCount($wgUser->getID()); |
| 157 | + $gifts_title = Title::makeTitle(NS_SPECIAL, 'ViewGifts'); |
| 158 | + $output = ""; |
| 159 | + if( $gift_count ){ |
| 160 | + $output .= "<p> |
| 161 | + <img src=\"{$wgUploadPath}/common/icon_package_get.gif\" alt=\"\" border=\"0\"/> |
| 162 | + <a href=\"".$gifts_title->escapeFullURL()."\" rel=\"nofollow\">".wfMsgExt('mp-request-new-gift', 'parsemag', $gift_count)."</a> |
| 163 | + </p>"; |
| 164 | + } |
| 165 | + return $output; |
| 166 | + } |
| 167 | + |
| 168 | + function getNewSystemGiftLink(){ |
| 169 | + global $wgUser, $IP, $wgUploadPath; |
| 170 | + wfLoadExtensionMessages('UserWelcome'); |
| 171 | + require_once("$IP/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php"); |
| 172 | + $gift_count = UserSystemGifts::getNewSystemGiftCount($wgUser->getID()); |
| 173 | + $gifts_title = Title::makeTitle(NS_SPECIAL, 'ViewSystemGifts'); |
| 174 | + $output = ""; |
| 175 | + |
| 176 | + if( $gift_count ){ |
| 177 | + $output .= "<p> |
| 178 | + <img src=\"{$wgUploadPath}/common/awardIcon.png\" alt=\"\" border=\"0\"/> |
| 179 | + <a href=\"".$gifts_title->escapeFullURL()."\" rel=\"nofollow\">".wfMsgExt('mp-request-new-award', 'parsemag', $gift_count)."</a> |
| 180 | + </p>"; |
| 181 | + } |
| 182 | + |
| 183 | + return $output; |
| 184 | + } |
| 185 | + |
| 186 | + function getNewMessagesLink(){ |
| 187 | + global $wgUser, $wgUploadPath; |
| 188 | + wfLoadExtensionMessages('UserWelcome'); |
| 189 | + $new_messages = UserBoard::getNewMessageCount($wgUser->getID()); |
| 190 | + $output = ''; |
| 191 | + if( $new_messages ){ |
| 192 | + $board_link = Title::makeTitle(NS_SPECIAL, 'UserBoard'); |
| 193 | + $output .= "<p> |
| 194 | + <img src=\"{$wgUploadPath}/common/emailIcon.gif\" alt=\"email icon\" border=\"\"/> |
| 195 | + <a href=\"".$board_link->escapeFullURL()."\" rel=\"nofollow\">".wfMsg('mp-request-new-message')."</a> |
| 196 | + </p>"; |
| 197 | + } |
| 198 | + return $output; |
| 199 | + } |
\ No newline at end of file |
Property changes on: trunk/extensions/UserWelcome/UserWelcome.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 200 | + native |
Index: trunk/extensions/UserWelcome/common/editIcon.gif |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UserWelcome/common/editIcon.gif |
___________________________________________________________________ |
Name: svn:mime-type |
2 | 201 | + application/octet-stream |
Index: trunk/extensions/UserWelcome/common/emailIcon.gif |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UserWelcome/common/emailIcon.gif |
___________________________________________________________________ |
Name: svn:mime-type |
3 | 202 | + application/octet-stream |
Index: trunk/extensions/UserWelcome/common/addedFriendIcon.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: trunk/extensions/UserWelcome/common/addedFriendIcon.png |
___________________________________________________________________ |
Name: svn:mime-type |
4 | 203 | + image/png |
Index: trunk/extensions/UserWelcome/common/icon_package_get.gif |
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes on: trunk/extensions/UserWelcome/common/icon_package_get.gif |
___________________________________________________________________ |
Name: svn:mime-type |
5 | 204 | + application/octet-stream |
Index: trunk/extensions/UserWelcome/common/addedFoeIcon.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: trunk/extensions/UserWelcome/common/addedFoeIcon.png |
___________________________________________________________________ |
Name: svn:mime-type |
6 | 205 | + image/png |
Index: trunk/extensions/UserWelcome/common/awardIcon.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: trunk/extensions/UserWelcome/common/awardIcon.png |
___________________________________________________________________ |
Name: svn:mime-type |
7 | 206 | + image/png |
Index: trunk/extensions/UserWelcome/common/challengeIcon.png |
Cannot display: file marked as a binary type. |
svn:mime-type = image/png |
Property changes on: trunk/extensions/UserWelcome/common/challengeIcon.png |
___________________________________________________________________ |
Name: svn:mime-type |
8 | 207 | + image/png |
Index: trunk/extensions/UserWelcome/UserWelcome.i18n.php |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for UserWelcome extension. |
| 5 | + * |
| 6 | + * @ingroup Extensions |
| 7 | + */ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +/** English |
| 12 | + * @author Wikia, Inc. |
| 13 | + */ |
| 14 | +$messages['en'] = array( |
| 15 | + 'mp-userlevels-link' => 'User Levels', // This is the help page...e.g. English default is Help:User Levels -- you can define a new help page with this msg. |
| 16 | + 'mp-welcome-upload' => 'Upload', |
| 17 | + 'mp-welcome-edit' => 'Edit', |
| 18 | + 'mp-welcome-points' => '$1 points', |
| 19 | + 'mp-welcome-needed-points' => 'To advance to <b><a href="$1">$2</a></b> earn <i>$3</i> more points!', |
| 20 | + 'mp-welcome-logged-in' => 'Hello $1', |
| 21 | + 'mp-requests-title' => 'Requests', |
| 22 | + 'mp-requests-message' => 'You have the following requests.', |
| 23 | + 'mp-request-new-message' => 'new message', |
| 24 | + 'mp-request-new-award' => '$1 new {{PLURAL:$1|award|awards}}', |
| 25 | + 'mp-request-new-gift' => '$1 new {{PLURAL:$1|gift|gifts}}', |
| 26 | + 'mp-request-new-foe' => '$1 new {{PLURAL:$1|foe|foes}}', |
| 27 | + 'mp-request-new-friend' => '$1 new {{PLURAL:$1|friend|friends}}', |
| 28 | +); |
| 29 | + |
| 30 | +/** Finnish (Suomi) |
| 31 | + * @author Jack Phoenix |
| 32 | + */ |
| 33 | +$messages['fi'] = array( |
| 34 | + 'mp-userlevels-link' => 'Käyttäjätasot', |
| 35 | + 'mp-welcome-upload' => 'Tallenna', |
| 36 | + 'mp-welcome-edit' => 'Muokkaa', |
| 37 | + 'mp-welcome-points' => '$1 pistettä', |
| 38 | + 'mp-welcome-needed-points' => 'Päästäksesi tasolle <b><a href="$1">$2</a></b>, ansaitse <i>$3</i> pistettä lisää!', |
| 39 | + 'mp-welcome-logged-in' => 'Hei $1', |
| 40 | + 'mp-requests-title' => 'Pyynnöt', |
| 41 | + 'mp-requests-message' => 'Sinulla on seuraavat pyynnöt.', |
| 42 | + 'mp-request-new-message' => 'uusi viesti', |
| 43 | + 'mp-request-new-award' => '$1 {{PLURAL:$1|uusi palkinto|uutta palkintoa}}', |
| 44 | + 'mp-request-new-gift' => '$1 {{PLURAL:$1|uusi lahja|uutta lahjaa}}', |
| 45 | + 'mp-request-new-foe' => '$1 {{PLURAL:$1|uusi vihollinen|uutta vihollista}}', |
| 46 | + 'mp-request-new-friend' => '$1 {{PLURAL:$1|uusi ystävä|uutta ystävää}}', |
| 47 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/UserWelcome/UserWelcome.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 48 | + native |