Rtdwivedi has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/69973


Change subject: Editing system for pages separated.
......................................................................

Editing system for pages separated.

Change-Id: I2ec8b7423b083966e6fd1fb5c73b7f4d194f04b1
---
M ProofreadPage.body.php
M ProofreadPage.php
A includes/EditProofreadPage.php
3 files changed, 203 insertions(+), 201 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/73/69973/1

diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php
index 4ed4565..75e4306 100644
--- a/ProofreadPage.body.php
+++ b/ProofreadPage.body.php
@@ -101,24 +101,6 @@
        }
 
        /**
-        * Set up our custom edition system.
-        *
-        * @param Article $article  being edited
-        * @param User $user User performing the edit
-        * @return boolean hook return value
-        */
-       public static function onCustomEditor( $article, $user ) {
-               global $request;
-               if ( $article->getTitle()->inNamespace( 
self::getIndexNamespaceId() ) ) { //TODO ExternalEditor case
-                       $editor = new EditProofreadIndexPage( $article );
-                       $editor->edit();
-                       return false;
-               } else {
-                       return true;
-               }
-       }
-
-       /**
         * Set up our custom parser hooks when initializing parser.
         *
         * @param Parser $parser
@@ -936,112 +918,6 @@
        }
 
        /**
-        * @param $editpage EditPage
-        * @param $request WebRequest
-        * @return bool
-        */
-       public static function onEditPageImportFormData( $editpage, $request ) {
-               $title = $editpage->getTitle();
-               // abort if we are not a page
-               if ( !$title->inNamespace( self::getPageNamespaceId() ) ) {
-                       return true;
-               }
-               if ( !$request->wasPosted() ) {
-                       return true;
-               }
-               $editpage->quality = $request->getVal( 'wpQuality' );
-               $editpage->username = $editpage->safeUnicodeInput( $request, 
'wpProofreader' );
-               $editpage->header = $editpage->safeUnicodeInput( $request, 
'wpHeaderTextbox' );
-               $editpage->footer = $editpage->safeUnicodeInput( $request, 
'wpFooterTextbox' );
-
-               // we want to keep ordinary spaces at the end of the main 
textbox
-               $text = rtrim( $request->getText( 'wpTextbox1' ), 
"\t\n\r\0\x0B" );
-               $editpage->textbox1 = $request->getBool( 'safemode' )
-                       ? $editpage->unmakesafe( $text )
-                       : $text;
-
-               if( in_array( $editpage->quality, array( '0', '1', '2', '3', 
'4' ) ) ) {
-                       // format the page
-                       $text = '<noinclude><pagequality level="' . 
$editpage->quality . '" user="' . $editpage->username . '" />' .
-                               '<div class="pagetext">' . 
$editpage->header."\n\n\n</noinclude>" .
-                               $editpage->textbox1 .
-                               "<noinclude>" . $editpage->footer . 
'</div></noinclude>';
-                       $editpage->textbox1 = $text;
-               } else {
-                       // replace deprecated template
-                       $text = $editpage->textbox1;
-                       $text = preg_replace(
-                               
"/\{\{PageQuality\|(0|1|2|3|4)(|\|(.*?))\}\}/is",
-                               "<pagequality level=\"\\1\" user=\"\\3\" />",
-                               $text
-                       );
-                       $editpage->textbox1 = $text;
-               }
-               return true;
-       }
-
-       /**
-        * Check the format of pages in "Page" namespace.
-        *
-        * @param $editpage EditPage
-        * @return Boolean
-        */
-       public static function onEditPageAttemptSave( $editpage ) {
-               global $wgOut, $wgUser;
-
-               $title = $editpage->mTitle;
-
-               // abort if we are not a page
-               if ( !$title->inNamespace( self::getPageNamespaceId() ) ) {
-                       return true;
-               }
-
-               $text = $editpage->textbox1;
-               // parse the page
-               list( $q, $username, $ptext ) = self::parse_page( $text, $title 
);
-               if( $q == -1 ) {
-                       $editpage->textbox1 = $ptext;
-                       $q = 1;
-               }
-
-               // read previous revision, so that I know how much I need to 
add to pr_index
-               $rev = Revision::newFromTitle( $title, false, 
Revision::READ_LATEST );
-               if( $rev ) {
-                       $old_text = $rev->getText();
-                       list( $old_q, $old_username, $old_ptext ) = 
self::parse_page( $old_text, $title );
-                       if( $old_q != -1 ) {
-                               // check usernames
-                               if( ( $old_q != $q ) && !$wgUser->isAllowed( 
'pagequality' ) ) {
-                                       $wgOut->showErrorPage( 
'proofreadpage_nologin', 'proofreadpage_nologintext' );
-                                       return false;
-                               }
-                               if ( ( ( $old_username != $username ) || ( 
$old_q != $q ) ) && ( $wgUser->getName() != $username ) ) {
-                                       $wgOut->showErrorPage( 
'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
-                                       return false;
-                               }
-                               if( ( ( $q == 4 ) && ( $old_q < 3 ) ) || ( ( $q 
== 4 ) && ( $old_q == 3 ) && ( $old_username == $username ) ) ) {
-                                       $wgOut->showErrorPage( 
'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
-                                       return false;
-                               }
-                       } else {
-                               $old_q = 1;
-                       }
-               } else {
-                       if( $q == 4 ) {
-                               $wgOut->showErrorPage( 
'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
-                               return false;
-                       }
-                       $old_q = -1;
-               }
-
-               $editpage->getArticle()->new_q = $q;
-               $editpage->getArticle()->old_q = $old_q;
-
-               return true;
-       }
-
-
-       /**
         * Updates index data for an index referencing the specified page.
         * @param $title Title: page title object
         * @param $deleted Boolean: indicates whether the page was deleted
@@ -1098,78 +974,6 @@
                        self::updateIndexOfPage( $title );
                }
 
-               return true;
-       }
-
-       /**
-        * @param $article Article
-        * @return bool
-        */
-       public static function onArticleSaveComplete( $article ) {
-               $title = $article->getTitle();
-
-               // if it's an index, update pr_index table
-               if ( $title->inNamespace( self::getIndexNamespaceId() ) ) {
-                       self::update_pr_index( $article );
-                       return true;
-               }
-
-               // return if it is not a page
-               if ( !$title->inNamespace( self::getPageNamespaceId() ) ) {
-                       return true;
-               }
-
-               /* check if there is an index */
-               if ( !isset( $title->prpIndexPage ) ) {
-                       self::loadIndex( $title );
-               }
-               if( $title->prpIndexPage === null ) {
-                       return true;
-               }
-
-               /**
-                * invalidate the cache of the index page
-                */
-               $title->prpIndexPage->getTitle()->invalidateCache();
-
-               /**
-                * update pr_index iteratively
-                */
-               $indexId = $title->prpIndexPage->getTitle()->getArticleID();
-               $x = ProofreadPageDbConnector::getIndexDataFromIndexPageId( 
$indexId );
-               if( $x ) {
-                       $a = ProofreadIndexDbConnector::replaceIndexById( $x, 
$indexId );
-               }
-
-               return true;
-       }
-
-       /**
-        * Preload text layer from multipage formats
-        * @param $textbox1
-        * @param $mTitle Title
-        * @return bool
-        */
-       public static function onEditFormPreloadText( &$textbox1, $mTitle ) {
-               global $wgContLang;
-
-               list( $page_namespace, $index_namespace ) = 
self::getPageAndIndexNamespace();
-               if ( preg_match( "/^$page_namespace:(.*?)\/(.*?)$/", 
$mTitle->getPrefixedText(), $m ) ) {
-                       $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] );
-                       if ( !$imageTitle ) {
-                               return true;
-                       }
-
-                       $image = wfFindFile( $imageTitle );
-                       if ( $image && $image->exists() ) {
-                               $text = $image->getHandler()->getPageText( 
$image, $wgContLang->parseFormattedNumber( $m[2] ) );
-                               if ( $text ) {
-                                       $text = preg_replace( "/(\\\\n)/", 
"\n", $text );
-                                       $text = preg_replace( "/(\\\\\d*)/", 
'', $text );
-                                       $textbox1 = $text;
-                               }
-                       }
-               }
                return true;
        }
 
diff --git a/ProofreadPage.php b/ProofreadPage.php
index 5aab7a4..1b574f9 100644
--- a/ProofreadPage.php
+++ b/ProofreadPage.php
@@ -138,20 +138,20 @@
 $wgHooks['BeforePageDisplay'][] = 'ProofreadPage::onBeforePageDisplay';
 $wgHooks['GetLinkColours'][] = 'ProofreadPage::onGetLinkColours';
 $wgHooks['ImageOpenShowImageInlineBefore'][] = 
'ProofreadPage::onImageOpenShowImageInlineBefore';
-$wgHooks['EditPage::attemptSave'][] = 'ProofreadPage::onEditPageAttemptSave';
-$wgHooks['ArticleSaveComplete'][] = 'ProofreadPage::onArticleSaveComplete';
+$wgHooks['EditPage::attemptSave'][] = 
'EditProofreadPage::onEditPageAttemptSave';
+$wgHooks['ArticleSaveComplete'][] = 'EditProofreadPage::onArticleSaveComplete';
 $wgHooks['ArticleDelete'][] = 'ProofreadPage::onArticleDelete';
 $wgHooks['ArticleUndelete'][] = 'ProofreadPage::onArticleUndelete';
-$wgHooks['EditFormPreloadText'][] = 'ProofreadPage::onEditFormPreloadText';
+$wgHooks['EditFormPreloadText'][] = 'EditProofreadPage::onEditFormPreloadText';
 $wgHooks['ArticlePurge'][] = 'ProofreadPage::onArticlePurge';
 $wgHooks['SpecialMovepageAfterMove'][] = 
'ProofreadPage::onSpecialMovepageAfterMove';
 $wgHooks['LoadExtensionSchemaUpdates'][] = 
'ProofreadIndexDbConnector::onLoadExtensionSchemaUpdates';
-$wgHooks['EditPage::importFormData'][] = 
'ProofreadPage::onEditPageImportFormData';
+$wgHooks['EditPage::importFormData'][] = 
'EditProofreadPage::onEditPageImportFormData';
 $wgHooks['OutputPageParserOutput'][] = 
'ProofreadPage::onOutputPageParserOutput';
 $wgHooks['wgQueryPages'][] = 'ProofreadPage::onwgQueryPages';
 $wgHooks['GetPreferences'][] = 'ProofreadPage::onGetPreferences';
 $wgHooks['LinksUpdateConstructed'][] = 
'ProofreadPage::onLinksUpdateConstructed';
-$wgHooks['CustomEditor'][] = 'ProofreadPage::onCustomEditor';
+$wgHooks['CustomEditor'][] = 'EditProofreadPage::onCustomEditor';
 $wgHooks['CanonicalNamespaces'][] = 'ProofreadPage::addCanonicalNamespaces';
 
 
diff --git a/includes/EditProofreadPage.php b/includes/EditProofreadPage.php
new file mode 100644
index 0000000..455b4cc
--- /dev/null
+++ b/includes/EditProofreadPage.php
@@ -0,0 +1,198 @@
+<?php
+
+class EditProofreadPage extends EditPage {
+       /**
+        * @param $article Article
+        * @return bool
+        */
+       public static function onArticleSaveComplete( $article ) {
+               $title = $article->getTitle();
+
+               // if it's an index, update pr_index table
+               if ( $title->inNamespace( ProofreadPage::getIndexNamespaceId() 
) ) {
+                       ProofreadPage::update_pr_index( $article );
+                       return true;
+               }
+
+               // return if it is not a page
+               if ( !$title->inNamespace( ProofreadPage::getPageNamespaceId() 
) ) {
+                       return true;
+               }
+
+               /* check if there is an index */
+               if ( !isset( $title->prpIndexPage ) ) {
+                       ProofreadPage::loadIndex( $title );
+               }
+               if( $title->prpIndexPage === null ) {
+                       return true;
+               }
+
+               /**
+                * invalidate the cache of the index page
+                */
+               $title->prpIndexPage->getTitle()->invalidateCache();
+
+               /**
+                * update pr_index iteratively
+                */
+               $indexId = $title->prpIndexPage->getTitle()->getArticleID();
+               $x = ProofreadPageDbConnector::getIndexDataFromIndexPageId( 
$indexId );
+               if( $x ) {
+                       $a = ProofreadIndexDbConnector::replaceIndexById( $x, 
$indexId );
+               }
+
+               return true;
+       }
+
+       /**
+        * Preload text layer from multipage formats
+        * @param $textbox1
+        * @param $mTitle Title
+        * @return bool
+        */
+       public static function onEditFormPreloadText( &$textbox1, $mTitle ) {
+               global $wgContLang;
+
+               list( $page_namespace, $index_namespace ) = 
ProofreadPage::getPageAndIndexNamespace();
+               if ( preg_match( "/^$page_namespace:(.*?)\/(.*?)$/", 
$mTitle->getPrefixedText(), $m ) ) {
+                       $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] );
+                       if ( !$imageTitle ) {
+                               return true;
+                       }
+
+                       $image = wfFindFile( $imageTitle );
+                       if ( $image && $image->exists() ) {
+                               $text = $image->getHandler()->getPageText( 
$image, $wgContLang->parseFormattedNumber( $m[2] ) );
+                               if ( $text ) {
+                                       $text = preg_replace( "/(\\\\n)/", 
"\n", $text );
+                                       $text = preg_replace( "/(\\\\\d*)/", 
'', $text );
+                                       $textbox1 = $text;
+                               }
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * Set up our custom edition system.
+        *
+        * @param Article $article  being edited
+        * @param User $user User performing the edit
+        * @return boolean hook return value
+        */
+       public static function onCustomEditor( $article, $user ) {
+               global $request;
+               if ( $article->getTitle()->inNamespace( 
ProofreadPage::getIndexNamespaceId() ) ) { //TODO ExternalEditor case
+                       $editor = new EditProofreadIndexPage( $article );
+                       $editor->edit();
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+
+       /**
+        * @param $editpage EditPage
+        * @param $request WebRequest
+        * @return bool
+        */
+       public static function onEditPageImportFormData( $editpage, $request ) {
+               $title = $editpage->getTitle();
+               // abort if we are not a page
+               if ( !$title->inNamespace( ProofreadPage::getPageNamespaceId() 
) ) {
+                       return true;
+               }
+               if ( !$request->wasPosted() ) {
+                       return true;
+               }
+               $editpage->quality = $request->getVal( 'wpQuality' );
+               $editpage->username = $editpage->safeUnicodeInput( $request, 
'wpProofreader' );
+               $editpage->header = $editpage->safeUnicodeInput( $request, 
'wpHeaderTextbox' );
+               $editpage->footer = $editpage->safeUnicodeInput( $request, 
'wpFooterTextbox' );
+
+               // we want to keep ordinary spaces at the end of the main 
textbox
+               $text = rtrim( $request->getText( 'wpTextbox1' ), 
"\t\n\r\0\x0B" );
+               $editpage->textbox1 = $request->getBool( 'safemode' )
+                       ? $editpage->unmakesafe( $text )
+                       : $text;
+
+               if( in_array( $editpage->quality, array( '0', '1', '2', '3', 
'4' ) ) ) {
+                       // format the page
+                       $text = '<noinclude><pagequality level="' . 
$editpage->quality . '" user="' . $editpage->username . '" />' .
+                               '<div class="pagetext">' . 
$editpage->header."\n\n\n</noinclude>" .
+                               $editpage->textbox1 .
+                               "<noinclude>" . $editpage->footer . 
'</div></noinclude>';
+                       $editpage->textbox1 = $text;
+               } else {
+                       // replace deprecated template
+                       $text = $editpage->textbox1;
+                       $text = preg_replace(
+                               
"/\{\{PageQuality\|(0|1|2|3|4)(|\|(.*?))\}\}/is",
+                               "<pagequality level=\"\\1\" user=\"\\3\" />",
+                               $text
+                       );
+                       $editpage->textbox1 = $text;
+               }
+               return true;
+       }
+
+       /**
+        * Check the format of pages in "Page" namespace.
+        *
+        * @param $editpage EditPage
+        * @return Boolean
+        */
+       public static function onEditPageAttemptSave( $editpage ) {
+               global $wgOut, $wgUser;
+
+               $title = $editpage->mTitle;
+
+               // abort if we are not a page
+               if ( !$title->inNamespace( ProofreadPage::getPageNamespaceId() 
) ) {
+                       return true;
+               }
+
+               $text = $editpage->textbox1;
+               // parse the page
+               list( $q, $username, $ptext ) = ProofreadPage::parse_page( 
$text, $title );
+               if( $q == -1 ) {
+                       $editpage->textbox1 = $ptext;
+                       $q = 1;
+               }
+
+               // read previous revision, so that I know how much I need to 
add to pr_index
+               $rev = Revision::newFromTitle( $title, false, 
Revision::READ_LATEST );
+               if( $rev ) {
+                       $old_text = $rev->getText();
+                       list( $old_q, $old_username, $old_ptext ) = 
ProofreadPage::parse_page( $old_text, $title );
+                       if( $old_q != -1 ) {
+                               // check usernames
+                               if( ( $old_q != $q ) && !$wgUser->isAllowed( 
'pagequality' ) ) {
+                                       $wgOut->showErrorPage( 
'proofreadpage_nologin', 'proofreadpage_nologintext' );
+                                       return false;
+                               }
+                               if ( ( ( $old_username != $username ) || ( 
$old_q != $q ) ) && ( $wgUser->getName() != $username ) ) {
+                                       $wgOut->showErrorPage( 
'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
+                                       return false;
+                               }
+                               if( ( ( $q == 4 ) && ( $old_q < 3 ) ) || ( ( $q 
== 4 ) && ( $old_q == 3 ) && ( $old_username == $username ) ) ) {
+                                       $wgOut->showErrorPage( 
'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
+                                       return false;
+                               }
+                       } else {
+                               $old_q = 1;
+                       }
+               } else {
+                       if( $q == 4 ) {
+                               $wgOut->showErrorPage( 
'proofreadpage_notallowed', 'proofreadpage_notallowedtext' );
+                               return false;
+                       }
+                       $old_q = -1;
+               }
+
+               $editpage->getArticle()->new_q = $q;
+               $editpage->getArticle()->old_q = $old_q;
+
+               return true;
+       }
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/69973
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2ec8b7423b083966e6fd1fb5c73b7f4d194f04b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Rtdwivedi <ellydwivedi2...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to