Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php |
— | — | @@ -736,6 +736,9 @@ |
737 | 737 | $index = array_key_exists( 'index', $args ) ? $args['index'] : null; |
738 | 738 | $from = array_key_exists( 'from', $args ) ? $args['from'] : null; |
739 | 739 | $to = array_key_exists( 'to', $args ) ? $args['to'] : null; |
| 740 | + $include = array_key_exists( 'include', $args ) ? $args['include'] : null; |
| 741 | + $exclude = array_key_exists( 'exclude', $args ) ? $args['exclude'] : null; |
| 742 | + $step = array_key_exists( 'step', $args ) ? $args['step'] : null; |
740 | 743 | $header = array_key_exists( 'header', $args ) ? $args['header'] : null; |
741 | 744 | $tosection = array_key_exists( 'tosection', $args ) ? $args['tosection'] : null; |
742 | 745 | $fromsection = array_key_exists( 'fromsection', $args ) ? $args['fromsection'] : null; |
— | — | @@ -762,8 +765,9 @@ |
763 | 766 | |
764 | 767 | list( $links, $params, $attributes ) = self::parse_index( $index_title ); |
765 | 768 | |
766 | | - if( $from || $to ) { |
| 769 | + if( $from || $to || $include ) { |
767 | 770 | $pages = array(); |
| 771 | + |
768 | 772 | if( $links == null ) { |
769 | 773 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index ); |
770 | 774 | if ( !$imageTitle ) { |
— | — | @@ -775,36 +779,75 @@ |
776 | 780 | } |
777 | 781 | $count = $image->pageCount(); |
778 | 782 | |
779 | | - if( !$from ) { |
780 | | - $from = 1; |
| 783 | + if( !$step ) { |
| 784 | + $step = 1; |
781 | 785 | } |
782 | | - if( !$to ) { |
783 | | - $to = $count; |
| 786 | + if( !is_numeric( $step ) || $step < 1 ) { |
| 787 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>'; |
784 | 788 | } |
785 | 789 | |
786 | | - if( !is_numeric( $from ) || !is_numeric( $to ) ) { |
787 | | - return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>'; |
| 790 | + $pagenums = array(); |
| 791 | + |
| 792 | + //add page selected with $include in pagenums |
| 793 | + if( $include ) { |
| 794 | + $list = self::parse_num_list( $include ); |
| 795 | + if( $list == null ) { |
| 796 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
| 797 | + } |
| 798 | + $pagenums = $list; |
788 | 799 | } |
789 | | - if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) { |
790 | | - return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
| 800 | + |
| 801 | + //ad pages selected with form and to in pagenums |
| 802 | + if( $from || $to ) { |
| 803 | + if( !$from ) { |
| 804 | + $from = 1; |
| 805 | + } |
| 806 | + if( !$to ) { |
| 807 | + $to = $count; |
| 808 | + } |
| 809 | + if( !is_numeric( $from ) || !is_numeric( $to ) || !is_numeric( $step ) ) { |
| 810 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>'; |
| 811 | + } |
| 812 | + if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) { |
| 813 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
| 814 | + } |
| 815 | + |
| 816 | + for( $i = $from; $i <= $to; $i++ ) { |
| 817 | + $pagenums[$i] = $i; |
| 818 | + } |
791 | 819 | } |
792 | | - if( $to - $from > 1000 ) { |
| 820 | + |
| 821 | + //remove excluded pages form $pagenums |
| 822 | + if( $exclude ) { |
| 823 | + $excluded = self::parse_num_list( $exclude ); |
| 824 | + if( $excluded == null ) { |
| 825 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
| 826 | + } |
| 827 | + $pagenums = array_diff( $pagenums, $excluded ); |
| 828 | + } |
| 829 | + |
| 830 | + if( count($pagenums)/$step > 1000 ) { |
793 | 831 | return '<strong class="error">' . wfMsgForContent( 'proofreadpage_interval_too_large' ) . '</strong>'; |
794 | 832 | } |
795 | 833 | |
796 | | - for( $i = $from; $i <= $to; $i++ ) { |
797 | | - list( $pagenum, $links, $mode ) = self::pageNumber( $i, $params ); |
798 | | - $page = str_replace( ' ' , '_', "$index/" . $i ); |
799 | | - if( $i == $from ) { |
800 | | - $from_page = $page; |
801 | | - $from_pagenum = $pagenum; |
| 834 | + ksort( $pagenums ); //we must sort the array even if the numerical keys are in a good order. |
| 835 | + if( reset( $pagenums ) > $count ) { |
| 836 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
| 837 | + } |
| 838 | + |
| 839 | + //Create the list of pages to translude. the step system start with the smaller pagenum |
| 840 | + $mod = reset( $pagenums ) % $step; |
| 841 | + foreach( $pagenums as $num ) { |
| 842 | + if( $step == 1 || $num % $step == $mod ) { |
| 843 | + list( $pagenum, $links, $mode ) = self::pageNumber( $num, $params ); |
| 844 | + $page = str_replace( ' ' , '_', "$index/" . $num ); |
| 845 | + $pages[] = array($page, $pagenum); |
802 | 846 | } |
803 | | - if( $i == $to ) { |
804 | | - $to_page = $page; |
805 | | - $to_pagenum = $pagenum; |
806 | | - } |
807 | | - $pages[] = array( $page, $pagenum ); |
808 | 847 | } |
| 848 | + |
| 849 | + list( $from_page, $from_pagenum ) = end( $pages ); |
| 850 | + list( $to_page, $to_pagenum ) = reset( $pages ); |
| 851 | + |
809 | 852 | } else { |
810 | 853 | if( $from ) { |
811 | 854 | $adding = false; |
— | — | @@ -971,6 +1014,35 @@ |
972 | 1015 | } |
973 | 1016 | |
974 | 1017 | /** |
| 1018 | + * Parse a comma-separated list of pages. A dash indicates an interval of pages |
| 1019 | + * example: 1-10,23,38 |
| 1020 | + * Return an array of pages, or null if the input does not comply to the syntax |
| 1021 | + */ |
| 1022 | + private static function parse_num_list($input) { |
| 1023 | + $input = str_replace(array(' ', '\t', '\n'), '', $input); |
| 1024 | + $list = explode( ',', $input ); |
| 1025 | + $nums = array(); |
| 1026 | + foreach( $list as $item ) { |
| 1027 | + if( is_numeric( $item ) ) { |
| 1028 | + $nums[$item] = $item; |
| 1029 | + } else { |
| 1030 | + $interval = explode( '-', $item ); |
| 1031 | + if( count( $interval ) != 2 |
| 1032 | + || !is_numeric( $interval[0] ) |
| 1033 | + || !is_numeric( $interval[1] ) |
| 1034 | + || $interval[1] < $interval[0] |
| 1035 | + ) { |
| 1036 | + return null; |
| 1037 | + } |
| 1038 | + for( $i = $interval[0]; $i <= $interval[1]; $i += 1 ) { |
| 1039 | + $nums[$i] = $i; |
| 1040 | + } |
| 1041 | + } |
| 1042 | + } |
| 1043 | + return $nums; |
| 1044 | + } |
| 1045 | + |
| 1046 | + /** |
975 | 1047 | * Set is_toc flag (true if page is a table of contents) |
976 | 1048 | */ |
977 | 1049 | public static function onOutputPageParserOutput( $outputPage, $parserOutput ) { |