r23132 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23131‎ | r23132 | r23133 >
Date:19:25, 20 June 2007
Author:aaron
Status:old
Tags:
Comment:
*Hook and OOP cleanup
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -495,10 +495,11 @@
496496 global $wgUser;
497497 // Only trigger on article view for content pages, not for protect/delete/hist
498498 if( !$article || !$article->exists() || !$article->mTitle->isContentPage() || $action !='view' )
499 - return;
 499+ return true;
500500
501 - // User must have review rights
502 - if( !$wgUser->isAllowed( 'review' ) ) return;
 501+ // User must have review rightss
 502+ if( !$wgUser->isAllowed( 'review' ) )
 503+ return true;
503504
504505 $parserOutput = $parserCache->get( $article, $wgUser );
505506 if( $parserOutput ) {
@@ -539,7 +540,8 @@
540541 $fname = 'FlaggedRevs::extraLinksUpdate';
541542 wfProfileIn( $fname );
542543
543 - if( !$title->isContentPage() ) return;
 544+ if( !$title->isContentPage() )
 545+ return true;
544546 # Check if this page has a stable version
545547 $sv = self::getOverridingPageRev( $title );
546548 if( !$sv ) return;
@@ -608,7 +610,8 @@
609611
610612 static function parserFetchStableTemplate( &$parser, &$title, &$skip, &$id ) {
611613 // Trigger for stable version parsing only
612 - if( !isset($parser->isStable) || !$parser->isStable ) return;
 614+ if( !isset($parser->isStable) || !$parser->isStable )
 615+ return true;
613616
614617 $dbr = wfGetDB( DB_SLAVE );
615618 $id = $dbr->selectField('flaggedtemplates', 'ft_tmp_rev_id',
@@ -631,7 +634,8 @@
632635
633636 static function parserMakeStableImageLink( &$parser, &$nt, &$skip, &$time ) {
634637 // Trigger for stable version parsing only
635 - if( !isset($parser->isStable) || !$parser->isStable ) return;
 638+ if( !isset($parser->isStable) || !$parser->isStable )
 639+ return true;
636640
637641 $dbr = wfGetDB( DB_SLAVE );
638642 $time = $dbr->selectField('flaggedimages', 'fi_img_timestamp',
@@ -652,7 +656,8 @@
653657
654658 static function galleryFindStableFileTime( &$ig, &$nt, &$time ) {
655659 // Trigger for stable version parsing only
656 - if( !isset($ig->isStable) || !$ig->isStable ) return;
 660+ if( !isset($ig->isStable) || !$ig->isStable )
 661+ return true;
657662
658663 $dbr = wfGetDB( DB_SLAVE );
659664 $time = $dbr->selectField('flaggedimages', 'fi_img_timestamp',
@@ -663,7 +668,8 @@
664669
665670 static function parserMakeGalleryStable( &$parser, &$ig ) {
666671 // Trigger for stable version parsing only
667 - if( !isset($parser->isStable) || !$parser->isStable ) return;
 672+ if( !isset($parser->isStable) || !$parser->isStable )
 673+ return true;
668674
669675 $ig->isStable = true;
670676 }
@@ -694,14 +700,16 @@
695701 public static function autoPromoteUser( &$article, &$user, &$text, &$summary, &$isminor, &$iswatch, &$section ) {
696702 global $wgUser, $wgFlaggedRevsAutopromote;
697703
698 - if( !$wgFlaggedRevsAutopromote ) return;
699 -
 704+ if( !$wgFlaggedRevsAutopromote )
 705+ return true;
 706+ // Grab current groups
700707 $groups = $user->getGroups();
701708 $now = time();
702709 $usercreation = wfTimestamp(TS_UNIX,$user->mRegistration);
703710 $userage = floor(($now-$usercreation) / 86400);
704711 // Do not give this to bots
705 - if( in_array( 'bot', $groups ) ) return;
 712+ if( in_array( 'bot', $groups ) )
 713+ return true;
706714 // Check if we need to promote...
707715 $vars = $wgFlaggedRevsAutopromote;
708716 if( !in_array('editor',$groups) && $userage >= $vars['days'] && $user->getEditCount() >= $vars['edits']
@@ -729,7 +737,7 @@
730738 /**
731739 * Do the current URL params allow for overriding by stable revisions?
732740 */
733 - function pageOverride() {
 741+ static function pageOverride() {
734742 global $wgTitle, $wgFlaggedRevsAnonOnly, $wgFlaggedRevsOverride, $wgUser, $wgRequest, $action;
735743 // This only applies to viewing content pages
736744 if( $action !='view' || !$wgTitle->isContentPage() ) return;
@@ -761,7 +769,8 @@
762770 // Grab page and rev ids
763771 $pageid = $article->getId();
764772 $revid = $article->mRevision ? $article->mRevision->mId : $article->getLatest();
765 - if( !$revid ) return;
 773+ if( !$revid )
 774+ return true;
766775
767776 $vis_id = $revid;
768777 $tag = ''; $notes = '';
@@ -864,7 +873,8 @@
865874 $revid = $editform->mArticle->getLatest();
866875 }
867876 // Grab the ratings for this revision if any
868 - if( !$revid ) return;
 877+ if( !$revid )
 878+ return true;
869879 // Set new body html text as that of now
870880 $tag = '';
871881 // Check the newest stable version
@@ -890,44 +900,48 @@
891901 global $wgArticle, $action;
892902
893903 if( !$wgArticle || !$wgArticle->exists() || !$wgArticle->mTitle->isContentPage() || $action !='view' )
894 - return;
 904+ return true;
895905 // Check if page is protected
896906 if( !$wgArticle->mTitle->quickUserCan( 'edit' ) ) {
897 - return;
 907+ return true;
898908 }
899909 // Get revision ID
900910 $revId = ( $wgArticle->mRevision ) ? $wgArticle->mRevision->mId : $wgArticle->getLatest();
901911 // We cannot review deleted revisions
902912 if( is_object($wgArticle->mRevision) && $wgArticle->mRevision->mDeleted )
903 - return;
 913+ return true;
904914 // Add quick review links IF we did not override, otherwise, they might
905915 // review a revision that parses out newer templates/images than what they saw.
906916 // Revisions are always reviewed based on current templates/images.
907917 if( $this->pageOverride() ) {
908918 $tfrev = $this->getOverridingRev();
909 - if( $tfrev ) return;
 919+ if( $tfrev ) return true;
910920 }
911921 $this->addQuickReview( $revId, $out, false );
912922 }
913923
914 - function setPermaLink( &$sktmp, &$nav_urls, &$oldid, &$revid ) {
915 - global $wgTitle;
 924+ function setPermaLink( &$sktmp, &$nav_urls, &$revid, &$revid ) {
916925 // Non-content pages cannot be validated
917 - if( !$wgTitle->isContentPage() || !$this->pageOverride() ) return;
 926+ if( !$this->pageOverride() ) return true;
918927 // Check for an overridabe revision
919928 $tfrev = $this->getOverridingRev();
920 - if( !$tfrev ) return;
 929+ if( !$tfrev )
 930+ return true;
921931 // Replace "permalink" with an actual permanent link
922932 $nav_urls['permalink'] = array(
923933 'text' => wfMsg( 'permalink' ),
924934 'href' => $sktmp->makeSpecialUrl( 'Stableversions', "oldid={$tfrev->fr_rev_id}" )
925935 );
 936+
 937+ global $wgHooks;
926938 // Are we using the popular cite extension?
927 - if( isset($nav_urls['cite']) ) {
928 - $nav_urls['cite'] = array(
929 - 'text' => wfMsg( 'cite_article_link' ),
930 - 'href' => $sktmp->makeSpecialUrl( 'Cite', "page=" . wfUrlencode( "{$sktmp->thispage}" ) . "&id={$tfrev->fr_rev_id}" )
931 - );
 939+ if( in_array('wfSpecialCiteNav',$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink']) ) {
 940+ if( $sktmp->mTitle->getNamespace() === NS_MAIN && $revid !== 0 ) {
 941+ $nav_urls['cite'] = array(
 942+ 'text' => wfMsg( 'cite_article_link' ),
 943+ 'href' => $sktmp->makeSpecialUrl( 'Cite', "page=" . wfUrlencode( "{$sktmp->thispage}" ) . "&id={$tfrev->fr_rev_id}" )
 944+ );
 945+ }
932946 }
933947 }
934948
@@ -936,13 +950,15 @@
937951 // Get the subject page
938952 $title = $sktmp->mTitle->getSubjectPage();
939953 // Non-content pages cannot be validated
940 - if( !$title->isContentPage() || !$title->exists() ) return;
 954+ if( !$title->isContentPage() || !$title->exists() )
 955+ return true;
941956 $article = new Article( $title );
942957 // If we are viewing a page normally, and it was overridden,
943958 // change the edit tab to a "current revision" tab
944959 $tfrev = $this->getOverridingRev( $article );
945960 // No quality revs? Find the last reviewed one
946 - if( !is_object($tfrev) ) return;
 961+ if( !is_object($tfrev) )
 962+ return true;
947963 // Note that revisions may not be set to override for users
948964 if( $this->pageOverride() ) {
949965 # Remove edit option altogether
@@ -1032,7 +1048,37 @@
10331049 $content_actions = $new_actions;
10341050 }
10351051 }
1036 -
 1052+
 1053+ function addToPageHist( &$article ) {
 1054+ global $wgUser;
 1055+
 1056+ $this->pageFlaggedRevs = array();
 1057+ $rows = $this->getReviewedRevs( $article->getTitle() );
 1058+
 1059+ // Try to keep the skin readily accesible,
 1060+ // addToHistLine() will use it
 1061+ $this->skin = $wgUser->getSkin();
 1062+
 1063+ if( !$rows )
 1064+ return true;
 1065+
 1066+ foreach( $rows as $rev => $quality ) {
 1067+ $this->pageFlaggedRevs[$rev] = $quality;
 1068+ }
 1069+ }
 1070+
 1071+ function addToHistLine( &$row, &$s ) {
 1072+ global $wgUser;
 1073+
 1074+ if( isset($this->pageFlaggedRevs) && array_key_exists($row->rev_id,$this->pageFlaggedRevs) ) {
 1075+ $msg = ($this->pageFlaggedRevs[$row->rev_id] >= 1) ? 'hist-quality' : 'hist-stable';
 1076+ $special = SpecialPage::getTitleFor( 'Stableversions' );
 1077+ $s .= ' <tt><small><strong>' .
 1078+ $this->skin->makeLinkObj( $special, wfMsgHtml($msg), 'oldid='.$row->rev_id ) .
 1079+ '</strong></small></tt>';
 1080+ }
 1081+ }
 1082+
10371083 function addQuickReview( $id=NULL, $out ) {
10381084 global $wgOut, $wgTitle, $wgUser, $wgFlaggedRevsOverride, $wgFlaggedRevComments, $wgFlaggedRevsWatch;
10391085 // User must have review rights
@@ -1112,41 +1158,13 @@
11131159
11141160 $wgOut->addHTML( '<hr style="clear:both"></hr>' . $form );
11151161 }
1116 -
1117 - function addToPageHist( &$article ) {
1118 - global $wgUser;
1119 -
1120 - $this->pageFlaggedRevs = array();
1121 - $rows = $this->getReviewedRevs( $article->getTitle() );
1122 -
1123 - // Try to keep the skin readily accesible
1124 - $this->skin = $wgUser->getSkin();
1125 -
1126 - if( !$rows ) return;
1127 -
1128 - foreach( $rows as $rev => $quality ) {
1129 - $this->pageFlaggedRevs[$rev] = $quality;
1130 - }
1131 - }
1132 -
1133 - function addToHistLine( &$row, &$s ) {
1134 - global $wgUser;
1135 -
1136 - if( isset($this->pageFlaggedRevs) && array_key_exists($row->rev_id,$this->pageFlaggedRevs) ) {
1137 - $msg = ($this->pageFlaggedRevs[$row->rev_id] >= 1) ? 'hist-quality' : 'hist-stable';
1138 - $special = SpecialPage::getTitleFor( 'Stableversions' );
1139 - $s .= ' <tt><small><strong>' .
1140 - $this->skin->makeLinkObj( $special, wfMsgHtml($msg), 'oldid='.$row->rev_id ) .
1141 - '</strong></small></tt>';
1142 - }
1143 - }
11441162
11451163 /**
11461164 * Get latest quality rev, if not, the latest reviewed one
11471165 */
1148 - function getOverridingRev( $article=NULL ) {
1149 - if( !$row = $this->getLatestQualityRev( $article ) ) {
1150 - if( !$row = $this->getLatestStableRev( $article ) ) {
 1166+ function getOverridingRev() {
 1167+ if( !$row = $this->getLatestQualityRev() ) {
 1168+ if( !$row = $this->getLatestStableRev() ) {
11511169 return null;
11521170 }
11531171 }
@@ -1158,16 +1176,10 @@
11591177 * per the $wgFlaggedRevTags variable
11601178 * This passes rev_deleted revisions
11611179 * This is based on the current article and caches results
1162 - * Accepts an argument because of the fact that the article
1163 - * object for edit mode is part of the editform; insert only
1164 - * the article object for the current page!
11651180 * @output array ( rev, flags )
11661181 */
1167 - function getLatestQualityRev( $article=NULL ) {
1168 - global $wgArticle;
1169 -
1170 - $article = $article ? $article : $wgArticle;
1171 - $title = $article->getTitle();
 1182+ function getLatestQualityRev() {
 1183+ global $wgTitle;
11721184 // Cached results available?
11731185 if( isset($this->stablefound) ) {
11741186 return ( $this->stablefound ) ? $this->stablerev : null;
@@ -1179,8 +1191,8 @@
11801192 $result = $dbr->select(
11811193 array('flaggedrevs', 'revision'),
11821194 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
1183 - array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
1184 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted = 0'),
 1195+ array('fr_namespace' => $wgTitle->getNamespace(), 'fr_title' => $wgTitle->getDBkey(), 'fr_quality >= 1',
 1196+ 'fr_rev_id = rev_id', 'rev_page' => $wgTitle->getArticleID(), 'rev_deleted = 0'),
11851197 __METHOD__,
11861198 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
11871199 wfProfileOut( __METHOD__ );
@@ -1199,17 +1211,12 @@
12001212 * Get latest flagged revision
12011213 * This passes rev_deleted revisions
12021214 * This is based on the current article and caches results
1203 - * Accepts an argument because of the fact that the article
1204 - * object for edit mode is part of the editform; insert only
1205 - * the article object for the current page!
12061215 * The cache here doesn't make sense for arbitrary articles
12071216 * @output array ( rev, flags )
12081217 */
1209 - function getLatestStableRev( $article=NULL ) {
1210 - global $wgArticle;
 1218+ function getLatestStableRev() {
 1219+ global $wgTitle;
12111220
1212 - $article = $article ? $article : $wgArticle;
1213 - $title = $article->getTitle();
12141221 // Cached results available?
12151222 if( isset($this->latestfound) ) {
12161223 return ( $this->latestfound ) ? $this->latestrev : NULL;
@@ -1220,8 +1227,8 @@
12211228 $result = $dbr->select(
12221229 array('flaggedrevs', 'revision'),
12231230 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
1224 - array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
1225 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted = 0'),
 1231+ array('fr_namespace' => $wgTitle->getNamespace(), 'fr_title' => $wgTitle->getDBkey(),
 1232+ 'fr_rev_id = rev_id', 'rev_page' => $wgTitle->getArticleID(), 'rev_deleted = 0'),
12261233 __METHOD__,
12271234 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
12281235 wfProfileOut( __METHOD__ );
@@ -1276,19 +1283,18 @@
12771284 }
12781285
12791286 // Our class instances
1280 -$flaggedrevs = new FlaggedRevs();
1281 -$flaggedarticle = new FlaggedArticle();
 1287+$flaggedrevs = new FlaggedArticle();
12821288 // Main hooks, overrides pages content, adds tags, sets tabs and permalink
1283 -$wgHooks['SkinTemplateTabs'][] = array($flaggedarticle, 'setCurrentTab');
1284 -$wgHooks['ArticleViewHeader'][] = array($flaggedarticle, 'setPageContent');
1285 -$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = array($flaggedarticle, 'setPermaLink');
 1289+$wgHooks['SkinTemplateTabs'][] = array($flaggedrevs, 'setCurrentTab');
 1290+$wgHooks['ArticleViewHeader'][] = array($flaggedrevs, 'setPageContent');
 1291+$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = array($flaggedrevs, 'setPermaLink');
12861292 // Add tags do edit view
1287 -$wgHooks['EditPage::showEditForm:initial'][] = array($flaggedarticle, 'addToEditView');
 1293+$wgHooks['EditPage::showEditForm:initial'][] = array($flaggedrevs, 'addToEditView');
12881294 // Add review form
1289 -$wgHooks['BeforePageDisplay'][] = array($flaggedarticle, 'addReviewForm');
 1295+$wgHooks['BeforePageDisplay'][] = array($flaggedrevs, 'addReviewForm');
12901296 // Mark of items in page history
1291 -$wgHooks['PageHistoryBeforeList'][] = array($flaggedarticle, 'addToPageHist');
1292 -$wgHooks['PageHistoryLineEnding'][] = array($flaggedarticle, 'addToHistLine');
 1297+$wgHooks['PageHistoryBeforeList'][] = array($flaggedrevs, 'addToPageHist');
 1298+$wgHooks['PageHistoryLineEnding'][] = array($flaggedrevs, 'addToHistLine');
12931299 // Autopromote Editors
12941300 $wgHooks['ArticleSaveComplete'][] = array($flaggedrevs, 'autoPromoteUser');
12951301 // Update older, incomplete, page caches (ones that lack template Ids/image timestamps)
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php
@@ -33,7 +33,7 @@
3434 [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$4</i>. The [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} current revision]
3535 is usually [{{fullurl:{{FULLPAGENAMEE}}|action=edit}} editable] and more up to date. There {{plural:$3|is $3 revision|are $3 revisions}}
3636 ([{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=$2}} changes]) awaiting review.',
37 - 'revreview-static' => 'This is a [[Help:Article validation|reviewed]] revision of the page \'\'\'[[:$3]]\'\'\',
 37+ 'revreview-static' => 'This is a [[Help:Article validation|reviewed]] revision of \'\'\'[[:$3|this page]]\'\'\',
3838 [{{fullurl:Special:Log/review|page=$1}} approved] on <i>$2</i>. The [{{fullurl:$3|stable=0}} current revision]
3939 is usually editable and more up to date.',
4040 'revreview-toggle' => '(toggle details)',

Status & tagging log