Legoktm has submitted this change and it was merged. Change subject: Modernize the extension, ditch PHP entry point and i18n file ......................................................................
Modernize the extension, ditch PHP entry point and i18n file Bug: T145313 Change-Id: Icf23981a5e40a3fb155c0efbc2378c94a51edcc6 --- D ArticleRatings.php M ArticleRatingsHooks.php M RatingDataClass.php D RatingTag.php M SpecialChangeRating.php A extension.json A i18n/en.json A i18n/vi.json 8 files changed, 234 insertions(+), 175 deletions(-) Approvals: Legoktm: Verified SamanthaNguyen: Looks good to me, approved diff --git a/ArticleRatings.php b/ArticleRatings.php deleted file mode 100644 index 77af34f..0000000 --- a/ArticleRatings.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php -/** - * ArticleRating extension -- a complex interface for rating pages - * - * @file - * @ingroup Extensions - * @author Adam Carter (UltrasonicNXT) - * @link https://www.mediawiki.org/wiki/Extension:ArticleRatings Documentation - */ - -# Not an entry point -if ( !defined( 'MEDIAWIKI' ) ) { - die( 'This file is a MediaWiki extension, it is not a valid entry point' ); -} - -# Load classes -$wgAutoloadClasses['RatingData'] = __DIR__ . '/RatingDataClass.php'; -$wgAutoloadClasses['Rating'] = __DIR__ . '/RatingDataClass.php'; - -# Load hooks -$wgAutoloadClasses['AreHooks'] = __DIR__ . '/ArticleRatingsHooks.php'; -$wgHooks['BaseTemplateToolbox'][] = 'AreHooks::onBaseTemplateToolbox'; -$wgHooks['TitleMove'][] = 'AreHooks::onTitleMove'; -$wgHooks['ParserFirstCallInit'][] = 'wfRatingParserInit'; -$wgHooks['LoadExtensionSchemaUpdates'][] = 'AreHooks::onLoadExtensionSchemaUpdates'; -$wgHooks['ArticleDeleteComplete'][] = 'AreHooks::onArticleDeleteComplete'; - -include( __DIR__ . '/RatingTag.php' ); - -function wfRatingParserInit( Parser $parser ) { - $parser->setHook( 'rating', 'wfRatingRender' ); - return true; -} - -# Credits -$wgExtensionCredits['other'][] = array( - 'path' => __FILE__, - 'name' => 'ArticleRating', - 'version' => '2.4.0', - 'author' => 'UltrasonicNXT/Adam Carter', - 'url' => 'https://www.mediawiki.org/wiki/Extension:ArticleRatings', - 'descriptionmsg' => 'ratings-desc', -); - -# Group the special pages under the correct headers in Special:SpecialPages -$wgSpecialPageGroups['ChangeRating'] = 'other'; -$wgSpecialPageGroups['MassRatings'] = 'other'; - -# Set up Special:ChangeRating -$wgAutoloadClasses['SpecialChangeRating'] = __DIR__ . '/SpecialChangeRating.php'; -$wgSpecialPages['ChangeRating'] = 'SpecialChangeRating'; - -# Set up Special:MassRatings -$wgAutoloadClasses['SpecialMassRatings'] = __DIR__ . '/SpecialMassRatings.php'; -$wgSpecialPages['MassRatings'] = 'SpecialMassRatings'; - -# i18n -$wgExtensionMessagesFiles['ArticleRatings'] = __DIR__ . '/ArticleRatings.i18n.php'; -$wgExtensionMessagesFiles['ArticleRatingsAlias'] = __DIR__ . '/ArticleRatings.alias.php'; - -# Logs -$wgLogTypes[] = 'ratings'; -$wgLogActionsHandlers['ratings/*'] = 'LogFormatter'; - -# New user right -$wgAvailableRights[] = 'change-rating'; - -# TODO FIXME: -# this definition needs to be moved to Brickimedia's config file(s) -$wgGroupPermissions['reviewer']['change-rating'] = true; - -# vars -$wgAREUseInitialRatings = false; -$wgARENamespaces = $wgContentNamespaces; diff --git a/ArticleRatingsHooks.php b/ArticleRatingsHooks.php index 7e1a0ca..b2bb183 100644 --- a/ArticleRatingsHooks.php +++ b/ArticleRatingsHooks.php @@ -1,12 +1,137 @@ <?php + class AreHooks { - public static function onTitleMove( Title $title, Title $newtitle, User $user ) { + + /** + * Extension registration callback -- set $wgARENamespaces to $wgContentNa + */ + public static function onRegisterExtension() { + global $wgARENamespaces; + $wgARENamespaces = MWNamespace::getContentNamespaces(); + } + + /** + * Register the <rating> tag with the Parser. + * + * @param Parser $parser + * @return bool + */ + public static function onParserFirstCallInit( Parser $parser ) { + $parser->setHook( 'rating', array( __CLASS__, 'renderRating' ) ); + return true; + } + + /** + * Callback for the above function. + * + * @param mixed $input User-supplied input [unused] + * @param array $args Arguments for the tag (<rating page="Some page" ... />) + * @param Parser $parser + * @param PPFrame $frame + * @return string + */ + public static function renderRating( $input, array $args, Parser $parser, PPFrame $frame ) { + global $wgAREUseInitialRatings, $wgARENamespaces; + + $out = ''; + + if ( isset( $args['page'] ) && $args['page'] ) { + $page = $parser->recursiveTagParse( $args['page'], $frame ); // parse variables like {{{1}}} + + $title = Title::newFromText( $page ); + + if ( $title && $title->exists() ) { + $out .= '<span class="mw-rating-tag-page">'; + } else { + return wfMessage( 'are-no-such-page', $page )->parse(); + } + + if ( $title->isRedirect() ) { // follow redirects + $wikipage = WikiPage::factory( $title ); + $content = $wikipage->getContent( Revision::FOR_PUBLIC ); + $title = $content->getUltimateRedirectTarget(); + } + + $showAboutLink = false; + } else { + $title = $parser->getTitle(); + $out .= '<span class="mw-rating-tag">'; + + $showAboutLink = true; + } + + if ( !in_array( $title->getNamespace(), $wgARENamespaces ) ) { + return wfMessage( 'are-disallowed' )->parse(); + } + + if ( isset( $args['initial-rating'] ) && $wgAREUseInitialRatings ) { + $initRating = $args['initial-rating']; + } + + $dbr = wfGetDB( DB_SLAVE ); + + $field = $dbr->selectField( + 'ratings', + 'ratings_rating', + array( + 'ratings_title' => $title->getDBkey(), + 'ratings_namespace' => $title->getNamespace(), + ), + __METHOD__ + ); + + if ( $field ) { + $useRating = new Rating( $field ); + } else { // create rating + $ratings = RatingData::getAllRatings(); + + $useRating = RatingData::getDefaultRating(); + + if ( isset( $args['initial-rating'] ) ) { + foreach ( $ratings as $rating ) { + if ( $args['initial-rating'] == $rating->getCodename() ) { // check if the rating actually exists + $useRating = $rating; + } + } + } + + $dbw = wfGetDB( DB_MASTER ); + + $dbw->insert( + 'ratings', + array( + 'ratings_rating' => $useRating->getCodename(), + 'ratings_title' => $title->getDBkey(), + 'ratings_namespace' => $title->getNamespace() + ), + __METHOD__ + ); + } + + $aboutLink = ''; + + if ( $showAboutLink ) { + $aboutLink = $useRating->getAboutLink(); + } + + $out .= $aboutLink . $useRating->getImage() . '</span>'; + + return $out; + } + + public static function onTitleMove( Title $title, Title $newTitle, User $user ) { $dbw = wfGetDB( DB_MASTER ); $res = $dbw->update( 'ratings', - array( 'ratings_title' => $newtitle->getDBkey(), 'ratings_namespace' => $newtitle->getNamespace() ), - array( 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() ), + array( + 'ratings_title' => $newTitle->getDBkey(), + 'ratings_namespace' => $newTitle->getNamespace() + ), + array( + 'ratings_title' => $title->getDBkey(), + 'ratings_namespace' => $title->getNamespace() + ), __METHOD__ ); @@ -45,8 +170,8 @@ * @param WikiPage $article * @param User $user - * @param unknown $reason - * @param unknown $id + * @param string $reason + * @param int $id * @param unknown $content * @param unknown $logEntry */ @@ -57,11 +182,12 @@ $res = $dbw->delete( 'ratings', - array( 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() ), + array( + 'ratings_title' => $title->getDBkey(), + 'ratings_namespace' => $title->getNamespace() + ), __METHOD__ ); - - //file_put_contents( "C:/temp/fpc.log", "{$title->getArticleID()} {$title->getDBkey()} - $id" ); return true; } diff --git a/RatingDataClass.php b/RatingDataClass.php index 0869e7f..828c3cf 100644 --- a/RatingDataClass.php +++ b/RatingDataClass.php @@ -24,7 +24,7 @@ public static function getDefaultRating() { $JSON = self::getJSON(); - return new Rating( $JSON[0]["codename"] ); + return new Rating( $JSON[0]['codename'] ); } } diff --git a/RatingTag.php b/RatingTag.php deleted file mode 100644 index d7a96d3..0000000 --- a/RatingTag.php +++ /dev/null @@ -1,91 +0,0 @@ -<?php - -function wfRatingRender( $input, array $args, Parser $parser, PPFrame $frame ) { - global $wgAREUseInitialRatings, $wgARENamespaces; - - $out = ''; - - if ( isset( $args['page'] ) && $args['page'] ) { - $page = $parser->recursiveTagParse( $args['page'], $frame ); // parse variables like {{{1}}} - - $title = Title::newFromText( $page ); - - if ( $title && $title->exists() ) { - $out .= '<span class="mw-rating-tag-page">'; - } else { - return wfMessage( 'are-no-such-page', $page )->parse(); - } - - if ( $title->isRedirect() ) { // follow redirects - $wikipage = WikiPage::factory( $title ); - $content = $wikipage->getContent( Revision::FOR_PUBLIC ); - $title = $content->getUltimateRedirectTarget(); - } - - $showAboutLink = false; - } else { - $title = $parser->getTitle(); - $out .= '<span class="mw-rating-tag">'; - - $showAboutLink = true; - } - - if ( !in_array( $title->getNamespace(), $wgARENamespaces ) ) { - return wfMessage( 'are-disallowed' )->parse(); - } - - if ( isset( $args['initial-rating'] ) && $wgAREUseInitialRatings ) { - $initRating = $args['initial-rating']; - } - - $dbr = wfGetDB( DB_SLAVE ); - - $field = $dbr->selectField( - 'ratings', - 'ratings_rating', - array( - 'ratings_title' => $title->getDBkey(), - 'ratings_namespace' => $title->getNamespace(), - ), - __METHOD__ - ); - - if ( $field ) { - $useRating = new Rating( $field ); - - } else { // create rating - $ratings = RatingData::getAllRatings(); - - $useRating = RatingData::getDefaultRating(); - - if ( isset( $args['initial-rating'] ) ) { - foreach ( $ratings as $rating ) { - if ( $args['initial-rating'] == $rating->getCodename() ) { // check if the rating actually exists - $useRating = $rating; - } - } - } - - $dbw = wfGetDB( DB_MASTER ); - - $dbw->insert( - 'ratings', - array( - 'ratings_rating' => $useRating->getCodename(), - 'ratings_title' => $title->getDBkey(), - 'ratings_namespace' => $title->getNamespace() - ), - __METHOD__ - ); - } - - $aboutLink = ''; - - if ( $showAboutLink ) { - $aboutLink = $useRating->getAboutLink(); - } - - $out .= $aboutLink . $useRating->getImage() . '</span>'; - - return $out; -} \ No newline at end of file diff --git a/SpecialChangeRating.php b/SpecialChangeRating.php index 7a0b71a..653c87a 100644 --- a/SpecialChangeRating.php +++ b/SpecialChangeRating.php @@ -5,7 +5,7 @@ parent::__construct( 'ChangeRating', 'change-rating' ); } - public function execute( $page ) {; + public function execute( $page ) { global $wgARENamespaces; $this->checkPermissions(); diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..e77878c --- /dev/null +++ b/extension.json @@ -0,0 +1,54 @@ +{ + "name": "ArticleRating", + "version": "2.4.0", + "author": "UltrasonicNXT/Adam Carter", + "url": "https://www.mediawiki.org/wiki/Extension:ArticleRatings", + "descriptionmsg": "ratings-desc", + "type": "other", + "callback": "AreHooks::onRegisterExtension", + "GroupPermissions": { + "reviewer": { + "change-rating": true + } + }, + "AvailableRights": [ + "change-rating" + ], + "SpecialPages": { + "ChangeRating": "SpecialChangeRating", + "MassRatings": "SpecialMassRatings" + }, + "LogTypes": [ + "ratings" + ], + "LogActionsHandlers": { + "ratings/*": "LogFormatter" + }, + "MessagesDirs": { + "ArticleRatings": [ + "i18n" + ] + }, + "ExtensionMessagesFiles": { + "ArticleRatingsAlias": "ArticleRatings.alias.php" + }, + "AutoloadClasses": { + "RatingData": "RatingDataClass.php", + "Rating": "RatingDataClass.php", + "AreHooks": "ArticleRatingsHooks.php", + "SpecialChangeRating": "SpecialChangeRating.php", + "SpecialMassRatings": "SpecialMassRatings.php" + }, + "Hooks": { + "BaseTemplateToolbox": "AreHooks::onBaseTemplateToolbox", + "TitleMove": "AreHooks::onTitleMove", + "ParserFirstCallInit": "AreHooks::onParserFirstCallInit", + "LoadExtensionSchemaUpdates": "AreHooks::onLoadExtensionSchemaUpdates", + "ArticleDeleteComplete": "AreHooks::onArticleDeleteComplete" + }, + "config": { + "AREUseInitialRatings": false, + "ARENamespaces": [] + }, + "manifest_version": 1 +} diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 0000000..8f392c3 --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,31 @@ +{ + "@metadata": { + "authors": [ + "Adam Carter" + ] + }, + "changerating": "ChangeRating", + "changerating-back": "< Back to [[$1]].", + "changerating-intro-text": "What would you like to change ''$1'''s rating to?", + "changerating-missing-parameter": "No page name was given. The page should be specified in the URL.", + "changerating-no-such-page": "Sorry, the page \"$1\" does not exist.", + "changerating-reason": "Reason:", + "changerating-success": "Rating changed successfully.", + "changerating-submit": "Submit", + "massratings": "MassRatings", + "massratings-legend": "List pages by rating", + "log-name-ratings": "Rating Change Log", + "log-description-ratings": "This log shows all the recent changes to pages' ratings.", + "logentry-ratings-change": "$1 changed the rating of $3 from $5 to $4", + "ratings-desc": "A complex interface for rating pages", + "are-disallowed": "Ratings have been disallowed for this namespace", + "are-no-such-page": "The page \"$1\" does not exist.", + "are-rating-for-page": "<span class=\"mw-rating-rating-for\">Rating for \"$1\"</span>:", + "are-change-rating": "Change Rating", + "are-ratings": "", + "group-reviewer": "Reviewer", + "group-reviewer-member": "Reviewers", + "action-change-rating": "change article ratings", + "changerating-log-text": "Past rating changes on this article:", + "changerating-nolog-text": "There are no past rating changes on this article." +} diff --git a/i18n/vi.json b/i18n/vi.json new file mode 100644 index 0000000..e926e9d --- /dev/null +++ b/i18n/vi.json @@ -0,0 +1,13 @@ +{ + "@metadata": { + "authors": [ + "Codyn329" + ] + }, + "changerating": "Đánh giá sự thay đổi", + "massratings": "số đông đánh giá", + "log-name-ratings": "sự thay đổi Đánh giá ghi", + "log-descripiton-ratings": "Nhật ký này cho thấy tất cả các thay đổi gần đây để các trang's Dánh giá.", + "logentry-ratings-change": "$1 thay đổi đánh giá của $3 đến $4", + "rating-desc": "Một giao diện phức tạp để đánh giá các trang" +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/309828 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icf23981a5e40a3fb155c0efbc2378c94a51edcc6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ArticleRatings Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: SamanthaNguyen <samanthanguyen1...@gmail.com> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits