Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | $wgHooks['SpecialMovepageAfterMove'][] = array( &$this, 'movePage' ); |
52 | 52 | $wgHooks['LoadExtensionSchemaUpdates'][] = array( &$this, 'schema_update' ); |
53 | 53 | $wgHooks['EditPage::importFormData'][] = array( &$this, 'importFormData' ); |
| 54 | + $wgHooks['OutputPageParserOutput'][] = array( &$this, 'OutputPageParserOutput' ); |
54 | 55 | wfLoadExtensionMessages( 'ProofreadPage' ); |
55 | 56 | $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
56 | 57 | $this->index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
— | — | @@ -831,6 +832,7 @@ |
832 | 833 | } |
833 | 834 | $firstpage_title = Title::newFromText( "$page_namespace:$firstpage" ); |
834 | 835 | $parser->getOutput()->addTemplate( $firstpage_title, $firstpage_title->getArticleID(), $firstpage_title->getLatestRevID() ); |
| 836 | + $parser->getOutput()->is_toc = true; |
835 | 837 | } |
836 | 838 | |
837 | 839 | if( $header ) { |
— | — | @@ -872,6 +874,19 @@ |
873 | 875 | return $out; |
874 | 876 | } |
875 | 877 | |
| 878 | + |
| 879 | + /* |
| 880 | + * Set is_toc flag (true if page is a table of contents) |
| 881 | + */ |
| 882 | + function OutputPageParserOutput( $outputPage, $parserOutput ) { |
| 883 | + if( isset( $parserOutput->is_toc ) ) { |
| 884 | + $outputPage->is_toc = $parserOutput->is_toc; |
| 885 | + } else { |
| 886 | + $outputPage->is_toc = false; |
| 887 | + } |
| 888 | + return true; |
| 889 | + } |
| 890 | + |
876 | 891 | /* |
877 | 892 | * Try to parse a page. |
878 | 893 | * Return quality status of the page and username of the proofreader |
— | — | @@ -1303,7 +1318,6 @@ |
1304 | 1319 | if($id == -1) { |
1305 | 1320 | return true; |
1306 | 1321 | } |
1307 | | - |
1308 | 1322 | $page_namespace = $this->page_namespace; |
1309 | 1323 | $index_namespace = $this->index_namespace; |
1310 | 1324 | $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) ); |
— | — | @@ -1319,30 +1333,6 @@ |
1320 | 1334 | $templatelinks = $dbr->tableName( 'templatelinks' ); |
1321 | 1335 | $catlinks = $dbr->tableName( 'categorylinks' ); |
1322 | 1336 | |
1323 | | - // count transclusions from page namespace |
1324 | | - $res = $dbr->select( array( 'templatelinks', 'page' ), |
1325 | | - array( 'COUNT(page_id) AS count' ), |
1326 | | - array( "tl_from=$id", "tl_namespace=$page_ns_index" ), |
1327 | | - __METHOD__, null, |
1328 | | - array( 'page' => array( 'LEFT JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ) ) ) ; |
1329 | | - if( $res && $dbr->numRows( $res ) > 0 ) { |
1330 | | - $row = $dbr->fetchObject( $res ); |
1331 | | - $n = $row->count; |
1332 | | - $dbr->freeResult( $res ); |
1333 | | - } |
1334 | | - if($n == 0) { |
1335 | | - return true; |
1336 | | - } |
1337 | | - |
1338 | | - // find the proofreading status of transclusions |
1339 | | - $query = "SELECT COUNT(page_id) AS count FROM $templatelinks LEFT JOIN $page ON page_title=tl_title AND page_namespace=tl_namespace LEFT JOIN $catlinks ON cl_from=page_id WHERE tl_from=$id AND tl_namespace=$page_ns_index AND cl_to='###'"; |
1340 | | - $n0 = $this->query_count( $dbr, $query, 'proofreadpage_quality0_category' ); |
1341 | | - $n2 = $this->query_count( $dbr, $query, 'proofreadpage_quality2_category' ); |
1342 | | - $n3 = $this->query_count( $dbr, $query, 'proofreadpage_quality3_category' ); |
1343 | | - $n4 = $this->query_count( $dbr, $query, 'proofreadpage_quality4_category' ); |
1344 | | - // quality1 is the default value |
1345 | | - $n1 = $n - $n0 - $n2 - $n3 - $n4; |
1346 | | - |
1347 | 1337 | // find the index page |
1348 | 1338 | $indextitle = null; |
1349 | 1339 | $res = $dbr->select( array( 'templatelinks' ), |
— | — | @@ -1364,12 +1354,75 @@ |
1365 | 1355 | $dbr->freeResult( $res2 ); |
1366 | 1356 | } |
1367 | 1357 | } |
| 1358 | + |
| 1359 | + if( isset( $out->is_toc ) && $out->is_toc ) { |
| 1360 | + if ($indextitle) { |
| 1361 | + $res = $dbr->select( array( 'pr_index', 'page' ), |
| 1362 | + array( 'pr_count', 'pr_q0', 'pr_q1', 'pr_q2', 'pr_q3', 'pr_q4' ), |
| 1363 | + array( "page_title='$indextitle'", "page_namespace=$index_ns_index" ), |
| 1364 | + __METHOD__, null, |
| 1365 | + array( 'page' => array( 'LEFT JOIN', 'page_id=pr_page_id' ) ) ) ; |
| 1366 | + $row = $dbr->fetchObject( $res ); |
| 1367 | + if( $row ) { |
| 1368 | + $n0 = $row->pr_q0; |
| 1369 | + $n1 = $row->pr_q1; |
| 1370 | + $n2 = $row->pr_q2; |
| 1371 | + $n3 = $row->pr_q3; |
| 1372 | + $n4 = $row->pr_q4; |
| 1373 | + $n = $row->pr_count; |
| 1374 | + $ne = $n - ($n0+$n1+$n2+$n3+$n4); |
| 1375 | + } |
| 1376 | + } |
| 1377 | + } else { |
| 1378 | + // count transclusions from page namespace |
| 1379 | + $res = $dbr->select( array( 'templatelinks', 'page' ), |
| 1380 | + array( 'COUNT(page_id) AS count' ), |
| 1381 | + array( "tl_from=$id", "tl_namespace=$page_ns_index" ), |
| 1382 | + __METHOD__, null, |
| 1383 | + array( 'page' => array( 'LEFT JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ) ) ) ; |
| 1384 | + if( $res && $dbr->numRows( $res ) > 0 ) { |
| 1385 | + $row = $dbr->fetchObject( $res ); |
| 1386 | + $n = $row->count; |
| 1387 | + $dbr->freeResult( $res ); |
| 1388 | + } |
| 1389 | + // find the proofreading status of transclusions |
| 1390 | + $query = "SELECT COUNT(page_id) AS count FROM $templatelinks LEFT JOIN $page ON page_title=tl_title AND page_namespace=tl_namespace LEFT JOIN $catlinks ON cl_from=page_id WHERE tl_from=$id AND tl_namespace=$page_ns_index AND cl_to='###'"; |
| 1391 | + $n0 = $this->query_count( $dbr, $query, 'proofreadpage_quality0_category' ); |
| 1392 | + $n2 = $this->query_count( $dbr, $query, 'proofreadpage_quality2_category' ); |
| 1393 | + $n3 = $this->query_count( $dbr, $query, 'proofreadpage_quality3_category' ); |
| 1394 | + $n4 = $this->query_count( $dbr, $query, 'proofreadpage_quality4_category' ); |
| 1395 | + // quality1 is the default value |
| 1396 | + $n1 = $n - $n0 - $n2 - $n3 - $n4; |
| 1397 | + $ne = 0; |
| 1398 | + } |
| 1399 | + |
| 1400 | + if($n == 0) { |
| 1401 | + return true; |
| 1402 | + } |
| 1403 | + |
1368 | 1404 | $indexlink = ''; |
1369 | 1405 | if( $indextitle ) { |
1370 | 1406 | $sk = $wgUser->getSkin(); |
1371 | 1407 | $indexlink = $sk->makeKnownLink( "$index_namespace:$indextitle", "[index]" ); |
1372 | 1408 | } |
1373 | | - $output = wfMsgForContent( 'proofreadpage_quality_message', $n0*100/$n, $n1*100/$n, $n2*100/$n, $n3*100/$n, $n4*100/$n, $n, $indexlink ); |
| 1409 | + |
| 1410 | + $q0 = $n0*100/$n; |
| 1411 | + $q1 = $n1*100/$n; |
| 1412 | + $q2 = $n2*100/$n; |
| 1413 | + $q3 = $n3*100/$n; |
| 1414 | + $q4 = $n4*100/$n; |
| 1415 | + $qe = $ne*100/$n; |
| 1416 | + $void_cell = $ne ? "<td align=center style='border-style:dotted;border-width:1px;' width=\"{$qe}\"></td>" : ""; |
| 1417 | + $output = "<table class=\"pr_quality\" style=\"line-height:40%;\" border=0 cellpadding=0 cellspacing=0 ><tr> |
| 1418 | +<td align=center > </td> |
| 1419 | +<td align=center class='quality4' width=\"$q4\"></td> |
| 1420 | +<td align=center class='quality3' width=\"$q3\"></td> |
| 1421 | +<td align=center class='quality2' width=\"$q2\"></td> |
| 1422 | +<td align=center class='quality1' width=\"$q1\"></td> |
| 1423 | +<td align=center class='quality0' width=\"$q0\"></td> |
| 1424 | +$void_cell |
| 1425 | +<td ><span id=pr_index style=\"visibility:hidden;\">$indexlink</span></td> |
| 1426 | +</tr></table>"; |
1374 | 1427 | $out->setSubtitle( $out->getSubtitle() . $output ); |
1375 | 1428 | return true; |
1376 | 1429 | } |
Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php |
— | — | @@ -60,15 +60,6 @@ |
61 | 61 | Remarks||10', |
62 | 62 | 'proofreadpage_default_header' => '', |
63 | 63 | 'proofreadpage_default_footer' => '<references/>', |
64 | | - 'proofreadpage_quality_message' => "<table style=\"line-height:40%;\" border=0 cellpadding=0 cellspacing=0 ><tr> |
65 | | -<td align=center > </td> |
66 | | -<td align=center class='quality4' width=\"$5\"></td> |
67 | | -<td align=center class='quality3' width=\"$4\"></td> |
68 | | -<td align=center class='quality2' width=\"$3\"></td> |
69 | | -<td align=center class='quality1' width=\"$2\"></td> |
70 | | -<td align=center class='quality0' width=\"$1\"></td> |
71 | | -<td ><span id=pr_index style=\"visibility:hidden;\">$7</span></td> |
72 | | -</tr></table>", |
73 | 64 | 'proofreadpage_pages' => "{{PLURAL:$1|page|pages}}", |
74 | 65 | 'proofreadpage_specialpage_text' => '', |
75 | 66 | 'proofreadpage_specialpage_legend' => 'Search index pages', |