2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
6 # identify if this is a debian based distro
7 isdeb
() { command -v apt
&>/dev
/null
; }
8 # tee unique. append each stdin line if it does not exist in the file
12 for line
in "${MAPFILE[@]}"; do
13 grep -xFq "$line" "$1" &>/dev
/null ||
tee -a "$1" <<<"$line"
17 # get and reset an extension/skin repository, and enable it
20 local original_pwd
="$PWD"
22 local re
='[^/]*/[^/]*$' # last 2 parts of path
24 target
=$mw/${BASH_REMATCH[0]}
25 if [[ ! -e $target/.git
]]; then
26 git clone
$url $target
29 echo "mw-ext error: failed cd $target";
33 git checkout
-qf origin
/$mw_branch || git checkout
-qf origin
/master
41 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/extensions
/$ext
42 if [[ -e $mw/extensions
/$ext/extension.json
]]; then
45 wfLoadExtension( '$ext' );
49 require_once( "\$IP/extensions/$ext/$ext.php" );
53 # --quick is quicker than default flags,
54 # but still add a sleep to make sure everything works right
55 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
59 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/skins
/$skin
60 sed -i --follow-symlinks '/^wfLoadSkin/d' $mwc
61 sed -i --follow-symlinks '/^\$wgDefaultSkin/d' $mwc
63 \$wgDefaultSkin = "${skin,,*}";
64 wfLoadSkin( '$skin' );
66 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
69 if command -v apt
&>/dev
/null
; then
76 # <source lang="bash">
77 # From here on out, exit if a command fails.
78 # This will prevent us from not noticing an important failure.
79 # We recommend setting this for the entire installation session.
80 # If you are running commands interactively, it might be best to
81 # put it in your ~/.bashrc temporarily.
83 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
88 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
90 DEBIAN_FRONTEND
=noninteractive apt-get
install -y imagemagick curl
91 if apt-get
install -s mediawiki
&>/dev
/null
; then
92 # mediawiki is packaged in jessie backports.
93 DEBIAN_FRONTEND
=noninteractive apt-get
-y install php5-apcu mediawiki
95 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
96 if apt-get
install -s php7.0
&>/dev
/null
; then
97 # note, 7.0 is untested by the editor here, since it's not
98 # available in debian 8. it's listed as supported
99 # in the mediawiki page.
100 # noninteractive to avoid mysql password prompt.
101 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 \
102 default-mysql-server \
103 php7.0 php7.0
-mysql libapache2-mod-php7.0 php7.0
-xml \
104 php7.0
-apcu php7.0
-mbstring
106 # note: mbstring is recommended, but it's not available for php5 in
108 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 \
109 default-mysql-server \
110 php5 php5-mysql libapache2-mod-php5 php5-apcu
113 service apache2 restart
116 # fedora deps are missing a database, so some is translated from debian packages
117 yum
-y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
119 systemctl restart mariadb.service
120 systemctl
enable mariadb.service
121 systemctl
enable httpd.service
122 systemctl restart httpd.service
126 # slightly different depending on if we already set the root pass
127 if echo exit|mysql
-u root
-p"$dbpass"; then
128 # answer interactive prompts:
129 # mysql root pass, change pass? no, remove anon users? (default, yes)
130 # disallow remote root (default, yes), reload? (default, yes)
131 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
133 # I had 1 less newline at the start when doing ubuntu 14.04,
134 # compared to debian 8, so can't say this is especially portable.
135 # It won't hurt if it fails.
136 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
139 # <source lang="bash">
142 # this will just fail if it already exists which is fine
143 if [[ ! -e .git
]]; then
144 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/core.git .
146 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
149 git checkout
-f origin
/$mw_branch
151 # apply librejs patch
152 curl
"https://iankelling.org/git/?p=mediawiki-librejs-patch;a=blob_plain;f=mediawiki-1.28-librejs.patch;hb=HEAD" |
patch -r - -N -p1
153 # Get the php libraries wmf uses. Based on:
154 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
155 if [[ ! -e vendor
/.git
]]; then
156 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/vendor.git
159 git checkout
-f origin
/$mw_branch
162 # Drop any previous database which may have been installed while testing.
163 # If upgrading, we should have a db backup which will get restored.
164 # https://www.mediawiki.org/wiki/Manual:Upgrading
165 mysql
-u root
-p$dbpass <<'EOF' ||:
166 drop database my_wiki;
169 php
$mw/maintenance
/install.php
--pass $wikipass --scriptpath /w \
170 --dbuser root
--dbpass $dbpass "$mwdescription" "$wikiuser"
172 # lock down the wiki to only the initial owner until anti-spam measures are put in place
173 # limit edits to registered users
174 $wgGroupPermissions['*']['edit'] = false;
175 # don't allow any account creation
176 $wgGroupPermissions['*']['createaccount'] = false;
179 # <source lang="bash">
182 git_site
=https
://iankelling.org
/git
183 git clone
$git_site/acme-tiny-wrapper
187 acme-tiny-wrapper
/acme-tiny-wrapper
-t $mwdomain
189 git clone
$git_site/basic-https-conf
191 ServerAdmin $mw_email
193 # make the site's root url go to our main page
194 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
195 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
196 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
198 find -L $
(readlink
-f $mw) -name .htaccess \
199 |
while read line
; do
200 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
202 } | basic-https-conf
/apache-site
-r ${mw%/*} - $mwdomain
206 # <source lang="bash">
207 dd of
=$mw/..
/robots.txt
<<'EOF'
210 User-agent: ia_archiver
215 # <source lang="bash">
217 \$wgServer = "https://$mwdomain";
218 \$wgDBserver = "localhost";
219 \$wgRightsUrl = "$mw_RightsUrl";
220 \$wgRightsText = "$mw_RightsText";
221 \$wgRightsIcon = "$mw_RightsIcon";
224 # <source lang="bash">
226 \$wgPasswordSender = "$mw_email";
227 \$wgEmergencyContact = "$mw_email";
228 \$wgEnotifUserTalk = true; # UPO
229 \$wgEnotifWatchlist = true; # UPO
230 \$wgMainCacheType = CACHE_ACCEL;
231 \$wgEnableUploads = true;
232 \$wgUseInstantCommons = true;
236 # <source lang="bash">
238 # from https://www.mediawiki.org/wiki/Manual:Short_URL
239 $wgArticlePath = "/wiki/$1";
241 # https://www.mediawiki.org/wiki/Manual:Combating_spam
242 # check that url if our precautions don't work
243 # not using nofollow is good practice, as long as we avoid spam.
244 $wgNoFollowLinks = false;
245 # Allow user customization.
246 $wgAllowUserCss = true;
247 # use imagemagick over GD
248 $wgUseImageMagick = true;
249 # manual says this is not production ready, I think that is mostly
250 # because they are using MobileFrontend extension instead, which gives
251 # an even cleaner more minimal view, I plan to try setting it up
252 # sometime but this seems like a very nice improvement for now.
253 $wgVectorResponsive = true;
257 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
258 # Increase from default of 2M to 100M.
259 # This will at least allow high res pics etc.
260 php_ini
=$
(php
-r 'echo(php_ini_loaded_file());')
261 sed -i --follow-symlinks 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
263 service apache2 restart
265 systemctl restart httpd.service
268 # if you were to install as a normal user, you would need this for images
269 # sudo usermod -aG $apache_user $USER
271 # this doesn't propogate right away
272 chgrp
-R $apache_user $mw/images
273 chmod -R g
+w
$mw/images
275 # <source lang="bash">
278 #$wgFooterIcons = null;
280 # Make the toolbox go into the drop down.
282 if ! git remote show ian-kelling
&>/dev
/null
; then
283 git remote add ian-kelling https
://iankelling.org
/git
/forks
/Vector
285 git fetch ian-kelling
286 git checkout ian-kelling
/${mw_branch}-toolbox-in-dropdown
288 # <source lang="bash">
289 mw-ext Cite CiteThisPage CheckUser CSS Echo Gadgets ImageMap Interwiki News \
290 Nuke ParserFunctions Poem Renameuser SyntaxHighlight_GeSHi Variables
292 # <source lang="bash">
294 # recommended setup script to account for existing users
295 sudo
-u $apache_user php
$mw/extensions
/AntiSpoof
/maintenance
/batchAntiSpoof.php
297 # <source lang="bash">
299 apt-get
-y install php-wikidiff2
301 $wgExternalDiffEngine = 'wikidiff2';
303 dir
=$
(dirname $
(php
-r 'echo(php_ini_loaded_file());'))/..
/apache
2/conf.d
304 ln -sf ..
/..
/mods-available
/wikidiff2.ini
$dir
305 service apache2 restart
308 # <source lang="bash">
310 # php5-curl according to Math readme
313 if ! apt-get
-s install $curl_pkg &>/dev
/null
; then
316 apt-get
-y install latex-cjk-all texlive-latex-extra texlive-latex-base \
317 ghostscript imagemagick ocaml
$curl_pkg make
319 # todo, php5-curl equivalent on fedora
320 yum
-y install texlive-cjk ghostscript ImageMagick texlive ocaml
322 service apache2 restart
324 cd $mw/extensions
/Math
/math
; make # makes texvc
325 cd $mw/extensions
/Math
/texvccheck
; make
328 # Enable MathJax as rendering option
329 $wgUseMathJax = true;
330 # Enable LaTeXML as rendering option
331 $wgMathValidModes[] = 'latexml';
332 # Set LaTeXML as default rendering option, because it is nicest
333 $wgDefaultUserOptions['math'] = 'latexml';
336 # <source lang="bash">
338 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev
/null
; then
340 $wgEnableDnsBlacklist = true;
341 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
343 ini_set( 'pcre.backtrack_limit', '10M' );
344 $wgSpamBlacklistFiles = array(
345 "[[m:Spam blacklist]]",
346 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
351 # <source lang="bash">
352 mw-ext TitleBlacklist
353 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev
/null
; then
355 $wgTitleBlacklistSources = array(
358 'src' => 'MediaWiki:Titleblacklist',
362 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
368 # <source lang="bash">
371 # Enable Wikieditor by default
372 $wgDefaultUserOptions['usebetatoolbar'] = 1;
373 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
375 # Display the Preview and Changes tabs
376 $wgDefaultUserOptions['wikieditor-preview'] = 1;
379 # <source lang="bash">
382 # Mediawiki setting dependency for CategoryTree
386 # <source lang="bash">
389 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
390 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
391 $wgGroupPermissions['*']['abusefilter-view'] = true;
392 $wgGroupPermissions['*']['abusefilter-log'] = true;
393 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
394 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
395 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
398 # <source lang="bash">
402 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
403 $wgCaptchaClass = 'QuestyCaptcha';
404 # only captcha on registration
405 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
406 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
408 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
410 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
411 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
416 # <source lang="bash">
417 sed -i --follow-symlinks "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
419 # <source lang="bash">
421 if [[ ! -e ~
/pywikibot
/.git
]]; then
422 git clone
--recursive \
423 https
://gerrit.wikimedia.org
/r
/pywikibot
/core.git ~
/pywikibot
430 # <source lang="bash">
432 dd of
=user-config.py
<<EOF
434 usernames["$mwfamily"]['en'] = u'$wikiuser'
436 console_encoding = 'utf-8'
437 password_file = "secretsfile"
440 dd of
=secretsfile
<<EOF
441 ("$wikiuser", "$wikipass")
444 # it won't overrwrite an existing file. Remove if if one exists
445 rm -f pywikibot
/families
/${mwfamily}_family.py
447 apt-get
install -y python-requests
449 yum
-y install python-requests
452 python generate_family_file.py https
://$mwdomain/wiki
/Main_Page
"$mwfamily"
454 # Note, this needed only for ssl site
455 tee -a pywikibot
/families
/${mwfamily}_family.py
<<'EOF'
456 def protocol(self, code):
460 # <source lang="bash">
463 dd of
=scripts
/${mwfamily}_setup.py
<<EOF
467 site = pywikibot.Site()
469 page = pywikibot.Page(site, p)
471 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
472 page.save(force=True)
474 # Small/medium noncommercial wiki should be fine with no privacy policy
475 # based on https://www.mediawiki.org/wiki/Manual:Footer
476 x("MediaWiki:Privacy")
478 # licenses for uploads. Modified from the mediawiki's wiki
479 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
480 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
482 ** Unknown_copyright|I don't know exactly
483 ** PD|PD: public domain
484 ** CC BY|Creative Commons Attribution
485 ** CC BY-SA|Creative Commons Attribution ShareAlike
486 ** GFDL|GFDL: GNU Free Documentation License
487 ** GPL|GPL: GNU General Public License
488 ** LGPL|LGPL: GNU Lesser General Public License""")
489 x("MediaWiki:Copyright", '$mw_license')
490 x("MediaWiki:Mainpage-description", "$mwdescription")
494 # The rest of the settings are for the site style
496 # Remove various clutter
497 x("MediaWiki:Lastmodifiedat")
498 x("MediaWiki:Disclaimers")
499 x("MediaWiki:Viewcount")
500 x("MediaWiki:Aboutsite")
501 # remove these lines from sidebar
502 # ** recentchanges-url|recentchanges
503 # ** randompage-url|randompage
505 x("MediaWiki:Sidebar", """* navigation
506 ** mainpage|mainpage-description
512 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
513 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
514 /* panel width increased to fit full wiki name. */
515 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
516 div#footer, #mw-head-base, div#content { margin-left: 1em; }
517 #left-navigation { margin-left: 1em; }
520 /* logo, and toolbar hidden */
521 #p-logo, #p-tb.portal {
525 /* make the font size smaller for the misc stuff */
533 div#mw-content-text {
539 # this can spam a warning, so uniq it
540 python pwb.py
${mwfamily}_setup |
& uniq
542 # <source lang="bash">
543 s
=/etc
/cron.daily
/mediawiki_update
550 [[ -d $dir ]] || return 1
552 branch=$(git describe --all)
553 branch=${branch#remotes/}
555 new_head=$(git rev-parse $branch)
556 log=$(git log HEAD..$new_head)
557 if [[ ! $log ]]; then
562 git checkout -qf $new_head
566 for dir in extensions/* skins/* vendor; do
570 curl "https://iankelling.org/git/?p=mediawiki-librejs-patch;a=blob_plain;f=mediawiki-1.28-librejs.patch;hb=HEAD" | patch -r - -N -p1
572 php $mw/maintenance/update.php -q --quick