r52693 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52692‎ | r52693 | r52694 >
Date:14:03, 2 July 2009
Author:thomasv
Status:deferred
Tags:
Comment:
check for dupes in index page
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.i18n.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
@@ -19,6 +19,8 @@
2020 'proofreadpage_nosuch_file' => 'Error: no such file',
2121 'proofreadpage_badpage' => 'Wrong Format',
2222 '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.',
2325 'proofreadpage_nologin' => 'Not logged in',
2426 'proofreadpage_nologintext' => 'You must be [[Special:UserLogin|logged in]] to modify the proofreading status of pages.',
2527 'proofreadpage_notallowed' => 'Change not allowed',
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -2,7 +2,6 @@
33
44 /*
55 todo :
6 - - check for dupes in index page : when index is saved
76 - check unicity of the index page : when index is saved too
87 */
98
@@ -239,16 +238,20 @@
240239 * of parameters to pagelist, and a list of attributes.
241240 */
242241 function pr_parse_index( $index_title ){
243 - global $pr_page_namespace, $pr_index_namespace;
244242
245243 $err = array( false, false, array() );
246 -
247244 if ( !$index_title ) return $err;
248245 if ( !$index_title->exists() ) return $err;
249246
250247 $rev = Revision::newFromTitle( $index_title );
251248 $text = $rev->getText();
 249+ return pr_parse_index_text( $text );
 250+}
252251
 252+
 253+function pr_parse_index_text( $text ){
 254+ global $pr_page_namespace, $pr_index_namespace;
 255+
253256 //check if it is using pagelist
254257 preg_match_all( "/<pagelist([^<]*?)\/>/is", $text, $m, PREG_PATTERN_ORDER );
255258 if( $m[1] ) {
@@ -749,15 +752,26 @@
750753
751754 /*
752755 * Check the format of pages in "Page" namespace.
753 - * Todo: check that listed pages are unique for pages in "Index" namespace.
754756 */
755757
756758 function pr_attemptSave( $editpage ) {
757759 global $pr_page_namespace, $pr_index_namespace;
758760 global $wgOut, $wgUser;
759761
 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+
760775 //abort if we are not a page
761 - $title = $editpage->mTitle;
762776 if ( ! preg_match( "/^$pr_page_namespace:(.*)$/", $title->getPrefixedText() ) ) {
763777 return true;
764778 }

Status & tagging log