r50521 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50520‎ | r50521 | r50522 >
Date:16:48, 12 May 2009
Author:thomasv
Status:ok
Tags:
Comment:
fix page numbering for djvu files
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -100,7 +100,6 @@
101101 $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL();
102102 $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL();
103103
104 - //todo : we should read pagenum from the index if it is provided
105104 $title->pr_page_num = "$pagenr";
106105
107106 if( !$title->pr_index_title ) {
@@ -146,7 +145,6 @@
147146 $next_name = "$page_namespace:$name/" . ( $pagenr + 1 );
148147 $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL();
149148 $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL();
150 - $page_num = $pagenr;
151149
152150 if( !$index_title ) {
153151 //there is no index, or the page is not listed in the index : use canonical index
@@ -154,7 +152,6 @@
155153 }
156154 }
157155 else {
158 - $page_num = '';
159156 $prev_url = '';
160157 $next_url = '';
161158 }
@@ -178,7 +175,7 @@
179176
180177 /*
181178 read metadata from the index page
182 - read also pagenum if page_title is provided (not for djvu with pagelist)
 179+ if page_title is provided, return page number, previous and next pages
183180 */
184181
185182 function pr_parse_index($index_title, $page_title){
@@ -197,27 +194,42 @@
198195 $attributes = array();
199196
200197 if($page_title){
 198+ //find page number, previous and next pages
201199
202200 //default pagenum was set during load()
203201 if($page_title->pr_page_num) $attributes["pagenum"] = $page_title->pr_page_num;
204202
205 - $tag_pattern = "/\[\[($page_namespace:.*?)(\|(.*?)|)\]\]/i";
206 - preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER );
 203+ //check if it is using pagelist
 204+ preg_match( "/<pagelist(.*?)\/>/i", $text, $m );
 205+ if($m){
 206+ preg_match_all( "/([0-9a-z]*?)\=(.*?)\s/", $m[1]." ", $m2, PREG_PATTERN_ORDER );
 207+ $params = array();
 208+ for( $i=0; $i<count( $m2[1] ); $i++) {
 209+ $params[ $m2[1][$i] ] = $m2[2][$i];
 210+ }
 211+ list($view, $links, $mode) = pr_pageNumber($page_title->pr_page_num,$params);
 212+ $attributes["pagenum"] = $view;
 213+ }
 214+ else{
207215
208 - for( $i=0; $i<count( $links[1] ); $i++) {
209 - $a_title = Title::newFromText( $links[1][$i] );
210 - if(!$a_title) continue;
211 - if( $a_title->getPrefixedText() == $page_title->getPrefixedText() ) {
212 - $attributes["pagenum"] = $links[3][$i];
213 - break;
 216+ $tag_pattern = "/\[\[($page_namespace:.*?)(\|(.*?)|)\]\]/i";
 217+ preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER );
 218+
 219+ for( $i=0; $i<count( $links[1] ); $i++) {
 220+ $a_title = Title::newFromText( $links[1][$i] );
 221+ if(!$a_title) continue;
 222+ if( $a_title->getPrefixedText() == $page_title->getPrefixedText() ) {
 223+ $attributes["pagenum"] = $links[3][$i];
 224+ break;
 225+ }
214226 }
 227+ if( ($i>0) && ($i<count($links[1])) ){
 228+ $prev_title = Title::newFromText( $links[1][$i-1] );
 229+ }
 230+ if( ($i>=0) && ($i+1<count($links[1])) ){
 231+ $next_title = Title::newFromText( $links[1][$i+1] );
 232+ }
215233 }
216 - if( ($i>0) && ($i<count($links[1])) ){
217 - $prev_title = Title::newFromText( $links[1][$i-1] );
218 - }
219 - if( ($i>=0) && ($i+1<count($links[1])) ){
220 - $next_title = Title::newFromText( $links[1][$i+1] );
221 - }
222234 }
223235
224236 $var_names = explode(" ", wfMsgForContent('proofreadpage_js_attributes') );
@@ -537,10 +549,63 @@
538550 }
539551
540552
 553+
 554+function pr_pageNumber($i,$args){
 555+ $mode = 'normal'; //default
 556+ $offset = 0;
 557+ $links = true;
 558+ foreach ( $args as $num => $param ) {
 559+
 560+ if( ( preg_match( "/^([0-9]*)to([0-9]*)$/", $num, $m ) && ( $i>=$m[1] && $i<=$m[2] ) )
 561+ || ( is_numeric($num) && ($i == $num) ) ) {
 562+ $params = explode(";",$param);
 563+ foreach ( $params as $iparam ) {
 564+ switch($iparam){
 565+ case 'roman':
 566+ $mode = 'roman';
 567+ break;
 568+ case 'highroman':
 569+ $mode = 'highroman';
 570+ break;
 571+ case 'empty':
 572+ $links = false;
 573+ break;
 574+ default:
 575+ if(!is_numeric($iparam))
 576+ $mode = $iparam;
 577+ }
 578+ }
 579+ }
 580+
 581+ if( is_numeric($num) && ($i >= $num) ) {
 582+ $params = explode(";",$param);
 583+ foreach ( $params as $iparam )
 584+ if(is_numeric($iparam))
 585+ $offset = $num - $iparam;
 586+ }
 587+
 588+ }
 589+ $view = ($i - $offset);
 590+ switch($mode) {
 591+ case 'highroman':
 592+ $view = toRoman($view); break;
 593+ case 'roman':
 594+ $view = strtolower(toRoman($view)); break;
 595+ case 'normal':
 596+ $view = ''.$view; break;
 597+ case 'empty':
 598+ $view = ''.$view; break;
 599+ default:
 600+ $view = $mode;
 601+ }
 602+ return array($view,$links,$mode);
 603+}
 604+
 605+
 606+
541607 function pr_renderPageList( $input, $args ) {
542608
543609 global $wgUser, $wgTitle;
544 -
545610 wfLoadExtensionMessages( 'ProofreadPage' );
546611 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
547612 if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) {
@@ -593,50 +658,13 @@
594659
595660 $sk = $wgUser->getSkin();
596661
597 - $offset = 0;
598 - $mode = 'normal';
599662 for( $i=1; $i<$count+1 ; $i++) {
600663
601664 $pdbk = "$page_namespace:$name" . '/'. $i ;
602 - //default
603 - $mode = 'normal';
604 - $links = true;
 665+ list( $view, $links, $mode ) = pr_pageNumber($i,$args);
605666
606 - foreach ( $args as $num => $param ) {
 667+ if($mode == 'highroman' || $mode == 'roman') $view = '&nbsp;'.$view;
607668
608 - if( ( preg_match( "/^([0-9]*)to([0-9]*)$/", $num, $m ) && ( $i>=$m[1] && $i<=$m[2] ) )
609 - || ( is_numeric($num) && ($i == $num) ) ) {
610 - $params = explode(";",$param);
611 - foreach ( $params as $iparam ) {
612 - switch($iparam){
613 - case 'roman':
614 - $mode = 'roman';
615 - break;
616 - case 'highroman':
617 - $mode = 'highroman';
618 - break;
619 - case 'empty':
620 - $links = false;
621 - break;
622 - default:
623 - if(is_numeric($iparam))
624 - $offset = $i - $iparam;
625 - else
626 - $mode = $iparam;
627 -
628 - }
629 - }
630 - }
631 - }
632 -
633 - $view = ($i - $offset);
634 - if($mode == 'highroman') $view = '&nbsp;'.toRoman($view);
635 - elseif($mode == 'roman') $view = '&nbsp;'.strtolower(toRoman($view));
636 - elseif($mode == 'normal') $view = ''.$view;
637 - elseif($mode == 'empty') $view = ''.$view;
638 - else $view = $mode;
639 -
640 -
641669 $n = strlen($count) - strlen($view);
642670 if( $n && ($mode == 'normal' || $mode == 'empty') ){
643671 $txt = '<span style="visibility:hidden;">';

Status & tagging log