r55783 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55782‎ | r55783 | r55784 >
Date:19:21, 3 September 2009
Author:thomasv
Status:deferred
Tags:
Comment:
Generation of page headers in the 'pages' command
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -196,7 +196,7 @@
197197 }
198198
199199 //if the index page exists, find current page number, previous and next pages
200 - list( $links, $params, $attributes ) = pr_parse_index($index_title);
 200+ list( $text_links, $links, $params, $attributes ) = pr_parse_index($index_title);
201201
202202 if( $links==null ) {
203203 list($pagenum, $links, $mode) = pr_pageNumber($pagenr,$params);
@@ -269,6 +269,10 @@
270270 preg_match_all( $tag_pattern, $text, $links, PREG_PATTERN_ORDER );
271271 }
272272
 273+ //links in ns-0
 274+ $text_links_pattern = "/\[\[([^:\|]*?)(\|(.*?)|)\]\]/i";
 275+ preg_match_all( $text_links_pattern, $text, $text_links, PREG_PATTERN_ORDER );
 276+
273277 //read attributes
274278 $attributes = array();
275279 $var_names = explode(" ", wfMsgForContent('proofreadpage_js_attributes') );
@@ -282,7 +286,7 @@
283287 $attributes[$var] = '';
284288 }
285289 }
286 - return array( $links, $params, $attributes );
 290+ return array( $text_links, $links, $params, $attributes );
287291
288292 }
289293
@@ -683,7 +687,7 @@
684688
685689 /*
686690 * Parser hook that includes a list of pages.
687 - * It needs 3 parameters : index, from, to
 691+ * parameters : index, from, to, header
688692 */
689693 function pr_renderPages( $input, $args ) {
690694 global $wgParser, $wgTitle;
@@ -693,6 +697,7 @@
694698 $index = $args['index'];
695699 $from = $args['from'];
696700 $to = $args['to'];
 701+ $header = $args['header'];
697702
698703 if( ! $index ) {
699704 return '<strong class="error">' . wfMsgForContent( 'proofreadpage_index_expected' ) . '</strong>';
@@ -703,7 +708,7 @@
704709 }
705710
706711 $out = '';
707 - list( $links, $params, $attributes ) = pr_parse_index( $index_title );
 712+ list( $text_links, $links, $params, $attributes ) = pr_parse_index( $index_title );
708713
709714 if( $links==null ) {
710715 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index );
@@ -742,8 +747,9 @@
743748 } else {
744749 $out.= "{{:".$text."}}";
745750 }
 751+ if( $i == $from ) $from_pagenum = $pagenum;
 752+ if( $i == $to ) $to_pagenum = $pagenum;
746753 }
747 - $out = $wgParser->recursiveTagParse($out);
748754 }
749755 else {
750756 if($from) {
@@ -754,7 +760,10 @@
755761 for( $i=0; $i<count( $links[1] ); $i++) {
756762 $text = $links[1][$i];
757763 $pagenum = $links[3][$i];
758 - if($text == $from ) $adding = true;
 764+ if($text == $from ) {
 765+ $adding = true;
 766+ $from_pagenum = $pagenum;
 767+ }
759768 if($adding){
760769 $out.= "<span>{{:MediaWiki:Proofreadpage_pagenum_template|page="
761770 .$page_namespace.":".$text."|num=$pagenum}}</span>";
@@ -766,10 +775,41 @@
767776 $out.= "{{:".$page_namespace.":".$text."}}";
768777 }
769778 }
770 - if($text == $to ) $adding = false;
 779+ if($text == $to ) {
 780+ $adding = false;
 781+ $to_pagenum = $pagenum;
 782+ }
771783 }
772 - $out = $wgParser->recursiveTagParse($out);
773784 }
 785+
 786+ if( $header ) {
 787+ $h_out = '{{'.$header;
 788+ //find next and previous pages in list
 789+ for( $i=1; $i < count( $text_links[1] ); $i++) {
 790+ if( $text_links[1][$i] == $wgTitle->getPrefixedText() ) {
 791+ $current = $text_links[0][$i];
 792+ break;
 793+ }
 794+ }
 795+ if( ( $i > 1 ) && ( $i < count( $text_links[1] ) ) ) {
 796+ $prev = $text_links[0][$i-1];
 797+ }
 798+ if( ( $i >= 1 ) && ( $i + 1 < count( $text_links[1] ) ) ) {
 799+ $next = $text_links[0][$i+1];
 800+ }
 801+ if( $current ) $h_out .= "|current=$current";
 802+ if( $prev ) $h_out .= "|prev=$prev";
 803+ if( $next ) $h_out .= "|next=$next";
 804+ if( $from_pagenum ) $h_out .= "|from=$from_pagenum";
 805+ if( $to_pagenum ) $h_out .= "|to=$to_pagenum";
 806+ foreach ( $attributes as $key => $val ) {
 807+ $h_out .= "|$key=$val";
 808+ }
 809+ $h_out .= '}}';
 810+ $out = $h_out . $out;
 811+ }
 812+
 813+ $out = $wgParser->recursiveTagParse($out);
774814 return $out;
775815 }
776816
@@ -858,7 +898,7 @@
859899 //check that pages listed on an index are unique.
860900 if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) {
861901 $text = $editpage->textbox1;
862 - list( $links, $params, $attributes ) = pr_parse_index_text($text);
 902+ list( $text_links, $links, $params, $attributes ) = pr_parse_index_text($text);
863903 if( $links!=null && count($links[1]) != count( array_unique($links[1]))) {
864904 $wgOut->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' );
865905 return false;
@@ -1117,7 +1157,7 @@
11181158
11191159 //read the list of pages
11201160 $pages = array();
1121 - list( $links, $params, $attributes ) = pr_parse_index( $index_title );
 1161+ list( $text_links, $links, $params, $attributes ) = pr_parse_index( $index_title );
11221162 if( $links==null ) {
11231163 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index_title->getText() );
11241164 if ( $imageTitle ) {

Status & tagging log