jenkins-bot has submitted this change and it was merged.
Change subject: Editing system for pages separated.
......................................................................
Editing system for pages separated.
Change-Id: I2ec8b7423b083966e6fd1fb5c73b7f4d194f04b1
---
M ProofreadPage.body.php
M ProofreadPage.php
M includes/index/ProofreadIndexDbConnector.php
A includes/page/EditProofreadPagePage.php
R includes/page/ProofreadPageDbConnector.php
5 files changed, 210 insertions(+), 188 deletions(-)
Approvals:
Tpt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php
index 278f2e4..7ed9d26 100644
--- a/ProofreadPage.body.php
+++ b/ProofreadPage.body.php
@@ -135,7 +135,7 @@
* Query the database to find if the current page is referred in an
Index page.
* @param $title Title
*/
- private static function loadIndex( $title ) {
+ public static function loadIndex( $title ) {
$title->prpIndexPage = null;
$result = ProofreadIndexDbConnector::getRowsFromTitle( $title );
@@ -898,7 +898,7 @@
* Return quality status of the page and username of the proofreader
* Return -1 if the page cannot be parsed
*/
- private static function parse_page( $text, $title ) {
+ public static function parsePage( $text, $title ) {
global $wgUser;
$username = $wgUser->getName();
@@ -934,112 +934,6 @@
.
"$header\n\n\n</noinclude>$body<noinclude>\n$footer</noinclude>";
return array( -1, null, $new_text );
}
-
- /**
- * @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.
@@ -1098,78 +992,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 = ProofreadIndexDbConnector::getIndexDataFromIndexPageId(
$indexId );
- if( $x ) {
- $a = ProofreadIndexDbConnector::replaceIndexById( $x,
$indexId, $article );
- }
-
- 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;
}
@@ -1289,7 +1111,6 @@
$n1 = $total - $n0 - $n2 - $n3 - $n4;
$replace = ProofreadIndexDbConnector::setIndexData( $n, $n0,
$n1, $n2, $n3, $n4, $indexId );
-
}
/**
diff --git a/ProofreadPage.php b/ProofreadPage.php
index c7c2e8c..f989e27 100644
--- a/ProofreadPage.php
+++ b/ProofreadPage.php
@@ -40,10 +40,11 @@
$wgExtensionMessagesFiles['ProofreadPageAlias'] = $dir .
'ProofreadPage.alias.php';
$wgAutoloadClasses['ProofreadPage'] = $dir . 'ProofreadPage.body.php';
-$wgAutoloadClasses['ProofreadPageDbConnector'] = $dir .
'includes/ProofreadPageDbConnector.php';
+$wgAutoloadClasses['ProofreadPageDbConnector'] = $dir .
'includes/page/ProofreadPageDbConnector.php';
$wgAutoloadClasses['ProofreadPageInit'] = $dir .
'includes/ProofreadPageInit.php';
$wgAutoloadClasses['EditProofreadIndexPage'] = $dir .
'includes/index/EditProofreadIndexPage.php';
+$wgAutoloadClasses['EditProofreadPagePage'] = $dir .
'includes/page/EditProofreadPagePage.php';
$wgAutoloadClasses['ProofreadIndexEntry'] = $dir .
'includes/index/ProofreadIndexEntry.php';
$wgAutoloadClasses['ProofreadIndexValue'] = $dir .
'includes/index/ProofreadIndexValue.php';
$wgAutoloadClasses['ProofreadIndexPage'] = $dir .
'includes/index/ProofreadIndexPage.php';
@@ -137,15 +138,15 @@
$wgHooks['BeforePageDisplay'][] = 'ProofreadPage::onBeforePageDisplay';
$wgHooks['GetLinkColours'][] = 'ProofreadPage::onGetLinkColours';
$wgHooks['ImageOpenShowImageInlineBefore'][] =
'ProofreadPage::onImageOpenShowImageInlineBefore';
-$wgHooks['EditPage::attemptSave'][] = 'ProofreadPage::onEditPageAttemptSave';
-$wgHooks['ArticleSaveComplete'][] = 'ProofreadPage::onArticleSaveComplete';
+$wgHooks['EditPage::attemptSave'][] =
'EditProofreadPagePage::onEditPageAttemptSave';
+$wgHooks['ArticleSaveComplete'][] =
'EditProofreadPagePage::onArticleSaveComplete';
$wgHooks['ArticleDelete'][] = 'ProofreadPage::onArticleDelete';
$wgHooks['ArticleUndelete'][] = 'ProofreadPage::onArticleUndelete';
-$wgHooks['EditFormPreloadText'][] = 'ProofreadPage::onEditFormPreloadText';
+$wgHooks['EditFormPreloadText'][] =
'EditProofreadPagePage::onEditFormPreloadText';
$wgHooks['ArticlePurge'][] = 'ProofreadPage::onArticlePurge';
$wgHooks['SpecialMovepageAfterMove'][] =
'ProofreadPage::onSpecialMovepageAfterMove';
$wgHooks['LoadExtensionSchemaUpdates'][] =
'ProofreadIndexDbConnector::onLoadExtensionSchemaUpdates';
-$wgHooks['EditPage::importFormData'][] =
'ProofreadPage::onEditPageImportFormData';
+$wgHooks['EditPage::importFormData'][] =
'EditProofreadPagePage::onEditPageImportFormData';
$wgHooks['OutputPageParserOutput'][] =
'ProofreadPage::onOutputPageParserOutput';
$wgHooks['wgQueryPages'][] = 'ProofreadPage::onwgQueryPages';
$wgHooks['GetPreferences'][] = 'ProofreadPage::onGetPreferences';
diff --git a/includes/index/ProofreadIndexDbConnector.php
b/includes/index/ProofreadIndexDbConnector.php
index b2be1fa..019114a 100644
--- a/includes/index/ProofreadIndexDbConnector.php
+++ b/includes/index/ProofreadIndexDbConnector.php
@@ -58,9 +58,9 @@
/**
* @param $x Object
* @param $indexId integer
- * @param $article Article
+ * @param $article WikiPage
*/
- public static function replaceIndexById( $x, $indexId, Article $article
) {
+ public static function replaceIndexById( $x, $indexId, WikiPage
$article ) {
$n = $x->pr_count;
$n0 = $x->pr_q0;
$n1 = $x->pr_q1;
diff --git a/includes/page/EditProofreadPagePage.php
b/includes/page/EditProofreadPagePage.php
new file mode 100644
index 0000000..4aa3d8b
--- /dev/null
+++ b/includes/page/EditProofreadPagePage.php
@@ -0,0 +1,200 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup ProofreadPage
+ */
+
+class EditProofreadPagePage {
+
+ /**
+ * Preload text layer from multipage formats
+ * @param $textbox1
+ * @param $mTitle Title
+ * @return bool
+ */
+ public static function onEditFormPreloadText( &$textbox1, $mTitle ) {
+ global $wgContLang;
+
+ list( $pageNamespaceId, $indexNamespaceId ) =
ProofreadPage::getPageAndIndexNamespace();
+ if ( preg_match( "/^$pageNamespaceId:(.*?)\/(.*?)$/",
$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;
+ }
+
+ /**
+ * @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::parsePage(
$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::parsePage( $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;
+ }
+
+ /**
+ * @param $article WikiPage
+ * @return bool
+ */
+ public static function onArticleSaveComplete( WikiPage &$article ) {
+ $title = $article->getTitle();
+
+ // if it's an index, update pr_index table
+ if ( $title->inNamespace( ProofreadPage::getIndexNamespaceId()
) ) { //Move this part to EditProofreadIndexPage
+ 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 = ProofreadIndexDbConnector::getIndexDataFromIndexPageId(
$indexId );
+ if( $x ) {
+ $a = ProofreadIndexDbConnector::replaceIndexById( $x,
$indexId, $article );
+ }
+
+ return true;
+ }
+}
diff --git a/includes/ProofreadPageDbConnector.php
b/includes/page/ProofreadPageDbConnector.php
similarity index 100%
rename from includes/ProofreadPageDbConnector.php
rename to includes/page/ProofreadPageDbConnector.php
--
To view, visit https://gerrit.wikimedia.org/r/69973
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2ec8b7423b083966e6fd1fb5c73b7f4d194f04b1
Gerrit-PatchSet: 18
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Rtdwivedi <[email protected]>
Gerrit-Reviewer: Tpt <[email protected]>
Gerrit-Reviewer: Zaran <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits