Page MenuHomePhabricator

Reduce Social Tools code duplication
Open, MediumPublic

Description

In a lot of cases, bits of code are duplicated - probably unnecessarily. One example, is T98550/T100024. There are other examples out there, and we should seek these out and reduce them where possible.

Social Tools is a huge mess of dependencies anyway, but with duplicated code it becomes a whole lot worse.

Details

Related Gerrit Patches:
mediawiki/extensions/BlogPage : masterFinally make the "comments of the day" feature work again
mediawiki/extensions/Comments : masterComments of the day cleaned up & unconditionally enabled
mediawiki/extensions/Comments : master[WIP/UNTESTED?] Version 4.2.0: comments of the day cleaned up & unconditionally enabled
mediawiki/extensions/PollNY : masterVersion 3.3: less code duplication
mediawiki/extensions/QuizGame : masterVersion 3.2: less code duplication
mediawiki/extensions/PictureGame : masterVersion 3.2: less code duplication
mediawiki/extensions/SocialProfile : masterAdd some common/shared assets to be used by PictureGame, PollNY & QuizGame
mediawiki/extensions/SocialProfile : masterVersion 1.7.2: responsiveness, a tad bit less code duplication

Related Objects

Event Timeline

lcawte created this task.May 22 2015, 4:00 PM
lcawte raised the priority of this task from to Medium.
lcawte updated the task description. (Show Details)
lcawte added a project: Social-Tools.
lcawte added subscribers: lcawte, ashley.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMay 22 2015, 4:00 PM

Birthday formatting could should probably be totally rewritten, likely to use whatever methods the core Language class offers. It's awful, hacky and somewhat duplicated (between UserProfile and SpecialUpdateProfile classes). See rESPRcf0c2f84af6585a6d49354861e61242cb8de031a

PictureGame, PollNY and QuizGame all include a stripped-down version of Lokesh Dhakar's lightbox JS code. These three are almost identical; compared to the PollNY version, both PictureGame and QuizGame versions of the lightbox script include a jQuery( document ).ready( LightBox.init ); call at the bottom of the file to fire the lightbox once DOM is ready, and additionally the QuizGame version contains two additional opacity definitions in the setText function. Either way, this is a glorious nightmare.
Given that all of these extensions depend on the architecture provided by SocialProfile (the wAvatar class, point calculation via the UserStatsTrack class, etc.), it could be possible to create a folder like /extensions/SocialProfile/common/js/ and dump a "master copy" of the lightbox script there. This feels icky in the sense that if and when not everyone has PictureGame/PollNY/QuizGame installed, that script is just there, doing nothing but bloating up the total directory size. Then again disk space these days is pretty cheap and we probably don't need to worry about a few kilobytes...

On a very related matter, that's not all the code duplication as far as those three extensions go. Each extension's images directory is almost identical.

PictureGame's images directory:

  • addIcon.gif
  • ajax-loader.gif
  • ajax-loader-white.gif
  • commentsIcon.gif
  • overlay.png
  • pencilIcon.gif
  • sprite.png (combination of addIcon.gif, commentsIcon.gif, pencilIcon.gif and voteIcon.gif)
  • vote-bar-blue.gif
  • vote-bar-red.gif
  • voteIcon.gif

PollNY's images directory:

  • addIcon.gif
  • ajax-loader.gif
  • ajax-loader-white.gif
  • commentsIcon.gif
  • overlay.png
  • pencilIcon.gif
  • vote-bar-1.gif
  • vote-bar-2.gif
  • vote-bar-3.gif
  • vote-bar-4.gif
  • vote-bar-5.gif
  • voteIcon.gif

QuizGame's images directory:

  • addIcon.gif
  • ajax-loader.gif
  • ajax-loader-white.gif
  • commentsIcon.gif
  • overlay.png
  • pencilIcon.gif
  • sprite.png
  • vote-bar-blue.gif
  • vote-bar-green.gif
  • vote-bar-red.gif
  • vote-bar-yellow.gif
  • voteIcon.gif

So all three extensions contain the same icons, overlay and AJAX loader images; the only differences are in the vote-bar images and their naming:

  • /extensions/PictureGame/images/vote-bar-blue.gif == /extensions/PollNY/images/vote-bar-1.gif == /extensions/QuizGame/images/vote-bar-blue.gif
  • /extensions/PictureGame/images/vote-bar-red.gif == /extensions/PollNY/images/vote-bar-2.gif == /extensions/QuizGame/images/vote-bar-red.gif
  • /extensions/PollNY/images/vote-bar-3.gif == /extensions/QuizGame/images/vote-bar-green.gif
  • /extensions/PollNY/images/vote-bar-4.gif == /extensions/QuizGame/images/vote-bar-yellow.gif
  • /extensions/PollNY/images/vote-bar-5.gif (purple) does not exist in the other two directories

SocialProfile has a directory for common/shared (as in shared between SocialProfile "components", not sure if external social tools which still depend on SP use these) images, /extensions/SocialProfile/images/. It already contains ajax-loader-white.gif, pencilIcon.gif (under the file name editIcon.gif) and voteIcon.gif

And now for some duplicated things written in PHP:

  • the TagCloud class (TagCloudClass.php) — at least BlogPage and FanBoxes include this class, BlogPage's is just renamed to prevent naming conflicts. Given that both extensions require at least SocialProfile, I guess this should be dumped into SocialProfile's upcoming "shared" folder or something?
  • custom pagination code — usually indicated by the comment "Build next/prev nav", this is literally everywhere; at least the following extensions' following files include this code:
    • FanBoxes
      • SpecialViewFanBoxes.php
    • SocialProfile
      • SystemGifts
        • SpecialViewSystemGifts.php
      • UserBoard
        • SpecialUserBoard.php
      • UserGifts
        • SpecialGiveGift.php
        • SpecialViewGifts.php
      • UserRelationship
        • SpecialViewRelationships.php
    • SportsTeams
      • SpecialSimilarFans.php
      • SpecialViewFans.php
    • UserStatus
      • SpecialFanUpdates.php
      • SpecialUserStatus.php

Change 227714 had a related patch set uploaded (by Jack Phoenix):
Version 1.7.2: responsiveness, a tad bit less code duplication

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

Change 227714 merged by Jack Phoenix:
Version 1.7.2: responsiveness, a tad bit less code duplication

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

Change 231619 had a related patch set uploaded (by Jack Phoenix):
Add some common/shared assets to be used by PictureGame, PollNY & QuizGame

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

Change 231620 had a related patch set uploaded (by Jack Phoenix):
Version 3.2: less code duplication

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

Change 231623 had a related patch set uploaded (by Jack Phoenix):
Version 3.2: less code duplication

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

Change 231627 had a related patch set uploaded (by Jack Phoenix):
Version 3.3: less code duplication

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

Change 231619 merged by Jack Phoenix:
Add some common/shared assets to be used by PictureGame, PollNY & QuizGame

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

Change 231620 merged by Jack Phoenix:
Version 3.2: less code duplication

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

Change 231623 merged by Jack Phoenix:
Version 3.2: less code duplication

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

Change 231627 merged by Jack Phoenix:
Version 3.3: less code duplication

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

Change 275197 had a related patch set uploaded (by Jack Phoenix):
[WIP/UNTESTED?] Version 4.2.0: comments of the day cleaned up & unconditionally enabled

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

Change 275197 abandoned by Jack Phoenix:
[WIP/UNTESTED?] Version 4.2.0: comments of the day cleaned up & unconditionally enabled

Reason:
Will submit again as a new changeset.

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

Change 275198 had a related patch set uploaded (by Jack Phoenix):
[WIP/UNTESTED?] Version 4.2.0: comments of the day cleaned up & unconditionally enabled

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

SamanthaNguyen moved this task from Backlog to General on the Social-Tools board.May 8 2016, 3:08 PM

Change 275198 merged by Jack Phoenix:
Comments of the day cleaned up & unconditionally enabled

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

Change 331082 had a related patch set uploaded (by Jack Phoenix):
Finally make the "comments of the day" feature work again

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

Change 331082 merged by jenkins-bot:
Finally make the "comments of the day" feature work again

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