Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Fix for mw 1.31 php 7.0 #11

Merged
merged 12 commits into from
Feb 12, 2018
64 changes: 64 additions & 0 deletions api/CE_CommentCreatePageApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/*
* Copyright (C) Vulcan Inc.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @file
* @ingroup SemanticComments
*
* This file contains the ajax functions of comment component for Semantic Comments extension.
*
* @author Peter Grassberger <petertheone@gmail.com>
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( "This file is part of the SemanticComments extension. It is not a valid entry point.\n" );
}

class CECommentCreatePageApi extends ApiBase {

public function execute() {
$parameters = $this->extractRequestParams();
$title = CECommentUtils::unescape( $parameters['title'] );
$content = CECommentUtils::unescape( $parameters['content'] );
$edit = false;
if ( isset( $parameters['edit'] ) ) {
$edit = $parameters['edit'];
}

$value = CEComment::createComment( $title, $content, $edit );
$apiResult = $this->getResult();
$apiResult->addValue(null, 'data', $value);
}

public function getAllowedParams() {
return array(
'title' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
'content' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
'edit' => array(
ApiBase::PARAM_TYPE => 'boolean',
ApiBase::PARAM_REQUIRED => false,
),
);
}
}
137 changes: 137 additions & 0 deletions api/CE_CommentDeleteApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/*
* Copyright (C) Vulcan Inc.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @file
* @ingroup SemanticComments
*
* This file contains the ajax functions of comment component for Semantic Comments extension.
*
* @author Peter Grassberger <petertheone@gmail.com>
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( "This file is part of the SemanticComments extension. It is not a valid entry point.\n" );
}

class CECommentDeleteApi extends ApiBase {

public function execute() {
$parameters = $this->extractRequestParams();
$commentsToDelete = CECommentUtils::unescape( $parameters['commentsToDelete'] );
$fullDelete = false;
if ( isset( $parameters['fullDelete'] ) ) {
$fullDelete = $parameters['fullDelete'];
}

$value = null;
if ($fullDelete) {
$value = $this->fullDeleteComments( $commentsToDelete );
} else {
$value = $this->deleteComment( $commentsToDelete );
}
$apiResult = $this->getResult();
$apiResult->addValue(null, 'data', $value);
}

private function deleteComment( $pageName ) {
wfProfileIn( __METHOD__ . ' [Semantic Comments]' );
global $wgUser;
$pageName = CECommentUtils::unescape( $pageName );
$result = wfMessage( 'ce_nothing_deleted' )->text();
$success = true;
if ( $pageName != null ) {
try {
$title = Title::newFromText( $pageName );
if ( $title->getNamespace() != CE_COMMENT_NS ) {
$title = Title::makeTitle( CE_COMMENT_NS, $title );
}
$article = new Article( $title );
$articleContentText = ContentHandler::getContentText( $article->getPage()->getContent() );
$date = new Datetime( null, new DateTimeZone( 'UTC' ) );
$articleContentText = preg_replace( '/\|CommentContent.*}}/',
'|CommentContent=' . $wgUser->getName() . ' ' .
wfMessage( 'ce_comment_has_deleted' )->text() . ' ' .
$date->format( 'r' ) . '|CommentWasDeleted=true|}}',
$articleContentText
);
$article->doEditContent( ContentHandler::makeContent( $articleContentText, $title ), wfMessage( 'ce_comment_delete_reason' )->text() );
CEComment::updateRelatedArticle( $articleContentText );
$result = wfMessage( 'ce_comment_deletion_successful' )->text();
wfProfileOut( __METHOD__ . ' [Semantic Comments]' );
return CECommentUtils::createXMLResponse( $result, '0', $pageName );
} catch( Exception $e ) {
$result .= wfMessage( 'ce_comment_deletion_error' )->text();
$success = false;
wfProfileOut( __METHOD__ . ' [Semantic Comments]' );
return CECommentUtils::createXMLResponse( $result, '1', $pageName );
}
}

wfProfileOut( __METHOD__ . ' [Semantic Comments]' );
return CECommentUtils::createXMLResponse( 'sth went wrong here', '1', $pageName );
}

private function fullDeleteComments( $pageNames ) {
wfProfileIn( __METHOD__ . ' [Semantic Comments]' );
global $wgUser;
$pageNames = CECommentUtils::unescape( $pageNames );
$pageNames = explode( ',', $pageNames );
$result = wfMessage( 'ce_nothing_deleted' )->text();
$success = false;
foreach ( $pageNames as $pageName) {
try {
$title = Title::newFromText( $pageName );
if ( $title->getNamespace() != CE_COMMENT_NS ) {
$title = Title::makeTitle( CE_COMMENT_NS, $title );
}
$article = new Article( $title );
$articleContentText = ContentHandler::getContentText( $article->getPage()->getContent() );
$articleDel = $article->doDelete( wfMessage( 'ce_comment_delete_reason' )->text() );
$success = true;
} catch( Exception $e ) {
$result .= wfMessage( 'ce_comment_deletion_error' )->text();
$success = false;
wfProfileOut( __METHOD__ . ' [Semantic Comments]' );
return CECommentUtils::createXMLResponse( $result, '1', $pageName);
}
}
if( $success ) {
$result = wfMessage( 'ce_comment_massdeletion_successful' )->text();
wfProfileOut( __METHOD__ . ' [Semantic Comments]' );
return CECommentUtils::createXMLResponse( $result, '0', $pageNames[0] );
} else {
$pageNames = json_encode($pageNames);
wfProfileOut( __METHOD__ . ' [Semantic Comments]' );
return CECommentUtils::createXMLResponse( 'sth went wrong here', '1', $pageNames );
}
}

public function getAllowedParams() {
return array(
'commentsToDelete' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
'fullDelete' => array(
ApiBase::PARAM_TYPE => 'boolean',
ApiBase::PARAM_REQUIRED => false,
),
);
}
}
26 changes: 18 additions & 8 deletions includes/CE_GlobalFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* This file contains global functions that are called from the SemanticComments extension.
*
* @author Benjamin Langguth
* @author Peter Grassberger <petertheone@gmail.com>
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( "This file is part of the SemanticComments extension. It is not a valid entry point.\n" );
Expand All @@ -43,7 +44,7 @@ function enableSemanticComments() {
wfProfileIn( __METHOD__ . ' [SemanticComments]' );
global $cegIP, $cegEnableSemanticComments, $cegEnableComment,
$wgExtensionMessagesFiles, $wgExtensionFunctions,
$wgAutoloadClasses, $wgHooks;
$wgAutoloadClasses, $wgHooks, $wgAPIModules;

require_once($cegIP . '/specials/Comment/CE_CommentParserFunctions.php');

Expand All @@ -59,7 +60,11 @@ function enableSemanticComments() {
//--- Autoloading for exception classes ---
$wgAutoloadClasses['CEException'] = $cegIP . '/exeptions/CE_Exception.php';

require_once($cegIP . '/specials/Comment/CE_CommentAjaxAccess.php');
$wgAutoloadClasses['CECommentCreatePageApi'] = $cegIP . '/api/CE_CommentCreatePageApi.php';
$wgAPIModules['commentsCreatePage'] = '\CECommentCreatePageApi';

$wgAutoloadClasses['CECommentDeleteApi'] = $cegIP . '/api/CE_CommentDeleteApi.php';
$wgAPIModules['commentsDelete'] = '\CECommentDeleteApi';

$wgAutoloadClasses['CECommentSpecial'] = $cegIP . '/specials/Comment/CE_CommentSpecial.php';

Expand Down Expand Up @@ -88,12 +93,16 @@ function cefSetupExtension() {
$spns_text = $wgContLang->getNsText(NS_SPECIAL);
// register AddHTMLHeader functions for special pages
// to include javascript and css files (only on special page requests).

// maintenance fix from https://www.mediawiki.org/wiki/Topic:R29j2gav38ynedw7
if( !defined('DO_MAINTENANCE') ) {
$url = $wgRequest->getRequestURL();
if( stripos( $url, $spns_text . ":SemanticComments" ) !== false
|| stripos( $url, $spns_text . "%3ASemanticComments" ) !== false ) {
$wgOut->addModules( 'ext.ce.comment.specialpage' );
} else {
$wgOut->addModules( 'ext.ce.comment' );
if( stripos( $url, $spns_text . ":SemanticComments" ) !== false
|| stripos( $url, $spns_text . "%3ASemanticComments" ) !== false ) {
$wgOut->addModules( 'ext.ce.comment.specialpage' );
} else {
$wgOut->addModules( 'ext.ce.comment' );
}
}

### credits (see Special:Version) ###
Expand All @@ -103,7 +112,8 @@ function cefSetupExtension() {
'version' => CE_VERSION,
'author'=>array("Patrick Barret","Benjamin Langguth","Thomas Schweitzer"),
'url' => 'https://www.mediawiki.org/wiki/Extension:SemanticComments',
'description' => 'SemanticComments toolset, eg article comments.'
'description' => 'SemanticComments toolset, eg article comments.',
'license-name' => 'GPL-2.0+'
);

### Register autocompletion icon ###
Expand Down
Loading