Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | Remarks||10', |
53 | 53 | 'proofreadpage_default_header' => '<div class="pagetext">', |
54 | 54 | 'proofreadpage_default_footer' => '<references/></div>', |
| 55 | + 'proofreadpage_quality_message' => '<!-- -->', |
55 | 56 | ); |
56 | 57 | |
57 | 58 | /** Message documentation (Message documentation) |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | $wgHooks['ArticlePurge'][] = 'pr_articlePurge'; |
26 | 26 | $wgHooks['SpecialMovepageAfterMove'][] = 'pr_movePage'; |
27 | 27 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'pr_schema_update'; |
| 28 | +$wgHooks['OutputPageBeforeHTML'][] = 'pr_OutputPageBeforeHTML'; |
28 | 29 | |
29 | 30 | |
30 | 31 | # special page |
— | — | @@ -1081,3 +1082,96 @@ |
1082 | 1083 | $dbw->query ( $query ); |
1083 | 1084 | $dbw->commit(); |
1084 | 1085 | } |
| 1086 | + |
| 1087 | + |
| 1088 | + |
| 1089 | + |
| 1090 | +/* |
| 1091 | + * In ns-0, display the proofreading status of transcluded pages |
| 1092 | + */ |
| 1093 | +function pr_OutputPageBeforeHTML( $out, $text ) { |
| 1094 | + global $wgTitle, $wgUser; |
| 1095 | + global $pr_page_namespace, $pr_index_namespace; |
| 1096 | + |
| 1097 | + if($wgTitle->getNamespace() != NS_MAIN){ |
| 1098 | + return true; |
| 1099 | + } |
| 1100 | + |
| 1101 | + $id = $wgTitle->mArticleID; |
| 1102 | + if($id == -1) { |
| 1103 | + return true; |
| 1104 | + } |
| 1105 | + |
| 1106 | + $dbr = wfGetDB( DB_SLAVE ); |
| 1107 | + $pr_index = $dbr->tableName( 'pr_index' ); |
| 1108 | + $page = $dbr->tableName( 'page' ); |
| 1109 | + $pagelinks = $dbr->tableName( 'pagelinks' ); |
| 1110 | + $templatelinks = $dbr->tableName( 'templatelinks' ); |
| 1111 | + $catlinks = $dbr->tableName( 'categorylinks' ); |
| 1112 | + $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $pr_page_namespace ) ); |
| 1113 | + $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $pr_index_namespace ) ); |
| 1114 | + |
| 1115 | + # count transclusions from page namespace |
| 1116 | + $query = "SELECT COUNT(page_id) AS count FROM templatelinks LEFT JOIN $page ON page_title=tl_title where tl_from=$id and tl_namespace=$page_ns_index"; |
| 1117 | + $res = $dbr->query( $query , __METHOD__ ); |
| 1118 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1119 | + $row = $dbr->fetchObject( $res ); |
| 1120 | + $n = $row->count; |
| 1121 | + $dbr->freeResult( $res ); |
| 1122 | + } |
| 1123 | + if($n == 0) { |
| 1124 | + return true; |
| 1125 | + } |
| 1126 | + |
| 1127 | + # find the proofreading status of transclusions |
| 1128 | + $query = "SELECT COUNT(page_id) AS count FROM templatelinks LEFT JOIN $page ON page_title=tl_title LEFT JOIN $catlinks ON cl_from=page_id where tl_from=$id and tl_namespace=$page_ns_index AND cl_to='###'"; |
| 1129 | + |
| 1130 | + $q4 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality4_category' ) ); |
| 1131 | + $res = $dbr->query( str_replace( '###', $q4, $query) , __METHOD__ ); |
| 1132 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1133 | + $row = $dbr->fetchObject( $res ); |
| 1134 | + $n4 = $row->count; |
| 1135 | + $dbr->freeResult( $res ); |
| 1136 | + } |
| 1137 | + |
| 1138 | + $q3 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality3_category' ) ); |
| 1139 | + $res = $dbr->query( str_replace( '###', $q3, $query) , __METHOD__ ); |
| 1140 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1141 | + $row = $dbr->fetchObject( $res ); |
| 1142 | + $n3 = $row->count; |
| 1143 | + $dbr->freeResult( $res ); |
| 1144 | + } |
| 1145 | + |
| 1146 | + $q2 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality2_category' ) ); |
| 1147 | + $res = $dbr->query( str_replace( '###', $q2, $query) , __METHOD__ ); |
| 1148 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1149 | + $row = $dbr->fetchObject( $res ); |
| 1150 | + $n2 = $row->count; |
| 1151 | + $dbr->freeResult( $res ); |
| 1152 | + } |
| 1153 | + |
| 1154 | + $q0 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality0_category' ) ); |
| 1155 | + $res = $dbr->query( str_replace( '###', $q0, $query) , __METHOD__ ); |
| 1156 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1157 | + $row = $dbr->fetchObject( $res ); |
| 1158 | + $n0 = $row->count; |
| 1159 | + $dbr->freeResult( $res ); |
| 1160 | + } |
| 1161 | + |
| 1162 | + # q1 is default value |
| 1163 | + $n1 = $n - $n0 - $n2 - $n3 - $n4; |
| 1164 | + |
| 1165 | + # find the index page |
| 1166 | + $indexquery = "SELECT DISTINCT p2.page_title AS title FROM $templatelinks LEFT JOIN $page AS p1 ON page_title=tl_title LEFT JOIN $pagelinks ON pl_title=page_title LEFT JOIN $page AS p2 ON p2.page_id=pl_from WHERE tl_from=$id AND tl_namespace=$page_ns_index AND pl_title=p1.page_title AND p2.page_namespace=$index_ns_index"; |
| 1167 | + $res = $dbr->query( $indexquery , __METHOD__ ); |
| 1168 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1169 | + $row = $dbr->fetchObject( $res ); |
| 1170 | + $title = $row->title; |
| 1171 | + $dbr->freeResult( $res ); |
| 1172 | + } |
| 1173 | + $sk = $wgUser->getSkin(); |
| 1174 | + $indexlink = $sk->makeKnownLink( "$pr_index_namespace:$title", "[index]" ); |
| 1175 | + $output = wfMsgForContent( 'proofreadpage_quality_message', $n0, $n1, $n2, $n3, $n4, $n, $indexlink ); |
| 1176 | + $out->setSubtitle($output); |
| 1177 | + return true; |
| 1178 | +}; |