Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F8942
test.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
•
bzimport
Nov 22 2014, 12:13 AM
2014-11-22 00:13:25 (UTC+0)
Size
5 KB
Referenced Files
None
Subscribers
None
test.diff
View Options
Index: ProofreadPage_body.php
===================================================================
--- ProofreadPage_body.php (révision 112310)
+++ ProofreadPage_body.php (copie de travail)
@@ -736,6 +736,9 @@
$index = array_key_exists( 'index', $args ) ? $args['index'] : null;
$from = array_key_exists( 'from', $args ) ? $args['from'] : null;
$to = array_key_exists( 'to', $args ) ? $args['to'] : null;
+ $include = array_key_exists( 'include', $args ) ? $args['include'] : null;
+ $exclude = array_key_exists( 'exclude', $args ) ? $args['exclude'] : null;
+ $step = array_key_exists( 'step', $args ) ? $args['step'] : null;
$header = array_key_exists( 'header', $args ) ? $args['header'] : null;
$tosection = array_key_exists( 'tosection', $args ) ? $args['tosection'] : null;
$fromsection = array_key_exists( 'fromsection', $args ) ? $args['fromsection'] : null;
@@ -762,8 +765,9 @@
list( $links, $params, $attributes ) = self::parse_index( $index_title );
- if( $from || $to ) {
+ if( $from || $to || $include ) {
$pages = array();
+
if( $links == null ) {
$imageTitle = Title::makeTitleSafe( NS_IMAGE, $index );
if ( !$imageTitle ) {
@@ -775,36 +779,80 @@
}
$count = $image->pageCount();
- if( !$from ) {
- $from = 1;
+ if( !$step ) {
+ $step = 1;
}
- if( !$to ) {
- $to = $count;
+ if( !is_numeric( $step ) || $step < 1 ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>';
}
- if( !is_numeric( $from ) || !is_numeric( $to ) ) {
- return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>';
+ $pagenums = array();
+
+ //add page selected with $include in pagenums
+ if( $include ) {
+ $list = self::parse_num_list( $include );
+ if( $list == null ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
+ }
+ $pagenums = $list;
}
- if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) {
- return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
+
+ //ad pages selected with form and to in pagenums
+ if( $from || $to ) {
+ if( !$from ) {
+ $from = 1;
+ }
+ if( !$to ) {
+ $to = $count;
+ }
+ if( !is_numeric( $from ) || !is_numeric( $to ) || !is_numeric( $step ) ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>';
+ }
+ if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
+ }
+ if( $to - $from > 1000 ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_interval_too_large' ) . '</strong>';
+ }
+
+ for( $i = $from; $i <= $to; $i++ ) {
+ $pagenums[$i] = $i;
+ }
}
- if( $to - $from > 1000 ) {
+
+ if( count($pagenums) > 1000 ) {
return '<strong class="error">' . wfMsgForContent( 'proofreadpage_interval_too_large' ) . '</strong>';
}
- for( $i = $from; $i <= $to; $i++ ) {
- list( $pagenum, $links, $mode ) = self::pageNumber( $i, $params );
- $page = str_replace( ' ' , '_', "$index/" . $i );
- if( $i == $from ) {
- $from_page = $page;
- $from_pagenum = $pagenum;
+ //remove excluded pages form $pagenums
+ if( $exclude ) {
+ $excluded = self::parse_num_list( $exclude );
+ if( $excluded == null ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
}
- if( $i == $to ) {
- $to_page = $page;
- $to_pagenum = $pagenum;
+ $pagenums = array_diff( $pagenums, $excluded );
+ }
+
+
+ ksort( $pagenums ); //we must sort the array even if the numerical keys are in a good order.
+ if( reset( $pagenums ) > $count ) {
+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
+ }
+
+ //Create the list of pages to translude. the step system start with the smaller pagenum
+ $mod = reset( $pagenums ) % $step;
+ foreach( $pagenums as $num ) {
+ if( $step != 1 && $num % $step != $mod ) {
+ continue;
}
- $pages[] = array( $page, $pagenum );
+ list( $pagenum, $links, $mode ) = self::pageNumber( $num, $params );
+ $page = str_replace( ' ' , '_', "$index/" . $num );
+ $pages[] = array($page, $pagenum);
}
+
+ list( $from_page, $from_pagenum ) = end( $pages );
+ list( $to_page, $to_pagenum ) = reset( $pages );
+
} else {
if( $from ) {
$adding = false;
@@ -971,6 +1019,29 @@
}
/**
+ * Parse a list of page number like 1-10,23 . Return null if there is an error.
+ */
+ private static function parse_num_list($input) {
+ $input = str_replace(array(' ', '\t', '\n'), '', $input);
+ $list = explode( ',', $input );
+ $nums = array();
+ foreach( $list as $item ) {
+ if( is_numeric( $item ) ) {
+ $nums[$item] = $item;
+ } else {
+ $interval = explode( '-', $item );
+ if( count( $interval ) != 2 || !is_numeric( $interval[0] ) || !is_numeric( $interval[1] ) || $interval[1] < $interval[0] || $interval[1] - $interval[0] > 1000) {
+ return null;
+ }
+ for( $i = $interval[0]; $i <= $interval[1]; $i += 1 ) {
+ $nums[$i] = $i;
+ }
+ }
+ }
+ return $nums;
+ }
+
+ /**
* Set is_toc flag (true if page is a table of contents)
*/
public static function onOutputPageParserOutput( $outputPage, $parserOutput ) {
@@ -1479,6 +1550,7 @@
}
}
+ $n = 0;
if( isset( $out->is_toc ) && $out->is_toc ) {
if ( $indextitle ) {
$res = $dbr->select(
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8457
Default Alt Text
test.diff (5 KB)
Attached To
Mode
T36689: Add step property to the pages tag
Attached
Detach File
Event Timeline
Log In to Comment