r73746 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73745‎ | r73746 | r73747 >
Date:16:00, 25 September 2010
Author:thomasv
Status:ok
Tags:
Comment:
display quality indicator of the whole book for TOC pages
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.i18n.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -50,6 +50,7 @@
5151 $wgHooks['SpecialMovepageAfterMove'][] = array( &$this, 'movePage' );
5252 $wgHooks['LoadExtensionSchemaUpdates'][] = array( &$this, 'schema_update' );
5353 $wgHooks['EditPage::importFormData'][] = array( &$this, 'importFormData' );
 54+ $wgHooks['OutputPageParserOutput'][] = array( &$this, 'OutputPageParserOutput' );
5455 wfLoadExtensionMessages( 'ProofreadPage' );
5556 $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
5657 $this->index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
@@ -831,6 +832,7 @@
832833 }
833834 $firstpage_title = Title::newFromText( "$page_namespace:$firstpage" );
834835 $parser->getOutput()->addTemplate( $firstpage_title, $firstpage_title->getArticleID(), $firstpage_title->getLatestRevID() );
 836+ $parser->getOutput()->is_toc = true;
835837 }
836838
837839 if( $header ) {
@@ -872,6 +874,19 @@
873875 return $out;
874876 }
875877
 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+
876891 /*
877892 * Try to parse a page.
878893 * Return quality status of the page and username of the proofreader
@@ -1303,7 +1318,6 @@
13041319 if($id == -1) {
13051320 return true;
13061321 }
1307 -
13081322 $page_namespace = $this->page_namespace;
13091323 $index_namespace = $this->index_namespace;
13101324 $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) );
@@ -1319,30 +1333,6 @@
13201334 $templatelinks = $dbr->tableName( 'templatelinks' );
13211335 $catlinks = $dbr->tableName( 'categorylinks' );
13221336
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 -
13471337 // find the index page
13481338 $indextitle = null;
13491339 $res = $dbr->select( array( 'templatelinks' ),
@@ -1364,12 +1354,75 @@
13651355 $dbr->freeResult( $res2 );
13661356 }
13671357 }
 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+
13681404 $indexlink = '';
13691405 if( $indextitle ) {
13701406 $sk = $wgUser->getSkin();
13711407 $indexlink = $sk->makeKnownLink( "$index_namespace:$indextitle", "[index]" );
13721408 }
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 >&nbsp;</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>";
13741427 $out->setSubtitle( $out->getSubtitle() . $output );
13751428 return true;
13761429 }
Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
@@ -60,15 +60,6 @@
6161 Remarks||10',
6262 'proofreadpage_default_header' => '',
6363 'proofreadpage_default_footer' => '<references/>',
64 - 'proofreadpage_quality_message' => "<table style=\"line-height:40%;\" border=0 cellpadding=0 cellspacing=0 ><tr>
65 -<td align=center >&nbsp;</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>",
7364 'proofreadpage_pages' => "{{PLURAL:$1|page|pages}}",
7465 'proofreadpage_specialpage_text' => '',
7566 'proofreadpage_specialpage_legend' => 'Search index pages',

Follow-up revisions

RevisionCommit summaryAuthorDate
r73759Follow-up r73746 for Translateraymond18:04, 25 September 2010

Status & tagging log