[MediaWiki-commits] [Gerrit] mediawiki...ArticleToCategory2[master]: Convert ArticleToCategory2 to use extension registration
Mikaellindmark has submitted this change and it was merged. ( 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, 212 insertions(+), 201 deletions(-) Approvals: jenkins-bot: Checked Mikaellindmark: Verified; Looks good to me, approved diff --git a/ArticleToCategory2.hooks.php b/ArticleToCategory2.hooks.php new file mode 100644 index 000..1980063 --- /dev/null +++ b/ArticleToCategory2.hooks.php @@ -0,0 +1,154 @@ +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 + **/ + public static 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 + **/ + public static function wfCategoryChange( $catpage ) { + global $wgArticleToCategory2ConfigBlacklist, + $wgOut, $wgScript, $wgContLang, $wgUser; + $action = htmlspecialchars( $wgScript ); + if ( !$catpage->mTitle->quickUserCan( 'edit' ) + || !$catpage->mTitle->quickUserCan( 'create') + || !$wgUser->isAllowed( 'ArticleToCategory2') ) + { + return true; + } + if ( $wgArticleToCategory2ConfigBlacklist ) { + $excludedCategories=self::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=<< + +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) { + + return false; + } + return true; +} + + + + + + + +
[MediaWiki-commits] [Gerrit] mediawiki...ArticleToCategory2[master]: Convert ArticleToCategory2 to use extension registration
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 000..d842ef4 --- /dev/null +++ b/ArticleToCategory2.hooks.php @@ -0,0 +1,157 @@ +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=<< + +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) { + + return false; + } + return true; +} + + + + + + +