Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -100,7 +100,6 @@ |
101 | 101 | $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL(); |
102 | 102 | $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL(); |
103 | 103 | |
104 | | - //todo : we should read pagenum from the index if it is provided |
105 | 104 | $title->pr_page_num = "$pagenr"; |
106 | 105 | |
107 | 106 | if( !$title->pr_index_title ) { |
— | — | @@ -146,7 +145,6 @@ |
147 | 146 | $next_name = "$page_namespace:$name/" . ( $pagenr + 1 ); |
148 | 147 | $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL(); |
149 | 148 | $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL(); |
150 | | - $page_num = $pagenr; |
151 | 149 | |
152 | 150 | if( !$index_title ) { |
153 | 151 | //there is no index, or the page is not listed in the index : use canonical index |
— | — | @@ -154,7 +152,6 @@ |
155 | 153 | } |
156 | 154 | } |
157 | 155 | else { |
158 | | - $page_num = ''; |
159 | 156 | $prev_url = ''; |
160 | 157 | $next_url = ''; |
161 | 158 | } |
— | — | @@ -178,7 +175,7 @@ |
179 | 176 | |
180 | 177 | /* |
181 | 178 | 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 |
183 | 180 | */ |
184 | 181 | |
185 | 182 | function pr_parse_index($index_title, $page_title){ |
— | — | @@ -197,27 +194,42 @@ |
198 | 195 | $attributes = array(); |
199 | 196 | |
200 | 197 | if($page_title){ |
| 198 | + //find page number, previous and next pages |
201 | 199 | |
202 | 200 | //default pagenum was set during load() |
203 | 201 | if($page_title->pr_page_num) $attributes["pagenum"] = $page_title->pr_page_num; |
204 | 202 | |
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{ |
207 | 215 | |
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 | + } |
214 | 226 | } |
| 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 | + } |
215 | 233 | } |
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 | | - } |
222 | 234 | } |
223 | 235 | |
224 | 236 | $var_names = explode(" ", wfMsgForContent('proofreadpage_js_attributes') ); |
— | — | @@ -537,10 +549,63 @@ |
538 | 550 | } |
539 | 551 | |
540 | 552 | |
| 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 | + |
541 | 607 | function pr_renderPageList( $input, $args ) { |
542 | 608 | |
543 | 609 | global $wgUser, $wgTitle; |
544 | | - |
545 | 610 | wfLoadExtensionMessages( 'ProofreadPage' ); |
546 | 611 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
547 | 612 | if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) { |
— | — | @@ -593,50 +658,13 @@ |
594 | 659 | |
595 | 660 | $sk = $wgUser->getSkin(); |
596 | 661 | |
597 | | - $offset = 0; |
598 | | - $mode = 'normal'; |
599 | 662 | for( $i=1; $i<$count+1 ; $i++) { |
600 | 663 | |
601 | 664 | $pdbk = "$page_namespace:$name" . '/'. $i ; |
602 | | - //default |
603 | | - $mode = 'normal'; |
604 | | - $links = true; |
| 665 | + list( $view, $links, $mode ) = pr_pageNumber($i,$args); |
605 | 666 | |
606 | | - foreach ( $args as $num => $param ) { |
| 667 | + if($mode == 'highroman' || $mode == 'roman') $view = ' '.$view; |
607 | 668 | |
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 = ' '.toRoman($view); |
635 | | - elseif($mode == 'roman') $view = ' '.strtolower(toRoman($view)); |
636 | | - elseif($mode == 'normal') $view = ''.$view; |
637 | | - elseif($mode == 'empty') $view = ''.$view; |
638 | | - else $view = $mode; |
639 | | - |
640 | | - |
641 | 669 | $n = strlen($count) - strlen($view); |
642 | 670 | if( $n && ($mode == 'normal' || $mode == 'empty') ){ |
643 | 671 | $txt = '<span style="visibility:hidden;">'; |