Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php |
— | — | @@ -19,6 +19,8 @@ |
20 | 20 | 'proofreadpage_nosuch_file' => 'Error: no such file', |
21 | 21 | 'proofreadpage_badpage' => 'Wrong Format', |
22 | 22 | 'proofreadpage_badpagetext' => 'The format of the page you attempted to save is incorrect.', |
| 23 | + 'proofreadpage_indexdupe' => 'Duplicate link', |
| 24 | + 'proofreadpage_indexdupetext' => 'Pages cannot be listed more than once on an index page.', |
23 | 25 | 'proofreadpage_nologin' => 'Not logged in', |
24 | 26 | 'proofreadpage_nologintext' => 'You must be [[Special:UserLogin|logged in]] to modify the proofreading status of pages.', |
25 | 27 | 'proofreadpage_notallowed' => 'Change not allowed', |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -2,7 +2,6 @@ |
3 | 3 | |
4 | 4 | /* |
5 | 5 | todo : |
6 | | - - check for dupes in index page : when index is saved |
7 | 6 | - check unicity of the index page : when index is saved too |
8 | 7 | */ |
9 | 8 | |
— | — | @@ -239,16 +238,20 @@ |
240 | 239 | * of parameters to pagelist, and a list of attributes. |
241 | 240 | */ |
242 | 241 | function pr_parse_index( $index_title ){ |
243 | | - global $pr_page_namespace, $pr_index_namespace; |
244 | 242 | |
245 | 243 | $err = array( false, false, array() ); |
246 | | - |
247 | 244 | if ( !$index_title ) return $err; |
248 | 245 | if ( !$index_title->exists() ) return $err; |
249 | 246 | |
250 | 247 | $rev = Revision::newFromTitle( $index_title ); |
251 | 248 | $text = $rev->getText(); |
| 249 | + return pr_parse_index_text( $text ); |
| 250 | +} |
252 | 251 | |
| 252 | + |
| 253 | +function pr_parse_index_text( $text ){ |
| 254 | + global $pr_page_namespace, $pr_index_namespace; |
| 255 | + |
253 | 256 | //check if it is using pagelist |
254 | 257 | preg_match_all( "/<pagelist([^<]*?)\/>/is", $text, $m, PREG_PATTERN_ORDER ); |
255 | 258 | if( $m[1] ) { |
— | — | @@ -749,15 +752,26 @@ |
750 | 753 | |
751 | 754 | /* |
752 | 755 | * Check the format of pages in "Page" namespace. |
753 | | - * Todo: check that listed pages are unique for pages in "Index" namespace. |
754 | 756 | */ |
755 | 757 | |
756 | 758 | function pr_attemptSave( $editpage ) { |
757 | 759 | global $pr_page_namespace, $pr_index_namespace; |
758 | 760 | global $wgOut, $wgUser; |
759 | 761 | |
| 762 | + $title = $editpage->mTitle; |
| 763 | + |
| 764 | + //check that pages liste on an index are unique. |
| 765 | + if ( preg_match( "/^$pr_index_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
| 766 | + $text = $editpage->textbox1; |
| 767 | + list( $links, $params, $attributes ) = pr_parse_index_text($text); |
| 768 | + if( $links!=null && count($links[1]) != count( array_unique($links[1]))) { |
| 769 | + $wgOut->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' ); |
| 770 | + return false; |
| 771 | + }; |
| 772 | + return true; |
| 773 | + } |
| 774 | + |
760 | 775 | //abort if we are not a page |
761 | | - $title = $editpage->mTitle; |
762 | 776 | if ( ! preg_match( "/^$pr_page_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
763 | 777 | return true; |
764 | 778 | } |