2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
5 # for convenience, Mediawiki config file
6 mwc
="$mw/LocalSettings.php"
8 # identify if this is a debian based distro
9 isdeb
() { command -v apt
&>/dev
/null
; }
10 # tee unique. append each stdin line if it does not exist in the file
14 for line
in "${MAPFILE[@]}"; do
15 grep -xFq "$line" "$1" &>/dev
/null ||
tee -a "$1" <<<"$line"
19 # get and reset an extension/skin repository, and enable it
20 mw-ext
() { mw-extra extensions $@
; }
21 mw-skin
() { mw-extra skins $@
; }
24 local type=$1 # extension or skin
28 local original_pwd
="$PWD"
29 # it's ok that this fails if we already have it
30 url
=https
://git.wikimedia.org
/git
/mediawiki
32 if [[ ! -e $target/.git
]]; then
33 git clone
$url/$type/$ext.git
$target
36 echo "mw-ext error: failed cd $mw/extensions/$ext";
40 git checkout
-qf origin
/$mw_branch || git checkout
-qf origin
/master
45 if [[ -e $target/extension.json
]]; then
46 # new style extension. remove old style declaration
47 sed -i '#^require_once( "\\\$IP/extensions/\$ext/\$ext\.php" );#d' $mwc
49 wfLoadExtension( '$ext' );
53 require_once( "\$IP/extensions/$ext/$ext.php" );
58 sed -i '/^wfLoadSkin/d' $mwc
59 sed -i '/^\$wgDefaultSkin/d' $mwc
61 \$wgDefaultSkin = "${ext,,*}";
67 # --quick is quicker than default flags,
68 # but still add a sleep to make sure everything works right
69 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
72 if command -v apt
&>/dev
/null
; then
79 # <source lang="bash">
80 # From here on out, exit if a command fails.
81 # This will prevent us from not noticing an important failure.
82 # We recommend setting this for the entire installation session.
83 # If you are running commands interactively, it might be best to
84 # put it in your ~/.bashrc temporarily.
86 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
91 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
93 apt-get
install -y ImageMagick
94 if apt-get
install -s mediawiki
&>/dev
/null
; then
95 # in debian wheezy time-frame distros, mediawiki was packaged.
96 apt-get
-y install php-apc mediawiki
98 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
99 if apt-get
install -s php7.0
&>/dev
/null
; then
100 # note, 7.0 is untested by the editor here, since it's not
101 # available in debian 8. it's listed as supported
102 # in the mediawiki page.
103 # noninteractive to avoid mysql password prompt
104 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 mysql-server \
105 php7.0 php7.0
-mysql libapache2-mod-php7.0 php7.0
-xml \
108 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 mysql-server \
109 php5 php5-mysql libapache2-mod-php5 php5-apcu
112 service apache2 restart
115 # fedora deps are missing a database, so some is translated from debian packages
116 yum
-y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
118 systemctl restart mariadb.service
119 systemctl
enable mariadb.service
120 systemctl
enable httpd.service
121 systemctl restart httpd.service
125 # slightly different depending on if we already set the root pass
126 if echo exit|mysql
-u root
-p"$dbpass"; then
127 # answer interactive prompts:
128 # mysql root pass, change pass? no, remove anon users? (default, yes)
129 # disallow remote root (default, yes), reload? (default, yes)
130 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
132 # I had 1 less newline at the start when doing ubuntu 14.04,
133 # compared to debian 8, so can't say this is especially portable.
134 # It won't hurt if it fails.
135 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
138 # <source lang="bash">
141 # this will just fail if it already exists which is fine
142 if [[ ! -e .git
]]; then
143 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/core.git .
145 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
148 git checkout
-f origin
/$mw_branch
150 # Get the php libraries wmf uses. Based on:
151 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
152 if [[ ! -e vendor
/.git
]]; then
153 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/vendor.git
156 git checkout
-f origin
/$mw_branch
159 # Drop any previous database which may have been installed while testing.
160 # If upgrading, we should have a db backup which will get restored.
161 # https://www.mediawiki.org/wiki/Manual:Upgrading
162 mysql
-u root
-p$dbpass <<'EOF' ||:
163 drop database my_wiki;
166 php
$mw/maintenance
/install.php
--pass $wikipass --scriptpath /w \
167 --dbuser root
--dbpass $dbpass "$mwdescription" "$wikiuser"
169 # lock down the wiki to only the initial owner until anti-spam measures are put in place
170 # limit edits to registered users
171 $wgGroupPermissions['*']['edit'] = false;
172 # don't allow any account creation
173 $wgGroupPermissions['*']['createaccount'] = false;
176 # <source lang="bash">
177 tmpdir
="$(mktemp -d)"
179 wget http
://builds.piwik.org
/piwik.
zip
180 if isdeb
; then apt-get
-y install unzip; else yum
-y install unzip; fi
182 # gui installer suggested command
184 chown
-R www-data
:www-data piwik
186 chown
-R apache
:apache piwik
188 # remove any existing directory
189 rm -rf $mw/..
/analytics
190 mv piwik
$mw/..
/analytics
195 # <source lang="bash">
198 git_site
=https
://iankelling.org
/git
199 git clone
$git_site/acme-tiny-wrapper
203 acme-tiny-wrapper
/acme-tiny-wrapper
$mwdomain
205 git clone
$git_site/basic-https-conf
207 ServerAdmin $mw_email
209 # make the site's root url go to our main page
210 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
211 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
212 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
214 find -L $
(readlink
-f $mw/..
) -name .htaccess \
215 |
while read line
; do
216 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
218 } | basic-https-conf
/apache-site
-r ${mw%/*} - $mwdomain
220 # <source lang="bash">
221 dd of
=$mw/..
/robots.txt
<<'EOF'
224 User-agent: ia_archiver
229 # <source lang="bash">
231 \$wgServer = "https://$mwdomain";
232 \$wgDBserver = "localhost";
233 \$wgRightsUrl = "$mw_RightsUrl";
234 \$wgRightsText = "$mw_RightsText";
235 \$wgRightsIcon = "$mw_RightsIcon";
238 # <source lang="bash">
240 \$wgPasswordSender = "$mw_email";
241 \$wgEmergencyContact = "$mw_email";
242 \$wgEnotifUserTalk = true; # UPO
243 \$wgEnotifWatchlist = true; # UPO
244 \$wgMainCacheType = CACHE_ACCEL;
245 \$wgEnableUploads = true;
246 \$wgUseInstantCommons = true;
249 # <source lang="bash">
251 # from https://www.mediawiki.org/wiki/Manual:Short_URL
252 $wgArticlePath = "/wiki/$1";
254 # https://www.mediawiki.org/wiki/Manual:Combating_spam
255 # check that url if our precautions don't work
256 # not using nofollow is good practice, as long as we avoid spam.
257 $wgNoFollowLinks = false;
258 # Allow user customization.
259 $wgAllowUserJs = true;
260 $wgAllowUserCss = true;
262 # use imagemagick over GD
263 $wgUseImageMagick = true;
267 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
268 # Increase from default of 2M to 100M.
269 # This will at least allow high res pics etc.
270 php_ini
=$
(isdeb
&& echo /etc
/php
5/apache
2/php.ini ||
echo /etc
/php.ini
)
271 sed -i 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
273 service apache2 restart
275 systemctl restart httpd.service
278 # if you were to install as a normal user, you would need this for images
279 # sudo usermod -aG $apache_user $USER
281 # this doesn't propogate right away
282 chgrp
-R $apache_user $mw/images
283 chmod -R g
+w
$mw/images
285 # <source lang="bash">
288 #$wgFooterIcons = null;
290 # Make the toolbox go into the drop down.
292 if ! git remote show ian-kelling
&>/dev
/null
; then
293 git remote add ian-kelling https
://iankelling.org
/git
/Vector
295 git fetch ian-kelling
296 git checkout ian-kelling
/REL1_27-toolbox-in-dropdown
298 # <source lang="bash">
299 mw-ext Cite CiteThisPage CSS Echo Gadgets ImageMap Interwiki News \
300 Nuke ParserFunctions Poem SyntaxHighlight_GeSHi Variables
302 # <source lang="bash">
304 # recommended setup script to account for existing users
305 sudo
-u $apache_user php
$mw/extensions
/AntiSpoof
/maintenance
/batchAntiSpoof.php
307 # <source lang="bash">
309 sudo
-u $apache_user php
$mw/extensions
/CheckUser
/install.php
; sleep 1
311 # <source lang="bash">
313 apt-get
-y install php-wikidiff2
315 $wgExternalDiffEngine = 'wikidiff2';
317 ln -sf ..
/..
/mods-available
/wikidiff2.ini
/etc
/php
5/apache
2/conf.d
318 service apache2 restart
321 # <source lang="bash">
323 # php5-curl according to Math readme
326 if ! apt-get
-s install $curl_pkg &>/dev
/null
; then
329 apt-get
-y install latex-cjk-all texlive-latex-extra texlive-latex-base \
330 ghostscript imagemagick ocaml
$curl_pkg make
332 # todo, php5-curl equivalent on fedora
333 yum
-y install texlive-cjk ghostscript ImageMagick texlive ocaml
335 ln -sf ..
/..
/mods-available
/curl.ini
/etc
/php
5/apache
2/conf.d
336 service apache2 restart
338 cd $mw/extensions
/Math
/math
; make # makes texvc
339 cd $mw/extensions
/Math
/texvccheck
; make
342 # Enable MathJax as rendering option
343 $wgUseMathJax = true;
344 # Enable LaTeXML as rendering option
345 $wgMathValidModes[] = 'latexml';
346 # Set LaTeXML as default rendering option, because it is nicest
347 $wgDefaultUserOptions['math'] = 'latexml';
350 # <source lang="bash">
352 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev
/null
; then
354 $wgEnableDnsBlacklist = true;
355 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
357 ini_set( 'pcre.backtrack_limit', '10M' );
358 $wgSpamBlacklistFiles = array(
359 "[[m:Spam blacklist]]",
360 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
365 # <source lang="bash">
366 mw-ext TitleBlacklist
367 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev
/null
; then
369 $wgTitleBlacklistSources = array(
372 'src' => 'MediaWiki:Titleblacklist',
376 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
382 # <source lang="bash">
385 # Enable Wikieditor by default
386 $wgDefaultUserOptions['usebetatoolbar'] = 1;
387 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
389 # Display the Preview and Changes tabs
390 $wgDefaultUserOptions['wikieditor-preview'] = 1;
393 # <source lang="bash">
396 # Mediawiki setting dependency for CategoryTree
400 # <source lang="bash">
403 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
404 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
405 $wgGroupPermissions['*']['abusefilter-view'] = true;
406 $wgGroupPermissions['*']['abusefilter-log'] = true;
407 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
408 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
409 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
412 # <source lang="bash">
416 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
417 $wgCaptchaClass = 'QuestyCaptcha';
418 # only captcha on registration
419 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
420 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
422 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
424 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
425 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
430 # <source lang="bash">
431 sed -i "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
433 # <source lang="bash">
435 if [[ ! -e ~
/pywikibot
/.git
]]; then
436 git clone
--recursive \
437 https
://gerrit.wikimedia.org
/r
/pywikibot
/core.git ~
/pywikibot
444 # <source lang="bash">
446 dd of
=user-config.py
<<EOF
448 usernames["$mwfamily"]['en'] = u'$wikiuser'
450 console_encoding = 'utf-8'
451 password_file = "secretsfile"
454 dd of
=secretsfile
<<EOF
455 ("$wikiuser", "$wikipass")
458 # it won't overrwrite an existing file. Remove if if one exists
459 rm -f pywikibot
/families
/${mwfamily}_family.py
461 apt-get
install -y python-requests
463 yum
-y install python-requests
466 python generate_family_file.py https
://$mwdomain/wiki
/Main_Page
"$mwfamily"
468 # Note, this needed only for ssl site
469 tee -a pywikibot
/families
/${mwfamily}_family.py
<<'EOF'
470 def protocol(self, code):
474 # <source lang="bash">
477 dd of
=scripts
/${mwfamily}_setup.py
<<EOF
481 site = pywikibot.Site()
483 page = pywikibot.Page(site, p)
485 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
486 page.save(force=True)
488 # Small/medium noncommercial wiki should be fine with no privacy policy
489 # based on https://www.mediawiki.org/wiki/Manual:Footer
490 x("MediaWiki:Privacy")
492 # licenses for uploads. Modified from the mediawiki's wiki
493 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
494 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
496 ** Unknown_copyright|I don't know exactly
497 ** PD|PD: public domain
498 ** CC BY|Creative Commons Attribution
499 ** CC BY-SA|Creative Commons Attribution ShareAlike
500 ** GFDL|GFDL: GNU Free Documentation License
501 ** GPL|GPL: GNU General Public License
502 ** LGPL|LGPL: GNU Lesser General Public License""")
503 x("MediaWiki:Copyright", '$mw_license')
504 x("MediaWiki:Mainpage-description", "$mwdescription")
508 # The rest of the settings are for the site style
510 # Remove various clutter
511 x("MediaWiki:Lastmodifiedat")
512 x("MediaWiki:Disclaimers")
513 x("MediaWiki:Viewcount")
514 x("MediaWiki:Aboutsite")
515 # remove these lines from sidebar
516 # ** recentchanges-url|recentchanges
517 # ** randompage-url|randompage
519 x("MediaWiki:Sidebar", """* navigation
520 ** mainpage|mainpage-description
526 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
527 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
528 /* panel width increased to fit full wiki name. */
529 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
530 div#footer, #mw-head-base, div#content { margin-left: 1em; }
531 #left-navigation { margin-left: 1em; }
534 /* logo, and toolbar hidden */
535 #p-logo, #p-tb.portal {
539 /* make the font size smaller for the misc stuff */
547 div#mw-content-text {
553 python pwb.py
${mwfamily}_setup
555 # <source lang="bash">
556 s
=/etc
/cron.daily
/mediawiki_update
562 git checkout origin/$mw_branch
563 git rebase ian/REL1_23-toolbox-in-dropdown
569 git checkout origin/$mw_branch || git checkout -qf origin/master
573 php $mw/maintenance/update.php -q
577 # <source lang="bash">
578 # based on recommendation from install page
579 if ! dpkg
-s php5-gd
&>/dev
/null
; then
580 apt-get
install -y php5-gd
581 service apache2 restart
584 # docs suggests using separate database user
585 mysql
-u root
-p$dbpass <<EOF
586 GRANT ALL ON piwik.* TO 'piwik'@'localhost' IDENTIFIED BY '$piwik_pass';
590 php_ini
=$
(isdeb
&& echo /etc
/php
5/apache
2/php.ini ||
echo /etc
/php.ini
)
591 # based on the install page. however, ths option is changing with php7.0
592 opt
=always_populate_raw_post_data
593 sed -ri "/^ *$opt\b/d;/^ *\[PHP\]/a $opt = -1" $php_ini
594 service apache2 restart
596 # <source lang="bash">
597 git clone https
://github.com
/DaSchTour
/piwik-mediawiki-extension.git
$mw/extensions
/Piwik
600 \$wgPiwikURL = '$mwdomain/analytics/';
601 \$wgPiwikIDSite = '1';