http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73746

Revision: 73746
Author:   thomasv
Date:     2010-09-25 16:00:40 +0000 (Sat, 25 Sep 2010)

Log Message:
-----------
display quality indicator of the whole book for TOC pages

Modified Paths:
--------------
    trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
    trunk/extensions/ProofreadPage/ProofreadPage_body.php

Modified: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
===================================================================
--- trunk/extensions/ProofreadPage/ProofreadPage.i18n.php       2010-09-25 
15:51:25 UTC (rev 73745)
+++ trunk/extensions/ProofreadPage/ProofreadPage.i18n.php       2010-09-25 
16:00:40 UTC (rev 73746)
@@ -60,15 +60,6 @@
 Remarks||10',
        'proofreadpage_default_header'        => '',
        'proofreadpage_default_footer'        => '<references/>',
-       'proofreadpage_quality_message'       => "<table 
style=\"line-height:40%;\" border=0 cellpadding=0 cellspacing=0 ><tr>
-<td align=center >&nbsp;</td>
-<td align=center class='quality4' width=\"$5\"></td>
-<td align=center class='quality3' width=\"$4\"></td>
-<td align=center class='quality2' width=\"$3\"></td>
-<td align=center class='quality1' width=\"$2\"></td>
-<td align=center class='quality0' width=\"$1\"></td>
-<td ><span id=pr_index style=\"visibility:hidden;\">$7</span></td>
-</tr></table>",
        'proofreadpage_pages'        => "{{PLURAL:$1|page|pages}}",
        'proofreadpage_specialpage_text'       => '',
        'proofreadpage_specialpage_legend'     => 'Search index pages',

Modified: trunk/extensions/ProofreadPage/ProofreadPage_body.php
===================================================================
--- trunk/extensions/ProofreadPage/ProofreadPage_body.php       2010-09-25 
15:51:25 UTC (rev 73745)
+++ trunk/extensions/ProofreadPage/ProofreadPage_body.php       2010-09-25 
16:00:40 UTC (rev 73746)
@@ -50,6 +50,7 @@
                $wgHooks['SpecialMovepageAfterMove'][] = array( &$this, 
'movePage' );
                $wgHooks['LoadExtensionSchemaUpdates'][] = array( &$this, 
'schema_update' );
                $wgHooks['EditPage::importFormData'][] = array( &$this, 
'importFormData' );
+               $wgHooks['OutputPageParserOutput'][] = array( &$this, 
'OutputPageParserOutput' );
                wfLoadExtensionMessages( 'ProofreadPage' );
                $this->page_namespace = preg_quote( wfMsgForContent( 
'proofreadpage_namespace' ), '/' );
                $this->index_namespace = preg_quote( wfMsgForContent( 
'proofreadpage_index_namespace' ), '/' );
@@ -831,6 +832,7 @@
                        }
                        $firstpage_title = Title::newFromText( 
"$page_namespace:$firstpage" );
                        $parser->getOutput()->addTemplate( $firstpage_title, 
$firstpage_title->getArticleID(), $firstpage_title->getLatestRevID() );
+                       $parser->getOutput()->is_toc = true;
                }
 
                if( $header ) {
@@ -872,6 +874,19 @@
                return $out;
        }
 
+
+       /*
+        * Set is_toc flag (true if page is a table of contents)
+        */
+       function OutputPageParserOutput( $outputPage, $parserOutput ) {
+               if( isset( $parserOutput->is_toc ) ) {
+                       $outputPage->is_toc = $parserOutput->is_toc;
+               } else {
+                       $outputPage->is_toc = false;
+               }
+               return true;
+       }
+
        /* 
         * Try to parse a page.
         * Return quality status of the page and username of the proofreader
@@ -1303,7 +1318,6 @@
                if($id == -1) {
                        return true;
                }
-       
                $page_namespace = $this->page_namespace;
                $index_namespace = $this->index_namespace;
                $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( 
$page_namespace ) );
@@ -1319,30 +1333,6 @@
                $templatelinks = $dbr->tableName( 'templatelinks' );
                $catlinks = $dbr->tableName( 'categorylinks' );
 
-               // count transclusions from page namespace
-               $res = $dbr->select( array( 'templatelinks', 'page' ),
-                                    array( 'COUNT(page_id) AS count' ),
-                                    array( "tl_from=$id", 
"tl_namespace=$page_ns_index" ),
-                                    __METHOD__, null,
-                                    array( 'page' => array( 'LEFT JOIN', 
'page_title=tl_title AND page_namespace=tl_namespace' ) ) ) ;
-               if( $res && $dbr->numRows( $res ) > 0 ) {
-                       $row = $dbr->fetchObject( $res );
-                       $n = $row->count;
-                       $dbr->freeResult( $res );
-               }
-               if($n == 0) {
-                       return true;
-               }
-
-               // find the proofreading status of transclusions
-               $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='###'";
-               $n0 = $this->query_count( $dbr, $query, 
'proofreadpage_quality0_category' );
-               $n2 = $this->query_count( $dbr, $query, 
'proofreadpage_quality2_category' );
-               $n3 = $this->query_count( $dbr, $query, 
'proofreadpage_quality3_category' );
-               $n4 = $this->query_count( $dbr, $query, 
'proofreadpage_quality4_category' );
-               // quality1 is the default value
-               $n1 = $n - $n0 - $n2 - $n3 - $n4;
-
                // find the index page
                $indextitle = null;
                $res = $dbr->select( array( 'templatelinks' ),
@@ -1364,12 +1354,75 @@
                                $dbr->freeResult( $res2 );
                        }
                }
+
+               if( isset( $out->is_toc ) && $out->is_toc ) {
+                       if ($indextitle) {
+                               $res = $dbr->select( array( 'pr_index', 'page' 
),
+                                                    array( 'pr_count', 
'pr_q0', 'pr_q1', 'pr_q2', 'pr_q3', 'pr_q4' ),
+                                                    array( 
"page_title='$indextitle'", "page_namespace=$index_ns_index" ),
+                                                    __METHOD__, null,
+                                                    array( 'page' => array( 
'LEFT JOIN', 'page_id=pr_page_id' ) ) ) ;
+                               $row = $dbr->fetchObject( $res );
+                               if( $row ) {
+                                       $n0 = $row->pr_q0;
+                                       $n1 = $row->pr_q1;
+                                       $n2 = $row->pr_q2;
+                                       $n3 = $row->pr_q3;
+                                       $n4 = $row->pr_q4;
+                                       $n = $row->pr_count;
+                                       $ne = $n - ($n0+$n1+$n2+$n3+$n4);
+                               }
+                       }
+               } else {
+                       // count transclusions from page namespace
+                       $res = $dbr->select( array( 'templatelinks', 'page' ),
+                                            array( 'COUNT(page_id) AS count' ),
+                                            array( "tl_from=$id", 
"tl_namespace=$page_ns_index" ),
+                                            __METHOD__, null,
+                                            array( 'page' => array( 'LEFT 
JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ) ) ) ;
+                       if( $res && $dbr->numRows( $res ) > 0 ) {
+                               $row = $dbr->fetchObject( $res );
+                               $n = $row->count;
+                               $dbr->freeResult( $res );
+                       }
+                       // find the proofreading status of transclusions
+                       $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='###'";
+                       $n0 = $this->query_count( $dbr, $query, 
'proofreadpage_quality0_category' );
+                       $n2 = $this->query_count( $dbr, $query, 
'proofreadpage_quality2_category' );
+                       $n3 = $this->query_count( $dbr, $query, 
'proofreadpage_quality3_category' );
+                       $n4 = $this->query_count( $dbr, $query, 
'proofreadpage_quality4_category' );
+                       // quality1 is the default value
+                       $n1 = $n - $n0 - $n2 - $n3 - $n4;
+                       $ne = 0;
+               }
+
+               if($n == 0) {
+                       return true;
+               }
+
                $indexlink = '';
                if( $indextitle ) {
                        $sk = $wgUser->getSkin();
                        $indexlink = $sk->makeKnownLink( 
"$index_namespace:$indextitle", "[index]" );
                }
-               $output = wfMsgForContent( 'proofreadpage_quality_message', 
$n0*100/$n, $n1*100/$n, $n2*100/$n, $n3*100/$n, $n4*100/$n, $n, $indexlink );
+
+               $q0 = $n0*100/$n;
+               $q1 = $n1*100/$n;
+               $q2 = $n2*100/$n;
+               $q3 = $n3*100/$n;
+               $q4 = $n4*100/$n;
+               $qe = $ne*100/$n;
+               $void_cell = $ne ? "<td align=center 
style='border-style:dotted;border-width:1px;' width=\"{$qe}\"></td>" : "";
+               $output = "<table class=\"pr_quality\" 
style=\"line-height:40%;\" border=0 cellpadding=0 cellspacing=0 ><tr>
+<td align=center >&nbsp;</td>
+<td align=center class='quality4' width=\"$q4\"></td>
+<td align=center class='quality3' width=\"$q3\"></td>
+<td align=center class='quality2' width=\"$q2\"></td>
+<td align=center class='quality1' width=\"$q1\"></td>
+<td align=center class='quality0' width=\"$q0\"></td>
+$void_cell
+<td ><span id=pr_index style=\"visibility:hidden;\">$indexlink</span></td>
+</tr></table>";
                $out->setSubtitle( $out->getSubtitle() . $output );
                return true;
        }



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to