Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #mediawiki
- ---------
- #!/bin/bash
- # Set the variables
- WIKI_URL="https://example.com/w/api.php"
- PAGE_TITLE="Page_title"
- TOKEN=$(curl -s "$WIKI_URL?action=query&meta=tokens&type=csrf&format=json" | jq -r '.query.tokens.csrftoken')
- SUMMARY="Edit summary"
- CONTENT="New page content"
- # Make the API call to edit the page
- curl -s -X POST "$WIKI_URL" \
- -d "action=edit" \
- -d "title=$PAGE_TITLE" \
- -d "format=json" \
- -d "summary=$SUMMARY" \
- -d "text=$CONTENT" \
- -d "token=$TOKEN"
- # Verify that the edit was successful
- if [ $? -eq 0 ]; then
- echo "Page $PAGE_TITLE edited successfully"
- else
- echo "Edit failed"
- fi
- --------------------
- #!/bin/bash
- # Set the variables
- DATE=$(date +%Y%m%d)
- DB_NAME="mediawiki"
- DB_USER="root"
- DB_PASSWORD="your_password"
- BACKUP_DIR="/path/to/backup/directory"
- BACKUP_FILE="$BACKUP_DIR/$DB_NAME-$DATE.sql.gz"
- # Create the backup directory if it doesn't exist
- if [ ! -d "$BACKUP_DIR" ]; then
- mkdir -p "$BACKUP_DIR"
- fi
- # Create the backup
- docker exec -i mediawiki /usr/bin/mysqldump -u $DB_USER --password=$DB_PASSWORD $DB_NAME | gzip > $BACKUP_FILE
- # Verify that the backup was created
- if [ -f "$BACKUP_FILE" ]; then
- echo "Backup of database $DB_NAME created at $BACKUP_FILE"
- else
- echo "Backup failed"
- fi
- --------------------
- #!/bin/bash
- # Set the variables
- DB_NAME="mediawiki"
- DB_USER="root"
- DB_PASSWORD="your_password"
- BACKUP_FILE="/path/to/backup/file.sql.gz"
- # Check if the backup file exists
- if [ ! -f "$BACKUP_FILE" ]; then
- echo "Backup file not found"
- exit 1
- fi
- # Restore the backup to the database
- gunzip -c "$BACKUP_FILE" | docker exec -i mediawiki /usr/bin/mysql -u $DB_USER --password=$DB_PASSWORD $DB_NAME
- # Verify that the restore was successful
- if [ $? -eq 0 ]; then
- echo "Database $DB_NAME restored from $BACKUP_FILE"
- else
- echo "Restore failed"
- fi
- --------------------
- #!/bin/bash
- # Set the MediaWiki version and port number
- MEDIAWIKI_VERSION="1.36.1"
- PORT="8080"
- # Create a directory to hold the MediaWiki files
- mkdir mediawiki
- cd mediawiki
- # Download the MediaWiki Docker image
- docker pull mediawiki:$MEDIAWIKI_VERSION
- # Create a Docker container and start it
- docker run --name mediawiki -p $PORT:80 -v $(pwd):/var/www/data -d mediawiki:$MEDIAWIKI_VERSION
- # Wait for the container to start up
- sleep 5
- # Get the initial login credentials
- docker logs mediawiki 2>&1 | grep "Admin username" -A 1
- echo "MediaWiki is now running at http://localhost:$PORT"
- #This script sets the MediaWiki version and port number, creates a directory to hold the MediaWiki files, downloads the MediaWiki #Docker image, creates a Docker container using the downloaded image, and starts the container. It then waits for the container to #start up and retrieves the initial login credentials from the container logs.
- #You can save this script to a file (e.g., install_mediawiki.sh) and run it from the command line using bash install_mediawiki.sh. #Note that you may need to modify the script to fit your specific needs (e.g., setting different port numbers or MediaWiki versions).
- ----------------------
- #This script uses the requests library to make an API request to the MediaWiki site, passing in the necessary parameters to create a new #page (action, title, text, summary, format, and token). The get_edit_token function is a separate function that retrieves an edit token #required for making API edits. Note that this script is just an example, and may need to be modified to fit the specific MediaWiki site #and login credentials that you are using. Also, be sure to handle any errors that may occur during the API request.
- import requests
- # Set the API endpoint and login credentials
- api_endpoint = "https://example.com/api.php"
- api_username = "your_username"
- api_password = "your_password"
- # Set the page title and content
- page_title = "New_Page_Title"
- page_content = "This is the content of the new page."
- # Set the edit summary
- edit_summary = "Created a new page using the API"
- # Make the API request to create the new page
- api_request = requests.post(api_endpoint, data={
- "action": "edit",
- "title": page_title,
- "text": page_content,
- "summary": edit_summary,
- "format": "json",
- "token": get_edit_token(api_endpoint, api_username, api_password)
- })
- # Check the API response to see if the page was created successfully
- if api_request.json()["edit"]["result"] == "Success":
- print(f"Page '{page_title}' was created successfully!")
- else:
- print("There was an error creating the page.")
- --------------------
- Perl: This script uses the LWP::UserAgent module to make an API request to the MediaWiki site, passing in the necessary parameters to create a new page (action, title, text, summary, format, and token). The get_edit_token function is a separate function that retrieves an edit token required for making API edits.
- Note that this script is just an example, and may need to be modified to fit the specific MediaWiki site and login credentials that you are using. Also, be sure to handle any errors that may occur during the API request.
- use LWP::UserAgent;
- use JSON;
- # Set the API endpoint and login credentials
- my $api_endpoint = "https://example.com/api.php";
- my $api_username = "your_username";
- my $api_password = "your_password";
- # Set the page title and content
- my $page_title = "New_Page_Title";
- my $page_content = "This is the content of the new page.";
- # Set the edit summary
- my $edit_summary = "Created a new page using the API";
- # Make the API request to create the new page
- my $ua = LWP::UserAgent->new;
- my $api_request = $ua->post($api_endpoint, [
- action => 'edit',
- title => $page_title,
- text => $page_content,
- summary => $edit_summary,
- format => 'json',
- token => get_edit_token($api_endpoint, $api_username, $api_password),
- ]);
- # Decode the JSON response
- my $api_response = decode_json($api_request->content);
- # Check the API response to see if the page was created successfully
- if ($api_response->{'edit'}{'result'} eq 'Success') {
- print "Page '$page_title' was created successfully!\n";
- } else {
- print "There was an error creating the page.\n";
- }
- # Get the edit token required for making API edits
- sub get_edit_token {
- my ($api_endpoint, $api_username, $api_password) = @_;
- my $ua = LWP::UserAgent->new;
- my $api_request = $ua->post($api_endpoint, [
- action => 'query',
- meta => 'tokens',
- type => 'login',
- format => 'json',
- ]);
- my $api_response = decode_json($api_request->content);
- my $login_token = $api_response->{'query'}{'tokens'}{'logintoken'};
- $api_request = $ua->post($api_endpoint, [
- action => 'login',
- lgname => $api_username,
- lgpassword => $api_password,
- lgtoken => $login_token,
- format => 'json',
- ]);
- $api_request = $ua->post($api_endpoint, [
- action => 'query',
- meta => 'tokens',
- type => 'edit',
- format => 'json',
- ]);
- $api_response = decode_json($api_request->content);
- my $edit_token = $api_response->{'query'}{'tokens'}{'edittoken'};
- return $edit_token;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement