Reception123 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/374682 )

Change subject: Convert ArticleToCategory2 to use extension registration
......................................................................

Convert ArticleToCategory2 to use extension registration

Bug: T174478
Change-Id: Id4103af2ccffd0b5b3acf4f90e8ae1b3bd7d7bcf
---
A ArticleToCategory2.hooks.php
M ArticleToCategory2.php
A extension.json
3 files changed, 215 insertions(+), 202 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleToCategory2 
refs/changes/82/374682/1

diff --git a/ArticleToCategory2.hooks.php b/ArticleToCategory2.hooks.php
new file mode 100644
index 0000000..d842ef4
--- /dev/null
+++ b/ArticleToCategory2.hooks.php
@@ -0,0 +1,157 @@
+<?php
+/******************************
+ * Add category to the new page
+ * The category name is escaped to prevent JavaScript injection
+ *
+ * @param string $text The text to prefill edit form with
+ * @return bool true
+ ******************************/
+class EditFormPreloadText {
+       function wfAddCategory( &$text ) {
+               global $wgContLang;
+
+               if ( array_key_exists( 'category', $_GET ) && array_key_exists( 
'new', $_GET )) {
+                       $cname =  $_GET['category'];
+                       if ( $_GET['new'] == 1 ) {
+                               $text = "\n\n[[" . $wgContLang->getNsText( 
NS_CATEGORY ) . ":" .
+                                               htmlspecialchars( $cname ) . 
"]]";
+                       }
+               }
+               return true;
+       }
+}
+ 
+/******************************
+ * Function to get the excluded categories list (blacklist)
+ * the list is retrieved from Add Article to Category 2 excluded categories 
page.
+ *
+ * @return string $excludedCategories
+ ******************************/
+       function getExcludedCategories() {
+               global $wgRequest;
+
+               $excludedCategories = array();
+               $specialcatpage='Add Article to Category 2 excluded categories';
+
+               if ( $wgRequest->getVal( 'action' ) == 'edit' ) {
+                       return true;
+               }
+               $rev = Revision::newFromTitle( Title::makeTitle( 8, 
$specialcatpage ) );
+               if ( $rev ) {
+                       $content = $rev->getText();
+                       if ( $content != "" ) {
+                               $changed = false;
+                               $c = explode( "\n", $content );
+                               foreach ( $c as $entry ) {
+                                       if ( $entry[0]==';' ) {
+                                               $cat = trim( substr( $entry, 1 
) );
+                                               $excludedCategories[] = $cat;
+                                       }
+                               }
+ 
+                       }
+               } else {
+                       echo (" Page : \"" . $specialcatpage . "\" does not 
exist !");
+               }
+               return $excludedCategories;
+}
+ 
+       /******************************
+       * Generate the input box
+       *
+       * @param string $catpage The category article
+       * @return bool true to do the default behavior of CategoryPage::view
+       ******************************/
+class CategoryPageView {
+       function wfCategoryChange( $catpage ) {
+               global $wgarticletocategory2ConfigBlacklist, 
$wgarticletocategory2ConfigAddcat,
+                       $wgOut, $wgScript, $wgContLang, $wgUser;
+                       $action = htmlspecialchars( $wgScript );
+               if ( !$catpage->mTitle->quickUserCan( 'edit' )
+                       || !$catpage->mTitle->quickUserCan( 'create')
+                       || !$wgUser->isAllowed( 'ArticleToCategory2') )
+               {
+                       return true;
+               }
+               if ( $wgarticletocategory2ConfigBlacklist ) {
+                       $excludedCategories=getExcludedCategories();
+                       foreach ($excludedCategories as $value) {
+                               if ( $catpage->mTitle->getText() == $value ) {
+                                       return true;
+                               }
+                       }
+               }
+       }
+       $boxtext  = wfMessage( 
'articletocategory2-create-article-under-category-text' )->text();
+       $btext =    wfMessage( 
'articletocategory2-create-article-under-category-button' )->text();
+       $boxtext2 = wfMessage( 
'articletocategory2-create-category-under-category-text' )->text();
+       $btext2 =   wfMessage( 
'articletocategory2-create-category-under-category-button' )->text();
+ 
+       $cattitle = $wgContLang->getNsText( NS_CATEGORY );
+ 
+       /*** javascript blocks ***/
+       $formstart=<<<FORMSTART
+<!-- Add Article Extension Start -->
+<script type="text/javascript">
+function clearText(thefield) {
+       if (thefield.defaultValue==thefield.value)
+               thefield.value = ""
+}
+function addText(thefield) {
+       if (thefield.value=="")
+               thefield.value = thefield.defaultValue
+}
+ 
+function addTextTitle(thefield) {
+       if (thefield.value=="") {
+               thefield.value = thefield.defaultValue;
+       } else {
+               thefield.value = '{$cattitle}:'+thefield.value;
+       }
+}
+ 
+function isemptyx(form) {
+       if (form.title.value=="" || form.title.value==form.title.defaultValue) {
+               <!-- alert(.title.value); -->
+               return false;
+       }
+       return true;
+}
+</script>
+ 
+<table border="0" align="right" width="423" cellspacing="0" cellpadding="0">
+       <tr>
+       <td width="100%" align="right" bgcolor="">
+       <form name="createbox" action="{$action}" onsubmit="return 
isemptyx(this);" method="get" class="createbox">
+               <input type='hidden' name="action" value="edit">
+               <input type='hidden' name="new" value="1">
+               <input type='hidden' name="category" 
value="{$catpage->mTitle->getText()}">
+ 
+               <input class="createboxInput" name="title" type="text" 
value="{$boxtext}" size="38" style="color:#666;" onfocus="clearText(this);" 
onblur="addText(this);"/>
+               <input type='submit' name="create" class="createboxButton" 
value="{$btext}"/>
+       </form>
+FORMSTART;
+       $formcategory=<<<FORMCATEGORY
+       <form name="createbox" action="{$action}" onsubmit="return 
isemptyx(this);" method="get" class="createbox">
+               <input type='hidden' name="action" value="edit">
+               <input type='hidden' name="new" value="1">
+               <input type='hidden' name="category" 
value="{$catpage->mTitle->getText()}">
+ 
+               <input class="createboxInput" name="title" type="text" 
value="{$boxtext2}" size="38" style="color:#666;" onfocus="clearText(this);" 
onblur="addTextTitle(this);"/>
+               <input type='submit' name="create" class="createboxButton" 
value="{$btext2}"/>
+       </form>
+FORMCATEGORY;
+       $formend=<<<FORMEND
+       </td>
+       </tr>
+</table>
+<!-- Add Article Extension End -->
+FORMEND;
+       /*** javascript blocks end ***/
+       $wgOut->addHTML( $formstart );
+       if ( $wgUser->isAllowed( 'ArticleToCategory2AddCat' ) ) {
+               $wgOut->addHTML( $formcategory );
+       }
+       $wgOut->addHTML( $formend );
+       return true;
+}
diff --git a/ArticleToCategory2.php b/ArticleToCategory2.php
index 65cedd8..531c70a 100644
--- a/ArticleToCategory2.php
+++ b/ArticleToCategory2.php
@@ -24,206 +24,14 @@
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
         
 --------------------------------------------*/
-
-/**
- *  Protect against register globals vulnerabilities.
- *  This line must be present before any global variable is referenced.
- */
-if ( !defined('MEDIAWIKI') ) {
-       echo <<<HEREDOC
-To install the ArticleToCategory2 extension, put the following line in 
LocalSettings.php:<P>
-require_once( "\$IP/extensions/ArticleToCategory2/ArticleToCategory2.php" 
);<br>
-\$wgarticletocategory2ConfigBlacklist=false;<br>
-\$wgGroupPermissions['*']['ArticleToCategory2'] = true;<br>
-\$wgGroupPermissions['*']['ArticleToCategory2AddCat'] = false;<br>
-
-HEREDOC;
-       exit( 1 );
-}
-
-/** Set default values on configutation variables **/
-$wgarticletocategory2ConfigBlacklist=false;
-/* Set default 'true' for add article to category */
-$wgGroupPermissions['*']['ArticleToCategory2'] = true;
-/* Set default 'false' for add category to category */
-$wgGroupPermissions['*']['ArticleToCategory2AddCat'] = false;
- 
-$wgExtensionCredits['other'][] = array(
-       'path' => __FILE__,
-       'name' => 'Add Article to Category 2',
-       'descriptionmsg' => 'articletocategory2-desc',
-       'version' => '1.1',
-       'author' => array(
-               '[http://www.mediawiki.org/wiki/User:BiGreat Liang Chen 
\'BiGreat\'] (original code)',
-               'Julien Devincre (exclude categories)',
-               '[http://www.mediawiki.org/wiki/User:Cm Cynthia Mattingly] 
(i18n, adding category)',
-               '[http://www.mediawiki.org/wiki/User:MikaelLindmark Mikael 
Lindmark] (adding options, input check)'),
-       'url' => 'https://www.mediawiki.org/wiki/Extension:ArticleToCategory2',
-    'license-name' => 'GPL-3.0+'
-);
-
-/*** Hook functions ***/
-$wgHooks['EditFormPreloadText'][] = 'wfAddCategory';
-$wgHooks['CategoryPageView'][] = 'wfCategoryChange';
- 
-$dir = dirname(__FILE__) . '/';
- 
-/*** Internationalisation ***/
-$wgExtensionMessagesFiles['ArticleToCategory2'] = $dir . 
'ArticleToCategory2.i18n.php';
-
-
- 
-/******************************
- * Add category to the new page
- * The category name is escaped to prevent JavaScript injection
- *
- * @param string $text The text to prefill edit form with
- * @return bool true
- ******************************/
-function wfAddCategory( &$text ) {
-       global $wgContLang;
-
-       if ( array_key_exists( 'category', $_GET ) && array_key_exists( 'new', 
$_GET )) {
-               $cname =  $_GET['category'];
-               if ( $_GET['new'] == 1 ) {
-                       $text = "\n\n[[" . $wgContLang->getNsText( NS_CATEGORY 
) . ":" .
-                               htmlspecialchars( $cname ) . "]]";
-               }
-       }
-       return true;
-}
- 
-/******************************
- * Function to get the excluded categories list (blacklist)
- * the list is retrieved from Add Article to Category 2 excluded categories 
page.
- *
- * @return string $excludedCategories
- ******************************/
-function getExcludedCategories() {
-       global $wgRequest;
-
-       $excludedCategories = array();
-       $specialcatpage='Add Article to Category 2 excluded categories';
-
-       if ( $wgRequest->getVal( 'action' ) == 'edit' ) {
-               return true;
-       }
-       $rev = Revision::newFromTitle( Title::makeTitle( 8, $specialcatpage ) );
-       if ( $rev ) {
-               $content = $rev->getText();
-               if ( $content != "" ) {
-                       $changed = false;
-                       $c = explode( "\n", $content );
-                       foreach ( $c as $entry ) {
-                               if ( $entry[0]==';' ) {
-                                       $cat = trim( substr( $entry, 1 ) );
-                                       $excludedCategories[] = $cat;
-                               }
-                       }
- 
-               }
-       } else {
-               echo (" Page : \"" . $specialcatpage . "\" does not exist !");
-       }
-       return $excludedCategories;
-}
- 
-/******************************
- * Generate the input box
- *
- * @param string $catpage The category article
- * @return bool true to do the default behavior of CategoryPage::view
- ******************************/
-function wfCategoryChange( $catpage ) {
-       global $wgarticletocategory2ConfigBlacklist, 
$wgarticletocategory2ConfigAddcat,
-               $wgOut, $wgScript, $wgContLang, $wgUser;
-
-       $action = htmlspecialchars( $wgScript );
-       if ( !$catpage->mTitle->quickUserCan( 'edit' )
-               || !$catpage->mTitle->quickUserCan( 'create')
-               || !$wgUser->isAllowed( 'ArticleToCategory2') )
-       {
-               return true;
-       }
-       if ( $wgarticletocategory2ConfigBlacklist ) {
-               $excludedCategories=getExcludedCategories();
-               foreach ($excludedCategories as $value) {
-                       if ( $catpage->mTitle->getText() == $value ) {
-                               return true;
-                       }
-               }
-       }
-
-       $boxtext  = wfMessage( 
'articletocategory2-create-article-under-category-text' )->text();
-       $btext =    wfMessage( 
'articletocategory2-create-article-under-category-button' )->text();
-       $boxtext2 = wfMessage( 
'articletocategory2-create-category-under-category-text' )->text();
-       $btext2 =   wfMessage( 
'articletocategory2-create-category-under-category-button' )->text();
- 
-       $cattitle = $wgContLang->getNsText( NS_CATEGORY );
- 
-       /*** javascript blocks ***/
-       $formstart=<<<FORMSTART
-<!-- Add Article Extension Start -->
-<script type="text/javascript">
-function clearText(thefield) {
-       if (thefield.defaultValue==thefield.value)
-               thefield.value = ""
-}
-function addText(thefield) {
-       if (thefield.value=="")
-               thefield.value = thefield.defaultValue
-}
- 
-function addTextTitle(thefield) {
-       if (thefield.value=="") {
-               thefield.value = thefield.defaultValue;
-       } else {
-               thefield.value = '{$cattitle}:'+thefield.value;
-       }
-}
- 
-function isemptyx(form) {
-       if (form.title.value=="" || form.title.value==form.title.defaultValue) {
-               <!-- alert(.title.value); -->
-               return false;
-       }
-       return true;
-}
-</script>
- 
-<table border="0" align="right" width="423" cellspacing="0" cellpadding="0">
-       <tr>
-       <td width="100%" align="right" bgcolor="">
-       <form name="createbox" action="{$action}" onsubmit="return 
isemptyx(this);" method="get" class="createbox">
-               <input type='hidden' name="action" value="edit">
-               <input type='hidden' name="new" value="1">
-               <input type='hidden' name="category" 
value="{$catpage->mTitle->getText()}">
- 
-               <input class="createboxInput" name="title" type="text" 
value="{$boxtext}" size="38" style="color:#666;" onfocus="clearText(this);" 
onblur="addText(this);"/>
-               <input type='submit' name="create" class="createboxButton" 
value="{$btext}"/>
-       </form>
-FORMSTART;
-       $formcategory=<<<FORMCATEGORY
-       <form name="createbox" action="{$action}" onsubmit="return 
isemptyx(this);" method="get" class="createbox">
-               <input type='hidden' name="action" value="edit">
-               <input type='hidden' name="new" value="1">
-               <input type='hidden' name="category" 
value="{$catpage->mTitle->getText()}">
- 
-               <input class="createboxInput" name="title" type="text" 
value="{$boxtext2}" size="38" style="color:#666;" onfocus="clearText(this);" 
onblur="addTextTitle(this);"/>
-               <input type='submit' name="create" class="createboxButton" 
value="{$btext2}"/>
-       </form>
-FORMCATEGORY;
-       $formend=<<<FORMEND
-       </td>
-       </tr>
-</table>
-<!-- Add Article Extension End -->
-FORMEND;
-       /*** javascript blocks end ***/
-       $wgOut->addHTML( $formstart );
-       if ( $wgUser->isAllowed( 'ArticleToCategory2AddCat' ) ) {
-               $wgOut->addHTML( $formcategory );
-       }
-       $wgOut->addHTML( $formend );
-       return true;
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'ArticleToCategory2' );
+       wfWarn(
+               'Deprecated PHP entry point used for ArticleToCategory2 
extension. ' .
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );
+       return;
+} else {
+       die( 'This version of the ArticleToCategory2 extension requires 
MediaWiki 1.29+' );
 }
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..bfaabdd
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,48 @@
+{
+       "name": "ArticleToCategory2",
+       "version": "1.1",
+       "author": [
+               "[https://www.mediawiki.org/wiki/User:MikaelLindmark Mikael 
Lindmark]",
+               "Liang Chen",
+               "Julien Devincre",
+               "Cynthia Mattingly"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:ArticleToCategory2";,
+       "descriptionmsg": "articletocategory2-desc",
+       "license-name": "GPL-2.0+",
+       "AutoloadClasses": {
+               "ArticleToCategory2Hooks": "ArticleToCategory2.hooks.php"
+       },
+       "MessagesDirs": {
+               "ArticleToCategory2": [
+                       "i18n"
+               ]
+       },
+       "config": {
+               "ArticleToCategory2ConfigBlacklist": {
+                       "value": false,
+                       "description": "Set this flag to true to enable the 
category blacklist in \"MediaWiki:Add Article to Category 2 excluded 
categories\" page (you need to create this page first)"
+               }
+       },
+       "SpecialPages": {
+               "ArticleToCategory2": "ArticleToCategory2"
+       },
+       "ExtensionMessagesFiles": {
+               "ArticleToCategory2": "ArticleToCategory2.i18n.php"
+       },
+       "AvailableRights": [
+               "author",
+               "authorprotect"
+       ],
+       "GroupPermissions": {
+               "*": {
+                       "ArticleToCategory2": true,
+                       "ArticleToCategory2AddCat": false
+               }
+       },
+       "Hooks": {
+               "EditFormPreloadText: LastModifiedHooks::wfAddCategory",
+               "CategoryPageView: LastModifiedHooks::wfCategoryChange"
+       },
+       "manifest_version": 2
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4103af2ccffd0b5b3acf4f90e8ae1b3bd7d7bcf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleToCategory2
Gerrit-Branch: master
Gerrit-Owner: Reception123 <utilizator.receptie...@gmail.com>

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

Reply via email to